File indexing completed on 2025-01-18 09:42:45
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_NOWIDE_DETAIL_IS_STRING_CONTAINER_HPP_INCLUDED
0008 #define BOOST_NOWIDE_DETAIL_IS_STRING_CONTAINER_HPP_INCLUDED
0009
0010 #include <cstddef>
0011 #include <type_traits>
0012
0013 namespace boost {
0014 namespace nowide {
0015 namespace detail {
0016 template<class...>
0017 struct make_void
0018 {
0019 typedef void type;
0020 };
0021
0022 template<class... Ts>
0023 using void_t = typename make_void<Ts...>::type;
0024
0025 template<typename T>
0026 struct is_char_type : std::false_type
0027 {};
0028 template<>
0029 struct is_char_type<char> : std::true_type
0030 {};
0031 template<>
0032 struct is_char_type<wchar_t> : std::true_type
0033 {};
0034 template<>
0035 struct is_char_type<char16_t> : std::true_type
0036 {};
0037 template<>
0038 struct is_char_type<char32_t> : std::true_type
0039 {};
0040 #ifdef __cpp_char8_t
0041 template<>
0042 struct is_char_type<char8_t> : std::true_type
0043 {};
0044 #endif
0045
0046 template<typename T>
0047 struct is_c_string : std::false_type
0048 {};
0049 template<typename T>
0050 struct is_c_string<const T*> : is_char_type<T>
0051 {};
0052
0053 template<typename T>
0054 using const_data_result = decltype(std::declval<const T>().data());
0055
0056 template<typename T>
0057 using get_data_width =
0058 std::integral_constant<std::size_t, sizeof(typename std::remove_pointer<const_data_result<T>>::type)>;
0059 template<typename T>
0060 using size_result = decltype(std::declval<T>().size());
0061
0062 template<typename T>
0063 using has_narrow_data = std::integral_constant<bool, (get_data_width<T>::value == 1)>;
0064
0065
0066
0067
0068 template<typename T, bool isNarrow, typename = void>
0069 struct is_string_container : std::false_type
0070 {};
0071
0072 template<typename T, bool isNarrow>
0073 struct is_string_container<T, isNarrow, void_t<decltype(T::npos), size_result<T>, const_data_result<T>>>
0074 : std::integral_constant<bool,
0075 std::is_integral<decltype(T::npos)>::value
0076 && std::is_integral<size_result<T>>::value
0077 && is_c_string<const_data_result<T>>::value
0078 && isNarrow == has_narrow_data<T>::value>
0079 {};
0080
0081 template<typename T>
0082 using requires_narrow_string_container = typename std::enable_if<is_string_container<T, true>::value>::type;
0083 template<typename T>
0084 using requires_wide_string_container = typename std::enable_if<is_string_container<T, false>::value>::type;
0085
0086 template<typename T>
0087 using requires_narrow_char = typename std::enable_if<sizeof(T) == 1 && is_char_type<T>::value>::type;
0088 template<typename T>
0089 using requires_wide_char = typename std::enable_if<(sizeof(T) > 1) && is_char_type<T>::value>::type;
0090
0091 }
0092 }
0093 }
0094
0095 #endif