Eric Fiselier | 1de15f5 | 2014-11-04 01:54:44 +0000 | [diff] [blame] | 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> |
Marshall Clow | 275b6bb | 2014-11-17 15:04:46 +0000 | [diff] [blame] | 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: |
| 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 | |
| 40 | template <class T> |
| 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 | } |
Eric Fiselier | 1de15f5 | 2014-11-04 01:54:44 +0000 | [diff] [blame] | 49 | |
| 50 | int main() |
| 51 | { |
Marshall Clow | 275b6bb | 2014-11-17 15:04:46 +0000 | [diff] [blame] | 52 | test<int>(); |
| 53 | test<double>(); |
| 54 | test<std::string>(); |
| 55 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 56 | test<MoveOnly>(); |
| 57 | #endif |
Eric Fiselier | 1de15f5 | 2014-11-04 01:54:44 +0000 | [diff] [blame] | 58 | } |