std::is_bind_expression

From cppreference.com
< cpp‎ | utility‎ | functional
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)   
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)
Elementary string conversions
(C++17)
(C++17)
 
Function objects
Function wrappers
(C++11)
(C++11)
Partial function application
(C++20)(C++23)
(C++11)
is_bind_expression
(C++11)
Function invocation
(C++17)(C++23)
Identity function object
(C++20)
Reference wrappers
(C++11)(C++11)
Transparent operator wrappers
(C++14)
(C++14)
(C++14)
(C++14)  
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)
(C++14)

Negators
(C++17)
Searchers
Constrained comparators
Old binders and adaptors
(until C++17*)
(until C++17*)
(until C++17*)
(until C++17*)
(until C++17*)(until C++17*)(until C++17*)(until C++17*)
(until C++20*)
(until C++20*)
(until C++17*)(until C++17*)
(until C++17*)(until C++17*)

(until C++17*)
(until C++17*)(until C++17*)(until C++17*)(until C++17*)
(until C++20*)
(until C++20*)
 
Defined in header <functional>
template< class T >
struct is_bind_expression;
(since C++11)

If T is a type produced by a call to std::bind (but not std::bind_front or std::bind_back), this template is derived from std::true_type. For any other type (unless user-specialized), this template is derived from std::false_type.

This template may be specialized for a user-defined type T to implement UnaryTypeTrait with base characteristic of std::true_type to indicate that T should be treated by std::bind as if it were the type of a bind subexpression: when a bind-generated function object is invoked, a bound argument of this type will be invoked as a function object and will be given all the unbound arguments passed to the bind-generated object.

Helper variable template

template< class T >
inline constexpr bool is_bind_expression_v = is_bind_expression<T>::value;
(since C++17)

Inherited from std::integral_constant

Member constants

value
[static]
true if T is a function object generated by std::bind, false otherwise
(public static member constant)

Member functions

operator bool
converts the object to bool, returns value
(public member function)
operator()
(C++14)
returns value
(public member function)

Member types

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

Example

#include <functional>
#include <iostream>
#include <type_traits>
 
struct MyBind
{
    typedef int result_type;
    int operator()(int a, int b) const { return a + b; }
};
 
namespace std
{
    template<>
    struct is_bind_expression<MyBind> : public true_type {};
}
 
int f(int n1, int n2)
{
    return n1 + n2;
}
 
int main()
{
    // as if bind(f, bind(MyBind(), _1, _2), 2)
    auto b = std::bind(f, MyBind(), 2); 
 
    std::cout << "Adding 2 to the sum of 10 and 11 gives " << b(10, 11) << '\n';
}

Output:

Adding 2 to the sum of 10 and 11 gives 23

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 2010 C++11 user-defined specializations could only
be derived from std::false_type
can be derived from
std::true_type

See also

(C++11)
binds one or more arguments to a function object
(function template)