mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-12-16 03:08:52 +08:00
Merge branch 'main' into v4_1_0
This commit is contained in:
@@ -83,6 +83,14 @@ struct has_into_toml_method_impl
|
||||
static std::false_type check(...);
|
||||
};
|
||||
|
||||
struct has_template_into_toml_method_impl
|
||||
{
|
||||
template<typename T, typename TypeConfig>
|
||||
static std::true_type check(decltype(std::declval<T>().template into_toml<TypeConfig>())*);
|
||||
template<typename T, typename TypeConfig>
|
||||
static std::false_type check(...);
|
||||
};
|
||||
|
||||
struct has_specialized_from_impl
|
||||
{
|
||||
template<typename T>
|
||||
@@ -126,6 +134,9 @@ struct has_from_toml_method: decltype(has_from_toml_method_impl::check<T, TC>(nu
|
||||
template<typename T>
|
||||
struct has_into_toml_method: decltype(has_into_toml_method_impl::check<T>(nullptr)){};
|
||||
|
||||
template<typename T, typename TypeConfig>
|
||||
struct has_template_into_toml_method: decltype(has_template_into_toml_method_impl::check<T, TypeConfig>(nullptr)){};
|
||||
|
||||
template<typename T>
|
||||
struct has_specialized_from: decltype(has_specialized_from_impl::check<T>(nullptr)){};
|
||||
template<typename T>
|
||||
|
||||
@@ -1151,6 +1151,29 @@ class basic_value
|
||||
*this = ud.into_toml();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T, cxx::enable_if_t<cxx::conjunction<
|
||||
detail::has_template_into_toml_method<T, TypeConfig>,
|
||||
cxx::negation<detail::has_specialized_into<T>>
|
||||
>::value, std::nullptr_t> = nullptr>
|
||||
basic_value(const T& ud): basic_value(ud.template into_toml<TypeConfig>()) {}
|
||||
|
||||
template<typename T, cxx::enable_if_t<cxx::conjunction<
|
||||
detail::has_template_into_toml_method<T, TypeConfig>,
|
||||
cxx::negation<detail::has_specialized_into<T>>
|
||||
>::value, std::nullptr_t> = nullptr>
|
||||
basic_value(const T& ud, std::vector<std::string> com)
|
||||
: basic_value(ud.template into_toml<TypeConfig>(), std::move(com))
|
||||
{}
|
||||
template<typename T, cxx::enable_if_t<cxx::conjunction<
|
||||
detail::has_template_into_toml_method<T, TypeConfig>,
|
||||
cxx::negation<detail::has_specialized_into<T>>
|
||||
>::value, std::nullptr_t> = nullptr>
|
||||
basic_value& operator=(const T& ud)
|
||||
{
|
||||
*this = ud.template into_toml<TypeConfig>();
|
||||
return *this;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// empty value with region info ======================================= {{{
|
||||
|
||||
@@ -3577,6 +3577,14 @@ struct has_into_toml_method_impl
|
||||
static std::false_type check(...);
|
||||
};
|
||||
|
||||
struct has_template_into_toml_method_impl
|
||||
{
|
||||
template<typename T, typename TypeConfig>
|
||||
static std::true_type check(decltype(std::declval<T>().template into_toml<TypeConfig>())*);
|
||||
template<typename T, typename TypeConfig>
|
||||
static std::false_type check(...);
|
||||
};
|
||||
|
||||
struct has_specialized_from_impl
|
||||
{
|
||||
template<typename T>
|
||||
@@ -3620,6 +3628,9 @@ struct has_from_toml_method: decltype(has_from_toml_method_impl::check<T, TC>(nu
|
||||
template<typename T>
|
||||
struct has_into_toml_method: decltype(has_into_toml_method_impl::check<T>(nullptr)){};
|
||||
|
||||
template<typename T, typename TypeConfig>
|
||||
struct has_template_into_toml_method: decltype(has_template_into_toml_method_impl::check<T, TypeConfig>(nullptr)){};
|
||||
|
||||
template<typename T>
|
||||
struct has_specialized_from: decltype(has_specialized_from_impl::check<T>(nullptr)){};
|
||||
template<typename T>
|
||||
@@ -6660,6 +6671,29 @@ class basic_value
|
||||
*this = ud.into_toml();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T, cxx::enable_if_t<cxx::conjunction<
|
||||
detail::has_template_into_toml_method<T, TypeConfig>,
|
||||
cxx::negation<detail::has_specialized_into<T>>
|
||||
>::value, std::nullptr_t> = nullptr>
|
||||
basic_value(const T& ud): basic_value(ud.template into_toml<TypeConfig>()) {}
|
||||
|
||||
template<typename T, cxx::enable_if_t<cxx::conjunction<
|
||||
detail::has_template_into_toml_method<T, TypeConfig>,
|
||||
cxx::negation<detail::has_specialized_into<T>>
|
||||
>::value, std::nullptr_t> = nullptr>
|
||||
basic_value(const T& ud, std::vector<std::string> com)
|
||||
: basic_value(ud.template into_toml<TypeConfig>(), std::move(com))
|
||||
{}
|
||||
template<typename T, cxx::enable_if_t<cxx::conjunction<
|
||||
detail::has_template_into_toml_method<T, TypeConfig>,
|
||||
cxx::negation<detail::has_specialized_into<T>>
|
||||
>::value, std::nullptr_t> = nullptr>
|
||||
basic_value& operator=(const T& ud)
|
||||
{
|
||||
*this = ud.template into_toml<TypeConfig>();
|
||||
return *this;
|
||||
}
|
||||
// }}}
|
||||
|
||||
// empty value with region info ======================================= {{{
|
||||
|
||||
@@ -49,6 +49,25 @@ struct foobar
|
||||
int a;
|
||||
std::string b;
|
||||
};
|
||||
|
||||
struct corge
|
||||
{
|
||||
int a;
|
||||
std::string b;
|
||||
|
||||
void from_toml(const toml::value& v)
|
||||
{
|
||||
this->a = toml::find<int>(v, "a");
|
||||
this->b = toml::find<std::string>(v, "b");
|
||||
return ;
|
||||
}
|
||||
|
||||
template <typename TC>
|
||||
toml::basic_value<TC> into_toml() const
|
||||
{
|
||||
return toml::basic_value<TC>(typename toml::basic_value<TC>::table_type{{"a", this->a}, {"b", this->b}});
|
||||
}
|
||||
};
|
||||
} // extlib
|
||||
|
||||
namespace toml
|
||||
@@ -215,6 +234,19 @@ TEST_CASE("test_conversion_by_member_methods")
|
||||
CHECK(v == v2);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
const toml::value v(toml::table{{"a", 42}, {"b", "baz"}});
|
||||
|
||||
const auto corge = toml::get<extlib::corge>(v);
|
||||
CHECK_EQ(corge.a, 42);
|
||||
CHECK_EQ(corge.b, "baz");
|
||||
|
||||
const toml::value v2(corge);
|
||||
|
||||
CHECK_EQ(v, v2);
|
||||
}
|
||||
|
||||
{
|
||||
const toml::ordered_value v(toml::ordered_table{{"a", 42}, {"b", "baz"}});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user