Questions tagged [stdtuple]

Use this tag for questions about the C++ standard library template std::tuple. It represents an ordered, heterogeneous sequence of objects. Also add the tag [c++] when using this tag.

Also see and .

403 questions
3
votes
1 answer

Generically call member function on each element of a tuple

Step one: expand a tuple and pass elements to a function: I have a function which takes N parameters void func(int, double, char); and a tuple with the matching types std::tuple tuple; As per this stackoverflow question, I am…
Steve Lorimer
  • 27,059
  • 17
  • 118
  • 213
3
votes
1 answer

"unpack" std::array as arguments to function

Here is quite nice (not mine) example how u can expand (or "explode") tuple as arguments to function: template struct index_tuple_type { template using append = index_tuple_type; }; template struct make_index_impl…
The_Ham
  • 427
  • 3
  • 7
3
votes
1 answer

Why isn't `std::forward_as_tuple(1)` a constant expression?

#include int main() { static_assert(std::is_same, decltype(std::forward_as_tuple(1))>::value, ""); constexpr int x = 5; constexpr auto t1 = std::forward_as_tuple(1); // (1) constexpr…
SplinterOfChaos
  • 469
  • 3
  • 12
3
votes
2 answers

std::array compile time deduction

I have a piece of code that I tried to automatically decode a buffer given the awaited data types. The data are represented as tuples: std::tuple data; size_t bufferIndex; IOBuffer::ConstSPtr buffer( std::make_shared(5)…
Athanase
  • 933
  • 9
  • 25
3
votes
2 answers

Creating a C++ std::tuple projection function

I am looking for a projection function for std::tuple. I.e., the function receives a list of integers as template parameters and returns a tuple that only has the values at these indexes. For example, consider I have a tuple…
gexicide
  • 38,535
  • 21
  • 92
  • 152
3
votes
1 answer

Can I iterate over a C++11 std::tuple with openmp?

I have the following code given to iterate over std::tuple. The code is from here here. #include #include template inline typename std::enable_if
Johannes
  • 2,901
  • 5
  • 30
  • 50
3
votes
2 answers

Access tuple element in C++11 via compile time variable in function

The following minimal example compiles with g++ -std=c++11 -Wall tuple.cpp -o tuple: #include #include template char get_elem_i(std::tuple t) { return std::get(t); } int main() { std::tuple
Johannes
  • 2,901
  • 5
  • 30
  • 50
3
votes
2 answers

Common base class breaks empty base class optimization for tuples

gcc 4.7.1 does empty base class optimization for tuples, which I consider a really useful feature. However, there appears to be an unexpected limit to this: #include #include #include class A { }; class B : public A {…
MvG
  • 57,380
  • 22
  • 148
  • 276
2
votes
1 answer

How can I get the first N elements of a tuple c++?

lets say I had a function like the following, how could I get the first n elements of a tuple? template void foo(Ts... ts){ std::tuple all_elements(ts...); auto first_elements = //the first N elements of the…
2
votes
1 answer

Retrieving printf format parameter by type

The following lambda is supposed to return the string formatter for printf and alike at compiletime, however it doesn't seem to work as intended and I can't get behind it. Demo #include #include #include int main()…
glades
  • 3,778
  • 1
  • 12
  • 34
2
votes
1 answer

Use tuple in variadic template

I am designing a logger. I'll format for it. I made a design that I would predetermine the format string and then keep this data in a tuple and print it to the log. The code below is working now, but I want it to work in the parts I commented…
2
votes
0 answers

Can I deduce the type of function template arguments from aggegate-initialisation arguments without spelling out their type template?

I have a helper function f that receives a variadic number of tuple-like arguments, but I'd be okay restricting it to std::tuple. These are in practice always temporaries, so a typical call looks something like this: int i{}; f( …
bitmask
  • 32,434
  • 14
  • 99
  • 159
2
votes
1 answer

Constrain to function objects with one reference parameter of any type

I'm probably scratching the possibilities of C++ a bit here. I have this tuple for each function that executes a function for every tuple element. Now I want to constrain the incoming function object in a way that only allows for function objects…
glades
  • 3,778
  • 1
  • 12
  • 34
2
votes
1 answer

std::apply-ing sscanf into a tuple, tuple not fully updating

I have a structured string of data, and I want to parse it into a tuple. For each different kind of input string, the types and arrangement of the data can be different, so I want to use templates and scanf formats to avoid having to manage all…
Remy Porter
  • 353
  • 1
  • 3
  • 12
2
votes
0 answers

Is there a better way to get `std::tuple::operator==` to leverage `operator==` from another namespace?

I'm using a C struct (that I do not control) and wrote a freestanding operator== implementation for it in a namespace. I have another class that has that C struct as a member and that also has an operator== implementation. Originally I…
jamesdlin
  • 81,374
  • 13
  • 159
  • 204