The C++1x standard has deprecated the old STL binder functions in favor of the more universal std::bind
. However, it seems that std::not1
and std::not2
are not deprecated in favor of a universal std::not_
or something. The reality is that the <functional>
part of the STL, prior to C++1x, was really cumbersome to work with due to 1) the lack of lambdas, 2) the fact that the binders and negation functors required a nested typedef argument_type
, meaning they couldn't work with ordinary functions, and 3) the lack of variadic templates necessitated separate binder and negation functions depending on the number of arguments.
C++1x changed all of this, dramatically improving the usefulness of <functional>
. But for some reason, C++1x seems to have improved everything except std::not1
and std::not2
. Really, it would be nice to have a standard universal negate
function, like:
template <class F>
class negation
{
public:
negation(F f) : m_functor(f) { }
template <class... Args>
bool operator() (Args&&... args) const
{
return (!m_functor(args...));
}
private:
F m_functor;
};
template <class F>
inline negation<F> not_(F f)
{
return negation<F>(f);
}
This would of course deprecate std::not1
and std::not2
in the same way the old binders were deprecated.
Question(s): 1) I've looked through the C++1x draft, and don't see any mention of a universal negate
function. Did I miss it? 2) Is there some compelling reason why they added a universal bind
and deprecated the old binders, but failed to do the same for the negation functions?