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