|
Last change
on this file since 34b2f54d was b57ba05, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago |
|
Update headers in C++ files
|
-
Property mode
set to
100644
|
|
File size:
1.5 KB
|
| Line | |
|---|
| 1 | /*
|
|---|
| 2 | * SPDX-FileCopyrightText: 2018 Jaroslav Jindrak
|
|---|
| 3 | *
|
|---|
| 4 | * SPDX-License-Identifier: BSD-3-Clause
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | #ifndef LIBCPP_BITS_AUX
|
|---|
| 8 | #define LIBCPP_BITS_AUX
|
|---|
| 9 |
|
|---|
| 10 | namespace std
|
|---|
| 11 | {
|
|---|
| 12 | /**
|
|---|
| 13 | * 20.10.3, helper class:
|
|---|
| 14 | */
|
|---|
| 15 |
|
|---|
| 16 | template<class T, T v>
|
|---|
| 17 | struct integral_constant
|
|---|
| 18 | {
|
|---|
| 19 | static constexpr T value = v;
|
|---|
| 20 |
|
|---|
| 21 | using value_type = T;
|
|---|
| 22 | using type = integral_constant<T, v>;
|
|---|
| 23 |
|
|---|
| 24 | constexpr operator value_type() const noexcept
|
|---|
| 25 | {
|
|---|
| 26 | return value;
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | constexpr value_type operator()() const noexcept
|
|---|
| 30 | {
|
|---|
| 31 | return value;
|
|---|
| 32 | }
|
|---|
| 33 | };
|
|---|
| 34 |
|
|---|
| 35 | using true_type = integral_constant<bool, true>;
|
|---|
| 36 | using false_type = integral_constant<bool, false>;
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | namespace std::aux
|
|---|
| 40 | {
|
|---|
| 41 | /**
|
|---|
| 42 | * Two very handy templates, this allows us
|
|---|
| 43 | * to easily follow the T::type and T::value
|
|---|
| 44 | * convention by simply inheriting from specific
|
|---|
| 45 | * instantiations of these templates.
|
|---|
| 46 | * Examples:
|
|---|
| 47 | * 1) We need a struct with int typedef'd to type:
|
|---|
| 48 | *
|
|---|
| 49 | * stuct has_type_int: aux::type<int> {};
|
|---|
| 50 | * typename has_type_int::type x = 1; // x is of type int
|
|---|
| 51 | *
|
|---|
| 52 | * 2) We need a struct with static size_t member called value:
|
|---|
| 53 | *
|
|---|
| 54 | * struct has_value_size_t: aux::value<size_t, 1u> {};
|
|---|
| 55 | * std::printf("%u\n", has_value_size_t::value); // prints "1\n"
|
|---|
| 56 | */
|
|---|
| 57 |
|
|---|
| 58 | template<class T>
|
|---|
| 59 | struct type_is
|
|---|
| 60 | {
|
|---|
| 61 | using type = T;
|
|---|
| 62 | };
|
|---|
| 63 |
|
|---|
| 64 | // For compatibility with integral_constant.
|
|---|
| 65 | template<class T, T v>
|
|---|
| 66 | using value_is = std::integral_constant<T, v>;
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | #endif
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.