xref: /openbsd-src/gnu/gcc/libstdc++-v3/include/tr1/tuple (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert// class template tuple -*- C++ -*-
2*404b540aSrobert
3*404b540aSrobert// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4*404b540aSrobert//
5*404b540aSrobert// This file is part of the GNU ISO C++ Library.  This library is free
6*404b540aSrobert// software; you can redistribute it and/or modify it under the
7*404b540aSrobert// terms of the GNU General Public License as published by the
8*404b540aSrobert// Free Software Foundation; either version 2, or (at your option)
9*404b540aSrobert// any later version.
10*404b540aSrobert
11*404b540aSrobert// This library is distributed in the hope that it will be useful,
12*404b540aSrobert// but WITHOUT ANY WARRANTY; without even the implied warranty of
13*404b540aSrobert// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*404b540aSrobert// GNU General Public License for more details.
15*404b540aSrobert
16*404b540aSrobert// You should have received a copy of the GNU General Public License along
17*404b540aSrobert// with this library; see the file COPYING.  If not, write to the Free
18*404b540aSrobert// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19*404b540aSrobert// USA.
20*404b540aSrobert
21*404b540aSrobert// As a special exception, you may use this file as part of a free software
22*404b540aSrobert// library without restriction.  Specifically, if other files instantiate
23*404b540aSrobert// templates or use macros or inline functions from this file, or you compile
24*404b540aSrobert// this file and link it with other files to produce an executable, this
25*404b540aSrobert// file does not by itself cause the resulting executable to be covered by
26*404b540aSrobert// the GNU General Public License.  This exception does not however
27*404b540aSrobert// invalidate any other reasons why the executable file might be covered by
28*404b540aSrobert// the GNU General Public License.
29*404b540aSrobert
30*404b540aSrobert/** @file tr1/tuple
31*404b540aSrobert*  This is a TR1 C++ Library header.
32*404b540aSrobert*/
33*404b540aSrobert
34*404b540aSrobert// Chris Jefferson <chris@bubblescope.net>
35*404b540aSrobert
36*404b540aSrobert#ifndef _TR1_TUPLE
37*404b540aSrobert#define _TR1_TUPLE 1
38*404b540aSrobert
39*404b540aSrobert#include <tr1/utility>
40*404b540aSrobert#include <tr1/ref_fwd.h>
41*404b540aSrobert
42*404b540aSrobertnamespace std
43*404b540aSrobert{
44*404b540aSrobert_GLIBCXX_BEGIN_NAMESPACE(tr1)
45*404b540aSrobert
46*404b540aSrobert // An implementation specific class which is used in the tuple class
47*404b540aSrobert // when the tuple is not maximum possible size.
48*404b540aSrobert struct _NullClass { };
49*404b540aSrobert
50*404b540aSrobert /// Gives the type of the ith element of a given tuple type.
51*404b540aSrobert template<int __i, typename _Tp>
52*404b540aSrobert   struct tuple_element;
53*404b540aSrobert
54*404b540aSrobert /// Finds the size of a given tuple type.
55*404b540aSrobert template<typename _Tp>
56*404b540aSrobert   struct tuple_size;
57*404b540aSrobert
58*404b540aSrobert // Adds a const reference to a non-reference type.
59*404b540aSrobert template<typename _Tp>
60*404b540aSrobert   struct __add_c_ref
61*404b540aSrobert   { typedef const _Tp& type; };
62*404b540aSrobert
63*404b540aSrobert template<typename _Tp>
64*404b540aSrobert   struct __add_c_ref<_Tp&>
65*404b540aSrobert   { typedef _Tp& type; };
66*404b540aSrobert
67*404b540aSrobert // Adds a reference to a non-reference type.
68*404b540aSrobert template<typename _Tp>
69*404b540aSrobert   struct __add_ref
70*404b540aSrobert   { typedef _Tp& type; };
71*404b540aSrobert
72*404b540aSrobert template<typename _Tp>
73*404b540aSrobert   struct __add_ref<_Tp&>
74*404b540aSrobert   { typedef _Tp& type; };
75*404b540aSrobert
76*404b540aSrobert // Class used in the implementation of get
77*404b540aSrobert template<int __i, typename _Tp>
78*404b540aSrobert   struct __get_helper;
79*404b540aSrobert
80*404b540aSrobert // Returns a const reference to the ith element of a tuple.
81*404b540aSrobert // Any const or non-const ref elements are returned with their original type.
82*404b540aSrobert
83*404b540aSrobert // This class helps construct the various comparison operations on tuples
84*404b540aSrobert template<int __check_equal_size, int __i, int __j, typename _Tp, typename _Up>
85*404b540aSrobert   struct __tuple_compare;
86*404b540aSrobert
87*404b540aSrobert // Helper which adds a reference to a type when given a reference_wrapper
88*404b540aSrobert template<typename _Tp>
89*404b540aSrobert   struct __strip_reference_wrapper
90*404b540aSrobert   {
91*404b540aSrobert       typedef _Tp __type;
92*404b540aSrobert   };
93*404b540aSrobert
94*404b540aSrobert template<typename _Tp>
95*404b540aSrobert   struct __strip_reference_wrapper<reference_wrapper<_Tp> >
96*404b540aSrobert   {
97*404b540aSrobert     typedef _Tp& __type;
98*404b540aSrobert   };
99*404b540aSrobert
100*404b540aSrobert template<typename _Tp>
101*404b540aSrobert   struct __strip_reference_wrapper<const reference_wrapper<_Tp> >
102*404b540aSrobert   {
103*404b540aSrobert       typedef _Tp& __type;
104*404b540aSrobert   };
105*404b540aSrobert
106*404b540aSrobert  #include "tuple_defs.h"
107*404b540aSrobert
108*404b540aSrobert template<int __i, int __j, typename _Tp, typename _Up>
109*404b540aSrobert   struct __tuple_compare<0, __i, __j, _Tp, _Up>
110*404b540aSrobert   {
111*404b540aSrobert     static bool __eq(const _Tp& __t, const _Up& __u)
112*404b540aSrobert     {
113*404b540aSrobert       return get<__i>(__t) == get<__i>(__u) &&
114*404b540aSrobert          __tuple_compare<0, __i+1, __j, _Tp, _Up>::__eq(__t, __u);
115*404b540aSrobert     }
116*404b540aSrobert     static bool __less(const _Tp& __t, const _Up& __u)
117*404b540aSrobert     {
118*404b540aSrobert       return (get<__i>(__t) < get<__i>(__u)) || !(get<__i>(__u) < get<__i>(__t)) &&
119*404b540aSrobert          __tuple_compare<0, __i+1, __j, _Tp, _Up>::__less(__t, __u);
120*404b540aSrobert     }
121*404b540aSrobert   };
122*404b540aSrobert
123*404b540aSrobert template<int __i, typename _Tp, typename _Up>
124*404b540aSrobert   struct __tuple_compare<0, __i, __i, _Tp, _Up>
125*404b540aSrobert   {
126*404b540aSrobert     static bool __eq(const _Tp&, const _Up&)
127*404b540aSrobert     { return true; }
128*404b540aSrobert     static bool __less(const _Tp&, const _Up&)
129*404b540aSrobert     { return false; }
130*404b540aSrobert   };
131*404b540aSrobert
132*404b540aSrobert // A class (and instance) which can be used in 'tie' when an element
133*404b540aSrobert // of a tuple is not required
134*404b540aSrobert struct swallow_assign
135*404b540aSrobert {
136*404b540aSrobert   template<class T>
137*404b540aSrobert   swallow_assign&
138*404b540aSrobert     operator=(const T&)
139*404b540aSrobert     { return *this; }
140*404b540aSrobert };
141*404b540aSrobert
142*404b540aSrobert // TODO: Put this in some kind of shared file.
143*404b540aSrobert namespace
144*404b540aSrobert {
145*404b540aSrobert   swallow_assign ignore;
146*404b540aSrobert }; // anonymous namespace
147*404b540aSrobert
148*404b540aSrobert_GLIBCXX_END_NAMESPACE
149*404b540aSrobert}
150*404b540aSrobert
151*404b540aSrobert#define _GLIBCXX_CAT(x,y) _GLIBCXX_CAT2(x,y)
152*404b540aSrobert#define _GLIBCXX_CAT2(x,y) x##y
153*404b540aSrobert#define _SHORT_REPEAT
154*404b540aSrobert#define _GLIBCXX_REPEAT_HEADER <tr1/tuple_iterate.h>
155*404b540aSrobert#include <tr1/repeat.h>
156*404b540aSrobert#undef _GLIBCXX_REPEAT_HEADER
157*404b540aSrobert#undef _SHORT_REPEAT
158*404b540aSrobert
159*404b540aSrobert#include <tr1/functional>
160*404b540aSrobert
161*404b540aSrobert#endif
162