1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
|
// -*-c++-*-
// vim: set ft=cpp:
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file LICENSE.rst or https://cmake.org/licensing for details. */
#pragma once
#include <iterator> // IWYU pragma: keep
#if __cplusplus < 201402L || defined(_MSVC_LANG) && _MSVC_LANG < 201402L
# include <initializer_list>
#endif
#if __cplusplus < 202002L || defined(_MSVC_LANG) && _MSVC_LANG < 202002L
# include <cstddef>
# include <type_traits>
#endif
namespace cm {
using std::begin;
using std::end;
#if __cplusplus < 201402L || defined(_MSVC_LANG) && _MSVC_LANG < 201402L
template <typename C>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline auto cbegin(C const& c)
# else
inline constexpr auto cbegin(C const& c) noexcept(noexcept(std::begin(c)))
# endif
-> decltype(std::begin(c))
{
return std::begin(c);
}
template <typename C>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline auto cend(C const& c)
# else
inline constexpr auto cend(C const& c) noexcept(noexcept(std::end(c)))
# endif
-> decltype(std::end(c))
{
return std::end(c);
}
template <typename C>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline auto rbegin(C& c)
# else
inline constexpr auto rbegin(C& c)
# endif
-> decltype(c.rbegin())
{
return c.rbegin();
}
template <typename C>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline auto rbegin(C const& c)
# else
inline constexpr auto rbegin(C const& c)
# endif
-> decltype(c.rbegin())
{
return c.rbegin();
}
template <typename T, std::size_t N>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline std::reverse_iterator<T*> rbegin(T (&array)[N])
# else
inline constexpr std::reverse_iterator<T*> rbegin(T (&array)[N]) noexcept
# endif
{
return std::reverse_iterator<T*>(array + N);
}
template <typename T>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline std::reverse_iterator<T const*> rbegin(std::initializer_list<T> il)
# else
inline constexpr std::reverse_iterator<T const*> rbegin(
std::initializer_list<T> il) noexcept
# endif
{
return std::reverse_iterator<T const*>(il.end());
}
template <typename C>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline auto rend(C& c)
# else
inline constexpr auto rend(C& c)
# endif
-> decltype(c.rend())
{
return c.rend();
}
template <typename C>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline auto rend(C const& c)
# else
inline constexpr auto rend(C const& c)
# endif
-> decltype(c.rend())
{
return c.rend();
}
template <typename T, std::size_t N>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline std::reverse_iterator<T*> rend(T (&array)[N])
# else
inline constexpr std::reverse_iterator<T*> rend(T (&array)[N]) noexcept
# endif
{
return std::reverse_iterator<T*>(array);
}
template <typename T>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline std::reverse_iterator<T const*> rend(std::initializer_list<T> il)
# else
inline constexpr std::reverse_iterator<T const*> rend(
std::initializer_list<T> il) noexcept
# endif
{
return std::reverse_iterator<T const*>(il.begin());
}
template <typename C>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline auto crbegin(C const& c)
# else
inline constexpr auto crbegin(C const& c)
# endif
-> decltype(cm::rbegin(c))
{
return cm::rbegin(c);
}
template <typename C>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline auto crend(C const& c)
# else
inline constexpr auto crend(C const& c)
# endif
-> decltype(cm::rend(c))
{
return cm::rend(c);
}
#else
using std::cbegin;
using std::cend;
using std::rbegin;
using std::rend;
using std::crbegin;
using std::crend;
#endif
#if __cplusplus < 201703L || defined(_MSVC_LANG) && _MSVC_LANG < 201703L
template <typename C>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline auto size(C const& c)
# else
inline constexpr auto size(C const& c) noexcept(noexcept(c.size()))
# endif
-> decltype(c.size())
{
return c.size();
}
template <typename T, std::size_t N>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline std::size_t size(T const (&)[N])
# else
inline constexpr std::size_t size(T const (&)[N]) noexcept
# endif
{
return N;
}
template <typename C>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline auto empty(C const& c)
# else
inline constexpr auto empty(C const& c) noexcept(noexcept(c.empty()))
# endif
-> decltype(c.empty())
{
return c.empty();
}
template <typename T, std::size_t N>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline bool empty(T const (&)[N])
# else
inline constexpr bool empty(T const (&)[N]) noexcept
# endif
{
return false;
}
template <typename E>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline bool empty(std::initializer_list<E> il)
# else
inline constexpr bool empty(std::initializer_list<E> il) noexcept
# endif
{
return il.size() == 0;
}
template <typename C>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline auto data(C& c) -> decltype(c.data())
# else
inline constexpr auto data(C& c) noexcept(noexcept(c.data()))
# endif
-> decltype(c.data())
{
return c.data();
}
template <typename C>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline auto data(C const& c)
# else
inline constexpr auto data(C const& c) noexcept(noexcept(c.data()))
# endif
-> decltype(c.data())
{
return c.data();
}
template <typename T, std::size_t N>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline T* data(T (&array)[N])
# else
inline constexpr T* data(T (&array)[N]) noexcept
# endif
{
return array;
}
template <typename E>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline E const* data(std::initializer_list<E> il)
# else
inline constexpr E const* data(std::initializer_list<E> il) noexcept
# endif
{
return il.begin();
}
#else
using std::size;
using std::empty;
using std::data;
#endif
#if __cplusplus < 202002L || defined(_MSVC_LANG) && _MSVC_LANG < 202002L
template <typename C>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline auto ssize(C const& c)
# else
inline constexpr auto ssize(C const& c)
# endif
-> typename std::common_type<
std::ptrdiff_t, typename std::make_signed<decltype(c.size())>::type>::type
{
using signed_type = typename std::make_signed<decltype(c.size())>::type;
using result_type =
typename std::common_type<std::ptrdiff_t, signed_type>::type;
return static_cast<result_type>(c.size());
}
template <typename T, std::ptrdiff_t N>
# if defined(_MSC_VER) && _MSC_VER < 1900
inline std::ptrdiff_t ssize(T const (&)[N])
# else
inline constexpr std::ptrdiff_t ssize(T const (&)[N]) noexcept
# endif
{
return N;
}
#else
using std::ssize;
#endif
} // namespace cm
|