Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Function Object Binders.

#include <boost/tr1/functional.hpp>

or

#include <functional>

std::tr1::bind is a generalization of the standard functions std::bind1st and std::bind2nd. It supports arbitrary function objects, functions, function pointers, and member function pointers, and is able to bind any argument to a specific value or route input arguments into arbitrary positions. bind does not place any requirements on the function object; in particular, it does not need the result_type, first_argument_type and second_argument_type standard typedefs. For more information refer to the Boost.Bind documentation.

namespace std {
namespace tr1 {

// [3.6] Function object binders
template<class T> struct is_bind_expression;
template<class T> struct is_placeholder;
template<class F, class T1, ..., class Tn > unspecified bind(F f, T1 t1, ..., Tn tn );
template<class R, class F, class T1, ..., class Tn > unspecified bind(F f, T1 t1, ..., Tn tn );

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

} // namespace tr1
} // namespace std

Configuration: Boost.Config should (automatically) define the macro BOOST_HAS_TR1_BIND if your standard library implements this part of TR1.

Standard Conformity: The traits classes is_placeholder and is_bind_expression are not supported by the Boost implementation.

The named return value syntax isn't supported if the object being bound is a function pointer, for example:

std::tr1::bind(&my_proc, arg1, arg2 /* etc */); // works OK.
std::tr1::bind<double>(&my_proc, arg1, arg2 /* etc */); // causes compiler error.
std::tr1::bind<double>(my_function_object, arg1, arg2 /* etc */); // works OK.

On the other hand, the Boost implementation does work with pointers to overloaded functions, and optionally with function pointers with non-standard calling conventions.


PrevUpHomeNext