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.
Questions tagged [stdtuple]
403 questions
5
votes
1 answer
Is accessing a tuple of tuples of pointers and a mutexes thread-safe
Given the std::tuple,
using Tuple1 = std::tuple>;
using Tuple2 = std::tuple>;
std::tuple tuple;
And the function,
void baz()
{
auto tup =…

Babar Shariff
- 107
- 7
5
votes
2 answers
Why can a std::tuple not be assigned with an initializer list?
I wonder why this choice is made. It would allow to write many functions in a very clear and neat way.. for instance:
int greatestCommonDivisor(int a, int b)
{
if (b > a)
std::tie(a, b) = { b, a };
while (b > 0)
std::tie(a,…

mr_T
- 2,571
- 3
- 22
- 39
5
votes
1 answer
Structured bindings implementation underground and std::tuple
Is it true, that structured bindings in clang (I use recently builded clang version 4.0.0 (trunk 282683)) are implemented using some stuff from , like braces-init lists may use stuff from ?
I wrote simple code just to play…

Tomilov Anatoliy
- 15,657
- 10
- 64
- 169
5
votes
2 answers
How to output values to a tuple of streams in c++11
I am trying to write an stream operator << that can output to a std::tuple of streams instead of one stream. So basically, I am trying to write the Unix tee command in c++, and do:
std::tie(std::cout,std::clog) << 1;
I tried to write the stream…

thor
- 21,418
- 31
- 87
- 173
4
votes
2 answers
C++ std::tuple to std::tuple...>>
Given a variadic template, I would like to define an object that would be a tuple of vector of each type in the variadic template.
Something like:
template
class C {
std::tuple,…

canellas
- 491
- 5
- 17
4
votes
1 answer
C++ turn a std::tuple into a std::string?
I am writing a lightweight parser combinator library (akin to Boost::Spirit) as hobby project.
One thing I'd like to do, is to automatically be able to convert a Result>, Result>, etc. into a std::string.
And…

Qqwy
- 5,214
- 5
- 42
- 83
4
votes
4 answers
Why isn't it possible to make a tuple which contains a tuple and a unique_ptr as values in C++?
Putting an std::unique_ptr inside an std::tuple works without any issues, but when the tuple contains another tuple together with a unique_ptr as elements, then the compiler throws an error.
Example:
std::tuple>…

J.Doe
- 109
- 1
- 6
4
votes
1 answer
Tuple wrapper that works with get, tie, and other tuple operations
I have written a fancy "zip iterator" that already fulfils many roles (can be used in for_each, copy loops, container iterator range constructors etc...).
Under all the template code to work around the pairs/tuples involved, it comes down to the…

rubenvb
- 74,642
- 33
- 187
- 332
4
votes
3 answers
can a std::tuple be sorted at compilte-time/run-time depending on its values
I am wondering if a constexpr std::tuple can be sorted at compile-time:
template
struct A{ T val; }; // a constexpr-enabled class
constexpr auto t = std::make_tuple( A{3}, A{1.f}, A{2.0});
constexpr auto s = sort(t,…

Gabriel
- 8,990
- 6
- 57
- 101
4
votes
2 answers
dealing with rvalue ref inside tuple
I want to pass and forward tuples which contain rvalue ref. But I am not able to access the tuple element and do forwarding in the correct way.
In the example I provide also a structure with named elements instead of a std::tuple which works…

Klaus
- 24,205
- 7
- 58
- 113
4
votes
1 answer
c++ aggregates initialization with c-style arrays
In c++14 I have the following type:
std::tuple;
How can I properly initialize it? This
std::tuple a {{2,2},3};
gives me this error:
/usr/include/c++/5/tuple:108:25: error: array used as initializer
While…

Mario Demontis
- 469
- 3
- 11
4
votes
3 answers
C++ Convert tuple of homogeneous wrapped type to tuple of raw type
I'd like to call std::apply() to a function; however, I am unable to because the std::tuple I use is currently wrapped. For example:
#include
template
struct wrapped
{
wrapped(T t) : t(t) {}
T t;
};
template

Michael Choi
- 610
- 5
- 22
4
votes
2 answers
Can I placement new a std::tuple into a memory mapped region, and read it back later?
I have some packed structs which I will be writing to a memory mapped file. They are all POD.
To accommodate some generic programming I'm doing, I want to be able to write a std::tuple of several packed structs.
I'm worried that writing the members…

Steve Lorimer
- 27,059
- 17
- 118
- 213
4
votes
2 answers
C++: convert tuple to type T
I'm trying to make a class, called tuple_cnv with an (implicit) conversion operator to construct any object from a tuple (like the C++17 std::make_from_tuple function), but of recursive nature, in such a way that, if a tuple consists of other…

ABu
- 10,423
- 6
- 52
- 103
4
votes
2 answers
Why does std::get not have a single signature that accepts a forwarding reference
Why does std::get for std::tuple have so many overloads (http://en.cppreference.com/w/cpp/utility/tuple/get)? One corresponding to every possible combination of const & and &&? With each combination the const ref qualifiers on the return value is…

Curious
- 20,870
- 8
- 61
- 146