mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:58:09 +08:00
feat: enable to convert generic string
This commit is contained in:
@@ -109,16 +109,32 @@ get(const basic_value<TC>& v)
|
|||||||
return static_cast<T>(v.as_floating());
|
return static_cast<T>(v.as_floating());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// std::string with different char/trait/allocator
|
||||||
|
|
||||||
|
template<typename T, typename TC>
|
||||||
|
cxx::enable_if_t<cxx::conjunction<
|
||||||
|
detail::is_not_toml_type<T, basic_value<TC>>,
|
||||||
|
detail::is_1byte_std_basic_string<T>
|
||||||
|
>::value, T>
|
||||||
|
get(const basic_value<TC>& v)
|
||||||
|
{
|
||||||
|
using value_type = typename cxx::remove_cvref_t<T>::value_type;
|
||||||
|
using traits_type = typename cxx::remove_cvref_t<T>::traits_type;
|
||||||
|
using allocator_type = typename cxx::remove_cvref_t<T>::allocator_type;
|
||||||
|
return detail::to_string_of<value_type, traits_type, allocator_type>(v.as_string());
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// std::string_view
|
// std::string_view
|
||||||
|
|
||||||
#if defined(TOML11_HAS_STRING_VIEW)
|
#if defined(TOML11_HAS_STRING_VIEW)
|
||||||
|
|
||||||
template<typename T, typename TC>
|
template<typename T, typename TC>
|
||||||
cxx::enable_if_t<std::is_same<T, std::string_view>::value, std::string_view>
|
cxx::enable_if_t<detail::is_string_view_of<T, typename basic_value<TC>::string_type>::value, T>
|
||||||
get(const basic_value<TC>& v)
|
get(const basic_value<TC>& v)
|
||||||
{
|
{
|
||||||
return std::string_view(v.as_string());
|
return T(v.as_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // string_view
|
#endif // string_view
|
||||||
@@ -176,6 +192,9 @@ cxx::enable_if_t<cxx::conjunction<
|
|||||||
detail::has_push_back_method<T>, // .push_back() works
|
detail::has_push_back_method<T>, // .push_back() works
|
||||||
detail::is_not_toml_type<T, basic_value<TC>>, // but not toml::array
|
detail::is_not_toml_type<T, basic_value<TC>>, // but not toml::array
|
||||||
cxx::negation<detail::is_std_basic_string<T>>, // but not std::basic_string<CharT>
|
cxx::negation<detail::is_std_basic_string<T>>, // but not std::basic_string<CharT>
|
||||||
|
#if defined(TOML11_HAS_STRING_VIEW)
|
||||||
|
cxx::negation<detail::is_std_basic_string_view<T>>, // but not std::basic_string_view<CharT>
|
||||||
|
#endif
|
||||||
cxx::negation<detail::has_from_toml_method<T, TC>>, // no T.from_toml()
|
cxx::negation<detail::has_from_toml_method<T, TC>>, // no T.from_toml()
|
||||||
cxx::negation<detail::has_specialized_from<T>>, // no toml::from<T>
|
cxx::negation<detail::has_specialized_from<T>>, // no toml::from<T>
|
||||||
cxx::negation<std::is_constructible<T, const basic_value<TC>&>>
|
cxx::negation<std::is_constructible<T, const basic_value<TC>&>>
|
||||||
@@ -247,6 +266,9 @@ cxx::enable_if_t<cxx::conjunction<
|
|||||||
detail::has_push_back_method<T>, // .push_back() works
|
detail::has_push_back_method<T>, // .push_back() works
|
||||||
detail::is_not_toml_type<T, basic_value<TC>>, // but not toml::array
|
detail::is_not_toml_type<T, basic_value<TC>>, // but not toml::array
|
||||||
cxx::negation<detail::is_std_basic_string<T>>, // but not std::basic_string<CharT>
|
cxx::negation<detail::is_std_basic_string<T>>, // but not std::basic_string<CharT>
|
||||||
|
#if defined(TOML11_HAS_STRING_VIEW)
|
||||||
|
cxx::negation<detail::is_std_basic_string_view<T>>, // but not std::basic_string_view<CharT>
|
||||||
|
#endif
|
||||||
cxx::negation<detail::has_from_toml_method<T, TC>>, // no T.from_toml()
|
cxx::negation<detail::has_from_toml_method<T, TC>>, // no T.from_toml()
|
||||||
cxx::negation<detail::has_specialized_from<T>>, // no toml::from<T>
|
cxx::negation<detail::has_specialized_from<T>>, // no toml::from<T>
|
||||||
cxx::negation<std::is_constructible<T, const basic_value<TC>&>>
|
cxx::negation<std::is_constructible<T, const basic_value<TC>&>>
|
||||||
|
@@ -163,11 +163,31 @@ template<typename T>
|
|||||||
using is_std_forward_list = is_std_forward_list_impl<cxx::remove_cvref_t<T>>;
|
using is_std_forward_list = is_std_forward_list_impl<cxx::remove_cvref_t<T>>;
|
||||||
|
|
||||||
template<typename T> struct is_std_basic_string_impl : std::false_type{};
|
template<typename T> struct is_std_basic_string_impl : std::false_type{};
|
||||||
template<typename T>
|
template<typename C, typename T, typename A>
|
||||||
struct is_std_basic_string_impl<std::basic_string<T>> : std::true_type{};
|
struct is_std_basic_string_impl<std::basic_string<C, T, A>> : std::true_type{};
|
||||||
template<typename T>
|
template<typename T>
|
||||||
using is_std_basic_string = is_std_basic_string_impl<cxx::remove_cvref_t<T>>;
|
using is_std_basic_string = is_std_basic_string_impl<cxx::remove_cvref_t<T>>;
|
||||||
|
|
||||||
|
template<typename T> struct is_1byte_std_basic_string_impl : std::false_type{};
|
||||||
|
template<typename C, typename T, typename A>
|
||||||
|
struct is_1byte_std_basic_string_impl<std::basic_string<C, T, A>>
|
||||||
|
: std::integral_constant<bool, sizeof(C) == sizeof(char)> {};
|
||||||
|
template<typename T>
|
||||||
|
using is_1byte_std_basic_string = is_std_basic_string_impl<cxx::remove_cvref_t<T>>;
|
||||||
|
|
||||||
|
#if defined(TOML11_HAS_STRING_VIEW)
|
||||||
|
template<typename T> struct is_std_basic_string_view_impl : std::false_type{};
|
||||||
|
template<typename C, typename T>
|
||||||
|
struct is_std_basic_string_view_impl<std::basic_string_view<C, T>> : std::true_type{};
|
||||||
|
template<typename T>
|
||||||
|
using is_std_basic_string_view = is_std_basic_string_view_impl<cxx::remove_cvref_t<T>>;
|
||||||
|
|
||||||
|
template<typename V, typename S>
|
||||||
|
struct is_string_view_of : std::false_type {};
|
||||||
|
template<typename C, typename T>
|
||||||
|
struct is_string_view_of<std::basic_string_view<C, T>, std::basic_string<C, T>> : std::true_type {};
|
||||||
|
#endif
|
||||||
|
|
||||||
template<typename T> struct is_chrono_duration_impl: std::false_type{};
|
template<typename T> struct is_chrono_duration_impl: std::false_type{};
|
||||||
template<typename Rep, typename Period>
|
template<typename Rep, typename Period>
|
||||||
struct is_chrono_duration_impl<std::chrono::duration<Rep, Period>>: std::true_type{};
|
struct is_chrono_duration_impl<std::chrono::duration<Rep, Period>>: std::true_type{};
|
||||||
|
Reference in New Issue
Block a user