72 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 void24 25int count = 0;26 27void f_void_0()28{29 ++count;30}31 32struct A_void_033{34 void operator()() {++count;}35};36 37void38test_void_0()39{40 int save_count = count;41 // function42 {43 std::reference_wrapper<void ()> r1(f_void_0);44 r1();45 assert(count == save_count+1);46 save_count = count;47 }48 // function pointer49 {50 void (*fp)() = f_void_0;51 std::reference_wrapper<void (*)()> r1(fp);52 r1();53 assert(count == save_count+1);54 save_count = count;55 }56 // functor57 {58 A_void_0 a0;59 std::reference_wrapper<A_void_0> r1(a0);60 r1();61 assert(count == save_count+1);62 save_count = count;63 }64}65 66int main(int, char**)67{68 test_void_0();69 70 return 0;71}72