mirror of
https://github.com/nlohmann/json.git
synced 2024-12-25 06:17:54 +08:00
79 lines
2.1 KiB
C++
79 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#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
|
|
#include <utility> // index_sequence, make_index_sequence, index_sequence_for
|
|
|
|
#include <nlohmann/detail/macro_scope.hpp>
|
|
|
|
namespace nlohmann
|
|
{
|
|
namespace detail
|
|
{
|
|
|
|
template<typename T>
|
|
using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
|
|
|
|
#ifdef JSON_HAS_CPP_14
|
|
|
|
// the following utilities are natively available in C++14
|
|
using std::enable_if_t;
|
|
using std::index_sequence;
|
|
using std::make_index_sequence;
|
|
using std::index_sequence_for;
|
|
|
|
#else
|
|
|
|
// alias templates to reduce boilerplate
|
|
template<bool B, typename T = void>
|
|
using enable_if_t = typename std::enable_if<B, T>::type;
|
|
|
|
// 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)>;
|
|
|
|
#endif
|
|
|
|
// 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
|