Boost logo

Boost :

From: John Torjo (john.lists_at_[hidden])
Date: 2004-04-29 02:06:37

David Abrahams wrote:

>John Torjo <john.lists_at_[hidden]> writes:
>>Matthew Vogt wrote:
>>>Like the following:
>>>I guess it depends on how much you're willing to pay for syntactic sugar...
>>we're talking the same language ;) It seems that we posted our
>>solutions at about the same time ;)
>>My solution however does not involve any virtual call.
>Calling through internally stored function pointers may be a minor
>improvement over using virtual functions, but that's not crystal clear
>to me. It seems likely that compilers might optimize away the virtual
>calls because all vtables are known to be strictly constant, but the
>other optimization seems less likely.
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 {
   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) {}

   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); }
   const incrementer m_inc_func;
   const at_end m_at_end_func;
   const deref m_deref_func;

What do you think?


John Torjo
Freelancer, C++ article writer
-- mailto:john_at_[hidden]
   viewing/filtering logs can't get any easier than this!

Boost list run by bdawes at, gregod at, cpdaniel at, john at