How is std::tuple implemented?

One approach to implementing tuples is using multiple-inheritance. The tuple-elements are held by leaf-classes, and the tuple class itself inherits from multiple leafs. In pseudo-code: template<typename T0, typename T1, …, typename Tn> class PseudoTuple : TupleLeaf<0, T0>, TupleLeaf<1, T1>, …, TupleLeaf<n, Tn> { … }; Each leaf has an index, so that each base-class becomes … Read more

Tuple value by key

The canonical data structure for this type of queries is a dictionary: In [1]: t = ( …: (‘P’, ‘Shtg1’), …: (‘R’, u’Shtg2′), …: (‘D’, ‘Shtg3’), …: ) In [2]: d = dict(t) In [3]: d[‘P’] Out[3]: ‘Shtg1’ If you use a tuple, there is no way to avoid looping (either explicit or implicit).

C++11 Tagged Tuple

I’m not aware of any existing class that does this, but it’s fairly easy to throw something together using a std::tuple and an indexing typelist: #include <tuple> #include <iostream> template<typename… Ts> struct typelist { template<typename T> using prepend = typelist<T, Ts…>; }; template<typename T, typename… Ts> struct index; template<typename T, typename… Ts> struct index<T, T, … Read more

How to return named tuples in C#?

Like this: public (DateTime Start, DateTime End) DateRanges { get { return (DateTime.MinValue, DateTime.MaxValue); } } Note: This requires a recent version of C# and .Net. Incidentally, watch out for this usage pattern: var from = filter?.DateRanges.Start; var to = filter?.DateRanges.End; That’s inefficient because it causes two identical tuples to be created. This is better: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)