Skip to content

Instantly share code, notes, and snippets.

@tonisuter
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonisuter/155f057edb3d2b4baecf to your computer and use it in GitHub Desktop.
Save tonisuter/155f057edb3d2b4baecf to your computer and use it in GitHub Desktop.
Pipe & Stages with varying task types
#include <iostream>
#include <type_traits>
template<typename IN, typename OUT = IN>
struct node {
using in_type = IN;
using out_type = OUT;
};
template<class A, class...>
struct valid_stage_types : std::true_type {};
template<class A, class B, class... Bs>
struct valid_stage_types<A*, B*, Bs...> : std::integral_constant<bool, std::is_same<typename A::out_type, typename B::in_type>{} && valid_stage_types<B*, Bs...>{}> {};
class pipe {
public:
template<typename... STAGES>
pipe(STAGES ... stages) {
static_assert(valid_stage_types<STAGES...>{}, "Input & output types of the pipe's stages don't match");
//...
}
};
int main(int argc, char *argv[]) {
node<int, char> s1{};
node<char, std::string> s2{};
node<std::string, char> s3{};
pipe(&s1, &s2, &s3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment