Welcome, guest | Sign In | My Account | Store | Cart
#ifndef NUM_RANGE
#define NUM_RANGE

template<typename T>
struct Derefable { 
        const T& operator*() const { return x; }
        operator T&() { return x; }
        Derefable(const T& x=T{}) : x{x} { }
private:
        T x;
};      

namespace std {
template <typename T> Derefable<T> begin(const T&) { return {}; }
template <typename T> Derefable<T> end(const T& x) { return x; }
}

// usage example
// for (int i : 5) { ... }

#endif

Diff to Previous Revision

--- revision 1 2014-10-02 00:23:53
+++ revision 2 2014-10-02 12:13:52
@@ -6,6 +6,7 @@
         const T& operator*() const { return x; }
         operator T&() { return x; }
         Derefable(const T& x=T{}) : x{x} { }
+private:
         T x;
 };      
 

History