get part of std::tuple

With help of a compile-time integer list: #include <cstdlib> template <size_t… n> struct ct_integers_list { template <size_t m> struct push_back { typedef ct_integers_list<n…, m> type; }; }; template <size_t max> struct ct_iota_1 { typedef typename ct_iota_1<max-1>::type::template push_back<max>::type type; }; template <> struct ct_iota_1<0> { typedef ct_integers_list<> type; }; We could construct the tail simply by … Read more

get part of std::tuple

With help of a compile-time integer list: #include <cstdlib> template <size_t… n> struct ct_integers_list { template <size_t m> struct push_back { typedef ct_integers_list<n…, m> type; }; }; template <size_t max> struct ct_iota_1 { typedef typename ct_iota_1<max-1>::type::template push_back<max>::type type; }; template <> struct ct_iota_1<0> { typedef ct_integers_list<> type; }; We could construct the tail simply by … Read more

Is it possible to have tuple assignment to variables in Scala? [duplicate]

This isn’t simply “multiple variable assignment”, it’s fully-featured pattern matching! So the following are all valid: val (a, b) = (1, 2) val Array(a, b) = Array(1, 2) val h :: t = List(1, 2) val List(a, Some(b)) = List(1, Option(2)) This is the way that pattern matching works, it’ll de-construct something into smaller parts, … Read more

How to initialize all tuple elements by the same arguments?

The clearest way is just to construct each element in the tuple constructor argument list: template <typename… TElements> struct Container { Container(Foo foo, Bar bar) : tuple(TElements{foo, bar}…) {} std::tuple<TElements…> tuple; }; This will result in move (or copy) constructing each element of the tuple from its corresponding constructor parameter; if this is unacceptable you … Read more