Standard library header <functional> - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# Standard library header <functional>

From cppreference.com
< cpp‎ | header

This header is part of the function objects library and provides the standard hash function.

### [edit] Namespaces

placeholders | Defines placeholders for the unbound arguments in a std::bind expression
##### Constants
Defined in namespace `std::placeholders`
_1, _2, _3, _4, ... (C++11) | placeholders for the unbound arguments in a `std::bind` expression (constant) [edit]

### [edit] Classes

function (C++11) | wraps callable object of any type with specified function call signature (class template) [edit]
mem_fn (C++11) | creates a function object out of a pointer to a member (function template) [edit]
bad_function_call (C++11) | the exception thrown when invoking an empty std::function (class) [edit]
is_bind_expression (C++11) | indicates that an object is `std::bind` expression or can be used as one (class template) [edit]
is_placeholder (C++11) | indicates that an object is a standard placeholder or can be used as one (class template) [edit]
reference_wrapper (C++11) | `CopyConstructible` and `CopyAssignable` reference wrapper (class template) [edit]
##### Hashing
hash (C++11) | hash function object (class template) [edit]
template<> struct hash<bool>; template<> struct hash<char>; template<> struct hash<signed char>; template<> struct hash<unsigned char>; template<> struct hash<char16_t>; template<> struct hash<char32_t>; template<> struct hash<wchar_t>; template<> struct hash<short>; template<> struct hash<unsigned short>; template<> struct hash<int>; template<> struct hash<unsigned int>; template<> struct hash<long>; template<> struct hash<long long>; template<> struct hash<unsigned long>; template<> struct hash<unsigned long long>; template<> struct hash<float>; template<> struct hash<double>; template<> struct hash<long double>; template< class T > struct hash<T*>; | std::hash specializations for built-in types (class template specialization)

### [edit] Functions

bind (C++11) | binds one or more arguments to a function object (function template) [edit]
refcref (C++11)(C++11) | creates a std::reference_wrapper with a type deduced from its argument (function template) [edit]

### [edit] Function Objects

##### Arithmetic operations
plus | function object implementing x + y (class template) [edit]
minus | function object implementing x - y (class template) [edit]
multiplies | function object implementing x * y (class template) [edit]
divides | function object implementing x / y (class template) [edit]
modulus | function object implementing x % y (class template) [edit]
negate | function object implementing -x (class template) [edit]
##### Comparisons
equal_to | function object implementing x == y (class template) [edit]
not_equal_to | function object implementing x != y (class template) [edit]
greater | function object implementing x > y (class template) [edit]
less | function object implementing x < y (class template) [edit]
greater_equal | function object implementing x >= y (class template) [edit]
less_equal | function object implementing x <= y (class template) [edit]
##### Logical operations
logical_and | function object implementing x && y (class template) [edit]
logical_or | function object implementing x || y (class template) [edit]
logical_not | function object implementing !x (class template) [edit]
##### Bitwise operations
bit_and | function object implementing x & y (class template) [edit]
bit_or | function object implementing x | y (class template) [edit]
bit_xor | function object implementing x ^ y (class template) [edit]
##### Negators
unary_negate | wrapper function object returning the complement of the unary predicate it holds (class template) [edit]
binary_negate | wrapper function object returning the complement of the binary predicate it holds (class template) [edit]
not1 | constructs custom std::unary_negate object (function template) [edit]
not2 | constructs custom std::binary_negate object (function template) [edit]

### [edit] Deprecated in C++11

##### Base
unary_function (deprecated) | adaptor-compatible unary function base class (class template) [edit]
binary_function (deprecated) | adaptor-compatible binary function base class (class template) [edit]
##### Binders
binder1stbinder2nd (deprecated)(deprecated) | function object holding a binary function and one of its arguments (class template) [edit]
bind1stbind2nd (deprecated)(deprecated) | binds one argument to a binary function (function template) [edit]
##### Function adaptors
pointer_to_unary_function (deprecated) | adaptor-compatible wrapper for a pointer to unary function (class template) [edit]
pointer_to_binary_function (deprecated) | adaptor-compatible wrapper for a pointer to binary function (class template) [edit]
ptr_fun (deprecated) | creates an adaptor-compatible function object wrapper from a pointer to function (function template) [edit]
mem_fun_tmem_fun1_tconst_mem_fun_tconst_mem_fun1_t (deprecated)(deprecated)(deprecated)(deprecated) | wrapper for a pointer to nullary or unary member function, callable with a pointer to object (class template) [edit]
mem_fun (deprecated) | creates a wrapper from a pointer to member function, callable with a pointer to object (function template) [edit]
mem_fun_ref_tmem_fun1_ref_tconst_mem_fun_ref_tconst_mem_fun1_ref_t (deprecated)(deprecated)(deprecated)(deprecated) | wapper for a pointer to nullary or unary member function, callable with a reference to object (class template) [edit]
mem_fun_ref (deprecated) | creates a wrapper from a pointer to member function, callable with a reference to object (function template) [edit]

