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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// REQUIRES: c++03
10
11// <utility>
12
13// template <class T1, class T2> struct pair
14
15// pair& operator=(pair const& p);
16
17#include <utility>
18#include <memory>
19#include <cassert>
20
21#include "test_macros.h"
22
23struct NonAssignable {
24 NonAssignable() {}
25private:
26 NonAssignable& operator=(NonAssignable const&);
27};
28
29struct Incomplete;
30extern Incomplete inc_obj;
31
32struct ConstructibleFromInt {
33 ConstructibleFromInt() : value(-1) { }
34 explicit ConstructibleFromInt(int v) : value(v) { }
35 int value;
36};
37
38int main(int, char**)
39{
40 {
41 // Test that we don't constrain the assignment operator in C++03 mode.
42 // Since we don't have access control SFINAE having pair evaluate SFINAE
43 // may cause a hard error.
44 typedef std::pair<int, NonAssignable> P;
45 static_assert(std::is_copy_assignable<P>::value, "");
46 }
47 {
48 typedef std::pair<int, Incomplete&> P;
49 static_assert(std::is_copy_assignable<P>::value, "");
50 P p(42, inc_obj);
51 assert(&p.second == &inc_obj);
52 }
53 {
54 // The type is constructible from int, but not assignable from int.
55 // This ensures that operator=(pair const&) can be used in conjunction with
56 // pair(pair<U, V> const&) to mimic operator=(pair<U, V> const&) in C++03.
57 // This is weird but valid in C++03.
58 std::pair<ConstructibleFromInt, char> p;
59 std::pair<int, char> from(11, 'x');
60 p = from;
61 assert(p.first.value == 11);
62 assert(p.second == 'x');
63 }
64
65 return 0;
66}
67
68struct Incomplete {};
69Incomplete inc_obj;
70

source code of libcxx/test/std/utilities/utility/pairs/pairs.pair/assign_pair_cxx03.pass.cpp