
John Torjo <john.lists@torjo.com> writes:
Just a late thought: what if we were to make the internal data of crange<> const? I guess this should give an extra hint to the compiler:
template< class type> struct crange { protected: typedef crange<type> self_type; typedef void (*incrementer)(const self_type&); typedef bool (*at_end)(const self_type &); typedef type & (*deref)(const self_type&);
crange( incrementer inc_func, at_end at_end_func, deref deref_func) : m_inc_func(inc_func), m_at_end_func(at_end_func), m_deref_func(deref_func) {} public:
operator bool() const { return !m_at_end_func(*this); } const self_type & operator++() const { m_inc_func(*this); return *this; } type & operator*() const { return m_deref_func(*this); } private: const incrementer m_inc_func; const at_end m_at_end_func; const deref m_deref_func; };
What do you think?
Not much; my guess is that compilers very seldom use const object declarations for optimization, but I have no data. At least in the case of vtables the user really has no reasonable way of mutating it by casting away const, but I was only speculating about that, too. Someone should measure. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com