GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::make_from_tuple(3) C++ Standard Libary std::make_from_tuple(3)

std::make_from_tuple - std::make_from_tuple


Defined in header <tuple>
template< class T, class Tuple > (since C++17)
constexpr T make_from_tuple( Tuple&& t );


Construct an object of type T, using the elements of the tuple t as the arguments to
the constructor.


The program is ill-formed if the hypothetical variable definition T
var(std::get<Is>(std::forward<Tuple>(t))...); is ill-formed
, or T is a reference type and var is bound to a temporary object
(since C++23), where Is... denotes the parameter pack 0, 1, ...,
std::tuple_size_v<std::remove_reference_t<Tuple>> - 1.


t - tuple whose elements to be used as arguments to the constructor of T


The constructed T object or reference.


The tuple need not be std::tuple, and instead may be anything that supports std::get
and std::tuple_size; in particular, std::array and std::pair may be used.


Due to guaranteed copy elision, T need not be movable.


Feature-test macro: __cpp_lib_make_from_tuple


namespace detail {
template<class T, class Tuple, std::size_t... I>
constexpr T make_from_tuple_impl(Tuple&& t, std::index_sequence<I...>)
{
static_assert(std::is_constructible_v<T,
decltype(std::get<I>(std::declval<Tuple>()))...>);
#if __cpp_lib_reference_from_temporary >= 202202L
if constexpr (std::tuple_size_v<std::remove_reference_t<Tuple>> == 1) {
using tuple_first_t = decltype(std::get<0>(std::declval<Tuple>()));
static_assert(!std::reference_constructs_from_temporary_v<T, tuple_first_t>);
}
#endif
return T(std::get<I>(std::forward<Tuple>(t))...);
}
} // namespace detail


template<class T, class Tuple>
constexpr T make_from_tuple(Tuple&& t)
{
return detail::make_from_tuple_impl<T>(std::forward<Tuple>(t),
std::make_index_sequence<std::tuple_size_v<std::remove_reference_t<Tuple>>>{});
}

// Run this code


#include <iostream>
#include <tuple>


struct Foo {
Foo(int first, float second, int third) {
std::cout << first << ", " << second << ", " << third << "\n";
}
};


int main()
{
auto tuple = std::make_tuple(42, 3.14f, 0);
std::make_from_tuple<Foo>(std::move(tuple));
}


42, 3.14, 0


Defect reports


The following behavior-changing defect reports were applied retroactively to
previously published C++ standards.


DR Applied to Behavior as published Correct behavior
LWG 3528 C++17 cast containing reinterpret_cast etc. was disallowed
allowed in the case of 1-tuple


make_tuple creates a tuple object of the type defined by the argument types
(C++11) (function template)
forward_as_tuple creates a tuple of forwarding references
(C++11) (function template)
apply calls a function with a tuple of arguments
(C++17) (function template)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.