Last active
August 29, 2015 14:11
-
-
Save tonisuter/155f057edb3d2b4baecf to your computer and use it in GitHub Desktop.
Pipe & Stages with varying task types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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