80 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <functional>10 11// reference_wrapper12 13// template <class... ArgTypes>14// requires Callable<T, ArgTypes&&...>15// Callable<T, ArgTypes&&...>::result_type16// operator()(ArgTypes&&... args) const;17 18#include <functional>19#include <cassert>20 21#include "test_macros.h"22 23// 0 args, return int24 25int count = 0;26 27int f_int_0()28{29 return 3;30}31 32struct A_int_033{34 int operator()() {return 4;}35};36 37void38test_int_0()39{40 // function41 {42 std::reference_wrapper<int ()> r1(f_int_0);43 assert(r1() == 3);44 }45 // function pointer46 {47 int (*fp)() = f_int_0;48 std::reference_wrapper<int (*)()> r1(fp);49 assert(r1() == 3);50 }51 // functor52 {53 A_int_0 a0;54 std::reference_wrapper<A_int_0> r1(a0);55 assert(r1() == 4);56 }57}58 59// 1 arg, return void60 61void f_void_1(int i)62{63 count += i;64}65 66struct A_void_167{68 void operator()(int i)69 {70 count += i;71 }72};73 74int main(int, char**)75{76 test_int_0();77 78 return 0;79}80