libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

assign_rv_pair_U_V.pass.cpp (1437B)


      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
     11 
     12 // <utility>
     13 
     14 // template <class T1, class T2> struct pair
     15 
     16 // template<class U, class V> pair& operator=(pair<U, V>&& p);
     17 
     18 #include <utility>
     19 #include <memory>
     20 #include <cassert>
     21 #include <archetypes.hpp>
     22 
     23 struct Base
     24 {
     25     virtual ~Base() {}
     26 };
     27 
     28 struct Derived
     29     : public Base
     30 {
     31 };
     32 
     33 int main()
     34 {
     35     {
     36         typedef std::pair<std::unique_ptr<Derived>, short> P1;
     37         typedef std::pair<std::unique_ptr<Base>, long> P2;
     38         P1 p1(std::unique_ptr<Derived>(), static_cast<short>(4));
     39         P2 p2;
     40         p2 = std::move(p1);
     41         assert(p2.first == nullptr);
     42         assert(p2.second == 4);
     43     }
     44     {
     45        using C = TestTypes::TestType;
     46        using P = std::pair<int, C>;
     47        using T = std::pair<long, C>;
     48        T t(42, -42);
     49        P p(101, 101);
     50        C::reset_constructors();
     51        p = std::move(t);
     52        assert(C::constructed == 0);
     53        assert(C::assigned == 1);
     54        assert(C::copy_assigned == 0);
     55        assert(C::move_assigned == 1);
     56        assert(p.first == 42);
     57        assert(p.second.value == -42);
     58     }
     59 }