Questions tagged [stdapply]

The C++17 std::apply() function takes a function and a tuple and calls the function with the contents of the the tuple as its arguments.

std::apply invokes a callable object with arguments from a collection, whose type supports std::get and std::tuple_size methods. Examples of such collections are std::tuple, std::array and std::pair.

Some pre-C++17 compilers support experimental version of std::apply.

20 questions
1
vote
1 answer

C++: Using std::apply to iterate through a tuple in 2 parts: up to an index applying a lambda and then after an index applying a different lambda

If I want to iterate through a tuple using std::apply but not apply one function to the entire thing, how can I separate the tuple, i.e. apply one function to the first n values and another to all values after it? some_values would be a tuple which…
Doot
  • 555
  • 5
  • 15
0
votes
1 answer

set a value in std::tuple using a function that takes an index to the std::get

If You want to read data from vector of std::tuple You can use : #include #include #include #include #include #include using example = std::tuple
0
votes
3 answers

Initializing smart pointers in a tuple without knowing the type

I have a tuple of smart pointers (as a member of a class template) that I need to initialize. I use std::apply to iterate over tuples elsewhere, but how do I initialize them with new objects without knowing their type? Running the code below with a…
AreN
  • 3
  • 1
0
votes
1 answer

std::get does not forward rvalue-reference for std::apply

I am wondering why std::apply does not forward rvalue-reference when working with reference types in tuples (see Live): #include #include template void assertRvalueReference(T&& t) { …
Gabriel
  • 8,990
  • 6
  • 57
  • 101
0
votes
1 answer

Perferct forward a copied std::tuple

I need a bit of help. I need to perfect forward a tuple in a specific way. Imagine this template auto package_task(F&& func, Args&&... args) -> std::function { //for the purposes of this example imagine…
1
2