1#pragma once
2
3#include <ciso646> // not
4#include <cstddef> // size_t
5#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
6
7namespace nlohmann
8{
9namespace detail
10{
11// alias templates to reduce boilerplate
12template<bool B, typename T = void>
13using enable_if_t = typename std::enable_if<B, T>::type;
14
15template<typename T>
16using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
17
18// implementation of C++14 index_sequence and affiliates
19// source: https://stackoverflow.com/a/32223343
20template<std::size_t... Ints>
21struct index_sequence
22{
23 using type = index_sequence;
24 using value_type = std::size_t;
25 static constexpr std::size_t size() noexcept
26 {
27 return sizeof...(Ints);
28 }
29};
30
31template<class Sequence1, class Sequence2>
32struct merge_and_renumber;
33
34template<std::size_t... I1, std::size_t... I2>
35struct merge_and_renumber<index_sequence<I1...>, index_sequence<I2...>>
36 : index_sequence < I1..., (sizeof...(I1) + I2)... > {};
37
38template<std::size_t N>
39struct make_index_sequence
40 : merge_and_renumber < typename make_index_sequence < N / 2 >::type,
41 typename make_index_sequence < N - N / 2 >::type > {};
42
43template<> struct make_index_sequence<0> : index_sequence<> {};
44template<> struct make_index_sequence<1> : index_sequence<0> {};
45
46template<typename... Ts>
47using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
48
49// dispatch utility (taken from ranges-v3)
50template<unsigned N> struct priority_tag : priority_tag < N - 1 > {};
51template<> struct priority_tag<0> {};
52
53// taken from ranges-v3
54template<typename T>
55struct static_const
56{
57 static constexpr T value{};
58};
59
60template<typename T>
61constexpr T static_const<T>::value;
62} // namespace detail
63} // namespace nlohmann
64