#define UNIT r6_bits #include template< typename num_t > class bits { struct proxy { bool _value; bool *operator->() { return &_value; } }; struct iterator { using value_type = bool; using reference = bool; using pointer = proxy; using difference_type = ssize_t; using iterator_category = std::input_iterator_tag; num_t _value; num_t _mask; iterator &operator++() { _mask <<= 1; return *this; } bool operator*() const { return _value & _mask; } proxy operator->() const { return { **this }; } bool operator==( const iterator &other ) const { return _mask == other._mask; } bool operator!=( const iterator &other ) const { return !( *this == other ); } }; num_t _value; public: bits( num_t n ) : _value( n ) {} iterator begin() const { return { _value, 1 }; } iterator end() const { return { _value, 0 }; } }; #include "test_main.cpp"