Debian Codegraph @

libcxx/test/std/utilities/tuple/tuple.general/ignore.pass.cpp

raw
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
10
11 // <tuple>
12
13 // inline constexpr ignore-type ignore;
14
15 #include <cassert>
16 #include <cstdint>
17 #include <tuple>
18 #include <type_traits>
19
20 #include "test_macros.h"
21
22 static_assert(std::is_trivial<decltype(std::ignore)>::value, "");
23
24 #if TEST_STD_VER >= 17
25 [[nodiscard]] constexpr int test_nodiscard() { return 8294; }
26 #endif
27
28 TEST_CONSTEXPR_CXX14 bool test() {
29 { [[maybe_unused]] auto& ignore_v = std::ignore; }
30
31 { // Test that std::ignore provides converting assignment.
32 auto& res = (std::ignore = 42);
33 static_assert(noexcept(res = (std::ignore = 42)), "Must be noexcept");
34 assert(&res == &std::ignore);
35 }
36 { // Test bit-field binding.
37 struct S {
38 unsigned int bf : 3;
39 };
40 S s{0b010};
41 auto& res = (std::ignore = s.bf);
42 assert(&res == &std::ignore);
43 }
44 { // Test that std::ignore provides copy/move constructors
45 auto copy = std::ignore;
46 [[maybe_unused]] auto moved = std::move(copy);
47 }
48 { // Test that std::ignore provides copy/move assignment
49 auto copy = std::ignore;
50 copy = std::ignore;
51 auto moved = std::ignore;
52 moved = std::move(copy);
53 }
54
55 #if TEST_STD_VER >= 17
56 { std::ignore = test_nodiscard(); }
57 #endif
58
59 return true;
60 }
61
62 int main(int, char**) {
63 test();
64 #if TEST_STD_VER >= 14
65 static_assert(test(), "");
66 #endif
67
68 return 0;
69 }