diff --git a/include/toml11/get.hpp b/include/toml11/get.hpp index 6e204d3..dbf327a 100644 --- a/include/toml11/get.hpp +++ b/include/toml11/get.hpp @@ -109,16 +109,32 @@ get(const basic_value& v) return static_cast(v.as_floating()); } +// ============================================================================ +// std::string with different char/trait/allocator + +template +cxx::enable_if_t>, + detail::is_1byte_std_basic_string + >::value, T> +get(const basic_value& v) +{ + using value_type = typename cxx::remove_cvref_t::value_type; + using traits_type = typename cxx::remove_cvref_t::traits_type; + using allocator_type = typename cxx::remove_cvref_t::allocator_type; + return detail::to_string_of(v.as_string()); +} + // ============================================================================ // std::string_view #if defined(TOML11_HAS_STRING_VIEW) template -cxx::enable_if_t::value, std::string_view> +cxx::enable_if_t::string_type>::value, T> get(const basic_value& v) { - return std::string_view(v.as_string()); + return T(v.as_string()); } #endif // string_view @@ -176,6 +192,9 @@ cxx::enable_if_t, // .push_back() works detail::is_not_toml_type>, // but not toml::array cxx::negation>, // but not std::basic_string +#if defined(TOML11_HAS_STRING_VIEW) + cxx::negation>, // but not std::basic_string_view +#endif cxx::negation>, // no T.from_toml() cxx::negation>, // no toml::from cxx::negation&>> @@ -247,6 +266,9 @@ cxx::enable_if_t, // .push_back() works detail::is_not_toml_type>, // but not toml::array cxx::negation>, // but not std::basic_string +#if defined(TOML11_HAS_STRING_VIEW) + cxx::negation>, // but not std::basic_string_view +#endif cxx::negation>, // no T.from_toml() cxx::negation>, // no toml::from cxx::negation&>> diff --git a/include/toml11/traits.hpp b/include/toml11/traits.hpp index 69b6d1d..98dc059 100644 --- a/include/toml11/traits.hpp +++ b/include/toml11/traits.hpp @@ -163,11 +163,31 @@ template using is_std_forward_list = is_std_forward_list_impl>; template struct is_std_basic_string_impl : std::false_type{}; -template -struct is_std_basic_string_impl> : std::true_type{}; +template +struct is_std_basic_string_impl> : std::true_type{}; template using is_std_basic_string = is_std_basic_string_impl>; +template struct is_1byte_std_basic_string_impl : std::false_type{}; +template +struct is_1byte_std_basic_string_impl> + : std::integral_constant {}; +template +using is_1byte_std_basic_string = is_std_basic_string_impl>; + +#if defined(TOML11_HAS_STRING_VIEW) +template struct is_std_basic_string_view_impl : std::false_type{}; +template +struct is_std_basic_string_view_impl> : std::true_type{}; +template +using is_std_basic_string_view = is_std_basic_string_view_impl>; + +template +struct is_string_view_of : std::false_type {}; +template +struct is_string_view_of, std::basic_string> : std::true_type {}; +#endif + template struct is_chrono_duration_impl: std::false_type{}; template struct is_chrono_duration_impl>: std::true_type{};