Last active
August 6, 2022 12:09
-
-
Save yunusemreayhan/4a916248463f86402d0a74c32f05f9f3 to your computer and use it in GitHub Desktop.
Range Based Looper From Array
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> | |
using namespace std; | |
template<typename itemType> | |
class RangeBasedLooper { | |
itemType *beginItem; | |
int count; | |
public: | |
RangeBasedLooper(itemType *initialItem, int size_) : beginItem(initialItem), count(size_){} | |
itemType* begin() { | |
return beginItem; | |
} | |
itemType* end() { | |
return beginItem + count; | |
} | |
}; | |
int main() | |
{ | |
int a[] = {0,1,2,3,4,5}; | |
for(int& itr : RangeBasedLooper<int>(&(a[0]), sizeof(a)/sizeof(int))) { | |
cout << itr << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment