Home | History | Annotate | Download | only in meta.unary.prop
      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 // UNSUPPORTED: c++98, c++03, c++11, c++14
     11 
     12 // type_traits
     13 
     14 // is_swappable
     15 
     16 #include <type_traits>
     17 #include <utility>
     18 #include <vector>
     19 #include "test_macros.h"
     20 
     21 namespace MyNS {
     22 
     23 // Make the test types non-copyable so that generic std::swap is not valid.
     24 struct A {
     25   A(A const&) = delete;
     26   A& operator=(A const&) = delete;
     27 };
     28 
     29 struct B {
     30   B(B const&) = delete;
     31   B& operator=(B const&) = delete;
     32 };
     33 
     34 struct C {};
     35 struct D {};
     36 
     37 void swap(A&, A&) {}
     38 
     39 void swap(A&, B&) {}
     40 void swap(B&, A&) {}
     41 
     42 void swap(A&, C&) {} // missing swap(C, A)
     43 void swap(D&, C&) {}
     44 
     45 struct M {
     46   M(M const&) = delete;
     47   M& operator=(M const&) = delete;
     48 };
     49 
     50 void swap(M&&, M&&) {}
     51 
     52 } // namespace MyNS
     53 
     54 int main()
     55 {
     56     using namespace MyNS;
     57     {
     58         // Test that is_swappable applies an lvalue reference to the type.
     59         static_assert(std::is_swappable<A>::value, "");
     60         static_assert(std::is_swappable<A&>::value, "");
     61         static_assert(!std::is_swappable<M>::value, "");
     62         static_assert(!std::is_swappable<M&&>::value, "");
     63     }
     64     static_assert(!std::is_swappable<B>::value, "");
     65     static_assert(std::is_swappable<C>::value, "");
     66     {
     67         // test non-referencable types
     68         static_assert(!std::is_swappable<void>::value, "");
     69         static_assert(!std::is_swappable<int() const>::value, "");
     70         static_assert(!std::is_swappable<int() &>::value, "");
     71     }
     72     {
     73         // test for presense of is_swappable_v
     74         static_assert(std::is_swappable_v<int>);
     75         static_assert(!std::is_swappable_v<M>);
     76     }
     77 }
     78