Namespaces
Variants
Views
Actions

std::is_placeholder

From cppreference.com
< cpp‎ | utility‎ | functional
Revision as of 14:26, 2 November 2012 by P12bot (Talk | contribs)

 
 
 
Function objects
Function wrappers
(C++11)
(C++11)
Bind
(C++11)
is_placeholder
(C++11)
Reference wrappers
(C++11)(C++11)
Operator wrappers
Negators
Deprecated binders and adaptors
(deprecated)
(deprecated)
(deprecated)
(deprecated)
(deprecated)(deprecated)(deprecated)(deprecated)
(deprecated)
(deprecated)(deprecated)(deprecated)(deprecated)
(deprecated)(deprecated)
(deprecated)(deprecated)
 

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

<td>
Defined in header <functional>
</td>

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

<td >
template< class T >
struct is_placeholder;
</td>

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

If T is the type of a standard placeholder (_1, _2, _3, ...), then this template is derived from std::integral_constant<int,1>, std::integral_constant<int,2>, std::integral_constant<int,3>, respectively. If T is not a standard placeholder type, this template is derived from std::integral_constant<int,0>.

The template may be specialized for any user-defined type which should be treated by std::bind as if it was a placeholder for unbound arguments.

Contents

Inherited from std::integral_constant

Member constants

value
[static]
placeholder value or 0 for non-placeholder types
(public static member constant)

Member functions

operator int
converts the object to int, returns value
(public member function)

Member types

Type Definition
value_type int
type std::integral_constant<int, value>

Example

#include <iostream>
#include <type_traits>
#include <functional>
 
struct My_2 {
} my_2;
 
namespace std {
    template<>
    struct is_placeholder<My_2> : public integral_constant<int, 2> {};
}
 
int f(int n1, int n2)
{
    return n1+n2;
}
 
int main()
{
    std::cout << "Standard placeholder _5 is for the argument number "
              << std::is_placeholder<decltype(std::placeholders::_5)>::value
              << '\n';
 
    auto b = std::bind(f, my_2, 2);
    std::cout << "Adding 2 to 11 selected with a custom placeholder gives " 
              << b(10, 11) 
              << '\n';
}

Output:

Standard placeholder _5 is for the argument number 5
Adding 2 to 11 selected with a custom placeholder gives 13

See also

(C++11)
binds one or more arguments to a function object
(function template) [edit]
placeholders for the unbound arguments in a std::bind expression
(constant) [edit]