WPILibC++ 2024.1.1-beta-4
cpp_future.h
Go to the documentation of this file.
1// __ _____ _____ _____
2// __| | __| | | | JSON for Modern C++
3// | | |__ | | | | | | version 3.11.2
4// |_____|_____|_____|_|___| https://github.com/nlohmann/json
5//
6// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
7// SPDX-FileCopyrightText: 2018 The Abseil Authors
8// SPDX-License-Identifier: MIT
9
10#pragma once
11
12#include <array> // array
13#include <cstddef> // size_t
14#include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
15#include <utility> // index_sequence, make_index_sequence, index_sequence_for
16
18
20namespace detail
21{
22
23template<typename T>
25
26#ifdef JSON_HAS_CPP_14
27
28// the following utilities are natively available in C++14
33
34#else
35
36// alias templates to reduce boilerplate
37template<bool B, typename T = void>
39
40// The following code is taken from https://github.com/abseil/abseil-cpp/blob/10cb35e459f5ecca5b2ff107635da0bfa41011b4/absl/utility/utility.h
41// which is part of Google Abseil (https://github.com/abseil/abseil-cpp), licensed under the Apache License 2.0.
42
43//// START OF CODE FROM GOOGLE ABSEIL
44
45// integer_sequence
46//
47// Class template representing a compile-time integer sequence. An instantiation
48// of `integer_sequence<T, Ints...>` has a sequence of integers encoded in its
49// type through its template arguments (which is a common need when
50// working with C++11 variadic templates). `absl::integer_sequence` is designed
51// to be a drop-in replacement for C++14's `std::integer_sequence`.
52//
53// Example:
54//
55// template< class T, T... Ints >
56// void user_function(integer_sequence<T, Ints...>);
57//
58// int main()
59// {
60// // user_function's `T` will be deduced to `int` and `Ints...`
61// // will be deduced to `0, 1, 2, 3, 4`.
62// user_function(make_integer_sequence<int, 5>());
63// }
64template <typename T, T... Ints>
66{
67 using value_type = T;
68 static constexpr std::size_t size() noexcept
69 {
70 return sizeof...(Ints);
71 }
72};
73
74// index_sequence
75//
76// A helper template for an `integer_sequence` of `size_t`,
77// `absl::index_sequence` is designed to be a drop-in replacement for C++14's
78// `std::index_sequence`.
79template <size_t... Ints>
80using index_sequence = integer_sequence<size_t, Ints...>;
81
82namespace utility_internal
83{
84
85template <typename Seq, size_t SeqSize, size_t Rem>
86struct Extend;
87
88// Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency.
89template <typename T, T... Ints, size_t SeqSize>
90struct Extend<integer_sequence<T, Ints...>, SeqSize, 0>
91{
92 using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >;
93};
94
95template <typename T, T... Ints, size_t SeqSize>
96struct Extend<integer_sequence<T, Ints...>, SeqSize, 1>
97{
98 using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >;
99};
100
101// Recursion helper for 'make_integer_sequence<T, N>'.
102// 'Gen<T, N>::type' is an alias for 'integer_sequence<T, 0, 1, ... N-1>'.
103template <typename T, size_t N>
104struct Gen
105{
106 using type =
107 typename Extend < typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
108};
109
110template <typename T>
111struct Gen<T, 0>
112{
114};
115
116} // namespace utility_internal
117
118// Compile-time sequences of integers
119
120// make_integer_sequence
121//
122// This template alias is equivalent to
123// `integer_sequence<int, 0, 1, ..., N-1>`, and is designed to be a drop-in
124// replacement for C++14's `std::make_integer_sequence`.
125template <typename T, T N>
127
128// make_index_sequence
129//
130// This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`,
131// and is designed to be a drop-in replacement for C++14's
132// `std::make_index_sequence`.
133template <size_t N>
135
136// index_sequence_for
137//
138// Converts a typename pack into an index sequence of the same length, and
139// is designed to be a drop-in replacement for C++14's
140// `std::index_sequence_for()`
141template <typename... Ts>
143
144//// END OF CODE FROM GOOGLE ABSEIL
145
146#endif
147
148// dispatch utility (taken from ranges-v3)
149template<unsigned N> struct priority_tag : priority_tag < N - 1 > {};
150template<> struct priority_tag<0> {};
151
152// taken from ranges-v3
153template<typename T>
155{
156 static JSON_INLINE_VARIABLE constexpr T value{};
157};
158
159#ifndef JSON_HAS_CPP_17
160 template<typename T>
161 constexpr T static_const<T>::value;
162#endif
163
164template<typename T, typename... Args>
165inline constexpr std::array<T, sizeof...(Args)> make_array(Args&& ... args)
166{
167 return std::array<T, sizeof...(Args)> {{static_cast<T>(std::forward<Args>(args))...}};
168}
169
170} // namespace detail
#define WPI_JSON_NAMESPACE_END
Definition: abi_macros.h:59
#define WPI_JSON_NAMESPACE_BEGIN
Definition: abi_macros.h:53
Definition: core.h:1238
typename std::enable_if< B, T >::type enable_if_t
Definition: core.h:256
#define JSON_INLINE_VARIABLE
Definition: macro_scope.h:139
detail namespace with internal helper functions
Definition: ranges.h:23
constexpr std::array< T, sizeof...(Args)> make_array(Args &&... args)
Definition: cpp_future.h:165
integer_sequence< size_t, N... > index_sequence
Definition: ranges.h:193
typename std::enable_if< B, T >::type enable_if_t
Definition: cpp_future.h:38
make_integer_sequence< size_t, N > make_index_sequence
Definition: ranges.h:201
make_index_sequence< sizeof...(Ts)> index_sequence_for
Definition: cpp_future.h:142
type
Definition: core.h:556
typename std::remove_cv< typename std::remove_reference< T >::type >::type uncvref_t
Definition: cpp_future.h:24
Definition: ranges.h:187
static constexpr std::size_t size() noexcept
Definition: cpp_future.h:68
T value_type
Definition: ranges.h:188
Definition: ranges.h:196
Definition: cpp_future.h:149
Definition: cpp_future.h:155
static JSON_INLINE_VARIABLE constexpr T value
Definition: cpp_future.h:156
Definition: cpp_future.h:86
Definition: cpp_future.h:105
typename Extend< typename Gen< T, N/2 >::type, N/2, N % 2 >::type type
Definition: cpp_future.h:107