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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 ultra_embe
// Map implementation -*- C++ -*-
2
 
3
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4
// 2011, 2012 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
/*
27
 *
28
 * Copyright (c) 1994
29
 * Hewlett-Packard Company
30
 *
31
 * Permission to use, copy, modify, distribute and sell this software
32
 * and its documentation for any purpose is hereby granted without fee,
33
 * provided that the above copyright notice appear in all copies and
34
 * that both that copyright notice and this permission notice appear
35
 * in supporting documentation.  Hewlett-Packard Company makes no
36
 * representations about the suitability of this software for any
37
 * purpose.  It is provided "as is" without express or implied warranty.
38
 *
39
 *
40
 * Copyright (c) 1996,1997
41
 * Silicon Graphics Computer Systems, Inc.
42
 *
43
 * Permission to use, copy, modify, distribute and sell this software
44
 * and its documentation for any purpose is hereby granted without fee,
45
 * provided that the above copyright notice appear in all copies and
46
 * that both that copyright notice and this permission notice appear
47
 * in supporting documentation.  Silicon Graphics makes no
48
 * representations about the suitability of this software for any
49
 * purpose.  It is provided "as is" without express or implied warranty.
50
 */
51
 
52
/** @file bits/stl_map.h
53
 *  This is an internal header file, included by other library headers.
54
 *  Do not attempt to use it directly. @headername{map}
55
 */
56
 
57
#ifndef _STL_MAP_H
58
#define _STL_MAP_H 1
59
 
60
#include <bits/functexcept.h>
61
#include <bits/concept_check.h>
62
#if __cplusplus >= 201103L
63
#include <initializer_list>
64
#include <tuple>
65
#endif
66
 
67
namespace std _GLIBCXX_VISIBILITY(default)
68
{
69
_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
70
 
71
  /**
72
   *  @brief A standard container made up of (key,value) pairs, which can be
73
   *  retrieved based on a key, in logarithmic time.
74
   *
75
   *  @ingroup associative_containers
76
   *
77
   *  @tparam _Key  Type of key objects.
78
   *  @tparam  _Tp  Type of mapped objects.
79
   *  @tparam _Compare  Comparison function object type, defaults to less<_Key>.
80
   *  @tparam _Alloc  Allocator type, defaults to
81
   *                  allocator<pair<const _Key, _Tp>.
82
   *
83
   *  Meets the requirements of a <a href="tables.html#65">container</a>, a
84
   *  <a href="tables.html#66">reversible container</a>, and an
85
   *  <a href="tables.html#69">associative container</a> (using unique keys).
86
   *  For a @c map<Key,T> the key_type is Key, the mapped_type is T, and the
87
   *  value_type is std::pair<const Key,T>.
88
   *
89
   *  Maps support bidirectional iterators.
90
   *
91
   *  The private tree data is declared exactly the same way for map and
92
   *  multimap; the distinction is made entirely in how the tree functions are
93
   *  called (*_unique versus *_equal, same as the standard).
94
  */
95
  template <typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
96
            typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
97
    class map
98
    {
99
    public:
100
      typedef _Key                                          key_type;
101
      typedef _Tp                                           mapped_type;
102
      typedef std::pair<const _Key, _Tp>                    value_type;
103
      typedef _Compare                                      key_compare;
104
      typedef _Alloc                                        allocator_type;
105
 
106
    private:
107
      // concept requirements
108
      typedef typename _Alloc::value_type                   _Alloc_value_type;
109
      __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
110
      __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
111
                                _BinaryFunctionConcept)
112
      __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept)
113
 
114
    public:
115
      class value_compare
116
      : public std::binary_function<value_type, value_type, bool>
117
      {
118
        friend class map<_Key, _Tp, _Compare, _Alloc>;
119
      protected:
120
        _Compare comp;
121
 
122
        value_compare(_Compare __c)
123
        : comp(__c) { }
124
 
125
      public:
126
        bool operator()(const value_type& __x, const value_type& __y) const
127
        { return comp(__x.first, __y.first); }
128
      };
129
 
130
    private:
131
      /// This turns a red-black tree into a [multi]map. 
132
      typedef typename _Alloc::template rebind<value_type>::other
133
        _Pair_alloc_type;
134
 
135
      typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
136
                       key_compare, _Pair_alloc_type> _Rep_type;
137
 
138
      /// The actual tree structure.
139
      _Rep_type _M_t;
140
 
141
    public:
142
      // many of these are specified differently in ISO, but the following are
143
      // "functionally equivalent"
144
      typedef typename _Pair_alloc_type::pointer         pointer;
145
      typedef typename _Pair_alloc_type::const_pointer   const_pointer;
146
      typedef typename _Pair_alloc_type::reference       reference;
