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