Lumiera  0.pre.03
»edit your freedom«
util-tuple.hpp
1 /*
2  UTIL-TUPLE.hpp - helpers and convenience shortcuts for working with tuples
3 
4  Copyright (C) Lumiera.org
5  2023, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program 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  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
42 #ifndef UTIL_TUPLE_H
43 #define UTIL_TUPLE_H
44 
45 
46 #include <tuple>
47 #include <utility>
48 
49 
50 
51 namespace util {
52 
53  namespace { // recursive builder helper to unpack a sequence...
54 
55  template<size_t N>
56  using cnt_ = std::integral_constant<size_t, N>;
57 
58  template<class SEQ>
59  inline auto
60  _buildSeqTuple (cnt_<0>, SEQ&&)
61  {
62  return std::tuple<>{};
63  }
64 
65  template<size_t N, class SEQ>
66  inline auto
67  _buildSeqTuple (cnt_<N>, SEQ&& iter)
68  {
69  auto prefixTuple = std::tie (*iter);
70  ++iter;
71  return std::tuple_cat (prefixTuple, _buildSeqTuple (cnt_<N-1>{}, std::forward<SEQ> (iter)));
72  }
73  }//(End) unpacking helper
74 
75 
87  template<size_t N, class SEQ>
88  auto
89  seqTuple (SEQ&& iter)
90  {
91  return _buildSeqTuple (cnt_<N>{}, std::forward<SEQ> (iter));
92  }
93 
94 
95 } // namespace util
96 #endif /*UTIL_TUPLE_H*/