std::forward_as_tuple (3) - Linux Manuals
std::forward_as_tuple: std::forward_as_tuple
Command to display std::forward_as_tuple
manual in Linux: $ man 3 std::forward_as_tuple
NAME
std::forward_as_tuple - std::forward_as_tuple
Synopsis
Defined in header <tuple>
template< class... Types > (since C++11)
tuple<Types&&...> forward_as_tuple( Types&&... args ) noexcept; (constexpr since C++14)
Constructs a tuple of references to the arguments in args suitable for forwarding as an argument to a function. The tuple has rvalue reference data members when rvalues are used as arguments, and otherwise has lvalue reference data members.
Parameters
args - zero or more arguments to construct the tuple from
Return value
A std::tuple object created as if by std::tuple<Types&&...>(std::forward<Types>(args)...)
Notes
If the arguments are temporaries, forward_as_tuple does not extend their lifetime; they have to be used before the end of the full expression.
Example
// Run this code
#include <iostream>
#include <map>
#include <tuple>
#include <string>
int main()
{
std::map<int, std::string> m;
m.emplace(std::piecewise_construct,
std::forward_as_tuple(10),
std::forward_as_tuple(20, 'a'));
std::cout << "m[10] = " << m[10] << '\n';
// The following is an error: it produces a
// std::tuple<int&&, char&&> holding two dangling references.
//
// auto t = std::forward_as_tuple(20, 'a');
// m.emplace(std::piecewise_construct, std::forward_as_tuple(10), t);
}
Output:
m[10] = aaaaaaaaaaaaaaaaaaaa
See also
creates a tuple object of the type defined by the argument types
make_tuple (function template)
creates a tuple of lvalue references or unpacks a tuple into individual objects
tie (function template)
creates a tuple by concatenating any number of tuples
tuple_cat (function template)
apply calls a function with a tuple of arguments
(function template)
(C++17)
Pages related to std::forward_as_tuple
- std::forward_iterator_tag (3)
- std::forward_list (3) - std::forward_list
- std::forward_list<T,Allocator>::assign (3) - std::forward_list<T,Allocator>::assign
- std::forward_list<T,Allocator>::before_begin,cbefore_begin (3) - std::forward_list<T,Allocator>::before_begin,cbefore_begin
- std::forward_list<T,Allocator>::begin,std::forward_list<T,Allocator>::cbegin (3) - std::forward_list<T,Allocator>::begin,std::forward_list<T,Allocator>::cbegin
- std::forward_list<T,Allocator>::clear (3) - std::forward_list<T,Allocator>::clear
- std::forward_list<T,Allocator>::emplace_after (3) - std::forward_list<T,Allocator>::emplace_after
- std::forward_list<T,Allocator>::emplace_front (3) - std::forward_list<T,Allocator>::emplace_front
- std::forward_list<T,Allocator>::empty (3) - std::forward_list<T,Allocator>::empty
- std::forward_list<T,Allocator>::end,std::forward_list<T,Allocator>::cend (3) - std::forward_list<T,Allocator>::end,std::forward_list<T,Allocator>::cend
- std::forward_list<T,Allocator>::erase_after (3) - std::forward_list<T,Allocator>::erase_after
- std::forward_list<T,Allocator>::forward_list (3) - std::forward_list<T,Allocator>::forward_list
- std::forward_list<T,Allocator>::front (3) - std::forward_list<T,Allocator>::front
- std::forward_list<T,Allocator>::get_allocator (3) - std::forward_list<T,Allocator>::get_allocator
- std::forward_list<T,Allocator>::insert_after (3) - std::forward_list<T,Allocator>::insert_after
- std::forward_list<T,Allocator>::max_size (3) - std::forward_list<T,Allocator>::max_size
- std::forward_list<T,Allocator>::merge (3) - std::forward_list<T,Allocator>::merge