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 // <functional>
10 
11 // placeholders
12 // The placeholders are constexpr in C++17 and beyond.
13 // libc++ provides constexpr placeholders in C++11 and beyond.
14 
15 #include <functional>
16 #include <type_traits>
17 
18 #include "test_macros.h"
19 
20 template <class T>
21 void
test(const T & t)22 test(const T& t)
23 {
24     // Test default constructible.
25     T t2;
26     ((void)t2);
27     // Test copy constructible.
28     T t3 = t;
29     ((void)t3);
30     static_assert(std::is_nothrow_copy_constructible<T>::value, "");
31     static_assert(std::is_nothrow_move_constructible<T>::value, "");
32 }
33 
34 #if TEST_STD_VER >= 11
35 constexpr decltype(std::placeholders::_1)  default1{};
36 constexpr decltype(std::placeholders::_2)  default2{};
37 constexpr decltype(std::placeholders::_3)  default3{};
38 constexpr decltype(std::placeholders::_4)  default4{};
39 constexpr decltype(std::placeholders::_5)  default5{};
40 constexpr decltype(std::placeholders::_6)  default6{};
41 constexpr decltype(std::placeholders::_7)  default7{};
42 constexpr decltype(std::placeholders::_8)  default8{};
43 constexpr decltype(std::placeholders::_9)  default9{};
44 constexpr decltype(std::placeholders::_10) default10{};
45 
46 constexpr decltype(std::placeholders::_1)  cp1 = std::placeholders::_1;
47 constexpr decltype(std::placeholders::_2)  cp2 = std::placeholders::_2;
48 constexpr decltype(std::placeholders::_3)  cp3 = std::placeholders::_3;
49 constexpr decltype(std::placeholders::_4)  cp4 = std::placeholders::_4;
50 constexpr decltype(std::placeholders::_5)  cp5 = std::placeholders::_5;
51 constexpr decltype(std::placeholders::_6)  cp6 = std::placeholders::_6;
52 constexpr decltype(std::placeholders::_7)  cp7 = std::placeholders::_7;
53 constexpr decltype(std::placeholders::_8)  cp8 = std::placeholders::_8;
54 constexpr decltype(std::placeholders::_9)  cp9 = std::placeholders::_9;
55 constexpr decltype(std::placeholders::_10) cp10 = std::placeholders::_10;
56 #endif // TEST_STD_VER >= 11
57 
use_placeholders_to_prevent_unused_warning()58 void use_placeholders_to_prevent_unused_warning() {
59 #if TEST_STD_VER >= 11
60   ((void)cp1);
61   ((void)cp2);
62   ((void)cp3);
63   ((void)cp4);
64   ((void)cp5);
65   ((void)cp6);
66   ((void)cp7);
67   ((void)cp8);
68   ((void)cp9);
69   ((void)cp10);
70   ((void)default1);
71   ((void)default2);
72   ((void)default3);
73   ((void)default4);
74   ((void)default5);
75   ((void)default6);
76   ((void)default7);
77   ((void)default8);
78   ((void)default9);
79   ((void)default10);
80 #endif
81 }
82 
main(int,char **)83 int main(int, char**)
84 {
85     use_placeholders_to_prevent_unused_warning();
86     test(std::placeholders::_1);
87     test(std::placeholders::_2);
88     test(std::placeholders::_3);
89     test(std::placeholders::_4);
90     test(std::placeholders::_5);
91     test(std::placeholders::_6);
92     test(std::placeholders::_7);
93     test(std::placeholders::_8);
94     test(std::placeholders::_9);
95     test(std::placeholders::_10);
96 
97   return 0;
98 }
99