refactor is_compatible_object_type

This commit is contained in:
Théo DELRIEU 2018-09-05 16:35:30 +02:00
parent b59c3367c9
commit e84195ab7b
No known key found for this signature in database
GPG key ID: A5A505438C20539A
2 changed files with 40 additions and 32 deletions

View file

@ -65,17 +65,31 @@ struct is_complete_type : std::false_type {};
template <typename T> template <typename T>
struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {}; struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {};
template<bool B, class RealType, class CompatibleObjectType> template <typename BasicJsonType, typename CompatibleObjectType,
typename = void>
struct is_compatible_object_type_impl : std::false_type {}; struct is_compatible_object_type_impl : std::false_type {};
template<class RealType, class CompatibleObjectType> template <typename BasicJsonType, typename CompatibleObjectType>
struct is_compatible_object_type_impl<true, RealType, CompatibleObjectType> struct is_compatible_object_type_impl <
BasicJsonType, CompatibleObjectType,
enable_if_t<is_detected<mapped_type_t, CompatibleObjectType>::value and
is_detected<key_type_t, CompatibleObjectType>::value >>
{ {
static constexpr auto value =
std::is_constructible<typename RealType::key_type, typename CompatibleObjectType::key_type>::value and using object_t = typename BasicJsonType::object_t;
std::is_constructible<typename RealType::mapped_type, typename CompatibleObjectType::mapped_type>::value;
// macOS's is_constructible does not play well with nonesuch...
static constexpr bool value =
std::is_constructible<typename object_t::key_type,
typename CompatibleObjectType::key_type>::value and
std::is_constructible<typename object_t::mapped_type,
typename CompatibleObjectType::mapped_type>::value;
}; };
template <typename BasicJsonType, typename CompatibleObjectType>
struct is_compatible_object_type
: is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {};
template<bool B, class RealType, class CompatibleStringType> template<bool B, class RealType, class CompatibleStringType>
struct is_compatible_string_type_impl : std::false_type {}; struct is_compatible_string_type_impl : std::false_type {};
@ -87,16 +101,6 @@ struct is_compatible_string_type_impl<true, RealType, CompatibleStringType>
std::is_constructible<RealType, CompatibleStringType>::value; std::is_constructible<RealType, CompatibleStringType>::value;
}; };
template<class BasicJsonType, class CompatibleObjectType>
struct is_compatible_object_type
{
static auto constexpr value = is_compatible_object_type_impl <
conjunction<negation<std::is_same<void, CompatibleObjectType>>,
is_detected<mapped_type_t, CompatibleObjectType>,
is_detected<key_type_t, CompatibleObjectType>>::value,
typename BasicJsonType::object_t, CompatibleObjectType >::value;
};
template<class BasicJsonType, class CompatibleStringType> template<class BasicJsonType, class CompatibleStringType>
struct is_compatible_string_type struct is_compatible_string_type
{ {

View file

@ -445,17 +445,31 @@ struct is_complete_type : std::false_type {};
template <typename T> template <typename T>
struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {}; struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {};
template<bool B, class RealType, class CompatibleObjectType> template <typename BasicJsonType, typename CompatibleObjectType,
typename = void>
struct is_compatible_object_type_impl : std::false_type {}; struct is_compatible_object_type_impl : std::false_type {};
template<class RealType, class CompatibleObjectType> template <typename BasicJsonType, typename CompatibleObjectType>
struct is_compatible_object_type_impl<true, RealType, CompatibleObjectType> struct is_compatible_object_type_impl <
BasicJsonType, CompatibleObjectType,
enable_if_t<is_detected<mapped_type_t, CompatibleObjectType>::value and
is_detected<key_type_t, CompatibleObjectType>::value >>
{ {
static constexpr auto value =
std::is_constructible<typename RealType::key_type, typename CompatibleObjectType::key_type>::value and using object_t = typename BasicJsonType::object_t;
std::is_constructible<typename RealType::mapped_type, typename CompatibleObjectType::mapped_type>::value;
// macOS's is_constructible does not play well with nonesuch...
static constexpr bool value =
std::is_constructible<typename object_t::key_type,
typename CompatibleObjectType::key_type>::value and
std::is_constructible<typename object_t::mapped_type,
typename CompatibleObjectType::mapped_type>::value;
}; };
template <typename BasicJsonType, typename CompatibleObjectType>
struct is_compatible_object_type
: is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {};
template<bool B, class RealType, class CompatibleStringType> template<bool B, class RealType, class CompatibleStringType>
struct is_compatible_string_type_impl : std::false_type {}; struct is_compatible_string_type_impl : std::false_type {};
@ -467,16 +481,6 @@ struct is_compatible_string_type_impl<true, RealType, CompatibleStringType>
std::is_constructible<RealType, CompatibleStringType>::value; std::is_constructible<RealType, CompatibleStringType>::value;
}; };
template<class BasicJsonType, class CompatibleObjectType>
struct is_compatible_object_type
{
static auto constexpr value = is_compatible_object_type_impl <
conjunction<negation<std::is_same<void, CompatibleObjectType>>,
is_detected<mapped_type_t, CompatibleObjectType>,
is_detected<key_type_t, CompatibleObjectType>>::value,
typename BasicJsonType::object_t, CompatibleObjectType >::value;
};
template<class BasicJsonType, class CompatibleStringType> template<class BasicJsonType, class CompatibleStringType>
struct is_compatible_string_type struct is_compatible_string_type
{ {