Last active
November 8, 2017 10:58
-
-
Save DimChtz/ca9b9dd25412806c42bfb18270a6a02f to your computer and use it in GitHub Desktop.
Range function for 2d loop in 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
| #include <iostream> | |
| #include <vector> | |
| #include <utility> | |
| template<typename T> | |
| std::vector<std::pair<T, T>> range2(T start1, T end1, T start2, T end2) { | |
| std::vector<std::pair<T, T>> loopValues{}; | |
| for (T i = start1; i < end1; ++i) { | |
| for (T j = start2; j < end2; ++j) { | |
| loopValues.push_back(std::make_pair (i, j)); | |
| } | |
| } | |
| return loopValues; | |
| } | |
| int main() { | |
| for (auto p : range2(1, 3, 1, 3)) { | |
| std::cout << p.first << p.second << std::endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment