1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03, c++11, c++14 |
10 | |
11 | // <charconv> |
12 | |
13 | // Bitmask type |
14 | // enum class chars_format { |
15 | // scientific = unspecified, |
16 | // fixed = unspecified, |
17 | // hex = unspecified, |
18 | // general = fixed | scientific |
19 | // }; |
20 | |
21 | #include <cassert> |
22 | #include <charconv> |
23 | #include <type_traits> |
24 | |
25 | #include "test_macros.h" |
26 | |
27 | constexpr bool test() { |
28 | using cf = std::chars_format; |
29 | using ut = std::underlying_type<cf>::type; |
30 | |
31 | { |
32 | cf x = cf::scientific; |
33 | x |= cf::fixed; |
34 | assert(x == cf::general); |
35 | } |
36 | { |
37 | cf x = cf::general; |
38 | x &= cf::fixed; |
39 | assert(x == cf::fixed); |
40 | } |
41 | { |
42 | cf x = cf::general; |
43 | x ^= cf::fixed; |
44 | assert(x == cf::scientific); |
45 | } |
46 | |
47 | assert(static_cast<ut>(cf::scientific & (cf::fixed | cf::hex)) == 0); |
48 | assert(static_cast<ut>(cf::fixed & (cf::scientific | cf::hex)) == 0); |
49 | assert(static_cast<ut>(cf::hex & (cf::scientific | cf::fixed)) == 0); |
50 | |
51 | assert((cf::scientific | cf::fixed) == cf::general); |
52 | |
53 | assert(static_cast<ut>(cf::scientific & cf::fixed) == 0); |
54 | |
55 | assert((cf::general ^ cf::fixed) == cf::scientific); |
56 | |
57 | assert((~cf::hex & cf::general) == cf::general); |
58 | |
59 | return true; |
60 | } |
61 | |
62 | std::chars_format x; |
63 | static_assert(std::is_same<std::chars_format, decltype(~x)>::value, "" ); |
64 | static_assert(std::is_same<std::chars_format, decltype(x & x)>::value, "" ); |
65 | static_assert(std::is_same<std::chars_format, decltype(x | x)>::value, "" ); |
66 | static_assert(std::is_same<std::chars_format, decltype(x ^ x)>::value, "" ); |
67 | static_assert(std::is_same<std::chars_format&, decltype(x &= x)>::value, "" ); |
68 | static_assert(std::is_same<std::chars_format&, decltype(x |= x)>::value, "" ); |
69 | static_assert(std::is_same<std::chars_format&, decltype(x ^= x)>::value, "" ); |
70 | |
71 | int main(int, char**) { |
72 | assert(test()); |
73 | static_assert(test(), "" ); |
74 | |
75 | return 0; |
76 | } |
77 | |