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

std::tie - std::tie


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


Creates a tuple of lvalue references to its arguments or instances of std::ignore.


args - zero or more lvalue arguments to construct the tuple from.


A std::tuple object containing lvalue references.


template <typename... Args>
constexpr // since C++14
std::tuple<Args&...> tie(Args&... args) noexcept {
return {args...};
}


std::tie may be used to unpack a std::pair because std::tuple has a converting
assignment from pairs:


bool result;
std::tie(std::ignore, result) = set.insert(value);


std::tie can be used to introduce lexicographical comparison to a struct or to
unpack a tuple:

// Run this code


#include <iostream>
#include <string>
#include <set>
#include <tuple>


struct S {
int n;
std::string s;
float d;
bool operator<(const S& rhs) const
{
// compares n to rhs.n,
// then s to rhs.s,
// then d to rhs.d
return std::tie(n, s, d) < std::tie(rhs.n, rhs.s, rhs.d);
}
};


int main()
{
std::set<S> set_of_s; // S is LessThanComparable


S value{42, "Test", 3.14};
std::set<S>::iterator iter;
bool inserted;


// unpacks the return value of insert into iter and inserted
std::tie(iter, inserted) = set_of_s.insert(value);


if (inserted)
std::cout << "Value was inserted successfully\n";
}


Value was inserted successfully


Structured binding (C++17) binds the specified names to sub-objects or tuple
elements of the initializer
make_tuple creates a tuple object of the type defined by the
(C++11) argument types
(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)
ignore placeholder to skip an element when unpacking a tuple
(C++11) using tie
(constant)

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.