Namespaces
Variants
Views
Actions

std::ignore

From cppreference.com
< cpp‎ | utility‎ | tuple
Revision as of 11:08, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <tuple>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td >
const /*unspecified*/ ignore;
</td>

<td class="t-dcl-nopad"> </td> <td > (since C++11) </td> </tr> Template:ddcl list end

An object of unspecified type such that any value can be assigned to it with no effect. Intended for use with std::tie when unpacking a std::tuple, as a placeholder for the arguments that are not used.

Example

unpack a pair returned by set.insert(), but only save the boolean.

#include <iostream>
#include <string>
#include <set>
#include <tuple>
 
int main()
{
    std::set<std::string> set_of_str;
    bool inserted;
    std::tie(std::ignore, inserted) = set_of_str.insert("Test");
    if (inserted) {
        std::cout << "Value was inserted sucessfully\n";
    }
}

Output:

Value was inserted sucessfully
creates a tuple of lvalue references or unpacks a tuple into individual objects
(function template) [edit]