Skip to content

Instantly share code, notes, and snippets.

@yunusemreayhan
Last active August 6, 2022 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yunusemreayhan/4a916248463f86402d0a74c32f05f9f3 to your computer and use it in GitHub Desktop.
Save yunusemreayhan/4a916248463f86402d0a74c32f05f9f3 to your computer and use it in GitHub Desktop.
Range Based Looper From Array
#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