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_tuple(3) C++ Standard Libary std::make_tuple(3)

std::make_tuple - std::make_tuple


Defined in header <tuple>
template< class... Types > (since C++11)
std::tuple<VTypes...> make_tuple( Types&&... args ); (constexpr since C++14)


Creates a tuple object, deducing the target type from the types of arguments.


For each Ti in Types..., the corresponding type Vi in VTypes... is
std::decay<Ti>::type unless application of std::decay results in
std::reference_wrapper<X> for some type X, in which case the deduced type is X&.


args - zero or more arguments to construct the tuple from


A std::tuple object containing the given values, created as if by
std::tuple<VTypes...>(std::forward<Types>(t)...).


template <class T>
struct unwrap_refwrapper
{
using type = T;
};


template <class T>
struct unwrap_refwrapper<std::reference_wrapper<T>>
{
using type = T&;
};


template <class T>
using unwrap_decay_t = typename unwrap_refwrapper<typename std::decay<T>::type>::type;
// or use std::unwrap_ref_decay_t (since C++20)


template <class... Types>
constexpr // since C++14
std::tuple<unwrap_decay_t<Types>...> make_tuple(Types&&... args)
{
return std::tuple<unwrap_decay_t<Types>...>(std::forward<Types>(args)...);
}

// Run this code


#include <iostream>
#include <tuple>
#include <functional>


std::tuple<int, int> f() // this function returns multiple values
{
int x = 5;
return std::make_tuple(x, 7); // return {x,7}; in C++17
}


int main()
{
// heterogeneous tuple construction
int n = 1;
auto t = std::make_tuple(10, "Test", 3.14, std::ref(n), n);
n = 7;
std::cout << "The value of t is " << "("
<< std::get<0>(t) << ", " << std::get<1>(t) << ", "
<< std::get<2>(t) << ", " << std::get<3>(t) << ", "
<< std::get<4>(t) << ")\n";


// function returning multiple values
int a, b;
std::tie(a, b) = f();
std::cout << a << " " << b << "\n";
}


The value of t is (10, Test, 3.14, 7, 1)
5 7


tie creates a tuple of lvalue references or unpacks a tuple into
(C++11) individual objects
(function template)
forward_as_tuple creates a tuple of forwarding references
(C++11) (function template)
tuple_cat creates a tuple by concatenating any number of tuples
(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.