I’d like to use std::make_pair usable with e.g. std::bind2nd so that I get an unary function object which I could use with e.g. std::transform.
Right now I’m using
template <typename T, typename U>
struct pair_creator : std::binary_function<T, U, std::pair<T, U> >
{
std::pair<T, U> operator()( T arg1, U arg2 ) const {
return std::make_pair( arg1, arg2 );
}
};
// ...
std::transform( start1, end2, start2, std::bind2nd( pair_creator<int, bool>(), true ) );
but I wonder – is there an easier way to make std::make_pair (or potentially any other binary function) usable with the binders except by writing little wrapper classes like pair_creator by hand?
I’d need a C++03 solution (for some obscure reason, stackoverflow always rewrites my c++0x tag to c++11 when saving the post…).
You need
std::ptr_fun, which turns a plain function pointer into an adaptable binary function object (or a unary function object, if you pass it a one-arg function):ptr_funis declared:And for the unary version: