brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 7133310 Raw
78 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++0310 11// <utility>12 13// template <class T1, class T2> struct pair14 15// pair(pair&&) = default;16 17#include <cassert>18#include <memory>19#include <type_traits>20#include <utility>21 22#include "test_macros.h"23 24struct Dummy {25  Dummy(Dummy const&) = delete;26  Dummy(Dummy &&) = default;27};28 29struct NotCopyOrMoveConstructible {30  NotCopyOrMoveConstructible() = default;31  NotCopyOrMoveConstructible(NotCopyOrMoveConstructible const&) = delete;32  NotCopyOrMoveConstructible(NotCopyOrMoveConstructible&&) = delete;33};34 35int main(int, char**)36{37    {38        typedef std::pair<int, short> P1;39        static_assert(std::is_move_constructible<P1>::value, "");40        P1 p1(3, static_cast<short>(4));41        P1 p2 = std::move(p1);42        assert(p2.first == 3);43        assert(p2.second == 4);44    }45    {46        using P = std::pair<Dummy, int>;47        static_assert(!std::is_copy_constructible<P>::value, "");48        static_assert(std::is_move_constructible<P>::value, "");49    }50    {51        // When constructing a pair containing a reference, we only bind the52        // reference, so it doesn't matter whether the type is or isn't53        // copy/move constructible.54        {55            using P = std::pair<NotCopyOrMoveConstructible&, int>;56            static_assert(std::is_move_constructible<P>::value, "");57 58            NotCopyOrMoveConstructible obj;59            P p2{obj, 3};60            P p1(std::move(p2));61            assert(&p1.first == &obj);62            assert(&p2.first == &obj);63        }64        {65            using P = std::pair<NotCopyOrMoveConstructible&&, int>;66            static_assert(std::is_move_constructible<P>::value, "");67 68            NotCopyOrMoveConstructible obj;69            P p2{std::move(obj), 3};70            P p1(std::move(p2));71            assert(&p1.first == &obj);72            assert(&p2.first == &obj);73        }74    }75 76    return 0;77}78