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 // struct is_placeholder 12 13 #include <functional> 14 #include <type_traits> 15 16 #include "test_macros.h" 17 18 template <int Expected, class T> 19 void 20 test(const T&) 21 { 22 static_assert(std::is_placeholder<T>::value == Expected, ""); 23 LIBCPP_STATIC_ASSERT(std::is_placeholder<T&>::value == Expected, ""); 24 LIBCPP_STATIC_ASSERT(std::is_placeholder<const T>::value == Expected, ""); 25 LIBCPP_STATIC_ASSERT(std::is_placeholder<const T&>::value == Expected, ""); 26 static_assert(std::is_base_of<std::integral_constant<int, Expected>, std::is_placeholder<T> >::value, ""); 27 LIBCPP_STATIC_ASSERT(std::is_base_of<std::integral_constant<int, Expected>, std::is_placeholder<T&> >::value, ""); 28 LIBCPP_STATIC_ASSERT(std::is_base_of<std::integral_constant<int, Expected>, std::is_placeholder<const T> >::value, ""); 29 LIBCPP_STATIC_ASSERT(std::is_base_of<std::integral_constant<int, Expected>, std::is_placeholder<const T&> >::value, ""); 30 31 #if TEST_STD_VER > 14 32 ASSERT_SAME_TYPE(decltype(std::is_placeholder_v<T>), const int); 33 static_assert(std::is_placeholder_v<T> == Expected, ""); 34 LIBCPP_STATIC_ASSERT(std::is_placeholder_v<T&> == Expected, ""); 35 LIBCPP_STATIC_ASSERT(std::is_placeholder_v<const T> == Expected, ""); 36 LIBCPP_STATIC_ASSERT(std::is_placeholder_v<const T&> == Expected, ""); 37 #endif 38 } 39 40 struct C {}; 41 42 int main(int, char**) 43 { 44 test<1>(std::placeholders::_1); 45 test<2>(std::placeholders::_2); 46 test<3>(std::placeholders::_3); 47 test<4>(std::placeholders::_4); 48 test<5>(std::placeholders::_5); 49 test<6>(std::placeholders::_6); 50 test<7>(std::placeholders::_7); 51 test<8>(std::placeholders::_8); 52 test<9>(std::placeholders::_9); 53 test<10>(std::placeholders::_10); 54 test<0>(4); 55 test<0>(5.5); 56 test<0>('a'); 57 test<0>(C()); 58 59 return 0; 60 } 61