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.
It seems like a std::tuple containing one or more references has unexpected behavior with regards to construction and assignment (especially copy/move construction and copy/move assignment). It's different from the behavior of both…
What are the templates that I have to specialize to support std::get?
struct MyClass {
int a;
};
template
struct MyContainer {
MyClass array[I];
};
What do I have to specialize to be able to do:
MyContainer<16>…
I'm trying to practice some template programming. Maybe there's a standard way to do this, and I would be thankful for such answers, but my main goal is to practice the template programming techniques, so I tried to implement it myself:
I need to…
I want to implement a generic tuple_map function that takes a functor and an std::tuple, applies the functor to every element of this tuple and returns an std::tuple of results. The implementation is pretty straightforward, however the question…
I was trying to swap two variables using std::tie() as per the following code (I am aware of std::swap, I was just trying this out of curiosity):
#include
#include
using std::cin; using std::tie;
using std::cout; using…
I can't initialize std::tuple elements element-wise from a std::tuple of compatible types. Why doesn't it work as with boost::tuple?
#include
#include
template
struct Foo
{
// error: cannot convert…
I have function at designed to access std::tuple element by index specified in runtime
template
inline typename std::enable_if<_Index == std::tuple_size<_Tuple>::value,…
After trying to make a std::get(std::tuple) method myself, I'm not so sure how it's implemented by compilers. I know std::tuple has a constructor like this:
tuple(Args&&... args);
But what exactly is args... assigned to? I think this is useful…
I would expect that in C++20 the following code prints nothing between prints of A and B (since I expect guaranteed RVO to kick in). But output is:
A
Bye
B
C
Bye
Bye
So presumably one temporary is being created.
#include
#include…
In many of my unit tests I need to compare the contents of simple structs having only data members:
struct Object {
int start;
int stop;
std::string message;
}
Now, if I want to write something like:
CHECK(object1==object2);
I always have to…
My basic idea was to derive my own class from std::tuple to get some helper types inside like this:
template
class TypeContainer: public std::tuple
{
public:
using BaseType = std::tuple;
static…
Suppose I have a template which is parametrized by a class type and a number of argument types. a set of arguments matching these types are stored in a tuple. How can one pass these to a constructor of the class type?
In almost C++11…
I've a complex type C depending on a template parameter which I need in a (length bounded) sequence. A constexpr function next() is available to go from C_n -> C_n+1. As every sequence element has a different type I'm using a std::tuple to store the…
The code as follows
#include
int main()
{
auto [a] = std::make_tuple(1);
return [a]() -> int { return a; }();
}
produces an error in clang 12:
:6:13: error: 'a' in capture list does not name a variable
return [a]() ->…