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.hpp" 19 20 #include "test_macros.h" 21 22 bool is5 ( int i ) { return i == 5; } 23 24 template <typename T> 25 bool call_pred ( T pred ) { return pred(5); } 26 27 int main(int, char**) 28 { 29 { 30 int i = 0; 31 std::reference_wrapper<int> r1 = std::ref(i); 32 std::reference_wrapper<int> r2 = std::ref(r1); 33 assert(&r2.get() == &i); 34 } 35 { 36 unary_counting_predicate<bool(*)(int), int> cp(is5); 37 assert(!cp(6)); 38 assert(cp.count() == 1); 39 assert(call_pred(cp)); 40 assert(cp.count() == 1); 41 assert(call_pred(std::ref(cp))); 42 assert(cp.count() == 2); 43 } 44 45 return 0; 46 } 47