// Copyright Toru Niina 2017. // Distributed under the MIT License. #ifndef TOML11_TRAITS #define TOML11_TRAITS #include #include #include #include namespace toml { namespace detail { template using unwrap_t = typename std::decay::type; // --------------------------------------------------------------------------- // check whether type T is a kind of container/map class struct has_iterator_impl { template static std::true_type check(typename T::iterator*); template static std::false_type check(...); }; struct has_value_type_impl { template static std::true_type check(typename T::value_type*); template static std::false_type check(...); }; struct has_key_type_impl { template static std::true_type check(typename T::key_type*); template static std::false_type check(...); }; struct has_mapped_type_impl { template static std::true_type check(typename T::mapped_type*); template static std::false_type check(...); }; struct has_resize_method_impl { constexpr static std::size_t dummy=0; template static std::true_type check(decltype(std::declval().resize(dummy))*); template static std::false_type check(...); }; /// Intel C++ compiler can not use decltype in parent class declaration, here /// is a hack to work around it. https://stackoverflow.com/a/23953090/4692076 #ifdef __INTEL_COMPILER #define decltype(...) std::enable_if::type #endif template struct has_iterator : decltype(has_iterator_impl::check(nullptr)){}; template struct has_value_type : decltype(has_value_type_impl::check(nullptr)){}; template struct has_key_type : decltype(has_key_type_impl::check(nullptr)){}; template struct has_mapped_type : decltype(has_mapped_type_impl::check(nullptr)){}; template struct has_resize_method : decltype(has_resize_method_impl::check(nullptr)){}; #ifdef __INTEL_COMPILER #undef decltype(...) #endif // --------------------------------------------------------------------------- // C++17 and/or/not template struct conjunction : std::true_type{}; template struct conjunction : T{}; template struct conjunction : std::conditional(T::value), conjunction, T>::type {}; template struct disjunction : std::false_type{}; template struct disjunction : T {}; template struct disjunction : std::conditional(T::value), T, disjunction>::type {}; template struct negation : std::integral_constant(T::value)>{}; // --------------------------------------------------------------------------- // normal type checker template struct is_std_pair : std::false_type{}; template struct is_std_pair> : std::true_type{}; template struct is_std_tuple : std::false_type{}; template struct is_std_tuple> : std::true_type{}; template struct is_chrono_duration: std::false_type{}; template struct is_chrono_duration>: std::true_type{}; // --------------------------------------------------------------------------- // C++14 index_sequence template struct index_sequence{}; template struct push_back_index_sequence{}; template struct push_back_index_sequence, N> { typedef index_sequence type; }; template struct index_sequence_maker { typedef typename push_back_index_sequence< typename index_sequence_maker::type, N>::type type; }; template<> struct index_sequence_maker<0> { typedef index_sequence<0> type; }; template using make_index_sequence = typename index_sequence_maker::type; // --------------------------------------------------------------------------- // return_type_of_t #if __cplusplus >= 201703L template using return_type_of_t = std::invoke_result_t; #else // result_of is deprecated after C++17 template using return_type_of_t = typename std::result_of::type; #endif }// detail }//toml #endif // TOML_TRAITS