147
      typedef typename _Pair_alloc_type::const_reference const_reference;
148
      typedef typename _Rep_type::iterator               iterator;
149
      typedef typename _Rep_type::const_iterator         const_iterator;
150
      typedef typename _Rep_type::size_type              size_type;
151
      typedef typename _Rep_type::difference_type        difference_type;
152
      typedef typename _Rep_type::reverse_iterator       reverse_iterator;
153
      typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
154
 
155
      // [23.3.1.1] construct/copy/destroy
156
      // (get_allocator() is normally listed in this section, but seems to have
157
      // been accidentally omitted in the printed standard)
158
      /**
159
       *  @brief  Default constructor creates no elements.
160
       */
161
      map()
162
      : _M_t() { }
163
 
164
      /**
165
       *  @brief  Creates a %map with no elements.
166
       *  @param  __comp  A comparison object.
167
       *  @param  __a  An allocator object.
168
       */
169
      explicit
170
      map(const _Compare& __comp,
171
          const allocator_type& __a = allocator_type())
172
      : _M_t(__comp, _Pair_alloc_type(__a)) { }
173
 
174
      /**
175
       *  @brief  %Map copy constructor.
176
       *  @param  __x  A %map of identical element and allocator types.
177
       *
178
       *  The newly-created %map uses a copy of the allocation object
179
       *  used by @a __x.
180
       */
181
      map(const map& __x)
182
      : _M_t(__x._M_t) { }
183
 
184
#if __cplusplus >= 201103L
185
      /**
186
       *  @brief  %Map move constructor.
187
       *  @param  __x  A %map of identical element and allocator types.
188
       *
189
       *  The newly-created %map contains the exact contents of @a __x.
190
       *  The contents of @a __x are a valid, but unspecified %map.
191
       */
192
      map(map&& __x)
193
      noexcept(is_nothrow_copy_constructible<_Compare>::value)
194
      : _M_t(std::move(__x._M_t)) { }
195
 
196
      /**
197
       *  @brief  Builds a %map from an initializer_list.
198
       *  @param  __l  An initializer_list.
199
       *  @param  __comp  A comparison object.
200
       *  @param  __a  An allocator object.
201
       *
202
       *  Create a %map consisting of copies of the elements in the
203
       *  initializer_list @a __l.
204
       *  This is linear in N if the range is already sorted, and NlogN
205
       *  otherwise (where N is @a __l.size()).
206
       */
207
      map(initializer_list<value_type> __l,
208
          const _Compare& __comp = _Compare(),
209
          const allocator_type& __a = allocator_type())
210
      : _M_t(__comp, _Pair_alloc_type(__a))
211
      { _M_t._M_insert_unique(__l.begin(), __l.end()); }
212
#endif
213
 
214
      /**
215
       *  @brief  Builds a %map from a range.
216
       *  @param  __first  An input iterator.
217
       *  @param  __last  An input iterator.
218
       *
219
       *  Create a %map consisting of copies of the elements from
220
       *  [__first,__last).  This is linear in N if the range is
221
       *  already sorted, and NlogN otherwise (where N is
222
       *  distance(__first,__last)).
223
       */
224
      template<typename _InputIterator>
225
        map(_InputIterator __first, _InputIterator __last)
226
        : _M_t()
227
        { _M_t._M_insert_unique(__first, __last); }
228
 
229
      /**
230
       *  @brief  Builds a %map from a range.
231
       *  @param  __first  An input iterator.
232
       *  @param  __last  An input iterator.
233
       *  @param  __comp  A comparison functor.
234
       *  @param  __a  An allocator object.
235
       *
236
       *  Create a %map consisting of copies of the elements from
237
       *  [__first,__last).  This is linear in N if the range is
238
       *  already sorted, and NlogN otherwise (where N is
239
       *  distance(__first,__last)).
240
       */
241
      template<typename _InputIterator>
242
        map(_InputIterator __first, _InputIterator __last,
243
            const _Compare& __comp,
244
            const allocator_type& __a = allocator_type())
245
        : _M_t(__comp, _Pair_alloc_type(__a))
246
        { _M_t._M_insert_unique(__first, __last); }
247
 
248
      // FIXME There is no dtor declared, but we should have something
249
      // generated by Doxygen.  I don't know what tags to add to this
250
      // paragraph to make that happen:
251
      /**
252
       *  The dtor only erases the elements, and note that if the elements
253
       *  themselves are pointers, the pointed-to memory is not touched in any
254
       *  way.  Managing the pointer is the user's responsibility.
255
       */
256
 
257
      /**
258
       *  @brief  %Map assignment operator.
259
       *  @param  __x  A %map of identical element and allocator types.
260
       *
261
       *  All the elements of @a __x are copied, but unlike the copy
262
       *  constructor, the allocator object is not copied.
263
       */
