move_if_noexcept.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
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// <utility>
11
12// template <class T>
13//     typename conditional
14//     <
15//         !has_nothrow_move_constructor<T>::value && has_copy_constructor<T>::value,
16//         const T&,
17//         T&&
18//     >::type
19//     move_if_noexcept(T& x);
20
21#include <utility>
22
23class A
24{
25    A(const A&);
26    A& operator=(const A&);
27public:
28
29    A() {}
30#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
31    A(A&&) {}
32#endif
33};
34
35int main()
36{
37    int i = 0;
38    const int ci = 0;
39
40    A a;
41    const A ca;
42
43#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
44    static_assert((std::is_same<decltype(std::move_if_noexcept(i)), int&&>::value), "");
45    static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int&&>::value), "");
46    static_assert((std::is_same<decltype(std::move_if_noexcept(a)), const A&>::value), "");
47    static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A&>::value), "");
48#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
49    static_assert((std::is_same<decltype(std::move_if_noexcept(i)), const int>::value), "");
50    static_assert((std::is_same<decltype(std::move_if_noexcept(ci)), const int>::value), "");
51    static_assert((std::is_same<decltype(std::move_if_noexcept(a)), const A>::value), "");
52    static_assert((std::is_same<decltype(std::move_if_noexcept(ca)), const A>::value), "");
53#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
54
55}
56