This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Description
This is intended for the C++11 milestone:
Can requiring that unary_function and binary_function be the base class for a UnaryFunction or BinaryFunction in Thrust algorithms be made optional?
Not only does this remove the need for deriving from these types, I think (I'm just now starting to really learn C++11) that it also removes the need for writing constructors for small functors since they can instead be instantiated with aggregate initialization once the functors would no longer have a base class.
struct adds_a : public thrust::unary_function<int,int>
{
int _a;
adds_a(int a) : _a(a) {}
int operator()(int i) const { return i + this->_a; }
};
...
adds_a(3);
becomes:
struct adds_a
{
int _a;
int operator()(int i) const { return i + this->_a; }
};
...
adds_a{3};
I've already made this change in my private copy of Thrust via std::result_of in thrust/detail/type_traits/result_of.h.
template<typename Signature>
struct result_of
{
typedef typename std::result_of<Signature>::type type;
};