xref: /llvm-project/libcxx/test/std/utilities/function.objects/refwrap/refwrap.access/conversion.pass.cpp (revision 7fc6a55688c816f5fc1a5481ae7af25be7500356)
15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
95a83710eSEric Fiselier // <functional>
105a83710eSEric Fiselier 
115a83710eSEric Fiselier // reference_wrapper
125a83710eSEric Fiselier 
135a83710eSEric Fiselier // operator T& () const;
145a83710eSEric Fiselier 
155a83710eSEric Fiselier #include <functional>
165a83710eSEric Fiselier #include <cassert>
175a83710eSEric Fiselier 
18*7fc6a556SMarshall Clow #include "test_macros.h"
19*7fc6a556SMarshall Clow 
205a83710eSEric Fiselier class functor1
215a83710eSEric Fiselier {
225a83710eSEric Fiselier };
235a83710eSEric Fiselier 
245a83710eSEric Fiselier template <class T>
255a83710eSEric Fiselier void
test(T & t)265a83710eSEric Fiselier test(T& t)
275a83710eSEric Fiselier {
285a83710eSEric Fiselier     std::reference_wrapper<T> r(t);
295a83710eSEric Fiselier     T& r2 = r;
305a83710eSEric Fiselier     assert(&r2 == &t);
315a83710eSEric Fiselier }
325a83710eSEric Fiselier 
f()335a83710eSEric Fiselier void f() {}
345a83710eSEric Fiselier 
main(int,char **)352df59c50SJF Bastien int main(int, char**)
365a83710eSEric Fiselier {
375a83710eSEric Fiselier     void (*fp)() = f;
385a83710eSEric Fiselier     test(fp);
395a83710eSEric Fiselier     test(f);
405a83710eSEric Fiselier     functor1 f1;
415a83710eSEric Fiselier     test(f1);
425a83710eSEric Fiselier     int i = 0;
435a83710eSEric Fiselier     test(i);
445a83710eSEric Fiselier     const int j = 0;
455a83710eSEric Fiselier     test(j);
462df59c50SJF Bastien 
472df59c50SJF Bastien   return 0;
485a83710eSEric Fiselier }
49