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

make unary_function/binary_function optional (C++11) #624

@andrewcorrigan

Description

@andrewcorrigan

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;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions