mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-30 21:30:05 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			40 lines
		
	
	
	
		
			936 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
	
		
			936 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| #pragma once
 | |
| 
 | |
| #include <type_traits>
 | |
| 
 | |
| namespace scwx
 | |
| {
 | |
| namespace util
 | |
| {
 | |
| 
 | |
| template<typename T, T beginValue, T endValue>
 | |
| class Iterator
 | |
| {
 | |
|    typedef typename std::underlying_type<T>::type value_t;
 | |
|    int                                            value_;
 | |
| 
 | |
| public:
 | |
|    Iterator(const T& v) : value_(static_cast<value_t>(v)) {}
 | |
|    Iterator() : value_(static_cast<value_t>(beginValue)) {}
 | |
|    Iterator operator++()
 | |
|    {
 | |
|       ++value_;
 | |
|       return *this;
 | |
|    }
 | |
|    T        operator*() { return static_cast<T>(value_); }
 | |
|    Iterator begin() { return *this; } // Default constructor
 | |
|    Iterator end()
 | |
|    {
 | |
|       static const Iterator endIterator = ++Iterator(endValue);
 | |
|       return endIterator;
 | |
|    }
 | |
|    std::size_t count()
 | |
|    {
 | |
|       return static_cast<value_t>(endValue) - static_cast<value_t>(beginValue) +
 | |
|              1;
 | |
|    }
 | |
|    bool operator!=(const Iterator& i) { return value_ != i.value_; }
 | |
| };
 | |
| 
 | |
| } // namespace util
 | |
| } // namespace scwx
 | 