264
      map&
265
      operator=(const map& __x)
266
      {
267
        _M_t = __x._M_t;
268
        return *this;
269
      }
270
 
271
#if __cplusplus >= 201103L
272
      /**
273
       *  @brief  %Map move assignment operator.
274
       *  @param  __x  A %map of identical element and allocator types.
275
       *
276
       *  The contents of @a __x are moved into this map (without copying).
277
       *  @a __x is a valid, but unspecified %map.
278
       */
279
      map&
280
      operator=(map&& __x)
281
      {
282
        // NB: DR 1204.
283
        // NB: DR 675.
284
        this->clear();
285
        this->swap(__x);
286
        return *this;
287
      }
288
 
289
      /**
290
       *  @brief  %Map list assignment operator.
291
       *  @param  __l  An initializer_list.
292
       *
293
       *  This function fills a %map with copies of the elements in the
294
       *  initializer list @a __l.
295
       *
296
       *  Note that the assignment completely changes the %map and
297
       *  that the resulting %map's size is the same as the number
298
       *  of elements assigned.  Old data may be lost.
299
       */
300
      map&
301
      operator=(initializer_list<value_type> __l)
302
      {
303
        this->clear();
304
        this->insert(__l.begin(), __l.end());
305
        return *this;
306
      }
307
#endif
308
 
309
      /// Get a copy of the memory allocation object.
310
      allocator_type
311
      get_allocator() const _GLIBCXX_NOEXCEPT
312
      { return allocator_type(_M_t.get_allocator()); }
313
 
314
      // iterators
315
      /**
316
       *  Returns a read/write iterator that points to the first pair in the
317
       *  %map.
318
       *  Iteration is done in ascending order according to the keys.
319
       */
320
      iterator
321
      begin() _GLIBCXX_NOEXCEPT
322
      { return _M_t.begin(); }
323
 
324
      /**
325
       *  Returns a read-only (constant) iterator that points to the first pair
326
       *  in the %map.  Iteration is done in ascending order according to the
327
       *  keys.
328
       */
329
      const_iterator
330
      begin() const _GLIBCXX_NOEXCEPT
331
      { return _M_t.begin(); }
332
 
333
      /**
334
       *  Returns a read/write iterator that points one past the last
335
       *  pair in the %map.  Iteration is done in ascending order
336
       *  according to the keys.
337
       */
338
      iterator
339
      end() _GLIBCXX_NOEXCEPT
340
      { return _M_t.end(); }
341
 
342
      /**
343
       *  Returns a read-only (constant) iterator that points one past the last
344
       *  pair in the %map.  Iteration is done in ascending order according to
345
       *  the keys.
346
       */
347
      const_iterator
348
      end() const _GLIBCXX_NOEXCEPT
349
      { return _M_t.end(); }
350
 
351
      /**
352
       *  Returns a read/write reverse iterator that points to the last pair in
353
       *  the %map.  Iteration is done in descending order according to the
354
       *  keys.
355
       */
356
      reverse_iterator
357
      rbegin() _GLIBCXX_NOEXCEPT
358
      { return _M_t.rbegin(); }
359
 
360
      /**
361
       *  Returns a read-only (constant) reverse iterator that points to the
362
       *  last pair in the %map.  Iteration is done in descending order
363
       *  according to the keys.
364
       */
365
      const_reverse_iterator
366
      rbegin() const _GLIBCXX_NOEXCEPT
367
      { return _M_t.rbegin(); }
368
 
369
      /**
370
       *  Returns a read/write reverse iterator that points to one before the
371
       *  first pair in the %map.  Iteration is done in descending order
372
       *  according to the keys.
373
       */
374
      reverse_iterator
375
      rend() _GLIBCXX_NOEXCEPT
376
      { return _M_t.rend(); }
377
 
378
      /**
379
       *  Returns a read-only (constant) reverse iterator that points to one
380
       *  before the first pair in the %map.  Iteration is done in descending
381
       *  order according to the keys.
382
       */
383
      const_reverse_iterator
384
      rend() const _GLIBCXX_NOEXCEPT
385
      { return _M_t.rend(); }
386
 
387
#if __cplusplus >= 201103L
388
      /**
389
       *  Returns a read-only (constant) iterator that points to the first pair
390
       *  in the %map.  Iteration is done in ascending order according to the
391
       *  keys.
392
       */
393
      const_iterator
394
      cbegin() const noexcept
395
      { return _M_t.begin(); }
396
 
397
      /**
398
       *  Returns a read-only (constant) iterator that points one past the last
399
       *  pair in the %map.  Iteration is done in ascending order according to
400
       *  the keys.
401
       */
402
      const_iterator
403
      cend() const noexcept
404
      { return _M_t.end(); }
405
 
