33#ifndef DRAIN_TUPLE_BASE
34#define DRAIN_TUPLE_BASE
44#include "StringBuilder.h"
74template <
typename S,
size_t N=2>
83 typedef S
const* const_iterator;
85 static const size_t storageTypeSize;
102 const_iterator begin()
const = 0;
105 const_iterator end()
const = 0;
108 iterator begin() = 0;
118 const S &
at(
size_t i)
const {
121 return *(begin() + i);
129 throw std::runtime_error(
StringBuilder<
' '>(__FUNCTION__,
"index overflow:", i));
133 const S & operator[](
size_t i)
const {
144 return *(begin() + i);
152 throw std::runtime_error(
StringBuilder<
' '>(__FUNCTION__,
"index overflow:", i));
156 S & operator[](
size_t i){
163 const_iterator it = begin();
164 const_iterator tit = t.begin();
180 for (
const auto e: *
this){
198 return !(*
this == t);
205 for (const_iterator it = begin(); it != end(); ++it){
206 sequence.insert(sequence.end(), *it);
215 void set(
const tuplebase_t & t){
229 template <
class T2,
size_t N2=2>
244 void set(
const S & arg) {
252 template<
typename ... SS>
254 void set(
const S & arg,
const SS &... rest) {
261 void set(std::initializer_list<T> l){
288 typename T::const_iterator cit = sequence.begin();
289 iterator it = begin();
290 while (cit != sequence.end()){
296 throw std::runtime_error(
StringBuilder<
':'>(__FILE__,
':', __FUNCTION__,
": index overflow in assigning: ", *cit));
316 for (iterator it = begin(); it != end(); ++it){
335 for (const_iterator it = begin(); it != end(); ++it){
346 void toStream(std::ostream & ostr)
const {
351 std::string toStr(
char separator=
',')
const {
352 std::stringstream sstr;
362 void updateTuple(){};
374 template<
typename T2,
typename ... TT>
377 throw std::runtime_error(
StringBuilder<>(__FILE__,
':', __FUNCTION__,
": index (", i,
") overflow in assigning: ", arg,
",..."));
381 this->
at(i) =
static_cast<S
>(arg);
388template <
typename S,
size_t N>
389const size_t TupleBase<S,N>::storageTypeSize =
sizeof(S);
392template <
class S,
size_t N>
393std::ostream & operator<<(std::ostream & ostr,
const TupleBase<S,N> & tuple){
394 tuple.toStream(ostr);
399template <
typename S,
size_t N>
402 static const std::string & str(){
Definition StringBuilder.h:58
Definition TupleBase.h:75
static size_t size()
Return the number of elements.
Definition TupleBase.h:97
void setIndexed(size_t i)
Argument stack endpoint function; final step of variadic argument set(arg, ...) .
Definition TupleBase.h:368
T & toSequence(T &sequence) const
Copy elements to a Sequence, like stl::list, stl::set or stl::vector.
Definition TupleBase.h:203
bool operator!=(const tuplebase_t &t) const
Inequality operator.
Definition TupleBase.h:197
void fill(S i)
Set all the elements to i.
Definition TupleBase.h:315
bool operator==(const tuplebase_t &t) const
Equality operator.
Definition TupleBase.h:162
tuplebase_t & assignSequence(T &sequence, bool LENIENT=false)
Proposed for tuples only; derived classes should not shadow this.
Definition TupleBase.h:287
void setIndexed(size_t i, T2 arg, const TT &... rest)
Worker called by set(T2 arg, T2 arg2, ...)
Definition TupleBase.h:375
virtual void toStreamFormatted(std::ostream &ostr, char separator=',') const
Definition TupleBase.h:331
const S & at(size_t i) const
Return const reference to element i.
Definition TupleBase.h:118
void set(const TupleBase< T2, N2 > &t)
Assign tuple of different type and/or size.
Definition TupleBase.h:232
S & at(size_t i)
Return reference to element i.
Definition TupleBase.h:142
void set(const S &arg, const SS &... rest)
Set element(s).
Definition TupleBase.h:254
bool operator==(const value_type &t) const
Equality operator against single value.
Definition TupleBase.h:178
Definition DataSelector.cpp:1277
Definition TupleBase.h:52
static const S neutral_value
Zero, by default. For enum types, must be explicitly given.
Definition TupleBase.h:63
static const std::string name
Default implementation: name returned by std::type_info::name()
Definition Type.h:558