SpECTRE Documentation Coverage Report
Current view: top level - Utilities/TypeTraits - IsMaplike.hpp Coverage Total Hit
Commit: 0d1d717af84a81fb1284a20c4013708fe85cc2f0 Lines: 75.0 % 4 3
Test Date: 2026-10-22 17:29:42
Legend: Lines:     hit not hit

            Line data    Source code
       1            0 : // Distributed under the MIT License.
       2              : // See LICENSE.txt for details.
       3              : 
       4              : #pragma once
       5              : 
       6              : #include <type_traits>
       7              : 
       8              : #include "Utilities/Requires.hpp"
       9              : #include "Utilities/TypeTraits/IsIterable.hpp"
      10              : 
      11              : namespace tt {
      12              : /// @{
      13              : /// \ingroup TypeTraitsGroup
      14              : /// \brief Check if type `T` is like a std::map or std::unordored_map
      15              : ///
      16              : /// \details
      17              : /// Inherits from std::true_type if the type `T` has a type alias `key_type`,
      18              : /// type alias `mapped_type`, and `operator[](const typename T::key_type&)`
      19              : /// defined, otherwise inherits from std::false_type
      20              : ///
      21              : /// \usage
      22              : /// For any type `T`,
      23              : /// \code
      24              : /// using result = tt::is_maplike<T>;
      25              : /// \endcode
      26              : ///
      27              : /// \metareturns
      28              : /// std::bool_constant
      29              : ///
      30              : /// \semantics
      31              : /// If the type `T` has a type alias `key_type`,
      32              : /// type alias `mapped_type`, and `operator[](const typename T::key_type&)`
      33              : /// defined, then
      34              : /// \code
      35              : /// typename result::type = std::true_type;
      36              : /// \endcode
      37              : /// otherwise
      38              : /// \code
      39              : /// typename result::type = std::false_type;
      40              : /// \endcode
      41              : ///
      42              : /// \example
      43              : /// \snippet Test_IsMaplike.cpp is_maplike_example
      44              : /// \see std::map std::unordered_map is_a
      45              : /// \tparam T the type to check
      46              : template <typename T, typename = std::void_t<>>
      47            1 : struct is_maplike : std::false_type {};
      48              : 
      49              : /// \cond
      50              : template <typename T>
      51              : struct is_maplike<T, std::void_t<typename T::key_type, typename T::mapped_type,
      52              :                                  decltype(std::declval<T&>()[std::declval<
      53              :                                      const typename T::key_type&>()]),
      54              :                                  Requires<tt::is_iterable_v<T>>>>
      55              :     : std::true_type {};
      56              : /// \endcond
      57              : 
      58              : /// \see is_maplike
      59              : template <typename T>
      60            1 : constexpr bool is_maplike_v = is_maplike<T>::value;
      61              : 
      62              : /// \see is_maplike
      63              : template <typename T>
      64            1 : using is_maplike_t = typename is_maplike<T>::type;
      65              : /// @}
      66              : }  // namespace tt
        

Generated by: LCOV version 2.0-1