Debian Codegraph @

libstdc++-v3/testsuite/20_util/pair/cons/default_tmpl_args.cc

raw
1 // { dg-do compile { target c++23 } }
2
3 // P1951R1 Default Arguments for pair's Forwarding Constructor
4
5 #include <utility>
6 #include <vector>
7 #include <string>
8 #include <testsuite_hooks.h>
9
10 void
11 test_p1951r1_example()
12 {
13 std::pair<std::string, std::vector<std::string>> p("hello", {});
14 }
15
16 struct Counter
17 {
18 constexpr Counter() = default;
19 constexpr Counter(int) { }
20 constexpr Counter(const Counter& c) : copies(c.copies + 1), moves(c.moves) { }
21 constexpr Counter(Counter&& c) : copies(c.copies), moves(c.moves+1) { }
22 int copies = 0;
23 int moves = 0;
24 };
25
26 constexpr bool
27 test_count_copies()
28 {
29 std::pair<Counter, Counter> p1(1, {});
30 VERIFY( p1.first.copies == 0 && p1.second.copies == 0 );
31 VERIFY( p1.first.moves == 0 && p1.second.moves == 1 );
32
33 std::pair<Counter, Counter> p2({}, 1);
34 VERIFY( p2.first.copies == 0 && p2.second.copies == 0 );
35 VERIFY( p2.first.moves == 1 && p2.second.moves == 0 );
36
37 std::pair<Counter, Counter> p3({}, {});
38 VERIFY( p3.first.copies == 0 && p3.second.copies == 0 );
39 VERIFY( p3.first.moves == 1 && p3.second.moves == 1 );
40
41 return true;
42 }
43
44 int main()
45 {
46 test_p1951r1_example();
47 static_assert( test_count_copies() );
48 }