406
      /**
407
       *  Returns a read-only (constant) reverse iterator that points to the
408
       *  last pair in the %map.  Iteration is done in descending order
409
       *  according to the keys.
410
       */
411
      const_reverse_iterator
412
      crbegin() const noexcept
413
      { return _M_t.rbegin(); }
414
 
415
      /**
416
       *  Returns a read-only (constant) reverse iterator that points to one
417
       *  before the first pair in the %map.  Iteration is done in descending
418
       *  order according to the keys.
419
       */
420
      const_reverse_iterator
421
      crend() const noexcept
422
      { return _M_t.rend(); }
423
#endif
424
 
425
      // capacity
426
      /** Returns true if the %map is empty.  (Thus begin() would equal
427
       *  end().)
428
      */
429
      bool
430
      empty() const _GLIBCXX_NOEXCEPT
431
      { return _M_t.empty(); }
432
 
433
      /** Returns the size of the %map.  */
434
      size_type
435
      size() const _GLIBCXX_NOEXCEPT
436
      { return _M_t.size(); }
437
 
438
      /** Returns the maximum size of the %map.  */
439
      size_type
440
      max_size() const _GLIBCXX_NOEXCEPT
441
      { return _M_t.max_size(); }
442
 
443
      // [23.3.1.2] element access
444
      /**
445
       *  @brief  Subscript ( @c [] ) access to %map data.
446
       *  @param  __k  The key for which data should be retrieved.
447
       *  @return  A reference to the data of the (key,data) %pair.
448
       *
449
       *  Allows for easy lookup with the subscript ( @c [] )
450
       *  operator.  Returns data associated with the key specified in
451
       *  subscript.  If the key does not exist, a pair with that key
452
       *  is created using default values, which is then returned.
453
       *
454
       *  Lookup requires logarithmic time.
455
       */
456
      mapped_type&
457
      operator[](const key_type& __k)
458
      {
459
        // concept requirements
460
        __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>)
461
 
462
        iterator __i = lower_bound(__k);
463
        // __i->first is greater than or equivalent to __k.
464
        if (__i == end() || key_comp()(__k, (*__i).first))
465
#if __cplusplus >= 201103L
466
          __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct,
467
                                            std::tuple<const key_type&>(__k),
468
                                            std::tuple<>());
469
#else
470
          __i = insert(__i, value_type(__k, mapped_type()));
471
#endif
472
        return (*__i).second;
473
      }
474
 
475
#if __cplusplus >= 201103L
476
      mapped_type&
477
      operator[](key_type&& __k)
478
      {
479
        // concept requirements
480
        __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>)
481
 
482
        iterator __i = lower_bound(__k);
483
        // __i->first is greater than or equivalent to __k.
484
        if (__i == end() || key_comp()(__k, (*__i).first))
485
          __i = _M_t._M_emplace_hint_unique(__i, std::piecewise_construct,
486
                                        std::forward_as_tuple(std::move(__k)),
487
                                        std::tuple<>());
488
        return (*__i).second;
489
      }
490
#endif
491
 
492
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
493
      // DR 464. Suggestion for new member functions in standard containers.
494
      /**
495
       *  @brief  Access to %map data.
496
       *  @param  __k  The key for which data should be retrieved.
497
       *  @return  A reference to the data whose key is equivalent to @a __k, if
498
       *           such a data is present in the %map.
499
       *  @throw  std::out_of_range  If no such data is present.
500
       */
501
      mapped_type&
502
      at(const key_type& __k)
503
      {
504
        iterator __i = lower_bound(__k);
505
        if (__i == end() || key_comp()(__k, (*__i).first))
506
          __throw_out_of_range(__N("map::at"));
507
        return (*__i).second;
508
      }
509
 
510
      const mapped_type&
511
      at(const key_type& __k) const
512
      {
513
        const_iterator __i = lower_bound(__k);
514
        if (__i == end() || key_comp()(__k, (*__i).first))
515
          __throw_out_of_range(__N("map::at"));
516
        return (*__i).second;
517
      }
518
 
519
      // modifiers
520
#if __cplusplus >= 201103L
521
      /**
522
       *  @brief Attempts to build and insert a std::pair into the %map.
523
       *
524
       *  @param __args  Arguments used to generate a new pair instance (see
525
       *                std::piecewise_contruct for passing arguments to each
526
       *                part of the pair constructor).
527
       *
528
       *  @return  A pair, of which the first element is an iterator that points
529
       *           to the possibly inserted pair, and the second is a bool that
530
       *           is true if the pair was actually inserted.
531
       *
532
       *  This function attempts to build and insert a (key, value) %pair into
533
       *  the %map.
534
       *  A %map relies on unique keys and thus a %pair is only inserted if its
535
       *  first element (the key) is not already present in the %map.
536
       *
537
       *  Insertion requires logarithmic time.
538
       */