### [edit] Synopsis

    namespace std {

        // base (deprecated):
        template <class Arg, class Result> struct unary_function;
        template <class Arg1, class Arg2, class Result> struct binary_function;

        // reference_wrapper:
        template <class T> class reference_wrapper;
        template <class T> reference_wrapper<T> ref(T&) noexcept;
        template <class T> reference_wrapper<const T> cref(const T&) noexcept;
        template <class T> void ref(const T&&) = delete;
        template <class T> void cref(const T&&) = delete;
        template <class T> reference_wrapper<T> ref(reference_wrapper<T>) noexcept;
        template <class T> reference_wrapper<const T> cref(reference_wrapper<T>) noexcept;

        // arithmetic operations:
        template <class T> struct plus;
        template <class T> struct minus;
        template <class T> struct multiplies;
        template <class T> struct divides;
        template <class T> struct modulus;
        template <class T> struct negate;

        // comparisons:
        template <class T> struct equal_to;
        template <class T> struct not_equal_to;
        template <class T> struct greater;
        template <class T> struct less;
        template <class T> struct greater_equal;
        template <class T> struct less_equal;

        // logical operations:
        template <class T> struct logical_and;
        template <class T> struct logical_or;
        template <class T> struct logical_not;

        // bitwise operations:
        template <class T> struct bit_and;
        template <class T> struct bit_or;
        template <class T> struct bit_xor;

        // negators:
        template <class Predicate> class unary_negate;
        template <class Predicate>
            unary_negate<Predicate>
            not1(const Predicate&);
        template <class Predicate>  class binary_negate;
        template <class Predicate>
            binary_negate<Predicate>
            not2(const Predicate&);

        // bind:
        template<class T> struct is_bind_expression;
        template<class T> struct is_placeholder;
        template<class  F, class... BoundArgs>
            /*unspecified*/ bind(F&&, BoundArgs&&...);
        template<class  R, class F, class... BoundArgs>
            /*unspecified*/ bind(F&&, BoundArgs&&...);

        namespace placeholders {
            // M is the implementation-defined number of placeholders
            extern /*unspecified*/ _1;
            extern /*unspecified*/ _2;
            .
            .
            .
            extern /*unspecified*/ _M;
        }

        // binders (deprecated):
        template <class Fn> class binder1st;
        template <class Fn, class T>
            binder1st<Fn> bind1st(const Fn&, const T&);
        template <class Fn> class binder2nd;
        template <class Fn, class T>
            binder2nd<Fn> bind2nd(const Fn&, const T&);

        // adaptors (deprecated):
        template <class Arg, class Result> class pointer_to_unary_function;
        template <class Arg, class Result>
            pointer_to_unary_function<Arg,Result> ptr_fun(Result (*)(Arg));
        template <class Arg1, class Arg2, class Result>
            class pointer_to_binary_function;
        template <class Arg1, class Arg2, class Result>
            pointer_to_binary_function<Arg1,Arg2,Result>
            ptr_fun(Result (*)(Arg1,Arg2));

        // adaptors (deprecated):
        template<class S, class T> class mem_fun_t;
        template<class S, class T, class A> class mem_fun1_t;
        template<class S, class T>
            mem_fun_t<S,T> mem_fun(S (T::*f)());
        template<class S, class T, class A>
            mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
        template<class S, class T> class mem_fun_ref_t;
        template<class S, class T, class A> class mem_fun1_ref_t;
        template<class S, class T>
            mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)());
        template<class S, class T, class A>
            mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
        template <class S, class T> class const_mem_fun_t;
        template <class S, class T, class A> class const_mem_fun1_t;
        template <class S, class T>
            const_mem_fun_t<S,T> mem_fun(S (T::*f)() const);
        template <class S, class T, class A>
            const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
        template <class S, class T> class const_mem_fun_ref_t;
        template <class S, class T, class A> class const_mem_fun1_ref_t;
        template <class S, class T>
            const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const);
        template <class S, class T, class A>
            const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);

        // member function adaptors:
        template<class R, class T> /*unspecified*/ mem_fn(R T::*);
        template<class R, class T, class... Args>
            /*unspecified*/ mem_fn(R (T::*)(Args...));
        template<class R, class T, class... Args>
            /*unspecified*/ mem_fn(R (T::*)(Args...) const);
        template<class R, class T, class... Args>
            /*unspecified*/ mem_fn(R (T::*)(Args...) volatile);
        template<class R, class T, class... Args>
            /*unspecified*/ mem_fn(R (T::*)(Args...) const volatile);
        template<class R, class T, class... Args>
            /*unspecified*/ mem_fn(R (T::*)(Args...) &);
        template<class R, class T, class... Args>
            /*unspecified*/ mem_fn(R (T::*)(Args...) const &);
        template<class R, class T, class... Args>
            /*unspecified*/ mem_fn(R (T::*)(Args...) volatile &);
        template<class R, class T, class... Args>
            /*unspecified*/ mem_fn(R (T::*)(Args...) const volatile &);
        template<class R, class T, class... Args>
            /*unspecified*/ mem_fn(R (T::*)(Args...) &&);
        template<class R, class T, class... Args>
            /*unspecified*/ mem_fn(R (T::*)(Args...) const &&);
        template<class R, class T, class... Args>
            /*unspecified*/ mem_fn(R (T::*)(Args...) volatile &&);
        template<class R, class T, class... Args>
            /*unspecified*/ mem_fn(R (T::*)(Args...) const volatile &&);

        // polymorphic function wrappers:
        class bad_function_call;
        template<class> class function; // undefined
        template<class R, class... ArgTypes> class function<R(ArgTypes...)>;
        template<class R, class... ArgTypes>
            void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
        template<class R, class... ArgTypes>
            bool operator==(const function<R(ArgTypes...)>&, nullptr_t);
        template<class R, class... ArgTypes>
            bool operator==(nullptr_t, const function<R(ArgTypes...)>&);
        template<class R, class... ArgTypes>
            bool operator!=(const function<R(ArgTypes...)>&, nullptr_t);
        template<class R, class... ArgTypes>
            bool operator!=(nullptr_t, const function<R(ArgTypes...)>&);

        // hash function base template:
        template <class T> struct hash;

        // Hash function specializations
        template <> struct hash<bool>;
        template <> struct hash<char>;
        template <> struct hash<signed char>;
        template <> struct hash<unsigned char>;
        template <> struct hash<char16_t>;
        template <> struct hash<char32_t>;
        template <> struct hash<wchar_t>;
        template <> struct hash<short>;
        template <> struct hash<unsigned short>;
        template <> struct hash<int>;
        template <> struct hash<unsigned int>;
        template <> struct hash<long>;
        template <> struct hash<long long>;
        template <> struct hash<unsigned long>;
        template <> struct hash<unsigned long long>;
        template <> struct hash<float>;
        template <> struct hash<double>;
        template <> struct hash<long double>;
        template<class T> struct hash<T*>;

    }

#### [edit] Class std::reference_wrapper

    template <class T> class reference_wrapper {
    public :
        // types
        typedef T type;
        typedef /*Return type of T*/     result_type;          // not always defined
        typedef /*Single argument of T*/ argument_type;        // not always defined
        typedef /*1st argument of T*/    first_argument_type;  // not always defined
        typedef /*2nd argument of T*/    second_argument_type; // not always defined

        // construct/copy/destroy
        reference_wrapper(T&) noexcept;
        reference_wrapper(T&&) = delete;

        // do not bind to temporary objects
        reference_wrapper(const reference_wrapper<T>& x) noexcept;

        // assignment
        reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;

        // access
        operator T& () const noexcept;
        T& get() const noexcept;

        // invocation
        template <class... ArgTypes>
            typename result_of<T&(ArgTypes&&...)>::type
            operator() (ArgTypes&&...) const;

    };

#### [edit] Class std::is_bind_expression

    template<class T> struct is_bind_expression
        : integral_constant<bool, /*true

#### [edit] Class std::bad_function_call

    class bad_function_call : public std::exception {
    public:
        // constructor:
        bad_function_call() noexcept;
    };

#### [edit] Class std::function

    template<class> class function; // undefined

    template<class R, class... ArgTypes>
    class function<R(ArgTypes...)> {
    public:
        typedef R result_type;
        typedef T1 argument_type;       //  iff sizeof...(ArgTypes) == 1 and
                                        //  the type in ArgTypes is T1
        typedef T1 first_argument_type; //  iff sizeof...(ArgTypes) == 2 and
                                        //  ArgTypes contains T1 and T2
        typedef T2 second_argument_type;//  iff sizeof...(ArgTypes) == 2 and
                                        //  ArgTypes contains T1 and T2

        // construct/copy/destroy:
        function() noexcept;
        function(nullptr_t) noexcept;
        function(const function&);
        function(function&&);

        template<class F> function(F);
        template<class A> function(allocator_arg_t, const A&) noexcept;
        template<class A> function(allocator_arg_t, const A&, nullptr_t) noexcept;
        template<class A> function(allocator_arg_t, const A&, const function&);
        template<class A> function(allocator_arg_t, const A&, function&&);
        template<class F, class A> function(allocator_arg_t, const A&, F);

        function& operator=(const function&);
        function& operator=(function&&);
        function& operator=(nullptr_t);
        template<class F> function& operator=(F&&);
        template<class F> function& operator=(reference_wrapper<F>) noexcept;

        ~function();

        // function modifiers:
        void swap(function&) noexcept;
        template<class F, class A> void assign(F&&, const A&);

        // function capacity:
        explicit operator bool() const noexcept;

        // function invocation:
        R operator()(ArgTypes...) const;

        // function target access:
        const std::type_info& target_type() const noexcept;
        template <typename T>       T* target() noexcept;
        template <typename T> const T* target() const noexcept;

    };

### [edit] See Also

`<string>` | Specializes std::hash for std::string, std::u16string, std::u32string, std::wstring
`<system_error>` | Specializes std::hash for std::error_code
`<bitset>` | Specializes std::hash for std::bitset
`<memory>` | Specializes std::hash for std::unique_ptr, std::shared_ptr
`<typeindex>` | Specializes std::hash for std::type_index
`<vector>` | Specializes std::hash for std::vector<bool>
`<thread>` | Specializes std::hash for std::thread::id

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/header/functional&oldid=57485"