Created
May 28, 2022 16:42
-
-
Save SealtielFreak/683658f5d3cd9182c529078fe853eb93 to your computer and use it in GitHub Desktop.
Pipes in C++
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
template<typename T> | |
class Pipe { | |
T m_value; | |
public: | |
Pipe(const T &value) : m_value(value) { /**/ } | |
Pipe<T> operator |(const std::function<T(T)> &func) { | |
return func(m_value); | |
} | |
explicit operator T() const { | |
return m_value; | |
} | |
}; | |
/* | |
// Example usage: | |
int foo(int i) { | |
return i + 3; | |
} | |
int bzr(int i) { | |
return ++i; | |
} | |
int main() { | |
auto pipe = Pipe(0) | foo | |
| bzr; | |
int i = (int) pipe; // output: 4 | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment