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/] [tuple] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 ultra_embe
//  -*- C++ -*-
2
 
3
// Copyright (C) 2007-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
// .
24
 
25
/** @file include/tuple
26
 *  This is a Standard C++ Library header.
27
 */
28
 
29
#ifndef _GLIBCXX_TUPLE
30
#define _GLIBCXX_TUPLE 1
31
 
32
#pragma GCC system_header
33
 
34
#if __cplusplus < 201103L
35
# include 
36
#else
37
 
38
#include 
39
#include 
40
#include 
41
 
42
namespace std _GLIBCXX_VISIBILITY(default)
43
{
44
_GLIBCXX_BEGIN_NAMESPACE_VERSION
45
 
46
  // Adds a const reference to a non-reference type.
47
  template
48
    struct __add_c_ref
49
    { typedef const _Tp& type; };
50
 
51
  template
52
    struct __add_c_ref<_Tp&>
53
    { typedef _Tp& type; };
54
 
55
  // Adds a reference to a non-reference type.
56
  template
57
    struct __add_ref
58
    { typedef _Tp& type; };
59
 
60
  template
61
    struct __add_ref<_Tp&>
62
    { typedef _Tp& type; };
63
 
64
  // Adds an rvalue reference to a non-reference type.
65
  template
66
    struct __add_r_ref
67
    { typedef _Tp&& type; };
68
 
69
  template
70
    struct __add_r_ref<_Tp&>
71
    { typedef _Tp& type; };
72
 
73
  template
74
    struct _Head_base;
75
 
76
  template
77
    struct _Head_base<_Idx, _Head, true>
78
    : public _Head
79
    {
80
      constexpr _Head_base()
81
      : _Head() { }
82
 
83
      constexpr _Head_base(const _Head& __h)
84
      : _Head(__h) { }
85
 
86
      template
87
               enable_if
88
                                         __uses_alloc_base>::value>::type>
89
        constexpr _Head_base(_UHead&& __h)
90
        : _Head(std::forward<_UHead>(__h)) { }
91
 
92
      _Head_base(__uses_alloc0)
93
      : _Head() { }
94
 
95
      template
96
        _Head_base(__uses_alloc1<_Alloc> __a)
97
        : _Head(allocator_arg, *__a._M_a) { }
98
 
99
      template
100
        _Head_base(__uses_alloc2<_Alloc> __a)
101
        : _Head(*__a._M_a) { }
102
 
103
      template
104
        _Head_base(__uses_alloc0, _UHead&& __uhead)
105
        : _Head(std::forward<_UHead>(__uhead)) { }
106
 
107
      template
108
        _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
109
        : _Head(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) { }
110
 
111
      template
112
        _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
113
        : _Head(std::forward<_UHead>(__uhead), *__a._M_a) { }
114
 
115
      static constexpr _Head&
116
      _M_head(_Head_base& __b) noexcept { return __b; }
117
 
118
      static constexpr const _Head&
119
      _M_head(const _Head_base& __b) noexcept { return __b; }
120
    };
121
 
122
  template
123
    struct _Head_base<_Idx, _Head, false>
124
    {
125
      constexpr _Head_base()
126
      : _M_head_impl() { }
127
 
128
      constexpr _Head_base(const _Head& __h)
129
      : _M_head_impl(__h) { }
130
 
131
      template
132
               enable_if
133
                                         __uses_alloc_base>::value>::type>
134
        constexpr _Head_base(_UHead&& __h)
135
        : _M_head_impl(std::forward<_UHead>(__h)) { }
136
 
137
      _Head_base(__uses_alloc0)
138
      : _M_head_impl() { }
139
 
140
      template
141
        _Head_base(__uses_alloc1<_Alloc> __a)
142
        : _M_head_impl(allocator_arg, *__a._M_a) { }
143
 
144
      template
145
        _Head_base(__uses_alloc2<_Alloc> __a)
146
        : _M_head_impl(*__a._M_a) { }
147
 
148
      template
149
        _Head_base(__uses_alloc0, _UHead&& __uhead)
150
        : _M_head_impl(std::forward<_UHead>(__uhead)) { }
151
 
152
      template
153
        _Head_base(__uses_alloc1<_Alloc> __a, _UHead&& __uhead)
154
        : _M_head_impl(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead))
155
        { }
156
 
157
      template
158
        _Head_base(__uses_alloc2<_Alloc> __a, _UHead&& __uhead)
159
        : _M_head_impl(std::forward<_UHead>(__uhead), *__a._M_a) { }
160
 
161
      static constexpr _Head&
162
      _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
163
 
164
      static constexpr const _Head&
165
      _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
166
 
167
      _Head _M_head_impl;
168
    };
169
 
170
  /**
171
   * Contains the actual implementation of the @c tuple template, stored
172
   * as a recursive inheritance hierarchy from the first element (most
173
   * derived class) to the last (least derived class). The @c Idx
174
   * parameter gives the 0-based index of the element stored at this
175
   * point in the hierarchy; we use it to implement a constant-time
176
   * get() operation.
177
   */
178
  template
179
    struct _Tuple_impl;
180
 
181
  /**
182
   * Zero-element tuple implementation. This is the basis case for the
183
   * inheritance recursion.
184
   */
185
  template
186
    struct _Tuple_impl<_Idx>
187
    {
188
      template friend class _Tuple_impl;
189
 
190
      _Tuple_impl() = default;
191
 
192
      template
193
        _Tuple_impl(allocator_arg_t, const _Alloc&) { }
194
 
195
      template
196
        _Tuple_impl(allocator_arg_t, const _Alloc&, const _Tuple_impl&) { }
197
 
198
      template
199
        _Tuple_impl(allocator_arg_t, const _Alloc&, _Tuple_impl&&) { }
200
 
201
    protected:
202
      void _M_swap(_Tuple_impl&) noexcept { /* no-op */ }
203
    };
204
 
205
  template
206
    struct __is_empty_non_tuple : is_empty<_Tp> { };
207
 
208
  // Using EBO for elements that are tuples causes ambiguous base errors.
209
  template
210
    struct __is_empty_non_tuple> : false_type { };
211
 
212
  // Use the Empty Base-class Optimization for empty, non-final types.
213
  template
214
    using __empty_not_final
215
    = typename conditional<__is_final(_Tp), false_type,
216
                           __is_empty_non_tuple<_Tp>>::type;
217
 
218
  /**
219
   * Recursive tuple implementation. Here we store the @c Head element
220
   * and derive from a @c Tuple_impl containing the remaining elements
221
   * (which contains the @c Tail).
222
   */
223
  template
224
    struct _Tuple_impl<_Idx, _Head, _Tail...>
225
    : public _Tuple_impl<_Idx + 1, _Tail...>,
226
      private _Head_base<_Idx, _Head, __empty_not_final<_Head>::value>
227
    {
228
      template friend class _Tuple_impl;
229
 
230
      typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited;
231
      typedef _Head_base<_Idx, _Head, __empty_not_final<_Head>::value> _Base;
232
 
233
      static constexpr _Head&
234
      _M_head(_Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
235
 
236
      static constexpr const _Head&
237
      _M_head(const _Tuple_impl& __t) noexcept { return _Base::_M_head(__t); }
238
 
239
      static constexpr _Inherited&
240
      _M_tail(_Tuple_impl& __t) noexcept { return __t; }
241
 
242
      static constexpr const _Inherited&
243
      _M_tail(const _Tuple_impl& __t) noexcept { return __t; }
244
 
245
      constexpr _Tuple_impl()
246
      : _Inherited(), _Base() { }
247
 
248
      explicit
249
      constexpr _Tuple_impl(const _Head& __head, const _Tail&... __tail)
250
      : _Inherited(__tail...), _Base(__head) { }
251
 
252
      template
253
               enable_if::type>
254
        explicit
255
        constexpr _Tuple_impl(_UHead&& __head, _UTail&&... __tail)
256
        : _Inherited(std::forward<_UTail>(__tail)...),
257
          _Base(std::forward<_UHead>(__head)) { }
258
 
259
      constexpr _Tuple_impl(const _Tuple_impl&) = default;
260
 
261
      constexpr
262
      _Tuple_impl(_Tuple_impl&& __in)
263
      noexcept(__and_,
264
                      is_nothrow_move_constructible<_Inherited>>::value)
265
      : _Inherited(std::move(_M_tail(__in))),
266
        _Base(std::forward<_Head>(_M_head(__in))) { }
267
 
268
      template
269
        constexpr _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in)
270
        : _Inherited(_Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
271
          _Base(_Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { }
272
 
273
      template
274
        constexpr _Tuple_impl(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
275
        : _Inherited(std::move
276
                     (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
277
          _Base(std::forward<_UHead>
278
                (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { }
279
 
280
      template
281
        _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a)
282
        : _Inherited(__tag, __a),
283
          _Base(__use_alloc<_Head>(__a)) { }
284
 
285
      template
286
        _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
287
                    const _Head& __head, const _Tail&... __tail)
288
        : _Inherited(__tag, __a, __tail...),
289
          _Base(__use_alloc<_Head, _Alloc, _Head>(__a), __head) { }
290
 
291
      template
292
               typename = typename enable_if
293
                                             == sizeof...(_UTail)>::type>
294
        _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
295
                    _UHead&& __head, _UTail&&... __tail)
296
        : _Inherited(__tag, __a, std::forward<_UTail>(__tail)...),
297
          _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
298
                std::forward<_UHead>(__head)) { }
299
 
300
      template
301
        _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
302
                    const _Tuple_impl& __in)
303
        : _Inherited(__tag, __a, _M_tail(__in)),
304
          _Base(__use_alloc<_Head, _Alloc, _Head>(__a), _M_head(__in)) { }
305
 
306
      template
307
        _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
308
                    _Tuple_impl&& __in)
309
        : _Inherited(__tag, __a, std::move(_M_tail(__in))),
310
          _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
311
                std::forward<_Head>(_M_head(__in))) { }
312
 
313
      template
314
        _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
315
                    const _Tuple_impl<_Idx, _UElements...>& __in)
316
        : _Inherited(__tag, __a,
317
                     _Tuple_impl<_Idx, _UElements...>::_M_tail(__in)),
318
          _Base(__use_alloc<_Head, _Alloc, _Head>(__a),
319
                _Tuple_impl<_Idx, _UElements...>::_M_head(__in)) { }
320
 
321
      template
322
        _Tuple_impl(allocator_arg_t __tag, const _Alloc& __a,
323
                    _Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
324
        : _Inherited(__tag, __a, std::move
325
                     (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in))),
326
          _Base(__use_alloc<_Head, _Alloc, _UHead>(__a),
327
                std::forward<_UHead>
328
                (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in))) { }
329
 
330
      _Tuple_impl&
331
      operator=(const _Tuple_impl& __in)
332
      {
333
        _M_head(*this) = _M_head(__in);
334
        _M_tail(*this) = _M_tail(__in);
335
        return *this;
336
      }
337
 
338
      _Tuple_impl&
339
      operator=(_Tuple_impl&& __in)
340
      noexcept(__and_,
341
                      is_nothrow_move_assignable<_Inherited>>::value)
342
      {
343
        _M_head(*this) = std::forward<_Head>(_M_head(__in));
344
        _M_tail(*this) = std::move(_M_tail(__in));
345
        return *this;
346
      }
347
 
348
      template
349
        _Tuple_impl&
350
        operator=(const _Tuple_impl<_Idx, _UElements...>& __in)
351
        {
352
          _M_head(*this) = _Tuple_impl<_Idx, _UElements...>::_M_head(__in);
353
          _M_tail(*this) = _Tuple_impl<_Idx, _UElements...>::_M_tail(__in);
354
          return *this;
355
        }
356
 
357
      template
358
        _Tuple_impl&
359
        operator=(_Tuple_impl<_Idx, _UHead, _UTails...>&& __in)
360
        {
361
          _M_head(*this) = std::forward<_UHead>
362
            (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_head(__in));
363
          _M_tail(*this) = std::move
364
            (_Tuple_impl<_Idx, _UHead, _UTails...>::_M_tail(__in));
365
          return *this;
366
        }
367
 
368
    protected:
369
      void
370
      _M_swap(_Tuple_impl& __in)
371
      noexcept(noexcept(swap(std::declval<_Head&>(),
372
                             std::declval<_Head&>()))
373
               && noexcept(_M_tail(__in)._M_swap(_M_tail(__in))))
374
      {
375
        using std::swap;
376
        swap(_M_head(*this), _M_head(__in));
377
        _Inherited::_M_swap(_M_tail(__in));
378
      }
379
    };
380
 
381
  /// Primary class template, tuple
382
  template
383
    class tuple : public _Tuple_impl<0, _Elements...>
384
    {
385
      typedef _Tuple_impl<0, _Elements...> _Inherited;
386
 
387
    public:
388
      constexpr tuple()
389
      : _Inherited() { }
390
 
391
      explicit
392
      constexpr tuple(const _Elements&... __elements)
393
      : _Inherited(__elements...) { }
394
 
395
      template
396
        enable_if<__and_
397
                                        _Elements>...>::value>::type>
398
        explicit
399
        constexpr tuple(_UElements&&... __elements)
400
        : _Inherited(std::forward<_UElements>(__elements)...) {     }
401
 
402
      constexpr tuple(const tuple&) = default;
403
 
404
      constexpr tuple(tuple&&) = default;
405
 
406
      template
407
        enable_if<__and_
408
                                        _Elements>...>::value>::type>
409
        constexpr tuple(const tuple<_UElements...>& __in)
410
        : _Inherited(static_cast&>(__in))
411
        { }
412
 
413
      template
414
        enable_if<__and_
415
                                        _Elements>...>::value>::type>
416
        constexpr tuple(tuple<_UElements...>&& __in)
417
        : _Inherited(static_cast<_Tuple_impl<0, _UElements...>&&>(__in)) { }
418
 
419
      // Allocator-extended constructors.
420
 
421
      template
422
        tuple(allocator_arg_t __tag, const _Alloc& __a)
423
        : _Inherited(__tag, __a) { }
424
 
425
      template
426
        tuple(allocator_arg_t __tag, const _Alloc& __a,
427
              const _Elements&... __elements)
428
        : _Inherited(__tag, __a, __elements...) { }
429
 
430
      template
431
               enable_if
432
                         == sizeof...(_Elements)>::type>
433
        tuple(allocator_arg_t __tag, const _Alloc& __a,
434
              _UElements&&... __elements)
435
        : _Inherited(__tag, __a, std::forward<_UElements>(__elements)...)
436
        { }
437
 
438
      template
439
        tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
440
        : _Inherited(__tag, __a, static_cast(__in)) { }
441
 
442
      template
443
        tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
444
        : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
445
 
446
      template
447
               enable_if
448
                         == sizeof...(_Elements)>::type>
449
        tuple(allocator_arg_t __tag, const _Alloc& __a,
450
              const tuple<_UElements...>& __in)
451
        : _Inherited(__tag, __a,
452
                     static_cast&>(__in))
453
        { }
454
 
455
      template
456
               enable_if
457
                         == sizeof...(_Elements)>::type>
458
        tuple(allocator_arg_t __tag, const _Alloc& __a,
459
              tuple<_UElements...>&& __in)
460
        : _Inherited(__tag, __a,
461
                     static_cast<_Tuple_impl<0, _UElements...>&&>(__in))
462
        { }
463
 
464
      tuple&
465
      operator=(const tuple& __in)
466
      {
467
        static_cast<_Inherited&>(*this) = __in;
468
        return *this;
469
      }
470
 
471
      tuple&
472
      operator=(tuple&& __in)
473
      noexcept(is_nothrow_move_assignable<_Inherited>::value)
474
      {
475
        static_cast<_Inherited&>(*this) = std::move(__in);
476
        return *this;
477
      }
478
 
479
      template
480
               enable_if
481
                         == sizeof...(_Elements)>::type>
482
        tuple&
483
        operator=(const tuple<_UElements...>& __in)
484
        {
485
          static_cast<_Inherited&>(*this) = __in;
486
          return *this;
487
        }
488
 
489
      template
490
               enable_if
491
                         == sizeof...(_Elements)>::type>
492
        tuple&
493
        operator=(tuple<_UElements...>&& __in)
494
        {
495
          static_cast<_Inherited&>(*this) = std::move(__in);
496
          return *this;
497
        }
498
 
499
      void
500
      swap(tuple& __in)
501
      noexcept(noexcept(__in._M_swap(__in)))
502
      { _Inherited::_M_swap(__in); }
503
    };
504
 
505
  // Explicit specialization, zero-element tuple.
506
  template<>
507
    class tuple<>
508
    {
509
    public:
510
      void swap(tuple&) noexcept { /* no-op */ }
511
    };
512
 
513
  /// Partial specialization, 2-element tuple.
514
  /// Includes construction and assignment from a pair.
515
  template
516
    class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2>
517
    {
518
      typedef _Tuple_impl<0, _T1, _T2> _Inherited;
519
 
520
    public:
521
      constexpr tuple()
522
      : _Inherited() { }
523
 
524
      explicit
525
      constexpr tuple(const _T1& __a1, const _T2& __a2)
526
      : _Inherited(__a1, __a2) { }
527
 
528
      template
529
               enable_if<__and_,
530
                                is_convertible<_U2, _T2>>::value>::type>
531
        explicit
532
        constexpr tuple(_U1&& __a1, _U2&& __a2)
533
        : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
534
 
535
      constexpr tuple(const tuple&) = default;
536
 
537
      constexpr tuple(tuple&&) = default;
538
 
539
      template
540
        enable_if<__and_,
541
                         is_convertible>::value>::type>
542
        constexpr tuple(const tuple<_U1, _U2>& __in)
543
        : _Inherited(static_cast&>(__in)) { }
544
 
545
      template
546
               enable_if<__and_,
547
                                is_convertible<_U2, _T2>>::value>::type>
548
        constexpr tuple(tuple<_U1, _U2>&& __in)
549
        : _Inherited(static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in)) { }
550
 
551
      template
552
        enable_if<__and_,
553
                         is_convertible>::value>::type>
554
        constexpr tuple(const pair<_U1, _U2>& __in)
555
        : _Inherited(__in.first, __in.second) { }
556
 
557
      template
558
               enable_if<__and_,
559
                                is_convertible<_U2, _T2>>::value>::type>
560
        constexpr tuple(pair<_U1, _U2>&& __in)
561
        : _Inherited(std::forward<_U1>(__in.first),
562
                     std::forward<_U2>(__in.second)) { }
563
 
564
      // Allocator-extended constructors.
565
 
566
      template
567
        tuple(allocator_arg_t __tag, const _Alloc& __a)
568
        : _Inherited(__tag, __a) { }
569
 
570
      template
571
        tuple(allocator_arg_t __tag, const _Alloc& __a,
572
              const _T1& __a1, const _T2& __a2)
573
        : _Inherited(__tag, __a, __a1, __a2) { }
574
 
575
      template
576
        tuple(allocator_arg_t __tag, const _Alloc& __a, _U1&& __a1, _U2&& __a2)
577
        : _Inherited(__tag, __a, std::forward<_U1>(__a1),
578
                     std::forward<_U2>(__a2)) { }
579
 
580
      template
581
        tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
582
        : _Inherited(__tag, __a, static_cast(__in)) { }
583
 
584
      template
585
        tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
586
        : _Inherited(__tag, __a, static_cast<_Inherited&&>(__in)) { }
587
 
588
      template
589
        tuple(allocator_arg_t __tag, const _Alloc& __a,
590
              const tuple<_U1, _U2>& __in)
591
        : _Inherited(__tag, __a,
592
                     static_cast&>(__in))
593
        { }
594
 
595
      template
596
        tuple(allocator_arg_t __tag, const _Alloc& __a, tuple<_U1, _U2>&& __in)
597
        : _Inherited(__tag, __a, static_cast<_Tuple_impl<0, _U1, _U2>&&>(__in))
598
        { }
599
 
600
      template
601
        tuple(allocator_arg_t __tag, const _Alloc& __a,
602
              const pair<_U1, _U2>& __in)
603
        : _Inherited(__tag, __a, __in.first, __in.second) { }
604
 
605
      template
606
        tuple(allocator_arg_t __tag, const _Alloc& __a, pair<_U1, _U2>&& __in)
607
        : _Inherited(__tag, __a, std::forward<_U1>(__in.first),
608
                     std::forward<_U2>(__in.second)) { }
609
 
610
      tuple&
611
      operator=(const tuple& __in)
612
      {
613
        static_cast<_Inherited&>(*this) = __in;
614
        return *this;
615
      }
616
 
617
      tuple&
618
      operator=(tuple&& __in)
619
      noexcept(is_nothrow_move_assignable<_Inherited>::value)
620
      {
621
        static_cast<_Inherited&>(*this) = std::move(__in);
622
        return *this;
623
      }
624
 
625
      template
626
        tuple&
627
        operator=(const tuple<_U1, _U2>& __in)
628
        {
629
          static_cast<_Inherited&>(*this) = __in;
630
          return *this;
631
        }
632
 
633
      template
634
        tuple&
635
        operator=(tuple<_U1, _U2>&& __in)
636
        {
637
          static_cast<_Inherited&>(*this) = std::move(__in);
638
          return *this;
639
        }
640
 
641
      template
642
        tuple&
643
        operator=(const pair<_U1, _U2>& __in)
644
        {
645
          this->_M_head(*this) = __in.first;
646
          this->_M_tail(*this)._M_head(*this) = __in.second;
647
          return *this;
648
        }
649
 
650
      template
651
        tuple&
652
        operator=(pair<_U1, _U2>&& __in)
653
        {
654
          this->_M_head(*this) = std::forward<_U1>(__in.first);
655
          this->_M_tail(*this)._M_head(*this) = std::forward<_U2>(__in.second);
656
          return *this;
657
        }
658
 
659
      void
660
      swap(tuple& __in)
661
      noexcept(noexcept(__in._M_swap(__in)))
662
      { _Inherited::_M_swap(__in); }
663
    };
664
 
665
 
666
  /// Gives the type of the ith element of a given tuple type.
667
  template
668
    struct tuple_element;
669
 
670
  /**
671
   * Recursive case for tuple_element: strip off the first element in
672
   * the tuple and retrieve the (i-1)th element of the remaining tuple.
673
   */
674
  template
675
    struct tuple_element<__i, tuple<_Head, _Tail...> >
676
    : tuple_element<__i - 1, tuple<_Tail...> > { };
677
 
678
  /**
679
   * Basis case for tuple_element: The first element is the one we're seeking.
680
   */
681
  template
682
    struct tuple_element<0, tuple<_Head, _Tail...> >
683
    {
684
      typedef _Head type;
685
    };
686
 
687
  template
688
    struct tuple_element<__i, const _Tp>
689
    {
690
      typedef typename
691
      add_const::type>::type type;
692
    };
693
 
694
  template
695
    struct tuple_element<__i, volatile _Tp>
696
    {
697
      typedef typename
698
      add_volatile::type>::type type;
699
    };
700
 
701
  template
702
    struct tuple_element<__i, const volatile _Tp>
703
    {
704
      typedef typename
705
      add_cv::type>::type type;
706
    };
707
 
708
  /// Finds the size of a given tuple type.
709
  template
710
    struct tuple_size;
711
 
712
  template
713
    struct tuple_size
714
    : public integral_constant<
715
             typename remove_cv::value)>::type,
716
             tuple_size<_Tp>::value> { };
717
 
718
  template
719
    struct tuple_size
720
    : public integral_constant<
721
             typename remove_cv::value)>::type,
722
             tuple_size<_Tp>::value> { };
723
 
724
  template
725
    struct tuple_size
726
    : public integral_constant<
727
             typename remove_cv::value)>::type,
728
             tuple_size<_Tp>::value> { };
729
 
730
  /// class tuple_size
731
  template
732
    struct tuple_size>
733
    : public integral_constant { };
734
 
735
  template
736
    constexpr typename __add_ref<_Head>::type
737
    __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
738
    { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
739
 
740
  template
741
    constexpr typename __add_c_ref<_Head>::type
742
    __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) noexcept
743
    { return _Tuple_impl<__i, _Head, _Tail...>::_M_head(__t); }
744
 
745
  // Return a reference (const reference, rvalue reference) to the ith element
746
  // of a tuple.  Any const or non-const ref elements are returned with their
747
  // original type.
748
  template
749
    constexpr typename __add_ref<
750
                      typename tuple_element<__i, tuple<_Elements...>>::type
751
                    >::type
752
    get(tuple<_Elements...>& __t) noexcept
753
    { return __get_helper<__i>(__t); }
754
 
755
  template
756
    constexpr typename __add_c_ref<
757
                      typename tuple_element<__i, tuple<_Elements...>>::type
758
                    >::type
759
    get(const tuple<_Elements...>& __t) noexcept
760
    { return __get_helper<__i>(__t); }
761
 
762
  template
763
    constexpr typename __add_r_ref<
764
                      typename tuple_element<__i, tuple<_Elements...>>::type
765
                    >::type
766
    get(tuple<_Elements...>&& __t) noexcept
767
    { return std::forward
768
        tuple<_Elements...>>::type&&>(get<__i>(__t)); }
769
 
770
  // This class helps construct the various comparison operations on tuples
771
  template
772
           typename _Tp, typename _Up>
773
    struct __tuple_compare;
774
 
775
  template
776
    struct __tuple_compare<0, __i, __j, _Tp, _Up>
777
    {
778
      static constexpr bool
779
      __eq(const _Tp& __t, const _Up& __u)
780
      {
781
        return (get<__i>(__t) == get<__i>(__u) &&
782
                __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__eq(__t, __u));
783
      }
784
 
785
      static constexpr bool
786
      __less(const _Tp& __t, const _Up& __u)
787
      {
788
        return ((get<__i>(__t) < get<__i>(__u))
789
                || !(get<__i>(__u) < get<__i>(__t)) &&
790
                __tuple_compare<0, __i + 1, __j, _Tp, _Up>::__less(__t, __u));
791
      }
792
    };
793
 
794
  template
795
    struct __tuple_compare<0, __i, __i, _Tp, _Up>
796
    {
797
      static constexpr bool
798
      __eq(const _Tp&, const _Up&) { return true; }
799
 
800
      static constexpr bool
801
      __less(const _Tp&, const _Up&) { return false; }
802
    };
803
 
804
  template
805
    constexpr bool
806
    operator==(const tuple<_TElements...>& __t,
807
               const tuple<_UElements...>& __u)
808
    {
809
      typedef tuple<_TElements...> _Tp;
810
      typedef tuple<_UElements...> _Up;
811
      return bool(__tuple_compare::value - tuple_size<_Up>::value,
812
              0, tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u));
813
    }
814
 
815
  template
816
    constexpr bool
817
    operator<(const tuple<_TElements...>& __t,
818
              const tuple<_UElements...>& __u)
819
    {
820
      typedef tuple<_TElements...> _Tp;
821
      typedef tuple<_UElements...> _Up;
822
      return bool(__tuple_compare::value - tuple_size<_Up>::value,
823
              0, tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u));
824
    }
825
 
826
  template
827
    inline constexpr bool
828
    operator!=(const tuple<_TElements...>& __t,
829
               const tuple<_UElements...>& __u)
830
    { return !(__t == __u); }
831
 
832
  template
833
    inline constexpr bool
834
    operator>(const tuple<_TElements...>& __t,
835
              const tuple<_UElements...>& __u)
836
    { return __u < __t; }
837
 
838
  template
839
    inline constexpr bool
840
    operator<=(const tuple<_TElements...>& __t,
841
               const tuple<_UElements...>& __u)
842
    { return !(__u < __t); }
843
 
844
  template
845
    inline constexpr bool
846
    operator>=(const tuple<_TElements...>& __t,
847
               const tuple<_UElements...>& __u)
848
    { return !(__t < __u); }
849
 
850
  // NB: DR 705.
851
  template
852
    constexpr tuple::__type...>
853
    make_tuple(_Elements&&... __args)
854
    {
855
      typedef tuple::__type...>
856
        __result_type;
857
      return __result_type(std::forward<_Elements>(__args)...);
858
    }
859
 
860
  template
861
    tuple<_Elements&&...>
862
    forward_as_tuple(_Elements&&... __args) noexcept
863
    { return tuple<_Elements&&...>(std::forward<_Elements>(__args)...); }
864
 
865
  template
866
    struct __is_tuple_like_impl : false_type
867
    { };
868
 
869
  template
870
    struct __is_tuple_like_impl> : true_type
871
    { };
872
 
873
  template
874
    struct __is_tuple_like_impl> : true_type
875
    { };
876
 
877
  template
878
    struct __is_tuple_like_impl> : true_type
879
    { };
880
 
881
  // Internal type trait that allows us to sfinae-protect tuple_cat.
882
  template
883
    struct __is_tuple_like
884
    : public __is_tuple_like_impl
885
            ::type>::type>::type
886
    { };
887
 
888
  // Stores a tuple of indices.  Also used by bind() to extract the elements
889
  // in a tuple.
890
  template
891
    struct _Index_tuple
892
    {
893
      typedef _Index_tuple<_Indexes..., sizeof...(_Indexes)> __next;
894
    };
895
 
896
  // Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
897
  template
898
    struct _Build_index_tuple
899
    {
900
      typedef typename _Build_index_tuple<_Num - 1>::__type::__next __type;
901
    };
902
 
903
  template<>
904
    struct _Build_index_tuple<0>
905
    {
906
      typedef _Index_tuple<> __type;
907
    };
908
 
909
  template
910
    struct __make_tuple_impl;
911
 
912
  template
913
           std::size_t _Nm>
914
    struct __make_tuple_impl<_Idx, tuple<_Tp...>, _Tuple, _Nm>
915
    {
916
      typedef typename __make_tuple_impl<_Idx + 1, tuple<_Tp...,
917
        typename std::tuple_element<_Idx, _Tuple>::type>, _Tuple, _Nm>::__type
918
      __type;
919
    };
920
 
921
  template
922
    struct __make_tuple_impl<_Nm, tuple<_Tp...>, _Tuple, _Nm>
923
    {
924
      typedef tuple<_Tp...> __type;
925
    };
926
 
927
  template
928
    struct __do_make_tuple
929
    : public __make_tuple_impl<0, tuple<>, _Tuple,
930
                               std::tuple_size<_Tuple>::value>
931
    { };
932
 
933
  // Returns the std::tuple equivalent of a tuple-like type.
934
  template
935
    struct __make_tuple
936
    : public __do_make_tuple
937
            ::type>::type>
938
    { };
939
 
940
  // Combines several std::tuple's into a single one.
941
  template
942
    struct __combine_tuples;
943
 
944
  template<>
945
    struct __combine_tuples<>
946
    {
947
      typedef tuple<> __type;
948
    };
949
 
950
  template
951
    struct __combine_tuples>
952
    {
953
      typedef tuple<_Ts...> __type;
954
    };
955
 
956
  template
957
    struct __combine_tuples, tuple<_T2s...>, _Rem...>
958
    {
959
      typedef typename __combine_tuples,
960
                                        _Rem...>::__type __type;
961
    };
962
 
963
  // Computes the result type of tuple_cat given a set of tuple-like types.
964
  template
965
    struct __tuple_cat_result
966
    {
967
      typedef typename __combine_tuples
968
        ::__type...>::__type __type;
969
    };
970
 
971
  // Helper to determine the index set for the first tuple-like
972
  // type of a given set.
973
  template
974
    struct __make_1st_indices;
975
 
976
  template<>
977
    struct __make_1st_indices<>
978
    {
979
      typedef std::_Index_tuple<> __type;
980
    };
981
 
982
  template
983
    struct __make_1st_indices<_Tp, _Tpls...>
984
    {
985
      typedef typename std::_Build_index_tuple
986
        typename std::remove_reference<_Tp>::type>::value>::__type __type;
987
    };
988
 
989
  // Performs the actual concatenation by step-wise expanding tuple-like
990
  // objects into the elements,  which are finally forwarded into the
991
  // result tuple.
992
  template
993
    struct __tuple_concater;
994
 
995
  template
996
    struct __tuple_concater<_Ret, std::_Index_tuple<_Is...>, _Tp, _Tpls...>
997
    {
998
      template
999
        static constexpr _Ret
1000
        _S_do(_Tp&& __tp, _Tpls&&... __tps, _Us&&... __us)
1001
        {
1002
          typedef typename __make_1st_indices<_Tpls...>::__type __idx;
1003
          typedef __tuple_concater<_Ret, __idx, _Tpls...>      __next;
1004
          return __next::_S_do(std::forward<_Tpls>(__tps)...,
1005
                               std::forward<_Us>(__us)...,
1006
                               std::get<_Is>(std::forward<_Tp>(__tp))...);
1007
        }
1008
    };
1009
 
1010
  template
1011
    struct __tuple_concater<_Ret, std::_Index_tuple<>>
1012
    {
1013
      template
1014
        static constexpr _Ret
1015
        _S_do(_Us&&... __us)
1016
        {
1017
          return _Ret(std::forward<_Us>(__us)...);
1018
        }
1019
    };
1020
 
1021
  template
1022
           enable_if<__and_<__is_tuple_like<_Tpls>...>::value>::type>
1023
    constexpr auto
1024
    tuple_cat(_Tpls&&... __tpls)
1025
    -> typename __tuple_cat_result<_Tpls...>::__type
1026
    {
1027
      typedef typename __tuple_cat_result<_Tpls...>::__type __ret;
1028
      typedef typename __make_1st_indices<_Tpls...>::__type __idx;
1029
      typedef __tuple_concater<__ret, __idx, _Tpls...> __concater;
1030
      return __concater::_S_do(std::forward<_Tpls>(__tpls)...);
1031
    }
1032
 
1033
  template
1034
    inline tuple<_Elements&...>
1035
    tie(_Elements&... __args) noexcept
1036
    { return tuple<_Elements&...>(__args...); }
1037
 
1038
  template
1039
    inline void
1040
    swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
1041
    noexcept(noexcept(__x.swap(__y)))
1042
    { __x.swap(__y); }
1043
 
1044
  // A class (and instance) which can be used in 'tie' when an element
1045
  // of a tuple is not required
1046
  struct _Swallow_assign
1047
  {
1048
    template
1049
      const _Swallow_assign&
1050
      operator=(const _Tp&) const
1051
      { return *this; }
1052
  };
1053
 
1054
  const _Swallow_assign ignore{};
1055
 
1056
  /// Partial specialization for tuples
1057
  template
1058
    struct uses_allocator, _Alloc> : true_type { };
1059
 
1060
  // See stl_pair.h...
1061
  template
1062
    template
1063
      inline
1064
      pair<_T1, _T2>::
1065
      pair(piecewise_construct_t,
1066
           tuple<_Args1...> __first, tuple<_Args2...> __second)
1067
      : pair(__first, __second,
1068
             typename _Build_index_tuple::__type(),
1069
             typename _Build_index_tuple::__type())
1070
      { }
1071
 
1072
  template
1073
    template
1074
             typename... _Args2, std::size_t... _Indexes2>
1075
      inline
1076
      pair<_T1, _T2>::
1077
      pair(tuple<_Args1...>& __tuple1, tuple<_Args2...>& __tuple2,
1078
           _Index_tuple<_Indexes1...>, _Index_tuple<_Indexes2...>)
1079
      : first(std::forward<_Args1>(std::get<_Indexes1>(__tuple1))...),
1080
        second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
1081
      { }
1082
 
1083
_GLIBCXX_END_NAMESPACE_VERSION
1084
} // namespace
1085
 
1086
#endif // C++11
1087
 
1088
#endif // _GLIBCXX_TUPLE

powered by: WebSVN 2.1.0

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