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 // reference_wrapper 12 13 // template <ObjectType T> reference_wrapper<T> ref(reference_wrapper<T>t); 14 15 #include <functional> 16 #include <cassert> 17 18 #include "counting_predicates.h" 19 20 #include "test_macros.h" 21 is5(int i)22bool is5 ( int i ) { return i == 5; } 23 24 template <typename T> call_pred(T pred)25bool call_pred ( T pred ) { return pred(5); } 26 27 namespace adl { 28 struct A {}; ref(A)29 void ref(A) {} 30 } 31 main(int,char **)32int main(int, char**) 33 { 34 { 35 int i = 0; 36 std::reference_wrapper<int> r1 = std::ref(i); 37 std::reference_wrapper<int> r2 = std::ref(r1); 38 assert(&r2.get() == &i); 39 } 40 { 41 adl::A a; 42 std::reference_wrapper<adl::A> a1 = std::ref(a); 43 std::reference_wrapper<adl::A> a2 = std::ref(a1); 44 assert(&a2.get() == &a); 45 } 46 47 { 48 unary_counting_predicate<bool(*)(int), int> cp(is5); 49 assert(!cp(6)); 50 assert(cp.count() == 1); 51 assert(call_pred(cp)); 52 assert(cp.count() == 1); 53 assert(call_pred(std::ref(cp))); 54 assert(cp.count() == 2); 55 } 56 57 return 0; 58 } 59