| 1 |
// Variable Templates For Type Traits -*- C++ -*- |
| 2 |
|
| 3 |
// Copyright (C) 2014-2025 Free Software Foundation, Inc. |
| 4 |
// |
| 5 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 6 |
// software; you can redistribute it and/or modify it under the |
| 7 |
// terms of the GNU General Public License as published by the |
| 8 |
// Free Software Foundation; either version 3, or (at your option) |
| 9 |
// any later version. |
| 10 |
|
| 11 |
// This library is distributed in the hope that it will be useful, |
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
// GNU General Public License for more details. |
| 15 |
|
| 16 |
// Under Section 7 of GPL version 3, you are granted additional |
| 17 |
// permissions described in the GCC Runtime Library Exception, version |
| 18 |
// 3.1, as published by the Free Software Foundation. |
| 19 |
|
| 20 |
// You should have received a copy of the GNU General Public License and |
| 21 |
// a copy of the GCC Runtime Library Exception along with this program; |
| 22 |
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 23 |
// <http://www.gnu.org/licenses/>. |
| 24 |
|
| 25 |
/** @file experimental/type_traits |
| 26 |
* This is a TS C++ Library header. |
| 27 |
* |
| 28 |
* This header defines variable templates for the C++14 type traits. |
| 29 |
* |
| 30 |
* Equivalent variable templates are defined in namespace `std` since C++17. |
| 31 |
* @see variable_templates |
| 32 |
* |
| 33 |
* @ingroup libfund-ts |
| 34 |
* @since C++14 |
| 35 |
*/ |
| 36 |
|
| 37 |
// |
| 38 |
// N3932 Variable Templates For Type Traits (Revision 1) |
| 39 |
// |
| 40 |
|
| 41 |
#ifndef _GLIBCXX_EXPERIMENTAL_TYPE_TRAITS |
| 42 |
#define _GLIBCXX_EXPERIMENTAL_TYPE_TRAITS 1 |
| 43 |
|
| 44 |
#ifdef _GLIBCXX_SYSHDR |
| 45 |
#pragma GCC system_header |
| 46 |
#endif |
| 47 |
|
| 48 |
#if __cplusplus >= 201402L |
| 49 |
|
| 50 |
#include <type_traits> |
| 51 |
#include <experimental/bits/lfts_config.h> |
| 52 |
|
| 53 |
namespace std _GLIBCXX_VISIBILITY(default) |
| 54 |
{ |
| 55 |
_GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 56 |
|
| 57 |
namespace experimental |
| 58 |
{ |
| 59 |
inline namespace fundamentals_v1 |
| 60 |
{ |
| 61 |
/** @defgroup lfts_variable_templates Variable template for type traits |
| 62 |
* @ingroup libfund-ts |
| 63 |
* @since Library Fundamentals TS v1. C++14. |
| 64 |
* @see variable_templates |
| 65 |
*/ |
| 66 |
/** @ingroup lfts_variable_templates |
| 67 |
* @{ |
| 68 |
*/ |
| 69 |
#define __cpp_lib_experimental_type_trait_variable_templates 201402 |
| 70 |
|
| 71 |
// See C++14 20.10.4.1, primary type categories |
| 72 |
template <typename _Tp> |
| 73 |
constexpr bool is_void_v = is_void<_Tp>::value; |
| 74 |
template <typename _Tp> |
| 75 |
constexpr bool is_null_pointer_v = is_null_pointer<_Tp>::value; |
| 76 |
template <typename _Tp> |
| 77 |
constexpr bool is_integral_v = is_integral<_Tp>::value; |
| 78 |
template <typename _Tp> |
| 79 |
constexpr bool is_floating_point_v = is_floating_point<_Tp>::value; |
| 80 |
template <typename _Tp> |
| 81 |
constexpr bool is_array_v = is_array<_Tp>::value; |
| 82 |
template <typename _Tp> |
| 83 |
constexpr bool is_pointer_v = is_pointer<_Tp>::value; |
| 84 |
template <typename _Tp> |
| 85 |
constexpr bool is_lvalue_reference_v = is_lvalue_reference<_Tp>::value; |
| 86 |
template <typename _Tp> |
| 87 |
constexpr bool is_rvalue_reference_v = is_rvalue_reference<_Tp>::value; |
| 88 |
template <typename _Tp> |
| 89 |
constexpr bool is_member_object_pointer_v = |
| 90 |
is_member_object_pointer<_Tp>::value; |
| 91 |
template <typename _Tp> |
| 92 |
constexpr bool is_member_function_pointer_v = |
| 93 |
is_member_function_pointer<_Tp>::value; |
| 94 |
template <typename _Tp> |
| 95 |
constexpr bool is_enum_v = is_enum<_Tp>::value; |
| 96 |
template <typename _Tp> |
| 97 |
constexpr bool is_union_v = is_union<_Tp>::value; |
| 98 |
template <typename _Tp> |
| 99 |
constexpr bool is_class_v = is_class<_Tp>::value; |
| 100 |
template <typename _Tp> |
| 101 |
constexpr bool is_function_v = is_function<_Tp>::value; |
| 102 |
|
| 103 |
// See C++14 20.10.4.2, composite type categories |
| 104 |
template <typename _Tp> |
| 105 |
constexpr bool is_reference_v = is_reference<_Tp>::value; |
| 106 |
template <typename _Tp> |
| 107 |
constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; |
| 108 |
template <typename _Tp> |
| 109 |
constexpr bool is_fundamental_v = is_fundamental<_Tp>::value; |
| 110 |
template <typename _Tp> |
| 111 |
constexpr bool is_object_v = is_object<_Tp>::value; |
| 112 |
template <typename _Tp> |
| 113 |
constexpr bool is_scalar_v = is_scalar<_Tp>::value; |
| 114 |
template <typename _Tp> |
| 115 |
constexpr bool is_compound_v = is_compound<_Tp>::value; |
| 116 |
template <typename _Tp> |
| 117 |
constexpr bool is_member_pointer_v = is_member_pointer<_Tp>::value; |
| 118 |
|
| 119 |
// See C++14 20.10.4.3, type properties |
| 120 |
template <typename _Tp> |
| 121 |
constexpr bool is_const_v = is_const<_Tp>::value; |
| 122 |
template <typename _Tp> |
| 123 |
constexpr bool is_volatile_v = is_volatile<_Tp>::value; |
| 124 |
#pragma GCC diagnostic push |
| 125 |
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 126 |
template <typename _Tp> |
| 127 |
constexpr bool is_trivial_v = is_trivial<_Tp>::value; |
| 128 |
#pragma GCC diagnostic pop |
| 129 |
template <typename _Tp> |
| 130 |
constexpr bool is_trivially_copyable_v = is_trivially_copyable<_Tp>::value; |
| 131 |
template <typename _Tp> |
| 132 |
constexpr bool is_standard_layout_v = is_standard_layout<_Tp>::value; |
| 133 |
#pragma GCC diagnostic push |
| 134 |
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 135 |
template <typename _Tp> |
| 136 |
constexpr bool is_pod_v = is_pod<_Tp>::value; |
| 137 |
template <typename _Tp> |
| 138 |
constexpr bool is_literal_type_v = is_literal_type<_Tp>::value; |
| 139 |
#pragma GCC diagnostic pop |
| 140 |
template <typename _Tp> |
| 141 |
constexpr bool is_empty_v = is_empty<_Tp>::value; |
| 142 |
template <typename _Tp> |
| 143 |
constexpr bool is_polymorphic_v = is_polymorphic<_Tp>::value; |
| 144 |
template <typename _Tp> |
| 145 |
constexpr bool is_abstract_v = is_abstract<_Tp>::value; |
| 146 |
template <typename _Tp> |
| 147 |
constexpr bool is_final_v = is_final<_Tp>::value; |
| 148 |
template <typename _Tp> |
| 149 |
constexpr bool is_signed_v = is_signed<_Tp>::value; |
| 150 |
template <typename _Tp> |
| 151 |
constexpr bool is_unsigned_v = is_unsigned<_Tp>::value; |
| 152 |
template <typename _Tp, typename... _Args> |
| 153 |
constexpr bool is_constructible_v = is_constructible<_Tp, _Args...>::value; |
| 154 |
template <typename _Tp> |
| 155 |
constexpr bool is_default_constructible_v = |
| 156 |
is_default_constructible<_Tp>::value; |
| 157 |
template <typename _Tp> |
| 158 |
constexpr bool is_copy_constructible_v = is_copy_constructible<_Tp>::value; |
| 159 |
template <typename _Tp> |
| 160 |
constexpr bool is_move_constructible_v = is_move_constructible<_Tp>::value; |
| 161 |
template <typename _Tp, typename _Up> |
| 162 |
constexpr bool is_assignable_v = is_assignable<_Tp, _Up>::value; |
| 163 |
template <typename _Tp> |
| 164 |
constexpr bool is_copy_assignable_v = is_copy_assignable<_Tp>::value; |
| 165 |
template <typename _Tp> |
| 166 |
constexpr bool is_move_assignable_v = is_move_assignable<_Tp>::value; |
| 167 |
template <typename _Tp> |
| 168 |
constexpr bool is_destructible_v = is_destructible<_Tp>::value; |
| 169 |
template <typename _Tp, typename... _Args> |
| 170 |
constexpr bool is_trivially_constructible_v = |
| 171 |
is_trivially_constructible<_Tp, _Args...>::value; |
| 172 |
template <typename _Tp> |
| 173 |
constexpr bool is_trivially_default_constructible_v = |
| 174 |
is_trivially_default_constructible<_Tp>::value; |
| 175 |
template <typename _Tp> |
| 176 |
constexpr bool is_trivially_copy_constructible_v = |
| 177 |
is_trivially_copy_constructible<_Tp>::value; |
| 178 |
template <typename _Tp> |
| 179 |
constexpr bool is_trivially_move_constructible_v = |
| 180 |
is_trivially_move_constructible<_Tp>::value; |
| 181 |
template <typename _Tp, typename _Up> |
| 182 |
constexpr bool is_trivially_assignable_v = |
| 183 |
is_trivially_assignable<_Tp, _Up>::value; |
| 184 |
template <typename _Tp> |
| 185 |
constexpr bool is_trivially_copy_assignable_v = |
| 186 |
is_trivially_copy_assignable<_Tp>::value; |
| 187 |
template <typename _Tp> |
| 188 |
constexpr bool is_trivially_move_assignable_v = |
| 189 |
is_trivially_move_assignable<_Tp>::value; |
| 190 |
template <typename _Tp> |
| 191 |
constexpr bool is_trivially_destructible_v = |
| 192 |
is_trivially_destructible<_Tp>::value; |
| 193 |
template <typename _Tp, typename... _Args> |
| 194 |
constexpr bool is_nothrow_constructible_v = |
| 195 |
is_nothrow_constructible<_Tp, _Args...>::value; |
| 196 |
template <typename _Tp> |
| 197 |
constexpr bool is_nothrow_default_constructible_v = |
| 198 |
is_nothrow_default_constructible<_Tp>::value; |
| 199 |
template <typename _Tp> |
| 200 |
constexpr bool is_nothrow_copy_constructible_v = |
| 201 |
is_nothrow_copy_constructible<_Tp>::value; |
| 202 |
template <typename _Tp> |
| 203 |
constexpr bool is_nothrow_move_constructible_v = |
| 204 |
is_nothrow_move_constructible<_Tp>::value; |
| 205 |
template <typename _Tp, typename _Up> |
| 206 |
constexpr bool is_nothrow_assignable_v = |
| 207 |
is_nothrow_assignable<_Tp, _Up>::value; |
| 208 |
template <typename _Tp> |
| 209 |
constexpr bool is_nothrow_copy_assignable_v = |
| 210 |
is_nothrow_copy_assignable<_Tp>::value; |
| 211 |
template <typename _Tp> |
| 212 |
constexpr bool is_nothrow_move_assignable_v = |
| 213 |
is_nothrow_move_assignable<_Tp>::value; |
| 214 |
template <typename _Tp> |
| 215 |
constexpr bool is_nothrow_destructible_v = |
| 216 |
is_nothrow_destructible<_Tp>::value; |
| 217 |
template <typename _Tp> |
| 218 |
constexpr bool has_virtual_destructor_v = |
| 219 |
has_virtual_destructor<_Tp>::value; |
| 220 |
|
| 221 |
// See C++14 20.10.5, type property queries |
| 222 |
template <typename _Tp> |
| 223 |
constexpr size_t alignment_of_v = alignment_of<_Tp>::value; |
| 224 |
template <typename _Tp> |
| 225 |
constexpr size_t rank_v = rank<_Tp>::value; |
| 226 |
template <typename _Tp, unsigned _Idx = 0> |
| 227 |
constexpr size_t extent_v = extent<_Tp, _Idx>::value; |
| 228 |
|
| 229 |
// See C++14 20.10.6, type relations |
| 230 |
template <typename _Tp, typename _Up> |
| 231 |
constexpr bool is_same_v = false; |
| 232 |
template <typename _Tp> |
| 233 |
constexpr bool is_same_v<_Tp, _Tp> = true; |
| 234 |
template <typename _Base, typename _Derived> |
| 235 |
constexpr bool is_base_of_v = is_base_of<_Base, _Derived>::value; |
| 236 |
template <typename _From, typename _To> |
| 237 |
constexpr bool is_convertible_v = is_convertible<_From, _To>::value; |
| 238 |
/// @} |
| 239 |
|
| 240 |
// 3.3.2, Other type transformations |
| 241 |
// invocation_type (still unimplemented) |
| 242 |
// raw_invocation_type (still unimplemented) |
| 243 |
// invocation_type_t (still unimplemented) |
| 244 |
// raw_invocation_type_t (still unimplemented) |
| 245 |
} // namespace fundamentals_v1 |
| 246 |
|
| 247 |
inline namespace fundamentals_v2 |
| 248 |
{ |
| 249 |
/** |
| 250 |
* @defgroup lfts_detect Detection idiom |
| 251 |
* @ingroup libfund-ts |
| 252 |
* @since Library Fundamentals TS v2. C++14. |
| 253 |
*/ |
| 254 |
/** @ingroup lfts_detect |
| 255 |
* @{ |
| 256 |
*/ |
| 257 |
#define __cpp_lib_experimental_detect 201505 |
| 258 |
|
| 259 |
// [meta.detect] |
| 260 |
|
| 261 |
/// A metafunction that always yields void, used for detecting valid types. |
| 262 |
template<typename...> using void_t = void; |
| 263 |
|
| 264 |
#pragma GCC diagnostic push |
| 265 |
#pragma GCC diagnostic ignored "-Wctor-dtor-privacy" |
| 266 |
/// @internal |
| 267 |
struct __nonesuchbase {}; |
| 268 |
struct nonesuch : private __nonesuchbase |
| 269 |
{ |
| 270 |
~nonesuch() = delete; |
| 271 |
nonesuch(nonesuch const&) = delete; |
| 272 |
void operator=(nonesuch const&) = delete; |
| 273 |
}; |
| 274 |
#pragma GCC diagnostic pop |
| 275 |
|
| 276 |
template<typename _Default, template<typename...> class _Op, typename... _Args> |
| 277 |
using detected_or = std::__detected_or<_Default, _Op, _Args...>; |
| 278 |
|
| 279 |
template<typename _Default, template<typename...> class _Op, typename... _Args> |
| 280 |
using detected_or_t = typename detected_or<_Default, _Op, _Args...>::type; |
| 281 |
|
| 282 |
template<template<typename...> class _Op, typename... _Args> |
| 283 |
using detected_t = detected_or_t<nonesuch, _Op, _Args...>; |
| 284 |
|
| 285 |
template<template<typename...> class _Op, typename... _Args> |
| 286 |
using is_detected = typename detected_or<void, _Op, _Args...>::__is_detected; |
| 287 |
|
| 288 |
template<template<typename...> class _Op, typename... _Args> |
| 289 |
constexpr bool is_detected_v = is_detected<_Op, _Args...>::value; |
| 290 |
|
| 291 |
template<typename _Expected, template<typename...> class _Op, typename... _Args> |
| 292 |
using is_detected_exact = is_same<_Expected, detected_t<_Op, _Args...>>; |
| 293 |
|
| 294 |
template<typename _Expected, template<typename...> class _Op, typename... _Args> |
| 295 |
constexpr bool is_detected_exact_v |
| 296 |
= is_detected_exact<_Expected, _Op, _Args...>::value; |
| 297 |
|
| 298 |
template<typename _To, template<typename...> class _Op, typename... _Args> |
| 299 |
using is_detected_convertible |
| 300 |
= is_convertible<detected_t<_Op, _Args...>, _To>; |
| 301 |
|
| 302 |
template<typename _To, template<typename...> class _Op, typename... _Args> |
| 303 |
constexpr bool is_detected_convertible_v |
| 304 |
= is_detected_convertible<_To, _Op, _Args...>::value; |
| 305 |
/// @} |
| 306 |
|
| 307 |
/** |
| 308 |
* @defgroup lfts_logical Logical operator traits |
| 309 |
* @ingroup libfund-ts |
| 310 |
* @since Library Fundamentals TS v2. C++14. |
| 311 |
*/ |
| 312 |
/** @ingroup lfts_logical |
| 313 |
* @{ |
| 314 |
*/ |
| 315 |
#define __cpp_lib_experimental_logical_traits 201511 |
| 316 |
|
| 317 |
template<typename... _Bn> |
| 318 |
struct conjunction |
| 319 |
: __and_<_Bn...> |
| 320 |
{ }; |
| 321 |
|
| 322 |
template<typename... _Bn> |
| 323 |
struct disjunction |
| 324 |
: __or_<_Bn...> |
| 325 |
{ }; |
| 326 |
|
| 327 |
template<typename _Pp> |
| 328 |
struct negation |
| 329 |
: __not_<_Pp> |
| 330 |
{ }; |
| 331 |
|
| 332 |
template<typename... _Bn> |
| 333 |
constexpr bool conjunction_v |
| 334 |
= conjunction<_Bn...>::value; |
| 335 |
|
| 336 |
template<typename... _Bn> |
| 337 |
constexpr bool disjunction_v |
| 338 |
= disjunction<_Bn...>::value; |
| 339 |
|
| 340 |
template<typename _Pp> |
| 341 |
constexpr bool negation_v |
| 342 |
= negation<_Pp>::value; |
| 343 |
/// @} |
| 344 |
} // namespace fundamentals_v2 |
| 345 |
} // namespace experimental |
| 346 |
|
| 347 |
_GLIBCXX_END_NAMESPACE_VERSION |
| 348 |
} // namespace std |
| 349 |
|
| 350 |
#endif // __cplusplus <= 201103L |
| 351 |
|
| 352 |
#endif // _GLIBCXX_EXPERIMENTAL_TYPE_TRAITS |