539
      template<typename... _Args>
540
        std::pair<iterator, bool>
541
        emplace(_Args&&... __args)
542
        { return _M_t._M_emplace_unique(std::forward<_Args>(__args)...); }
543
 
544
      /**
545
       *  @brief Attempts to build and insert a std::pair into the %map.
546
       *
547
       *  @param  __pos  An iterator that serves as a hint as to where the pair
548
       *                should be inserted.
549
       *  @param  __args  Arguments used to generate a new pair instance (see
550
       *                 std::piecewise_contruct for passing arguments to each
551
       *                 part of the pair constructor).
552
       *  @return An iterator that points to the element with key of the
553
       *          std::pair built from @a __args (may or may not be that
554
       *          std::pair).
555
       *
556
       *  This function is not concerned about whether the insertion took place,
557
       *  and thus does not return a boolean like the single-argument emplace()
558
       *  does.
559
       *  Note that the first parameter is only a hint and can potentially
560
       *  improve the performance of the insertion process. A bad hint would
561
       *  cause no gains in efficiency.
562
       *
563
       *  See
564
       *  http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
565
       *  for more on @a hinting.
566
       *
567
       *  Insertion requires logarithmic time (if the hint is not taken).
568
       */
569
      template<typename... _Args>
570
        iterator
571
        emplace_hint(const_iterator __pos, _Args&&... __args)
572
        {
573
          return _M_t._M_emplace_hint_unique(__pos,
574
                                             std::forward<_Args>(__args)...);
575
        }
576
#endif
577
 
578
      /**
579
       *  @brief Attempts to insert a std::pair into the %map.
580
 
581
       *  @param __x Pair to be inserted (see std::make_pair for easy
582
       *             creation of pairs).
583
       *
584
       *  @return  A pair, of which the first element is an iterator that
585
       *           points to the possibly inserted pair, and the second is
586
       *           a bool that is true if the pair was actually inserted.
587
       *
588
       *  This function attempts to insert a (key, value) %pair into the %map.
589
       *  A %map relies on unique keys and thus a %pair is only inserted if its
590
       *  first element (the key) is not already present in the %map.
591
       *
592
       *  Insertion requires logarithmic time.
593
       */
594
      std::pair<iterator, bool>
595
      insert(const value_type& __x)
596
      { return _M_t._M_insert_unique(__x); }
597
 
598
#if __cplusplus >= 201103L
599
      template<typename _Pair, typename = typename
600
               std::enable_if<std::is_constructible<value_type,
601
                                                    _Pair&&>::value>::type>
602
        std::pair<iterator, bool>
603
        insert(_Pair&& __x)
604
        { return _M_t._M_insert_unique(std::forward<_Pair>(__x)); }
605
#endif
606
 
607
#if __cplusplus >= 201103L
608
      /**
609
       *  @brief Attempts to insert a list of std::pairs into the %map.
610
       *  @param  __list  A std::initializer_list<value_type> of pairs to be
611
       *                  inserted.
612
       *
613
       *  Complexity similar to that of the range constructor.
614
       */
615
      void
616
      insert(std::initializer_list<value_type> __list)
617
      { insert(__list.begin(), __list.end()); }
618
#endif
619
 
620
      /**
621
       *  @brief Attempts to insert a std::pair into the %map.
622
       *  @param  __position  An iterator that serves as a hint as to where the
623
       *                    pair should be inserted.
624
       *  @param  __x  Pair to be inserted (see std::make_pair for easy creation
625
       *               of pairs).
626
       *  @return An iterator that points to the element with key of
627
       *           @a __x (may or may not be the %pair passed in).
628
       *
629
 
630
       *  This function is not concerned about whether the insertion
631
       *  took place, and thus does not return a boolean like the
632
       *  single-argument insert() does.  Note that the first
633
       *  parameter is only a hint and can potentially improve the
634
       *  performance of the insertion process.  A bad hint would
635
       *  cause no gains in efficiency.
636
       *
637
       *  See
638
       *  http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html
639
       *  for more on @a hinting.
640
       *
641
       *  Insertion requires logarithmic time (if the hint is not taken).
642
       */
643
      iterator
644
#if __cplusplus >= 201103L
645
      insert(const_iterator __position, const value_type& __x)
646
#else
647
      insert(iterator __position, const value_type& __x)
648
#endif
649
      { return _M_t._M_insert_unique_(__position, __x); }
650
 
651
#if __cplusplus >= 201103L
652
      template<typename _Pair, typename = typename
653
               std::enable_if<std::is_constructible<value_type,
654
                                                    _Pair&&>::value>::type>
655
        iterator
656
        insert(const_iterator __position, _Pair&& __x)
657
        { return _M_t._M_insert_unique_(__position,
658
                                        std::forward<_Pair>(__x)); }
659
#endif
660
 
661
      /**
662
       *  @brief Template function that attempts to insert a range of elements.
663
       *  @param  __first  Iterator pointing to the start of the range to be
664
       *                   inserted.
665
       *  @param  __last  Iterator pointing to the end of the range.
666
       *
667
       *  Complexity similar to that of the range constructor.
668
       */
669
      template<typename _InputIterator>
670
        void
671
        insert(_InputIterator __first, _InputIterator __last)
672
        { _M_t._M_insert_unique(__first, __last); }
673
 
674
#if __cplusplus >= 201103L
675
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
676
      // DR 130. Associative erase should return an iterator.
677
      /**
678
       *  @brief Erases an element from a %map.
679
       *  @param  __position  An iterator pointing to the element to be erased.
680
       *  @return An iterator pointing to the element immediately following
681
       *          @a position prior to the element being erased. If no such
682
       *          element exists, end() is returned.
683
       *
684
       *  This function erases an element, pointed to by the given
685
       *  iterator, from a %map.  Note that this function only erases
686
       *  the element, and that if the element is itself a pointer,
687
       *  the pointed-to memory is not touched in any way.  Managing
688
       *  the pointer is the user's responsibility.
689
       */
690
      iterator
691
      erase(const_iterator __position)
692
      { return _M_t.erase(__position); }
693
 
694
      // LWG 2059.
695
      iterator
696
      erase(iterator __position)
697
      { return _M_t.erase(__position); }
698
#else
699
      /**
700
       *  @brief Erases an element from a %map.
701
       *  @param  __position  An iterator pointing to the element to be erased.
702
       *
703
       *  This function erases an element, pointed to by the given
704
       *  iterator, from a %map.  Note that this function only erases
705
       *  the element, and that if the element is itself a pointer,
706
       *  the pointed-to memory is not touched in any way.  Managing
707
       *  the pointer is the user's responsibility.
708
       */
709
      void
710
      erase(iterator __position)
711
      { _M_t.erase(__position); }
712
#endif
713
 
714
      /**
715
       *  @brief Erases elements according to the provided key.
716
       *  @param  __x  Key of element to be erased.
717
       *  @return  The number of elements erased.
718
       *
719
       *  This function erases all the elements located by the given key from
720
       *  a %map.
721
       *  Note that this function only erases the element, and that if
722
       *  the element is itself a pointer, the pointed-to memory is not touched
723
       *  in any way.  Managing the pointer is the user's responsibility.
724
       */
725
      size_type
726
      erase(const key_type& __x)
727
      { return _M_t.erase(__x); }
728
 
729
#if __cplusplus >= 201103L
730
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
731
      // DR 130. Associative erase should return an iterator.
732
      /**
733
       *  @brief Erases a [first,last) range of elements from a %map.
734
       *  @param  __first  Iterator pointing to the start of the range to be
735
       *                   erased.
736
       *  @param __last Iterator pointing to the end of the range to
737
       *                be erased.
738
       *  @return The iterator @a __last.
739
       *
740
       *  This function erases a sequence of elements from a %map.
741
       *  Note that this function only erases the element, and that if
742
       *  the element is itself a pointer, the pointed-to memory is not touched
743
       *  in any way.  Managing the pointer is the user's responsibility.
744
       */
745
      iterator
746
      erase(const_iterator __first, const_iterator __last)
747
      { return _M_t.erase(__first, __last); }
748
#else
749
      /**
750
       *  @brief Erases a [__first,__last) range of elements from a %map.
751
       *  @param  __first  Iterator pointing to the start of the range to be
752
       *                   erased.
753
       *  @param __last Iterator pointing to the end of the range to
754
       *                be erased.
755
       *
756
       *  This function erases a sequence of elements from a %map.
757
       *  Note that this function only erases the element, and that if
758
       *  the element is itself a pointer, the pointed-to memory is not touched
759
       *  in any way.  Managing the pointer is the user's responsibility.
760
       */
761
      void
762
      erase(iterator __first, iterator __last)
763
      { _M_t.erase(__first, __last); }
764
#endif
765
 
766
      /**
767
       *  @brief  Swaps data with another %map.
768
       *  @param  __x  A %map of the same element and allocator types.
769
       *
770
       *  This exchanges the elements between two maps in constant
771
       *  time.  (It is only swapping a pointer, an integer, and an
772
       *  instance of the @c Compare type (which itself is often
773
       *  stateless and empty), so it should be quite fast.)  Note
774
       *  that the global std::swap() function is specialized such
775
       *  that std::swap(m1,m2) will feed to this function.
776
       */
777
      void
778
      swap(map& __x)
779
      { _M_t.swap(__x._M_t); }
780
 
781
      /**
782
       *  Erases all elements in a %map.  Note that this function only
783
       *  erases the elements, and that if the elements themselves are
784
       *  pointers, the pointed-to memory is not touched in any way.
785
       *  Managing the pointer is the user's responsibility.
786
       */
787
      void
788
      clear() _GLIBCXX_NOEXCEPT
789
      { _M_t.clear(); }
790
 
791
      // observers
792
      /**
793
       *  Returns the key comparison object out of which the %map was
794
       *  constructed.
795
       */
796
      key_compare
797
      key_comp() const
798
      { return _M_t.key_comp(); }
799
 
800
      /**
801
       *  Returns a value comparison object, built from the key comparison
802
       *  object out of which the %map was constructed.
803
       */
804
      value_compare
805
      value_comp() const
806
      { return value_compare(_M_t.key_comp()); }
807
 
808
      // [23.3.1.3] map operations
809
      /**
810
       *  @brief Tries to locate an element in a %map.
811
       *  @param  __x  Key of (key, value) %pair to be located.
812
       *  @return  Iterator pointing to sought-after element, or end() if not
813
       *           found.
814
       *
815
       *  This function takes a key and tries to locate the element with which
816
       *  the key matches.  If successful the function returns an iterator
817
       *  pointing to the sought after %pair.  If unsuccessful it returns the
818
       *  past-the-end ( @c end() ) iterator.
819
       */
820
      iterator
821
      find(const key_type& __x)
822
      { return _M_t.find(__x); }
823
 
824
      /**
825
       *  @brief Tries to locate an element in a %map.
826
       *  @param  __x  Key of (key, value) %pair to be located.
827
       *  @return  Read-only (constant) iterator pointing to sought-after
828
       *           element, or end() if not found.
829
       *
830
       *  This function takes a key and tries to locate the element with which
831
       *  the key matches.  If successful the function returns a constant
832
       *  iterator pointing to the sought after %pair. If unsuccessful it
833
       *  returns the past-the-end ( @c end() ) iterator.
834
       */
835
      const_iterator
836
      find(const key_type& __x) const
837
      { return _M_t.find(__x); }
838
 
839
      /**
840
       *  @brief  Finds the number of elements with given key.
841
       *  @param  __x  Key of (key, value) pairs to be located.
842
       *  @return  Number of elements with specified key.
843
       *
844
       *  This function only makes sense for multimaps; for map the result will
845
       *  either be 0 (not present) or 1 (present).
846
       */
847
      size_type
848
      count(const key_type& __x) const
849
      { return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
850
 
851
      /**
852
       *  @brief Finds the beginning of a subsequence matching given key.
853
       *  @param  __x  Key of (key, value) pair to be located.
854
       *  @return  Iterator pointing to first element equal to or greater
855
       *           than key, or end().
856
       *
857
       *  This function returns the first element of a subsequence of elements
858
       *  that matches the given key.  If unsuccessful it returns an iterator
859
       *  pointing to the first element that has a greater value than given key
860
       *  or end() if no such element exists.
861
       */
862
      iterator
863
      lower_bound(const key_type& __x)
864
      { return _M_t.lower_bound(__x); }
865
 
866
      /**
867
       *  @brief Finds the beginning of a subsequence matching given key.
868
       *  @param  __x  Key of (key, value) pair to be located.
869
       *  @return  Read-only (constant) iterator pointing to first element
870
       *           equal to or greater than key, or end().
871
       *
872
       *  This function returns the first element of a subsequence of elements
873
       *  that matches the given key.  If unsuccessful it returns an iterator
874
       *  pointing to the first element that has a greater value than given key
875
       *  or end() if no such element exists.
876
       */
877
      const_iterator
878
      lower_bound(const key_type& __x) const
879
      { return _M_t.lower_bound(__x); }
880
 
881
      /**
882
       *  @brief Finds the end of a subsequence matching given key.
883
       *  @param  __x  Key of (key, value) pair to be located.
884
       *  @return Iterator pointing to the first element
885
       *          greater than key, or end().
886
       */
887
      iterator
888
      upper_bound(const key_type& __x)
889
      { return _M_t.upper_bound(__x); }
890
 
891
      /**
892
       *  @brief Finds the end of a subsequence matching given key.
893
       *  @param  __x  Key of (key, value) pair to be located.
894
       *  @return  Read-only (constant) iterator pointing to first iterator
895
       *           greater than key, or end().
896
       */
897
      const_iterator
898
      upper_bound(const key_type& __x) const
899
      { return _M_t.upper_bound(__x); }
900
 
901
      /**
902
       *  @brief Finds a subsequence matching given key.
903
       *  @param  __x  Key of (key, value) pairs to be located.
904
       *  @return  Pair of iterators that possibly points to the subsequence
905
       *           matching given key.
906
       *
907
       *  This function is equivalent to
908
       *  @code
909
       *    std::make_pair(c.lower_bound(val),
910
       *                   c.upper_bound(val))
911
       *  @endcode
912
       *  (but is faster than making the calls separately).
913
       *
914
       *  This function probably only makes sense for multimaps.
915
       */
916
      std::pair<iterator, iterator>
917
      equal_range(const key_type& __x)
918
      { return _M_t.equal_range(__x); }
919
 
920
      /**
921
       *  @brief Finds a subsequence matching given key.
922
       *  @param  __x  Key of (key, value) pairs to be located.
923
       *  @return  Pair of read-only (constant) iterators that possibly points
924
       *           to the subsequence matching given key.
925
       *
926
       *  This function is equivalent to
927
       *  @code
928
       *    std::make_pair(c.lower_bound(val),
929
       *                   c.upper_bound(val))
930
       *  @endcode
931
       *  (but is faster than making the calls separately).
932
       *
933
       *  This function probably only makes sense for multimaps.
934
       */
935
      std::pair<const_iterator, const_iterator>
936
      equal_range(const key_type& __x) const
937
      { return _M_t.equal_range(__x); }
938
 
939
      template<typename _K1, typename _T1, typename _C1, typename _A1>
940
        friend bool
941
        operator==(const map<_K1, _T1, _C1, _A1>&,
942
                   const map<_K1, _T1, _C1, _A1>&);
943
 
944
      template<typename _K1, typename _T1, typename _C1, typename _A1>
945
        friend bool
946
        operator<(const map<_K1, _T1, _C1, _A1>&,
947
                  const map<_K1, _T1, _C1, _A1>&);
948
    };
949
 
950
  /**
951
   *  @brief  Map equality comparison.
952
   *  @param  __x  A %map.
953
   *  @param  __y  A %map of the same type as @a x.
954
   *  @return  True iff the size and elements of the maps are equal.
955
   *
956
   *  This is an equivalence relation.  It is linear in the size of the
957
   *  maps.  Maps are considered equivalent if their sizes are equal,
958
   *  and if corresponding elements compare equal.
959
  */
960
  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
961
    inline bool
962
    operator==(const map<_Key, _Tp, _Compare, _Alloc>& __x,
963
               const map<_Key, _Tp, _Compare, _Alloc>& __y)
964
    { return __x._M_t == __y._M_t; }
965
 
966
  /**
967
   *  @brief  Map ordering relation.
968
   *  @param  __x  A %map.
969
   *  @param  __y  A %map of the same type as @a x.
970
   *  @return  True iff @a x is lexicographically less than @a y.
971
   *
972
   *  This is a total ordering relation.  It is linear in the size of the
973
   *  maps.  The elements must be comparable with @c <.
974
   *
975
   *  See std::lexicographical_compare() for how the determination is made.
976
  */
977
  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
978
    inline bool
979
    operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x,
980
              const map<_Key, _Tp, _Compare, _Alloc>& __y)
981
    { return __x._M_t < __y._M_t; }
982
 
983
  /// Based on operator==
984
  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
985
    inline bool
986
    operator!=(const map<_Key, _Tp, _Compare, _Alloc>& __x,
987
               const map<_Key, _Tp, _Compare, _Alloc>& __y)
988
    { return !(__x == __y); }
989
 
990
  /// Based on operator<
991
  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
992
    inline bool
993
    operator>(const map<_Key, _Tp, _Compare, _Alloc>& __x,
994
              const map<_Key, _Tp, _Compare, _Alloc>& __y)
995
    { return __y < __x; }
996
 
997
  /// Based on operator<
998
  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
999
    inline bool
1000
    operator<=(const map<_Key, _Tp, _Compare, _Alloc>& __x,
1001
               const map<_Key, _Tp, _Compare, _Alloc>& __y)
1002
    { return !(__y < __x); }
1003
 
1004
  /// Based on operator<
1005
  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1006
    inline bool
1007
    operator>=(const map<_Key, _Tp, _Compare, _Alloc>& __x,
1008
               const map<_Key, _Tp, _Compare, _Alloc>& __y)
1009
    { return !(__x < __y); }
1010
 
1011
  /// See std::map::swap().
1012
  template<typename _Key, typename _Tp, typename _Compare, typename _Alloc>
1013
    inline void
1014
    swap(map<_Key, _Tp, _Compare, _Alloc>& __x,
1015
         map<_Key, _Tp, _Compare, _Alloc>& __y)
1016
    { __x.swap(__y); }
1017
 
1018
_GLIBCXX_END_NAMESPACE_CONTAINER
1019
} // namespace std
1020
 
1021
#endif /* _STL_MAP_H */

powered by: WebSVN 2.1.0

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