1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <functional>
11 
12 // reference_wrapper
13 
14 // Test that reference wrapper meets the requirements of TriviallyCopyable,
15 // CopyConstructible and CopyAssignable.
16 
17 #include <functional>
18 #include <type_traits>
19 #include <string>
20 
21 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
22 class MoveOnly
23 {
24     MoveOnly(const MoveOnly&);
25     MoveOnly& operator=(const MoveOnly&);
26 
27     int data_;
28 public:
MoveOnly(int data=1)29     MoveOnly(int data = 1) : data_(data) {}
MoveOnly(MoveOnly && x)30     MoveOnly(MoveOnly&& x)
31         : data_(x.data_) {x.data_ = 0;}
operator =(MoveOnly && x)32     MoveOnly& operator=(MoveOnly&& x)
33         {data_ = x.data_; x.data_ = 0; return *this;}
34 
get() const35     int get() const {return data_;}
36 };
37 #endif
38 
39 
40 template <class T>
test()41 void test()
42 {
43     typedef std::reference_wrapper<T> Wrap;
44     static_assert(std::is_copy_constructible<Wrap>::value, "");
45     static_assert(std::is_copy_assignable<Wrap>::value, "");
46     // Extension up for standardization: See N4151.
47     static_assert(std::is_trivially_copyable<Wrap>::value, "");
48 }
49 
main()50 int main()
51 {
52     test<int>();
53     test<double>();
54     test<std::string>();
55 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
56     test<MoveOnly>();
57 #endif
58 }
59