Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #define forevery ,
- #define inside ,
- #define PythonRange2(expression, variable, collection) \
- [&collection]() \
- { \
- std::remove_reference<decltype(collection)>::type __collectionCopy; \
- for (const auto& variable : collection) \
- { \
- __collectionCopy.push_back(expression); \
- } \
- return __collectionCopy; \
- }()
- #define LeftBrace (
- #define PythonRange(expression) \
- PythonRange2 LeftBrace expression )
- int main() {
- std::vector<int> myList = { 1, 2, 3 };
- auto transformed = PythonRange(x * x forevery x inside myList);
- for (const auto& x : transformed)
- {
- std::cout << x << std::endl;
- } // 1, 4, 9
- }
Add Comment
Please, Sign In to add comment