move_if_noexcept.pass.cpp revision bc8d3f97eb5c958007f2713238472e0c1c8fe02c
1//===----------------------------------------------------------------------===//
2//
3// ��������������������The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. 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#ifdef _LIBCPP_MOVE
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#ifdef _LIBCPP_MOVE
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
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
54
55}
56