Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concepts #199

Open
antialize opened this issue Apr 26, 2016 · 0 comments
Open

concepts #199

antialize opened this issue Apr 26, 2016 · 0 comments

Comments

@antialize
Copy link
Collaborator

antialize commented Apr 26, 2016

gcc 6 just implemented concepts lite, perhaps we could extend tpie to use them for pipelining, here is an example of how they work.

#include <type_traits>
#include <utility>

class node {};


template <typename T>
concept bool pipenode() {
  return std::is_base_of<node, T>::value;
}

template <typename T>
concept bool movable() {
  return requires(T i, T x) {
    {x = std::move(i)}
    {new T(std::move(i))}
  };
}

template <typename T>
concept bool pushable_generic() {
  return requires (T t, typename T::item_type i) {
    {t.push(i)} -> void
                     };
}

template <typename T>
concept bool pushable_generic_node = pushable_generic<T>() && pipenode<T>() && movable<T>();

struct Monkey : public node{
  Monkey() {}
  //Monkey(Monkey && m) = delete;                                                                                                                                                                                                                                                        

  typedef int item_type;

  void push(int) {}
};

template <pushable_generic_node T>
void hat(T node) {
}

int main() {
  hat(Monkey());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant