summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/20_util/uses_allocator/construction.cc
blob: 51f0dc62d7edc75821b6a1768ef7e3398182417a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// { dg-do run { target c++11 } }

// Copyright (C) 2011-2019 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// 20.6.7.2 uses-allocator construction

#include <memory>
#include <tuple>
#include <testsuite_hooks.h>

struct MyAlloc { };

// type that can't be constructed with an allocator
struct CannotUse
{
  CannotUse(int) : ok(true) { }

  bool ok;
};

// type that can be constructed with an allocator
// but which has uses_allocator == false
struct DoesNotUse
{
  typedef MyAlloc allocator_type;

  DoesNotUse(int) : ok(true) { }
  DoesNotUse(std::allocator_arg_t, MyAlloc, int) : ok(false) { }
  DoesNotUse(int, MyAlloc) : ok(false) { }

  bool ok;
};

namespace std
{
  template<typename A> 
    struct uses_allocator<DoesNotUse, A> : false_type { };
}

// type that can be constructed with an allocator as second argument
struct UsesWithTag
{
  typedef MyAlloc allocator_type;

  UsesWithTag(int) : ok(false) { }
  UsesWithTag(std::allocator_arg_t, MyAlloc, int) : ok(true) { }
  UsesWithTag(int, MyAlloc) : ok(false) {  }

  bool ok;
};

// type that can be constructed with an allocator as last argument
struct UsesWithoutTag
{
  typedef MyAlloc allocator_type;

  UsesWithoutTag(int) : ok(false) { }
  UsesWithoutTag(int, MyAlloc) : ok(true) { }

  bool ok;
};


template<typename TestType, typename... T>
  bool test2(T... args)
  {
    using std::allocator_arg;
    using std::tuple;
    using std::get;

    tuple<TestType, T...> t(allocator_arg, MyAlloc(), 1, args...);

    return get<0>(t).ok;
  }

template<typename... T>
  void test(T... args)
  {
    VERIFY( test2<CannotUse>(args...) );
    VERIFY( test2<DoesNotUse>(args...) );
    VERIFY( test2<UsesWithTag>(args...) );
    VERIFY( test2<UsesWithoutTag>(args...) );
  }

int main()
{
  test();
  test(1);
  test(1, 2);
  return 0;
}