summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/20_util/allocator_traits/requirements/typedefs2.cc
blob: 308463c0e54d5786072a0f82e4a336498d4f2282 (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
// { dg-options "-std=gnu++11" }
//
// Copyright (C) 2013-2016 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/>.

#include <memory>
#include <testsuite_allocator.h>

// { dg-do compile }

template<typename T>
struct ptr
{
  ptr() = default;
  template<typename U>
    ptr(ptr<U> const& p) { }
};

// This doesn't meet the allocator requirements, it's only to check
// that allocator_traits finds the right nested types.
template<typename T>
struct alloc
{
  typedef T value_type;

  typedef ptr<T> pointer;
  typedef ptr<const T> const_pointer;
  typedef ptr<void> void_pointer;
  typedef ptr<const void> const_void_pointer;
  typedef int difference_type;
  typedef int size_type;

  typedef std::false_type propagate_on_container_copy_assignment;
  typedef std::false_type propagate_on_container_move_assignment;
  typedef std::false_type propagate_on_container_swap;
};

typedef alloc<int> alloc_type;
typedef std::allocator_traits<alloc_type> traits;

using std::is_same;

static_assert( is_same<traits::pointer, alloc_type::pointer>::value,
               "pointer" );

static_assert( is_same<traits::const_pointer,
                       alloc_type::const_pointer>::value,
               "const_pointer" );

static_assert( is_same<traits::void_pointer, alloc_type::void_pointer>::value,
               "void_pointer" );

static_assert( is_same<traits::const_void_pointer,
                       alloc_type::const_void_pointer>::value,
               "const_void_pointer");

static_assert( is_same<traits::difference_type,
                       alloc_type::difference_type>::value,
               "difference_type" );

static_assert( is_same<traits::size_type, alloc_type::size_type>::value,
               "size_type" );

static_assert( is_same<traits::size_type, alloc_type::size_type>::value,
               "size_type" );

static_assert( is_same<traits::propagate_on_container_copy_assignment,
                       alloc_type::propagate_on_container_copy_assignment
                      >::value,
               "propagate_on_container_copy_assignment" );

static_assert( is_same<traits::propagate_on_container_move_assignment,
                       alloc_type::propagate_on_container_move_assignment
                      >::value,
               "propagate_on_container_move_assignment" );

static_assert( is_same<traits::propagate_on_container_swap,
                       alloc_type::propagate_on_container_swap>::value,
               "propagate_on_container_swap" );