Created
February 5, 2017 16:56
-
-
Save dendisuhubdy/bc4b09e6da1680ee919564237ecf1ba5 to your computer and use it in GitHub Desktop.
Fold Expression C++
This file contains hidden or 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
| // foldExpression.cpp | |
| #include <iostream> | |
| bool allVar(){ | |
| return true; | |
| } | |
| template<typename T, typename ...Ts> | |
| bool allVar(T t, Ts ... ts){ | |
| return t && allVar(ts...); | |
| } | |
| template<typename... Args> | |
| bool all(Args... args) { return (... && args); } | |
| int main(){ | |
| std::cout << std::boolalpha; | |
| std::cout << "allVar(): " << allVar() << std::endl; | |
| std::cout << "all(): " << all() << std::endl; | |
| std::cout << "allVar(true): " << allVar(true) << std::endl; | |
| std::cout << "all(true): " << all(true) << std::endl; | |
| std::cout << "allVar(true, true, true, false): " << allVar(true, true, true, false) << std::endl; | |
| std::cout << "all(true, true, true, false): " << all(true, true, true, false) << std::endl; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment