|
30 | 30 | #endif |
31 | 31 |
|
32 | 32 | template <class A, bool Integral> |
33 | | -struct test_atomic |
34 | | -{ |
35 | | - test_atomic() |
36 | | - { |
37 | | - A a; (void)a; |
| 33 | +struct test_atomic { |
| 34 | + test_atomic() { |
| 35 | + A a; |
| 36 | + (void)a; |
38 | 37 | #if TEST_STD_VER >= 17 |
39 | 38 | static_assert((std::is_same_v<typename A::value_type, decltype(a.load())>), ""); |
40 | 39 | #endif |
41 | | - } |
| 40 | + } |
42 | 41 | }; |
43 | 42 |
|
44 | 43 | template <class A> |
45 | | -struct test_atomic<A, true> |
46 | | -{ |
47 | | - test_atomic() |
48 | | - { |
49 | | - A a; (void)a; |
| 44 | +struct test_atomic<A, true> { |
| 45 | + test_atomic() { |
| 46 | + A a; |
| 47 | + (void)a; |
50 | 48 | #if TEST_STD_VER >= 17 |
51 | 49 | static_assert((std::is_same_v<typename A::value_type, decltype(a.load())>), ""); |
52 | 50 | static_assert((std::is_same_v<typename A::value_type, typename A::difference_type>), ""); |
53 | 51 | #endif |
54 | | - } |
| 52 | + } |
55 | 53 | }; |
56 | 54 |
|
57 | 55 | template <class A> |
58 | | -struct test_atomic<A*, false> |
59 | | -{ |
60 | | - test_atomic() |
61 | | - { |
62 | | - A a; (void)a; |
| 56 | +struct test_atomic<A*, false> { |
| 57 | + test_atomic() { |
| 58 | + A a; |
| 59 | + (void)a; |
63 | 60 | #if TEST_STD_VER >= 17 |
64 | 61 | static_assert((std::is_same_v<typename A::value_type, decltype(a.load())>), ""); |
65 | 62 | static_assert((std::is_same_v<typename A::difference_type, std::ptrdiff_t>), ""); |
66 | 63 | #endif |
67 | | - } |
| 64 | + } |
68 | 65 | }; |
69 | 66 |
|
70 | 67 | template <class T> |
71 | | -void |
72 | | -test() |
73 | | -{ |
74 | | - using A = std::atomic<T>; |
| 68 | +void test() { |
| 69 | + using A = std::atomic<T>; |
75 | 70 | #if TEST_STD_VER >= 17 |
76 | | - static_assert((std::is_same_v<typename A::value_type, T>), ""); |
| 71 | + static_assert((std::is_same_v<typename A::value_type, T>), ""); |
77 | 72 | #endif |
78 | | - test_atomic<A, std::is_integral<T>::value && !std::is_same<T, bool>::value>(); |
| 73 | + test_atomic<A, std::is_integral<T>::value && !std::is_same<T, bool>::value>(); |
79 | 74 | } |
80 | 75 |
|
81 | 76 | struct TriviallyCopyable { |
82 | | - int i_; |
| 77 | + int i_; |
83 | 78 | }; |
84 | 79 |
|
85 | | -struct WeirdTriviallyCopyable |
86 | | -{ |
87 | | - char i, j, k; /* the 3 chars of doom */ |
| 80 | +struct WeirdTriviallyCopyable { |
| 81 | + char i, j, k; /* the 3 chars of doom */ |
88 | 82 | }; |
89 | 83 |
|
90 | | -struct PaddedTriviallyCopyable |
91 | | -{ |
92 | | - char i; int j; /* probably lock-free? */ |
| 84 | +struct PaddedTriviallyCopyable { |
| 85 | + char i; |
| 86 | + int j; /* probably lock-free? */ |
93 | 87 | }; |
94 | 88 |
|
95 | | -struct LargeTriviallyCopyable |
96 | | -{ |
97 | | - int i, j[127]; /* decidedly not lock-free */ |
| 89 | +struct LargeTriviallyCopyable { |
| 90 | + int i, j[127]; /* decidedly not lock-free */ |
98 | 91 | }; |
99 | 92 |
|
100 | | -int main(int, char**) |
101 | | -{ |
102 | | - test<bool> (); |
103 | | - test<char> (); |
104 | | - test<signed char> (); |
105 | | - test<unsigned char> (); |
106 | | - test<short> (); |
107 | | - test<unsigned short> (); |
108 | | - test<int> (); |
109 | | - test<unsigned int> (); |
110 | | - test<long> (); |
111 | | - test<unsigned long> (); |
112 | | - test<long long> (); |
113 | | - test<unsigned long long> (); |
| 93 | +int main(int, char**) { |
| 94 | + test<bool>(); |
| 95 | + test<char>(); |
| 96 | + test<signed char>(); |
| 97 | + test<unsigned char>(); |
| 98 | + test<short>(); |
| 99 | + test<unsigned short>(); |
| 100 | + test<int>(); |
| 101 | + test<unsigned int>(); |
| 102 | + test<long>(); |
| 103 | + test<unsigned long>(); |
| 104 | + test<long long>(); |
| 105 | + test<unsigned long long>(); |
114 | 106 | #if TEST_STD_VER > 17 && defined(__cpp_char8_t) |
115 | | - test<char8_t> (); |
| 107 | + test<char8_t>(); |
116 | 108 | #endif |
117 | | - test<char16_t> (); |
118 | | - test<char32_t> (); |
| 109 | + test<char16_t>(); |
| 110 | + test<char32_t>(); |
119 | 111 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
120 | | - test<wchar_t> (); |
| 112 | + test<wchar_t>(); |
121 | 113 | #endif |
122 | 114 |
|
123 | | - test<std::int_least8_t> (); |
124 | | - test<std::uint_least8_t> (); |
125 | | - test<std::int_least16_t> (); |
126 | | - test<std::uint_least16_t> (); |
127 | | - test<std::int_least32_t> (); |
128 | | - test<std::uint_least32_t> (); |
129 | | - test<std::int_least64_t> (); |
130 | | - test<std::uint_least64_t> (); |
131 | | - |
132 | | - test<std::int_fast8_t> (); |
133 | | - test<std::uint_fast8_t> (); |
134 | | - test<std::int_fast16_t> (); |
135 | | - test<std::uint_fast16_t> (); |
136 | | - test<std::int_fast32_t> (); |
137 | | - test<std::uint_fast32_t> (); |
138 | | - test<std::int_fast64_t> (); |
139 | | - test<std::uint_fast64_t> (); |
140 | | - |
141 | | - test< std::int8_t> (); |
142 | | - test<std::uint8_t> (); |
143 | | - test< std::int16_t> (); |
144 | | - test<std::uint16_t> (); |
145 | | - test< std::int32_t> (); |
146 | | - test<std::uint32_t> (); |
147 | | - test< std::int64_t> (); |
148 | | - test<std::uint64_t> (); |
149 | | - |
150 | | - test<std::intptr_t> (); |
151 | | - test<std::uintptr_t> (); |
152 | | - test<std::size_t> (); |
153 | | - test<std::ptrdiff_t> (); |
154 | | - test<std::intmax_t> (); |
155 | | - test<std::uintmax_t> (); |
156 | | - |
157 | | - test<std::uintmax_t> (); |
158 | | - test<std::uintmax_t> (); |
159 | | - |
160 | | - test<TriviallyCopyable>(); |
161 | | - test<PaddedTriviallyCopyable>(); |
| 115 | + test<std::int_least8_t>(); |
| 116 | + test<std::uint_least8_t>(); |
| 117 | + test<std::int_least16_t>(); |
| 118 | + test<std::uint_least16_t>(); |
| 119 | + test<std::int_least32_t>(); |
| 120 | + test<std::uint_least32_t>(); |
| 121 | + test<std::int_least64_t>(); |
| 122 | + test<std::uint_least64_t>(); |
| 123 | + |
| 124 | + test<std::int_fast8_t>(); |
| 125 | + test<std::uint_fast8_t>(); |
| 126 | + test<std::int_fast16_t>(); |
| 127 | + test<std::uint_fast16_t>(); |
| 128 | + test<std::int_fast32_t>(); |
| 129 | + test<std::uint_fast32_t>(); |
| 130 | + test<std::int_fast64_t>(); |
| 131 | + test<std::uint_fast64_t>(); |
| 132 | + |
| 133 | + test< std::int8_t>(); |
| 134 | + test<std::uint8_t>(); |
| 135 | + test< std::int16_t>(); |
| 136 | + test<std::uint16_t>(); |
| 137 | + test< std::int32_t>(); |
| 138 | + test<std::uint32_t>(); |
| 139 | + test< std::int64_t>(); |
| 140 | + test<std::uint64_t>(); |
| 141 | + |
| 142 | + test<std::intptr_t>(); |
| 143 | + test<std::uintptr_t>(); |
| 144 | + test<std::size_t>(); |
| 145 | + test<std::ptrdiff_t>(); |
| 146 | + test<std::intmax_t>(); |
| 147 | + test<std::uintmax_t>(); |
| 148 | + |
| 149 | + test<std::uintmax_t>(); |
| 150 | + test<std::uintmax_t>(); |
| 151 | + |
| 152 | + test<TriviallyCopyable>(); |
| 153 | + test<PaddedTriviallyCopyable>(); |
162 | 154 | #ifndef __APPLE__ // Apple doesn't ship libatomic |
163 | | - /* |
| 155 | + /* |
164 | 156 | These aren't going to be lock-free, |
165 | 157 | so some libatomic.a is necessary. |
166 | 158 | */ |
167 | | - test<WeirdTriviallyCopyable>(); |
168 | | - test<LargeTriviallyCopyable>(); |
| 159 | + test<WeirdTriviallyCopyable>(); |
| 160 | + test<LargeTriviallyCopyable>(); |
169 | 161 | #endif |
170 | 162 |
|
171 | 163 | #ifndef TEST_HAS_NO_THREADS |
172 | | - test<std::thread::id>(); |
| 164 | + test<std::thread::id>(); |
173 | 165 | #endif |
174 | | - test<std::chrono::nanoseconds>(); |
175 | | - test<float>(); |
| 166 | + test<std::chrono::nanoseconds>(); |
| 167 | + test<float>(); |
176 | 168 |
|
177 | 169 | #if TEST_STD_VER >= 20 |
178 | | - test<std::atomic_signed_lock_free::value_type>(); |
179 | | - static_assert(std::is_signed_v<std::atomic_signed_lock_free::value_type>); |
180 | | - static_assert(std::is_integral_v<std::atomic_signed_lock_free::value_type>); |
| 170 | + test<std::atomic_signed_lock_free::value_type>(); |
| 171 | + static_assert(std::is_signed_v<std::atomic_signed_lock_free::value_type>); |
| 172 | + static_assert(std::is_integral_v<std::atomic_signed_lock_free::value_type>); |
181 | 173 |
|
182 | | - test<std::atomic_unsigned_lock_free::value_type>(); |
183 | | - static_assert(std::is_unsigned_v<std::atomic_unsigned_lock_free::value_type>); |
184 | | - static_assert(std::is_integral_v<std::atomic_unsigned_lock_free::value_type>); |
| 174 | + test<std::atomic_unsigned_lock_free::value_type>(); |
| 175 | + static_assert(std::is_unsigned_v<std::atomic_unsigned_lock_free::value_type>); |
| 176 | + static_assert(std::is_integral_v<std::atomic_unsigned_lock_free::value_type>); |
185 | 177 | /* |
186 | 178 | test<std::shared_ptr<int>>(); |
187 | 179 | */ |
188 | 180 | #endif |
189 | 181 |
|
190 | | - return 0; |
| 182 | + return 0; |
191 | 183 | } |
0 commit comments