feat: from<T> and from_toml precede constructor

constructor sometimes has `template<T> ctor(const T&)` and it causes
ambiguity. To avoid it, from<T> and T.from_toml precedes any
constructor. But, to check the ambiguity between from<T> and from_toml,
they do not precede each other. If anyone define both from<T> and
from_toml, it causes compilation error.
This commit is contained in:
ToruNiina 2021-05-14 16:05:54 +09:00
parent e622595426
commit 0ac3919e08

View File

@ -259,12 +259,15 @@ template<typename T, typename C,
detail::enable_if_t<detail::has_specialized_from<T>::value, T>
get(const basic_value<C, M, V>&);
// T(const toml::value&) and T is not toml::basic_value
// T(const toml::value&) and T is not toml::basic_value,
// and it does not have `from<T>` nor `from_toml`.
template<typename T, typename C,
template<typename ...> class M, template<typename ...> class V>
detail::enable_if_t<detail::conjunction<
detail::negation<detail::is_basic_value<T>>,
std::is_constructible<T, const basic_value<C, M, V>&>
std::is_constructible<T, const basic_value<C, M, V>&>,
detail::negation<detail::has_from_toml_method<T, C, M, V>>,
detail::negation<detail::has_specialized_from<T>>
>::value, T>
get(const basic_value<C, M, V>&);
@ -450,8 +453,10 @@ get(const basic_value<C, M, V>& v)
template<typename T, typename C,
template<typename ...> class M, template<typename ...> class V>
detail::enable_if_t<detail::conjunction<
detail::negation<detail::is_basic_value<T>>,
std::is_constructible<T, const basic_value<C, M, V>&>
detail::negation<detail::is_basic_value<T>>, // T is not a toml::value
std::is_constructible<T, const basic_value<C, M, V>&>, // T is constructible from toml::value
detail::negation<detail::has_from_toml_method<T, C, M, V>>, // and T does not have T.from_toml(v);
detail::negation<detail::has_specialized_from<T>> // and T does not have toml::from<T>{};
>::value, T>
get(const basic_value<C, M, V>& v)
{