online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <vector> #include <utility> #include <iostream> template <class RandomAccessCollection> class RandomAccessContextIterator { public: RandomAccessContextIterator( RandomAccessCollection &c, size_t index ): m_collection ( c ), m_index ( index ) {} std::pair<size_t, typename RandomAccessCollection::value_type&> operator*() { return { m_index, m_collection[m_index] }; } void operator++() { ++m_index; } bool operator!=( RandomAccessContextIterator const &other ) const { return m_index != other.m_index; } private: size_t m_index; RandomAccessCollection &m_collection; }; template <class RandomAccessCollection> class RandomAccessContext { public: RandomAccessContext( RandomAccessCollection &c ): m_collection ( c ) {} RandomAccessContextIterator<RandomAccessCollection> begin() { return { m_collection, 0 }; } RandomAccessContextIterator<RandomAccessCollection> end() { return { m_collection, m_collection.size() }; } private: RandomAccessCollection &m_collection; }; template <class T> class Vector : public std::vector<T> { public: Vector( std::initializer_list<T> list ): std::vector<T>( list ) {} auto context() { return RandomAccessContext( *this ); } }; int main( int argc, char **argv ) { Vector v = { "Never", "gonna", "give", "you", "up" }; for ( auto &&[i,e] : v.context() ) std::cout << "Element at index " << i << " has value: " << e << "\n"; return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue