OpenCores
URL https://opencores.org/ocsvn/altor32/altor32/trunk

Subversion Repositories altor32

[/] [altor32/] [trunk/] [gcc-x64/] [or1knd-elf/] [or1knd-elf/] [include/] [c++/] [4.8.0/] [ext/] [alloc_traits.h] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 ultra_embe
// Allocator traits -*- C++ -*-
2
 
3
// Copyright (C) 2011-2012 Free Software Foundation, Inc.
4
//
5
// This file is part of the GNU ISO C++ Library.  This library is free
6
// software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 3, or (at your option)
9
// any later version.
10
 
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
 
16
// Under Section 7 of GPL version 3, you are granted additional
17
// permissions described in the GCC Runtime Library Exception, version
18
// 3.1, as published by the Free Software Foundation.
19
 
20
// You should have received a copy of the GNU General Public License and
21
// a copy of the GCC Runtime Library Exception along with this program;
22
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23
// <http://www.gnu.org/licenses/>.
24
 
25
/** @file ext/alloc_traits.h
26
 *  This file is a GNU extension to the Standard C++ Library.
27
 */
28
 
29
#ifndef _EXT_ALLOC_TRAITS_H
30
#define _EXT_ALLOC_TRAITS_H 1
31
 
32
#pragma GCC system_header
33
 
34
#if __cplusplus >= 201103L
35
# include <bits/alloc_traits.h>
36
#else
37
# include <bits/allocator.h>  // for __alloc_swap
38
#endif
39
 
40
namespace std _GLIBCXX_VISIBILITY(default)
41
{
42
_GLIBCXX_BEGIN_NAMESPACE_VERSION
43
  template<typename> struct allocator;
44
_GLIBCXX_END_NAMESPACE_VERSION
45
} // namespace
46
 
47
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
48
{
49
_GLIBCXX_BEGIN_NAMESPACE_VERSION
50
 
51
#if __cplusplus >= 201103L
52
  template<typename _Alloc>
53
    struct __allocator_always_compares_equal
54
    { static const bool value = false; };
55
 
56
  template<typename _Alloc>
57
    const bool __allocator_always_compares_equal<_Alloc>::value;
58
 
59
  template<typename _Tp>
60
    struct __allocator_always_compares_equal<std::allocator<_Tp>>
61
    { static const bool value = true; };
62
 
63
  template<typename _Tp>
64
    const bool __allocator_always_compares_equal<std::allocator<_Tp>>::value;
65
 
66
  template<typename, typename> struct array_allocator;
67
 
68
  template<typename _Tp, typename _Array>
69
    struct __allocator_always_compares_equal<array_allocator<_Tp, _Array>>
70
    { static const bool value = true; };
71
 
72
  template<typename _Tp, typename _Array>
73
    const bool
74
    __allocator_always_compares_equal<array_allocator<_Tp, _Array>>::value;
75
 
76
  template<typename> struct bitmap_allocator;
77
 
78
  template<typename _Tp>
79
    struct __allocator_always_compares_equal<bitmap_allocator<_Tp>>
80
    { static const bool value = true; };
81
 
82
  template<typename _Tp>
83
    const bool __allocator_always_compares_equal<bitmap_allocator<_Tp>>::value;
84
 
85
  template<typename> struct malloc_allocator;
86
 
87
  template<typename _Tp>
88
    struct __allocator_always_compares_equal<malloc_allocator<_Tp>>
89
    { static const bool value = true; };
90
 
91
  template<typename _Tp>
92
    const bool __allocator_always_compares_equal<malloc_allocator<_Tp>>::value;
93
 
94
  template<typename> struct mt_allocator;
95
 
96
  template<typename _Tp>
97
    struct __allocator_always_compares_equal<mt_allocator<_Tp>>
98
    { static const bool value = true; };
99
 
100
  template<typename _Tp>
101
    const bool __allocator_always_compares_equal<mt_allocator<_Tp>>::value;
102
 
103
  template<typename> struct new_allocator;
104
 
105
  template<typename _Tp>
106
    struct __allocator_always_compares_equal<new_allocator<_Tp>>
107
    { static const bool value = true; };
108
 
109
  template<typename _Tp>
110
    const bool __allocator_always_compares_equal<new_allocator<_Tp>>::value;
111
 
112
  template<typename> struct pool_allocator;
113
 
114
  template<typename _Tp>
115
    struct __allocator_always_compares_equal<pool_allocator<_Tp>>
116
    { static const bool value = true; };
117
 
118
  template<typename _Tp>
119
    const bool __allocator_always_compares_equal<pool_allocator<_Tp>>::value;
120
#endif
121
 
122
/**
123
 * @brief  Uniform interface to C++98 and C++0x allocators.
124
 * @ingroup allocators
125
*/
126
template<typename _Alloc>
127
  struct __alloc_traits
128
#if __cplusplus >= 201103L
129
  : std::allocator_traits<_Alloc>
130
#endif
131
  {
132
    typedef _Alloc allocator_type;
133
#if __cplusplus >= 201103L
134
    typedef std::allocator_traits<_Alloc>           _Base_type;
135
    typedef typename _Base_type::value_type         value_type;
136
    typedef typename _Base_type::pointer            pointer;
137
    typedef typename _Base_type::const_pointer      const_pointer;
138
    typedef typename _Base_type::size_type          size_type;
139
    typedef typename _Base_type::difference_type    difference_type;
140
    // C++0x allocators do not define reference or const_reference
141
    typedef value_type&                             reference;
142
    typedef const value_type&                       const_reference;
143
    using _Base_type::allocate;
144
    using _Base_type::deallocate;
145
    using _Base_type::construct;
146
    using _Base_type::destroy;
147
    using _Base_type::max_size;
148
 
149
  private:
150
    template<typename _Ptr>
151
      struct __is_custom_pointer
152
      : std::integral_constant<bool, std::is_same<pointer, _Ptr>::value
153
                                     && !std::is_pointer<_Ptr>::value>
154
      { };
155
 
156
  public:
157
    // overload construct for non-standard pointer types
158
    template<typename _Ptr, typename... _Args>
159
      static typename std::enable_if<__is_custom_pointer<_Ptr>::value>::type
160
      construct(_Alloc& __a, _Ptr __p, _Args&&... __args)
161
      {
162
        _Base_type::construct(__a, std::addressof(*__p),
163
                              std::forward<_Args>(__args)...);
164
      }
165
 
166
    // overload destroy for non-standard pointer types
167
    template<typename _Ptr>
168
      static typename std::enable_if<__is_custom_pointer<_Ptr>::value>::type
169
      destroy(_Alloc& __a, _Ptr __p)
170
      { _Base_type::destroy(__a, std::addressof(*__p)); }
171
 
172
    static _Alloc _S_select_on_copy(const _Alloc& __a)
173
    { return _Base_type::select_on_container_copy_construction(__a); }
174
 
175
    static void _S_on_swap(_Alloc& __a, _Alloc& __b)
176
    { std::__alloc_on_swap(__a, __b); }
177
 
178
    static constexpr bool _S_propagate_on_copy_assign()
179
    { return _Base_type::propagate_on_container_copy_assignment::value; }
180
 
181
    static constexpr bool _S_propagate_on_move_assign()
182
    { return _Base_type::propagate_on_container_move_assignment::value; }
183
 
184
    static constexpr bool _S_propagate_on_swap()
185
    { return _Base_type::propagate_on_container_swap::value; }
186
 
187
    static constexpr bool _S_always_equal()
188
    { return __allocator_always_compares_equal<_Alloc>::value; }
189
 
190
    static constexpr bool _S_nothrow_move()
191
    { return _S_propagate_on_move_assign() || _S_always_equal(); }
192
 
193
    static constexpr bool _S_nothrow_swap()
194
    {
195
      using std::swap;
196
      return !_S_propagate_on_swap()
197
        || noexcept(swap(std::declval<_Alloc&>(), std::declval<_Alloc&>()));
198
    }
199
 
200
    template<typename _Tp>
201
      struct rebind
202
      { typedef typename _Base_type::template rebind_alloc<_Tp> other; };
203
#else
204
 
205
    typedef typename _Alloc::pointer                pointer;
206
    typedef typename _Alloc::const_pointer          const_pointer;
207
    typedef typename _Alloc::value_type             value_type;
208
    typedef typename _Alloc::reference              reference;
209
    typedef typename _Alloc::const_reference        const_reference;
210
    typedef typename _Alloc::size_type              size_type;
211
    typedef typename _Alloc::difference_type        difference_type;
212
 
213
    static pointer
214
    allocate(_Alloc& __a, size_type __n)
215
    { return __a.allocate(__n); }
216
 
217
    static void deallocate(_Alloc& __a, pointer __p, size_type __n)
218
    { __a.deallocate(__p, __n); }
219
 
220
    template<typename _Tp>
221
      static void construct(_Alloc& __a, pointer __p, const _Tp& __arg)
222
      { __a.construct(__p, __arg); }
223
 
224
    static void destroy(_Alloc& __a, pointer __p)
225
    { __a.destroy(__p); }
226
 
227
    static size_type max_size(const _Alloc& __a)
228
    { return __a.max_size(); }
229
 
230
    static const _Alloc& _S_select_on_copy(const _Alloc& __a) { return __a; }
231
 
232
    static void _S_on_swap(_Alloc& __a, _Alloc& __b)
233
    {
234
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
235
      // 431. Swapping containers with unequal allocators.
236
      std::__alloc_swap<_Alloc>::_S_do_it(__a, __b);
237
    }
238
 
239
    template<typename _Tp>
240
      struct rebind
241
      { typedef typename _Alloc::template rebind<_Tp>::other other; };
242
#endif
243
  };
244
 
245
_GLIBCXX_END_NAMESPACE_VERSION
246
} // namespace
247
 
248
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.