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// Test fails due to use of is_trivially_* trait.
18// XFAIL: gcc-4.9
19
20#include <functional>
21#include <type_traits>
22#include <string>
23
24#include "test_macros.h"
25
26#if TEST_STD_VER >= 11
27class MoveOnly
28{
29    MoveOnly(const MoveOnly&);
30    MoveOnly& operator=(const MoveOnly&);
31
32    int data_;
33public:
34    MoveOnly(int data = 1) : data_(data) {}
35    MoveOnly(MoveOnly&& x)
36        : data_(x.data_) {x.data_ = 0;}
37    MoveOnly& operator=(MoveOnly&& x)
38        {data_ = x.data_; x.data_ = 0; return *this;}
39
40    int get() const {return data_;}
41};
42#endif
43
44
45template <class T>
46void test()
47{
48    typedef std::reference_wrapper<T> Wrap;
49    static_assert(std::is_copy_constructible<Wrap>::value, "");
50    static_assert(std::is_copy_assignable<Wrap>::value, "");
51    // Extension up for standardization: See N4151.
52    static_assert(std::is_trivially_copyable<Wrap>::value, "");
53}
54
55int main()
56{
57    test<int>();
58    test<double>();
59    test<std::string>();
60#if TEST_STD_VER >= 11
61    test<MoveOnly>();
62#endif
63}
64