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

How to split a std::string_views into a tuple-like objects using C++20 std::views::split?

According to this problem, we can using C++20's std::views::split to split std::string_view into range of std::string_views: std::string_view s = "this should be split into string_views"; auto views = s | std::views::split(' ') |…
康桓瑋
  • 33,481
  • 5
  • 40
  • 90
3
votes
1 answer

can I initialize an std::tuple from a vector array?

I have an std::vector containing a variant class. I want to construct a tuple with the same data. Is this possible? The normal construction methods for a tuple seem quite restrictive. //In reality, I'm using JUCE::var. …
Liam Goodacre
  • 381
  • 1
  • 10
3
votes
1 answer

Cleaner way of defining a constant vector of tuples in C++11

I have a constant vector of tuples, in which each tuple contains a key, name, quantity, value. This is how I am defining it- // tuple of key, name, quantity, value const std::vector >…
ravi
  • 6,140
  • 18
  • 77
  • 154
3
votes
3 answers

how to forward the types of tuple to specialize other template?

currently I'm working on a dynamic container structure, which represents one pod value or has vector of pointers with same container type. The container has an interface optional expect_value() 。 For pod types the implemention is simple. For…
spiritsaway
  • 635
  • 1
  • 7
  • 16
3
votes
2 answers

How to create a tuple of vectors of type deduced from a variadic template in C++17?

I have implemented a collection class that converts a vector of tuples to a tuple of vectors (it is essentially an AOS to SOA conversion). This code works for this example of two template classes. I was trying to make it more generic by using…
motam79
  • 3,542
  • 5
  • 34
  • 60
3
votes
1 answer

Insert value to a std::map from a tuple

I am just learning data structure of graph.And i'm trapped in such a situation. I have written my Graph class like template class Graph{}; where the Args of type char means the vertex of my Graph. However, when i want to…
user9462517
3
votes
4 answers

Constructing tuple of value from tuple of reference, with one-argument templated constructor

I have a tuple of const references std::tuple from which I construct a tuple of values std::tuple. For any size of tuple greater than 1, this works fine: (online example: https://godbolt.org/g/24E8tU) #include…
Lack
  • 1,625
  • 1
  • 17
  • 29
3
votes
1 answer

Unpack std::tuple in-place without the artificial layer for std::index_sequence

I have a function template: template void set_args(const void* p, Us&... args); I have a std::tuple that I want to unpack into args. My current solution is template void set_args_2( const void*…
Lingxi
  • 14,579
  • 2
  • 37
  • 93
3
votes
4 answers

Lambda function with map where key is tuple and value is double

I have a map, filled with values: std::map, double> Cache; When the size of map is greater than 100, I want to delete/erase only the map elements whose values in the key tuple are all more than 10. Here is how it can…
user8183713
3
votes
4 answers

Unclear syntax with std::tie

I'm just reading a bit about tuples. Now the following syntax is not clear to me: std::tie (myint, std::ignore, mychar) = mytuple; It's not difficult to grasp what it does, BUT what happens from a language point of view? We are somehow assigning to…
Michael
  • 7,407
  • 8
  • 41
  • 84
3
votes
1 answer

C++ perfect forward copy-only types to make_tuple

I'm playing with this little snippet: #include struct copy_only { copy_only() = default; copy_only(copy_only&&) = delete; copy_only(const copy_only&) = default; }; template void foo(Ts&& ...xs) { auto t =…
Przemek Kryger
  • 687
  • 4
  • 11
3
votes
2 answers

Issue with invalid use of incomplete type when using std::tuple_element

The following code implements a hash function for a std::tuple which is then used in a different segment of my code-base in a std::unordered_map of std::tuples. // compute hash function recursively through each std::tuple element template
sjrowlinson
  • 3,297
  • 1
  • 18
  • 35
3
votes
1 answer

Forcing std::tuple to contain std::pair

Is it possible to use std::tuple "partly specialized" so that it contains std::pair with varying T? UPD: the tuple should contain the pairs. So it is equivalent to using an array of fixed_t together with a regular std::tuple.
Alex
  • 1,165
  • 2
  • 9
  • 27
3
votes
2 answers

How to compare tuples of different length?

I would like to write a comparator which compares tuples of different length but have the same "prefix". Consider following case, I have two tuples. auto t1 = std::make_tuple(10, "Test1"); auto t2 = std::make_tuple(10, "Test", 3.14); I would like…
kreuzerkrieg
  • 3,009
  • 3
  • 28
  • 59
3
votes
1 answer

C++: Using type as map key introduces template substitution errors

I'm using a tuple as a key to track elements in a map, and then later iterating over the map to produce a string version of the map. To help me with the conversion, I have a template convenience function that will concatenate the tuple used as the…
sabreitweiser
  • 643
  • 3
  • 13