function template
<tuple>
std::forward_as_tupletemplate<class... Types> tuple<Types&&...> forward_as_tuple (Types&&... args) noexcept;
template<class... Types> constexpr tuple<Types&&...> forward_as_tuple (Types&&... args) noexcept;
Forward as tuple
Constructs a tuple object with rvalue references to the elements in args suitable to be forwarded as argument to a function.This function is designed to forward arguments, not to store its result in a named variable, since the returned object may contain references to temporary variables.
It is equivalent to:
1
2
3
4
5
template<class... Types>
tuple<Types&&...> forward_as_tuple (Types&&... args) noexcept
{
return tuple<Types&&...>(std::forward<Types>(args)...);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// forward_as_tuple example
#include <iostream> // std::cout
#include <tuple> // std::tuple, std::get, std::forward_as_tuple
#include <string> // std::string
void print_pack (std::tuple<std::string&&,int&&> pack) {
std::cout << std::get<0>(pack) << ", " << std::get<1>(pack) << '\n';
}
int main() {
std::string str ("John");
print_pack (std::forward_as_tuple(str+" Smith",25));
print_pack (std::forward_as_tuple(str+" Daniels",22));
return 0;
}
John Smith, 25 John Daniels, 22
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4