diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2020-09-07 12:57:04 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2020-09-07 12:57:04 +0200 |
commit | 0558244645611f314f47e0fa427f7323ce253eaf (patch) | |
tree | 824bcd55ec8577703345106d0a08e167407500a7 /include/lib/modernjson/detail/meta | |
parent | 0248c6352f2117e50fac71dd632a79d8fa4f8737 (diff) |
remove external libraries from main branch
Diffstat (limited to 'include/lib/modernjson/detail/meta')
-rw-r--r-- | include/lib/modernjson/detail/meta/cpp_future.hpp | 63 | ||||
-rw-r--r-- | include/lib/modernjson/detail/meta/detected.hpp | 56 | ||||
-rw-r--r-- | include/lib/modernjson/detail/meta/is_sax.hpp | 141 | ||||
-rw-r--r-- | include/lib/modernjson/detail/meta/type_traits.hpp | 347 | ||||
-rw-r--r-- | include/lib/modernjson/detail/meta/void_t.hpp | 13 |
5 files changed, 0 insertions, 620 deletions
diff --git a/include/lib/modernjson/detail/meta/cpp_future.hpp b/include/lib/modernjson/detail/meta/cpp_future.hpp deleted file mode 100644 index 948cd4f..0000000 --- a/include/lib/modernjson/detail/meta/cpp_future.hpp +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -#include <ciso646> // not -#include <cstddef> // size_t -#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type - -namespace nlohmann -{ -namespace detail -{ -// alias templates to reduce boilerplate -template<bool B, typename T = void> -using enable_if_t = typename std::enable_if<B, T>::type; - -template<typename T> -using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type; - -// implementation of C++14 index_sequence and affiliates -// source: https://stackoverflow.com/a/32223343 -template<std::size_t... Ints> -struct index_sequence -{ - using type = index_sequence; - using value_type = std::size_t; - static constexpr std::size_t size() noexcept - { - return sizeof...(Ints); - } -}; - -template<class Sequence1, class Sequence2> -struct merge_and_renumber; - -template<std::size_t... I1, std::size_t... I2> -struct merge_and_renumber<index_sequence<I1...>, index_sequence<I2...>> - : index_sequence < I1..., (sizeof...(I1) + I2)... > {}; - -template<std::size_t N> -struct make_index_sequence - : merge_and_renumber < typename make_index_sequence < N / 2 >::type, - typename make_index_sequence < N - N / 2 >::type > {}; - -template<> struct make_index_sequence<0> : index_sequence<> {}; -template<> struct make_index_sequence<1> : index_sequence<0> {}; - -template<typename... Ts> -using index_sequence_for = make_index_sequence<sizeof...(Ts)>; - -// dispatch utility (taken from ranges-v3) -template<unsigned N> struct priority_tag : priority_tag < N - 1 > {}; -template<> struct priority_tag<0> {}; - -// taken from ranges-v3 -template<typename T> -struct static_const -{ - static constexpr T value{}; -}; - -template<typename T> -constexpr T static_const<T>::value; -} // namespace detail -} // namespace nlohmann diff --git a/include/lib/modernjson/detail/meta/detected.hpp b/include/lib/modernjson/detail/meta/detected.hpp deleted file mode 100644 index 8fb318a..0000000 --- a/include/lib/modernjson/detail/meta/detected.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -#include <type_traits> - -#include <lib/modernjson/detail/meta/void_t.hpp> - -// http://en.cppreference.com/w/cpp/experimental/is_detected -namespace nlohmann -{ -namespace detail -{ -struct nonesuch -{ - nonesuch() = delete; - ~nonesuch() = delete; - nonesuch(nonesuch const&) = delete; - void operator=(nonesuch const&) = delete; -}; - -template <class Default, - class AlwaysVoid, - template <class...> class Op, - class... Args> -struct detector -{ - using value_t = std::false_type; - using type = Default; -}; - -template <class Default, template <class...> class Op, class... Args> -struct detector<Default, void_t<Op<Args...>>, Op, Args...> -{ - using value_t = std::true_type; - using type = Op<Args...>; -}; - -template <template <class...> class Op, class... Args> -using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t; - -template <template <class...> class Op, class... Args> -using detected_t = typename detector<nonesuch, void, Op, Args...>::type; - -template <class Default, template <class...> class Op, class... Args> -using detected_or = detector<Default, void, Op, Args...>; - -template <class Default, template <class...> class Op, class... Args> -using detected_or_t = typename detected_or<Default, Op, Args...>::type; - -template <class Expected, template <class...> class Op, class... Args> -using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>; - -template <class To, template <class...> class Op, class... Args> -using is_detected_convertible = - std::is_convertible<detected_t<Op, Args...>, To>; -} // namespace detail -} // namespace nlohmann diff --git a/include/lib/modernjson/detail/meta/is_sax.hpp b/include/lib/modernjson/detail/meta/is_sax.hpp deleted file mode 100644 index af63386..0000000 --- a/include/lib/modernjson/detail/meta/is_sax.hpp +++ /dev/null @@ -1,141 +0,0 @@ -#pragma once - -#include <cstdint> // size_t -#include <utility> // declval - -#include <lib/modernjson/detail/meta/detected.hpp> -#include <lib/modernjson/detail/meta/type_traits.hpp> - -namespace nlohmann -{ -namespace detail -{ -template <typename T> -using null_function_t = decltype(std::declval<T&>().null()); - -template <typename T> -using boolean_function_t = - decltype(std::declval<T&>().boolean(std::declval<bool>())); - -template <typename T, typename Integer> -using number_integer_function_t = - decltype(std::declval<T&>().number_integer(std::declval<Integer>())); - -template <typename T, typename Unsigned> -using number_unsigned_function_t = - decltype(std::declval<T &>().number_unsigned(std::declval<Unsigned>())); - -template <typename T, typename Float, typename String> -using number_float_function_t = decltype(std::declval<T &>().number_float( - std::declval<Float>(), std::declval<const String &>())); - -template <typename T, typename String> -using string_function_t = - decltype(std::declval<T &>().string(std::declval<String &>())); - -template <typename T> -using start_object_function_t = - decltype(std::declval<T &>().start_object(std::declval<std::size_t>())); - -template <typename T, typename String> -using key_function_t = - decltype(std::declval<T &>().key(std::declval<String &>())); - -template <typename T> -using end_object_function_t = decltype(std::declval<T &>().end_object()); - -template <typename T> -using start_array_function_t = - decltype(std::declval<T &>().start_array(std::declval<std::size_t>())); - -template <typename T> -using end_array_function_t = decltype(std::declval<T &>().end_array()); - -template <typename T, typename Exception> -using parse_error_function_t = decltype(std::declval<T &>().parse_error( - std::declval<std::size_t>(), std::declval<const std::string &>(), - std::declval<const Exception &>())); - -template <typename SAX, typename BasicJsonType> -struct is_sax -{ -private: - static_assert(is_basic_json<BasicJsonType>::value, - "BasicJsonType must be of type basic_json<...>"); - - using number_integer_t = typename BasicJsonType::number_integer_t; - using number_unsigned_t = typename BasicJsonType::number_unsigned_t; - using number_float_t = typename BasicJsonType::number_float_t; - using string_t = typename BasicJsonType::string_t; - using exception_t = typename BasicJsonType::exception; - -public: - static constexpr bool value = - is_detected_exact<bool, null_function_t, SAX>::value && - is_detected_exact<bool, boolean_function_t, SAX>::value && - is_detected_exact<bool, number_integer_function_t, SAX, - number_integer_t>::value && - is_detected_exact<bool, number_unsigned_function_t, SAX, - number_unsigned_t>::value && - is_detected_exact<bool, number_float_function_t, SAX, number_float_t, - string_t>::value && - is_detected_exact<bool, string_function_t, SAX, string_t>::value && - is_detected_exact<bool, start_object_function_t, SAX>::value && - is_detected_exact<bool, key_function_t, SAX, string_t>::value && - is_detected_exact<bool, end_object_function_t, SAX>::value && - is_detected_exact<bool, start_array_function_t, SAX>::value && - is_detected_exact<bool, end_array_function_t, SAX>::value && - is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value; -}; - -template <typename SAX, typename BasicJsonType> -struct is_sax_static_asserts -{ -private: - static_assert(is_basic_json<BasicJsonType>::value, - "BasicJsonType must be of type basic_json<...>"); - - using number_integer_t = typename BasicJsonType::number_integer_t; - using number_unsigned_t = typename BasicJsonType::number_unsigned_t; - using number_float_t = typename BasicJsonType::number_float_t; - using string_t = typename BasicJsonType::string_t; - using exception_t = typename BasicJsonType::exception; - -public: - static_assert(is_detected_exact<bool, null_function_t, SAX>::value, - "Missing/invalid function: bool null()"); - static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value, - "Missing/invalid function: bool boolean(bool)"); - static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value, - "Missing/invalid function: bool boolean(bool)"); - static_assert( - is_detected_exact<bool, number_integer_function_t, SAX, - number_integer_t>::value, - "Missing/invalid function: bool number_integer(number_integer_t)"); - static_assert( - is_detected_exact<bool, number_unsigned_function_t, SAX, - number_unsigned_t>::value, - "Missing/invalid function: bool number_unsigned(number_unsigned_t)"); - static_assert(is_detected_exact<bool, number_float_function_t, SAX, - number_float_t, string_t>::value, - "Missing/invalid function: bool number_float(number_float_t, const string_t&)"); - static_assert( - is_detected_exact<bool, string_function_t, SAX, string_t>::value, - "Missing/invalid function: bool string(string_t&)"); - static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value, - "Missing/invalid function: bool start_object(std::size_t)"); - static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value, - "Missing/invalid function: bool key(string_t&)"); - static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value, - "Missing/invalid function: bool end_object()"); - static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value, - "Missing/invalid function: bool start_array(std::size_t)"); - static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value, - "Missing/invalid function: bool end_array()"); - static_assert( - is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value, - "Missing/invalid function: bool parse_error(std::size_t, const " - "std::string&, const exception&)"); -}; -} // namespace detail -} // namespace nlohmann diff --git a/include/lib/modernjson/detail/meta/type_traits.hpp b/include/lib/modernjson/detail/meta/type_traits.hpp deleted file mode 100644 index 2f0af28..0000000 --- a/include/lib/modernjson/detail/meta/type_traits.hpp +++ /dev/null @@ -1,347 +0,0 @@ -#pragma once - -#include <ciso646> // not -#include <limits> // numeric_limits -#include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type -#include <utility> // declval - -#include <lib/modernjson/json_fwd.h> -#include <lib/modernjson/detail/meta/cpp_future.hpp> -#include <lib/modernjson/detail/meta/detected.hpp> -#include <lib/modernjson/detail/macro_scope.hpp> - -namespace nlohmann -{ -/*! -@brief detail namespace with internal helper functions - -This namespace collects functions that should not be exposed, -implementations of some @ref basic_json methods, and meta-programming helpers. - -@since version 2.1.0 -*/ -namespace detail -{ -///////////// -// helpers // -///////////// - -// Note to maintainers: -// -// Every trait in this file expects a non CV-qualified type. -// The only exceptions are in the 'aliases for detected' section -// (i.e. those of the form: decltype(T::member_function(std::declval<T>()))) -// -// In this case, T has to be properly CV-qualified to constraint the function arguments -// (e.g. to_json(BasicJsonType&, const T&)) - -template<typename> struct is_basic_json : std::false_type {}; - -NLOHMANN_BASIC_JSON_TPL_DECLARATION -struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {}; - -////////////////////////// -// aliases for detected // -////////////////////////// - -template <typename T> -using mapped_type_t = typename T::mapped_type; - -template <typename T> -using key_type_t = typename T::key_type; - -template <typename T> -using value_type_t = typename T::value_type; - -template <typename T> -using difference_type_t = typename T::difference_type; - -template <typename T> -using pointer_t = typename T::pointer; - -template <typename T> -using reference_t = typename T::reference; - -template <typename T> -using iterator_category_t = typename T::iterator_category; - -template <typename T> -using iterator_t = typename T::iterator; - -template <typename T, typename... Args> -using to_json_function = decltype(T::to_json(std::declval<Args>()...)); - -template <typename T, typename... Args> -using from_json_function = decltype(T::from_json(std::declval<Args>()...)); - -template <typename T, typename U> -using get_template_function = decltype(std::declval<T>().template get<U>()); - -// trait checking if JSONSerializer<T>::from_json(json const&, udt&) exists -template <typename BasicJsonType, typename T, typename = void> -struct has_from_json : std::false_type {}; - -template <typename BasicJsonType, typename T> -struct has_from_json<BasicJsonType, T, - enable_if_t<not is_basic_json<T>::value>> -{ - using serializer = typename BasicJsonType::template json_serializer<T, void>; - - static constexpr bool value = - is_detected_exact<void, from_json_function, serializer, - const BasicJsonType&, T&>::value; -}; - -// This trait checks if JSONSerializer<T>::from_json(json const&) exists -// this overload is used for non-default-constructible user-defined-types -template <typename BasicJsonType, typename T, typename = void> -struct has_non_default_from_json : std::false_type {}; - -template<typename BasicJsonType, typename T> -struct has_non_default_from_json<BasicJsonType, T, enable_if_t<not is_basic_json<T>::value>> -{ - using serializer = typename BasicJsonType::template json_serializer<T, void>; - - static constexpr bool value = - is_detected_exact<T, from_json_function, serializer, - const BasicJsonType&>::value; -}; - -// This trait checks if BasicJsonType::json_serializer<T>::to_json exists -// Do not evaluate the trait when T is a basic_json type, to avoid template instantiation infinite recursion. -template <typename BasicJsonType, typename T, typename = void> -struct has_to_json : std::false_type {}; - -template <typename BasicJsonType, typename T> -struct has_to_json<BasicJsonType, T, enable_if_t<not is_basic_json<T>::value>> -{ - using serializer = typename BasicJsonType::template json_serializer<T, void>; - - static constexpr bool value = - is_detected_exact<void, to_json_function, serializer, BasicJsonType&, - T>::value; -}; - - -/////////////////// -// is_ functions // -/////////////////// - -template <typename T, typename = void> -struct is_iterator_traits : std::false_type {}; - -template <typename T> -struct is_iterator_traits<std::iterator_traits<T>> -{ - private: - using traits = std::iterator_traits<T>; - - public: - static constexpr auto value = - is_detected<value_type_t, traits>::value && - is_detected<difference_type_t, traits>::value && - is_detected<pointer_t, traits>::value && - is_detected<iterator_category_t, traits>::value && - is_detected<reference_t, traits>::value; -}; - -// source: https://stackoverflow.com/a/37193089/4116453 - -template <typename T, typename = void> -struct is_complete_type : std::false_type {}; - -template <typename T> -struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {}; - -template <typename BasicJsonType, typename CompatibleObjectType, - typename = void> -struct is_compatible_object_type_impl : std::false_type {}; - -template <typename BasicJsonType, typename 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 >> -{ - - using object_t = typename BasicJsonType::object_t; - - // 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 <typename BasicJsonType, typename ConstructibleObjectType, - typename = void> -struct is_constructible_object_type_impl : std::false_type {}; - -template <typename BasicJsonType, typename ConstructibleObjectType> -struct is_constructible_object_type_impl < - BasicJsonType, ConstructibleObjectType, - enable_if_t<is_detected<mapped_type_t, ConstructibleObjectType>::value and - is_detected<key_type_t, ConstructibleObjectType>::value >> -{ - using object_t = typename BasicJsonType::object_t; - - static constexpr bool value = - (std::is_constructible<typename ConstructibleObjectType::key_type, typename object_t::key_type>::value and - std::is_same<typename object_t::mapped_type, typename ConstructibleObjectType::mapped_type>::value) or - (has_from_json<BasicJsonType, typename ConstructibleObjectType::mapped_type>::value or - has_non_default_from_json<BasicJsonType, typename ConstructibleObjectType::mapped_type >::value); -}; - -template <typename BasicJsonType, typename ConstructibleObjectType> -struct is_constructible_object_type - : is_constructible_object_type_impl<BasicJsonType, - ConstructibleObjectType> {}; - -template <typename BasicJsonType, typename CompatibleStringType, - typename = void> -struct is_compatible_string_type_impl : std::false_type {}; - -template <typename BasicJsonType, typename CompatibleStringType> -struct is_compatible_string_type_impl < - BasicJsonType, CompatibleStringType, - enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type, - value_type_t, CompatibleStringType>::value >> -{ - static constexpr auto value = - std::is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value; -}; - -template <typename BasicJsonType, typename ConstructibleStringType> -struct is_compatible_string_type - : is_compatible_string_type_impl<BasicJsonType, ConstructibleStringType> {}; - -template <typename BasicJsonType, typename ConstructibleStringType, - typename = void> -struct is_constructible_string_type_impl : std::false_type {}; - -template <typename BasicJsonType, typename ConstructibleStringType> -struct is_constructible_string_type_impl < - BasicJsonType, ConstructibleStringType, - enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type, - value_type_t, ConstructibleStringType>::value >> -{ - static constexpr auto value = - std::is_constructible<ConstructibleStringType, - typename BasicJsonType::string_t>::value; -}; - -template <typename BasicJsonType, typename ConstructibleStringType> -struct is_constructible_string_type - : is_constructible_string_type_impl<BasicJsonType, ConstructibleStringType> {}; - -template <typename BasicJsonType, typename CompatibleArrayType, typename = void> -struct is_compatible_array_type_impl : std::false_type {}; - -template <typename BasicJsonType, typename CompatibleArrayType> -struct is_compatible_array_type_impl < - BasicJsonType, CompatibleArrayType, - enable_if_t<is_detected<value_type_t, CompatibleArrayType>::value and - is_detected<iterator_t, CompatibleArrayType>::value and -// This is needed because json_reverse_iterator has a ::iterator type... -// Therefore it is detected as a CompatibleArrayType. -// The real fix would be to have an Iterable concept. - not is_iterator_traits< - std::iterator_traits<CompatibleArrayType>>::value >> -{ - static constexpr bool value = - std::is_constructible<BasicJsonType, - typename CompatibleArrayType::value_type>::value; -}; - -template <typename BasicJsonType, typename CompatibleArrayType> -struct is_compatible_array_type - : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {}; - -template <typename BasicJsonType, typename ConstructibleArrayType, typename = void> -struct is_constructible_array_type_impl : std::false_type {}; - -template <typename BasicJsonType, typename ConstructibleArrayType> -struct is_constructible_array_type_impl < - BasicJsonType, ConstructibleArrayType, - enable_if_t<std::is_same<ConstructibleArrayType, - typename BasicJsonType::value_type>::value >> - : std::true_type {}; - -template <typename BasicJsonType, typename ConstructibleArrayType> -struct is_constructible_array_type_impl < - BasicJsonType, ConstructibleArrayType, - enable_if_t<not std::is_same<ConstructibleArrayType, - typename BasicJsonType::value_type>::value and - is_detected<value_type_t, ConstructibleArrayType>::value and - is_detected<iterator_t, ConstructibleArrayType>::value and - is_complete_type< - detected_t<value_type_t, ConstructibleArrayType>>::value >> -{ - static constexpr bool value = - // This is needed because json_reverse_iterator has a ::iterator type, - // furthermore, std::back_insert_iterator (and other iterators) have a base class `iterator`... - // Therefore it is detected as a ConstructibleArrayType. - // The real fix would be to have an Iterable concept. - not is_iterator_traits < - std::iterator_traits<ConstructibleArrayType >>::value and - - (std::is_same<typename ConstructibleArrayType::value_type, typename BasicJsonType::array_t::value_type>::value or - has_from_json<BasicJsonType, - typename ConstructibleArrayType::value_type>::value or - has_non_default_from_json < - BasicJsonType, typename ConstructibleArrayType::value_type >::value); -}; - -template <typename BasicJsonType, typename ConstructibleArrayType> -struct is_constructible_array_type - : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {}; - -template <typename RealIntegerType, typename CompatibleNumberIntegerType, - typename = void> -struct is_compatible_integer_type_impl : std::false_type {}; - -template <typename RealIntegerType, typename CompatibleNumberIntegerType> -struct is_compatible_integer_type_impl < - RealIntegerType, CompatibleNumberIntegerType, - enable_if_t<std::is_integral<RealIntegerType>::value and - std::is_integral<CompatibleNumberIntegerType>::value and - not std::is_same<bool, CompatibleNumberIntegerType>::value >> -{ - // is there an assert somewhere on overflows? - using RealLimits = std::numeric_limits<RealIntegerType>; - using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>; - - static constexpr auto value = - std::is_constructible<RealIntegerType, - CompatibleNumberIntegerType>::value and - CompatibleLimits::is_integer and - RealLimits::is_signed == CompatibleLimits::is_signed; -}; - -template <typename RealIntegerType, typename CompatibleNumberIntegerType> -struct is_compatible_integer_type - : is_compatible_integer_type_impl<RealIntegerType, - CompatibleNumberIntegerType> {}; - -template <typename BasicJsonType, typename CompatibleType, typename = void> -struct is_compatible_type_impl: std::false_type {}; - -template <typename BasicJsonType, typename CompatibleType> -struct is_compatible_type_impl < - BasicJsonType, CompatibleType, - enable_if_t<is_complete_type<CompatibleType>::value >> -{ - static constexpr bool value = - has_to_json<BasicJsonType, CompatibleType>::value; -}; - -template <typename BasicJsonType, typename CompatibleType> -struct is_compatible_type - : is_compatible_type_impl<BasicJsonType, CompatibleType> {}; -} // namespace detail -} // namespace nlohmann diff --git a/include/lib/modernjson/detail/meta/void_t.hpp b/include/lib/modernjson/detail/meta/void_t.hpp deleted file mode 100644 index a256f85..0000000 --- a/include/lib/modernjson/detail/meta/void_t.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -namespace nlohmann -{ -namespace detail -{ -template <typename ...Ts> struct make_void -{ - using type = void; -}; -template <typename ...Ts> using void_t = typename make_void<Ts...>::type; -} // namespace detail -} // namespace nlohmann |