blob: 61e0bfa162d898ca40f518e10ffc71c514e5e2b0 [file] [log] [blame]
Eric Fiselier1de15f52014-11-04 01:54:44 +00001//===----------------------------------------------------------------------===//
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>
Marshall Clow275b6bb2014-11-17 15:04:46 +000019#include <string>
20
21#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
22class MoveOnly
23{
24 MoveOnly(const MoveOnly&);
25 MoveOnly& operator=(const MoveOnly&);
26
27 int data_;
28public:
29 MoveOnly(int data = 1) : data_(data) {}
30 MoveOnly(MoveOnly&& x)
31 : data_(x.data_) {x.data_ = 0;}
32 MoveOnly& operator=(MoveOnly&& x)
33 {data_ = x.data_; x.data_ = 0; return *this;}
34
35 int get() const {return data_;}
36};
37#endif
38
39
40template <class T>
41void 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}
Eric Fiselier1de15f52014-11-04 01:54:44 +000049
50int main()
51{
Marshall Clow275b6bb2014-11-17 15:04:46 +000052 test<int>();
53 test<double>();
54 test<std::string>();
55#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
56 test<MoveOnly>();
57#endif
Eric Fiselier1de15f52014-11-04 01:54:44 +000058}