I don't like auto over int, and other primitives. But auto in for loops or with iterators seems the way to go and is a bless!
typedef std::vector<bool> Vec;
Vec f(1, false);
for (typename Vec::value_type &&x : f) { std::cout << typeid(x).name() << std::endl; }
for (auto &&x : f) { std::cout << typeid(x).name() << std::endl; } template<class It> struct iterator_range { It b, e; It begin() const { return b; } It end() const { return e; } };
template<class It> iterator_range<It> make_iterator_range(It b, It e) { iterator_range<It> r = { b, e }; return r; }
template<class T> struct endian_reversed_iterator {
T *p;
struct reference {
T *p;
operator T() const { return boost::endian::endian_reverse(*p); }
reference &operator =(T const &other) const { *p = boost::endian::endian_reverse(other); }
};
endian_reversed_iterator(T *p) : p(p) { }
reference operator *() { reference r = { p }; return r; }
endian_reversed_iterator &operator++() { ++p; return *this; }
bool operator!=(endian_reversed_iterator const &other) const { return p != other.p; }
};
int main() {
unsigned arr[] = { 1, 2 };
for (auto x : make_iterator_range<endian_reversed_iterator<unsigned> >(&arr[0], &arr[2])) {
++x; // whatever
}
}