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/] [debug/] [set.h] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 ultra_embe
// Debugging set implementation -*- C++ -*-
2
 
3
// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4
// Free Software Foundation, Inc.
5
//
6
// This file is part of the GNU ISO C++ Library.  This library is free
7
// software; you can redistribute it and/or modify it under the
8
// terms of the GNU General Public License as published by the
9
// Free Software Foundation; either version 3, or (at your option)
10
// any later version.
11
 
12
// This library is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
// GNU General Public License for more details.
16
 
17
// Under Section 7 of GPL version 3, you are granted additional
18
// permissions described in the GCC Runtime Library Exception, version
19
// 3.1, as published by the Free Software Foundation.
20
 
21
// You should have received a copy of the GNU General Public License and
22
// a copy of the GCC Runtime Library Exception along with this program;
23
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24
// <http://www.gnu.org/licenses/>.
25
 
26
/** @file debug/set.h
27
 *  This file is a GNU debug extension to the Standard C++ Library.
28
 */
29
 
30
#ifndef _GLIBCXX_DEBUG_SET_H
31
#define _GLIBCXX_DEBUG_SET_H 1
32
 
33
#include <debug/safe_sequence.h>
34
#include <debug/safe_iterator.h>
35
#include <utility>
36
 
37
namespace std _GLIBCXX_VISIBILITY(default)
38
{
39
namespace __debug
40
{
41
  /// Class std::set with safety/checking/debug instrumentation.
42
  template<typename _Key, typename _Compare = std::less<_Key>,
43
           typename _Allocator = std::allocator<_Key> >
44
    class set
45
    : public _GLIBCXX_STD_C::set<_Key,_Compare,_Allocator>,
46
      public __gnu_debug::_Safe_sequence<set<_Key, _Compare, _Allocator> >
47
    {
48
      typedef _GLIBCXX_STD_C::set<_Key, _Compare, _Allocator> _Base;
49
 
50
      typedef typename _Base::const_iterator _Base_const_iterator;
51
      typedef typename _Base::iterator _Base_iterator;
52
      typedef __gnu_debug::_Equal_to<_Base_const_iterator> _Equal;
53
    public:
54
      // types:
55
      typedef _Key                                  key_type;
56
      typedef _Key                                  value_type;
57
      typedef _Compare                              key_compare;
58
      typedef _Compare                              value_compare;
59
      typedef _Allocator                            allocator_type;
60
      typedef typename _Base::reference             reference;
61
      typedef typename _Base::const_reference       const_reference;
62
 
63
      typedef __gnu_debug::_Safe_iterator<_Base_iterator, set>
64
                                                    iterator;
65
      typedef __gnu_debug::_Safe_iterator<_Base_const_iterator, set>
66
                                                    const_iterator;
67
 
68
      typedef typename _Base::size_type             size_type;
69
      typedef typename _Base::difference_type       difference_type;
70
      typedef typename _Base::pointer               pointer;
71
      typedef typename _Base::const_pointer         const_pointer;
72
      typedef std::reverse_iterator<iterator>       reverse_iterator;
73
      typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
74
 
75
      // 23.3.3.1 construct/copy/destroy:
76
      explicit set(const _Compare& __comp = _Compare(),
77
                   const _Allocator& __a = _Allocator())
78
      : _Base(__comp, __a) { }
79
 
80
      template<typename _InputIterator>
81
        set(_InputIterator __first, _InputIterator __last,
82
            const _Compare& __comp = _Compare(),
83
            const _Allocator& __a = _Allocator())
84
        : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
85
                                                                     __last)),
86
                __gnu_debug::__base(__last),
87
                __comp, __a) { }
88
 
89
      set(const set& __x)
90
      : _Base(__x) { }
91
 
92
      set(const _Base& __x)
93
      : _Base(__x) { }
94
 
95
#if __cplusplus >= 201103L
96
      set(set&& __x)
97
      noexcept(is_nothrow_copy_constructible<_Compare>::value)
98
      : _Base(std::move(__x))
99
      { this->_M_swap(__x); }
100
 
101
      set(initializer_list<value_type> __l,
102
          const _Compare& __comp = _Compare(),
103
          const allocator_type& __a = allocator_type())
104
      : _Base(__l, __comp, __a) { }
105
#endif
106
 
107
      ~set() _GLIBCXX_NOEXCEPT { }
108
 
109
      set&
110
      operator=(const set& __x)
111
      {
112
        *static_cast<_Base*>(this) = __x;
113
        this->_M_invalidate_all();
114
        return *this;
115
      }
116
 
117
#if __cplusplus >= 201103L
118
      set&
119
      operator=(set&& __x)
120
      {
121
        // NB: DR 1204.
122
        // NB: DR 675.
123
        __glibcxx_check_self_move_assign(__x);
124
        clear();
125
        swap(__x);
126
        return *this;
127
      }
128
 
129
      set&
130
      operator=(initializer_list<value_type> __l)
131
      {
132
        this->clear();
133
        this->insert(__l);
134
        return *this;
135
      }
136
#endif
137
 
138
      using _Base::get_allocator;
139
 
140
      // iterators:
141
      iterator
142
      begin() _GLIBCXX_NOEXCEPT
143
      { return iterator(_Base::begin(), this); }
144
 
145
      const_iterator
146
      begin() const _GLIBCXX_NOEXCEPT
147
      { return const_iterator(_Base::begin(), this); }
148
 
149
      iterator
150
      end() _GLIBCXX_NOEXCEPT
151
      { return iterator(_Base::end(), this); }
152
 
153
      const_iterator
154
      end() const _GLIBCXX_NOEXCEPT
155
      { return const_iterator(_Base::end(), this); }
156
 
157
      reverse_iterator
158
      rbegin() _GLIBCXX_NOEXCEPT
159
      { return reverse_iterator(end()); }
160
 
161
      const_reverse_iterator
162
      rbegin() const _GLIBCXX_NOEXCEPT
163
      { return const_reverse_iterator(end()); }
164
 
165
      reverse_iterator
166
      rend() _GLIBCXX_NOEXCEPT
167
      { return reverse_iterator(begin()); }
168
 
169
      const_reverse_iterator
170
      rend() const _GLIBCXX_NOEXCEPT
171
      { return const_reverse_iterator(begin()); }
172
 
173
#if __cplusplus >= 201103L
174
      const_iterator
175
      cbegin() const noexcept
176
      { return const_iterator(_Base::begin(), this); }
177
 
178
      const_iterator
179
      cend() const noexcept
180
      { return const_iterator(_Base::end(), this); }
181
 
182
      const_reverse_iterator
183
      crbegin() const noexcept
184
      { return const_reverse_iterator(end()); }
185
 
186
      const_reverse_iterator
187
      crend() const noexcept
188
      { return const_reverse_iterator(begin()); }
189
#endif
190
 
191
      // capacity:
192
      using _Base::empty;
193
      using _Base::size;
194
      using _Base::max_size;
195
 
196
      // modifiers:
197
#if __cplusplus >= 201103L
198
      template<typename... _Args>
199
        std::pair<iterator, bool>
200
        emplace(_Args&&... __args)
201
        {
202
          auto __res = _Base::emplace(std::forward<_Args>(__args)...);
203
          return std::pair<iterator, bool>(iterator(__res.first, this),
204
                                           __res.second);
205
        }
206
 
207
      template<typename... _Args>
208
        iterator
209
        emplace_hint(const_iterator __pos, _Args&&... __args)
210
        {
211
          __glibcxx_check_insert(__pos);
212
          return iterator(_Base::emplace_hint(__pos.base(),
213
                                              std::forward<_Args>(__args)...),
214
                          this);
215
        }
216
#endif
217
 
218
      std::pair<iterator, bool>
219
      insert(const value_type& __x)
220
      {
221
        std::pair<_Base_iterator, bool> __res = _Base::insert(__x);
222
        return std::pair<iterator, bool>(iterator(__res.first, this),
223
                                         __res.second);
224
      }
225
 
226
#if __cplusplus >= 201103L
227
      std::pair<iterator, bool>
228
      insert(value_type&& __x)
229
      {
230
        std::pair<_Base_iterator, bool> __res
231
          = _Base::insert(std::move(__x));
232
        return std::pair<iterator, bool>(iterator(__res.first, this),
233
                                         __res.second);
234
      }
235
#endif
236
 
237
      iterator
238
      insert(const_iterator __position, const value_type& __x)
239
      {
240
        __glibcxx_check_insert(__position);
241
        return iterator(_Base::insert(__position.base(), __x), this);
242
      }
243
 
244
#if __cplusplus >= 201103L
245
      iterator
246
      insert(const_iterator __position, value_type&& __x)
247
      {
248
        __glibcxx_check_insert(__position);
249
        return iterator(_Base::insert(__position.base(), std::move(__x)),
250
                        this);
251
      }
252
#endif
253
 
254
      template <typename _InputIterator>
255
        void
256
        insert(_InputIterator __first, _InputIterator __last)
257
        {
258
          __glibcxx_check_valid_range(__first, __last);
259
          _Base::insert(__gnu_debug::__base(__first),
260
                        __gnu_debug::__base(__last));
261
        }
262
 
263
#if __cplusplus >= 201103L
264
      void
265
      insert(initializer_list<value_type> __l)
266
      { _Base::insert(__l); }
267
#endif
268
 
269
#if __cplusplus >= 201103L
270
      iterator
271
      erase(const_iterator __position)
272
      {
273
        __glibcxx_check_erase(__position);
274
        this->_M_invalidate_if(_Equal(__position.base()));
275
        return iterator(_Base::erase(__position.base()), this);
276
      }
277
#else
278
      void
279
      erase(iterator __position)
280
      {
281
        __glibcxx_check_erase(__position);
282
        this->_M_invalidate_if(_Equal(__position.base()));
283
        _Base::erase(__position.base());
284
      }
285
#endif
286
 
287
      size_type
288
      erase(const key_type& __x)
289
      {
290
        _Base_iterator __victim = _Base::find(__x);
291
        if (__victim == _Base::end())
292
          return 0;
293
        else
294
          {
295
            this->_M_invalidate_if(_Equal(__victim));
296
            _Base::erase(__victim);
297
            return 1;
298
          }
299
      }
300
 
301
#if __cplusplus >= 201103L
302
      iterator
303
      erase(const_iterator __first, const_iterator __last)
304
      {
305
        // _GLIBCXX_RESOLVE_LIB_DEFECTS
306
        // 151. can't currently clear() empty container
307
        __glibcxx_check_erase_range(__first, __last);
308
        for (_Base_const_iterator __victim = __first.base();
309
             __victim != __last.base(); ++__victim)
310
          {
311
            _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
312
                                  _M_message(__gnu_debug::__msg_valid_range)
313
                                  ._M_iterator(__first, "first")
314
                                  ._M_iterator(__last, "last"));
315
            this->_M_invalidate_if(_Equal(__victim));
316
          }
317
        return iterator(_Base::erase(__first.base(), __last.base()), this);
318
      }
319
#else
320
      void
321
      erase(iterator __first, iterator __last)
322
      {
323
        // _GLIBCXX_RESOLVE_LIB_DEFECTS
324
        // 151. can't currently clear() empty container
325
        __glibcxx_check_erase_range(__first, __last);
326
        for (_Base_iterator __victim = __first.base();
327
             __victim != __last.base(); ++__victim)
328
          {
329
            _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(),
330
                                  _M_message(__gnu_debug::__msg_valid_range)
331
                                  ._M_iterator(__first, "first")
332
                                  ._M_iterator(__last, "last"));
333
            this->_M_invalidate_if(_Equal(__victim));
334
          }
335
        _Base::erase(__first.base(), __last.base());
336
      }
337
#endif
338
 
339
      void
340
      swap(set& __x)
341
      {
342
        _Base::swap(__x);
343
        this->_M_swap(__x);
344
      }
345
 
346
      void
347
      clear() _GLIBCXX_NOEXCEPT
348
      {
349
        this->_M_invalidate_all();
350
        _Base::clear();
351
      }
352
 
353
      // observers:
354
      using _Base::key_comp;
355
      using _Base::value_comp;
356
 
357
      // set operations:
358
      iterator
359
      find(const key_type& __x)
360
      { return iterator(_Base::find(__x), this); }
361
 
362
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
363
      // 214. set::find() missing const overload
364
      const_iterator
365
      find(const key_type& __x) const
366
      { return const_iterator(_Base::find(__x), this); }
367
 
368
      using _Base::count;
369
 
370
      iterator
371
      lower_bound(const key_type& __x)
372
      { return iterator(_Base::lower_bound(__x), this); }
373
 
374
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
375
      // 214. set::find() missing const overload
376
      const_iterator
377
      lower_bound(const key_type& __x) const
378
      { return const_iterator(_Base::lower_bound(__x), this); }
379
 
380
      iterator
381
      upper_bound(const key_type& __x)
382
      { return iterator(_Base::upper_bound(__x), this); }
383
 
384
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
385
      // 214. set::find() missing const overload
386
      const_iterator
387
      upper_bound(const key_type& __x) const
388
      { return const_iterator(_Base::upper_bound(__x), this); }
389
 
390
      std::pair<iterator,iterator>
391
      equal_range(const key_type& __x)
392
      {
393
        std::pair<_Base_iterator, _Base_iterator> __res =
394
        _Base::equal_range(__x);
395
        return std::make_pair(iterator(__res.first, this),
396
                              iterator(__res.second, this));
397
      }
398
 
399
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
400
      // 214. set::find() missing const overload
401
      std::pair<const_iterator,const_iterator>
402
      equal_range(const key_type& __x) const
403
      {
404
        std::pair<_Base_iterator, _Base_iterator> __res =
405
        _Base::equal_range(__x);
406
        return std::make_pair(const_iterator(__res.first, this),
407
                              const_iterator(__res.second, this));
408
      }
409
 
410
      _Base&
411
      _M_base() _GLIBCXX_NOEXCEPT       { return *this; }
412
 
413
      const _Base&
414
      _M_base() const _GLIBCXX_NOEXCEPT { return *this; }
415
 
416
    private:
417
      void
418
      _M_invalidate_all()
419
      {
420
        typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
421
        this->_M_invalidate_if(_Not_equal(_M_base().end()));
422
      }
423
    };
424
 
425
  template<typename _Key, typename _Compare, typename _Allocator>
426
    inline bool
427
    operator==(const set<_Key, _Compare, _Allocator>& __lhs,
428
               const set<_Key, _Compare, _Allocator>& __rhs)
429
    { return __lhs._M_base() == __rhs._M_base(); }
430
 
431
  template<typename _Key, typename _Compare, typename _Allocator>
432
    inline bool
433
    operator!=(const set<_Key, _Compare, _Allocator>& __lhs,
434
               const set<_Key, _Compare, _Allocator>& __rhs)
435
    { return __lhs._M_base() != __rhs._M_base(); }
436
 
437
  template<typename _Key, typename _Compare, typename _Allocator>
438
    inline bool
439
    operator<(const set<_Key, _Compare, _Allocator>& __lhs,
440
              const set<_Key, _Compare, _Allocator>& __rhs)
441
    { return __lhs._M_base() < __rhs._M_base(); }
442
 
443
  template<typename _Key, typename _Compare, typename _Allocator>
444
    inline bool
445
    operator<=(const set<_Key, _Compare, _Allocator>& __lhs,
446
               const set<_Key, _Compare, _Allocator>& __rhs)
447
    { return __lhs._M_base() <= __rhs._M_base(); }
448
 
449
  template<typename _Key, typename _Compare, typename _Allocator>
450
    inline bool
451
    operator>=(const set<_Key, _Compare, _Allocator>& __lhs,
452
               const set<_Key, _Compare, _Allocator>& __rhs)
453
    { return __lhs._M_base() >= __rhs._M_base(); }
454
 
455
  template<typename _Key, typename _Compare, typename _Allocator>
456
    inline bool
457
    operator>(const set<_Key, _Compare, _Allocator>& __lhs,
458
              const set<_Key, _Compare, _Allocator>& __rhs)
459
    { return __lhs._M_base() > __rhs._M_base(); }
460
 
461
  template<typename _Key, typename _Compare, typename _Allocator>
462
    void
463
    swap(set<_Key, _Compare, _Allocator>& __x,
464
         set<_Key, _Compare, _Allocator>& __y)
465
    { return __x.swap(__y); }
466
 
467
} // namespace __debug
468
} // namespace std
469
 
470
#endif

powered by: WebSVN 2.1.0

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