feat: add detail::has_specialization_from/into

This commit is contained in:
ToruNiina
2021-05-14 15:46:00 +09:00
parent c5a22b9d88
commit b6e2c6e235

View File

@@ -2,6 +2,10 @@
// Distributed under the MIT License.
#ifndef TOML11_TRAITS_HPP
#define TOML11_TRAITS_HPP
#include "from.hpp"
#include "into.hpp"
#include <chrono>
#include <forward_list>
#include <string>
@@ -84,6 +88,22 @@ struct has_into_toml_method_impl
static std::false_type check(...);
};
struct has_specialized_from_impl
{
template<typename T>
static std::false_type check(...);
template<typename T>
static std::true_type check(std::nullptr_t, std::size_t S = sizeof(::toml::from<T>));
};
struct has_specialized_into_impl
{
template<typename T>
static std::false_type check(...);
template<typename T>
static std::true_type check(std::nullptr_t, std::size_t S = sizeof(::toml::into<T>));
};
/// Intel C++ compiler can not use decltype in parent class declaration, here
/// is a hack to work around it. https://stackoverflow.com/a/23953090/4692076
#ifdef __INTEL_COMPILER
@@ -114,6 +134,11 @@ template<typename T>
struct has_into_toml_method
: decltype(has_into_toml_method_impl::check<T>(nullptr)){};
template<typename T>
struct has_specialized_from : decltype(has_specialized_from_impl::check<T>(nullptr)){};
template<typename T>
struct has_specialized_into : decltype(has_specialized_into_impl::check<T>(nullptr)){};
#ifdef __INTEL_COMPILER
#undef decltype
#endif