Boost logo

Boost :

Subject: Re: [boost] [Range] [Iterator] [MPL] make range_const/mutable_iterator<C>::typenon-existent if C is non-range
From: Arno Schödl (aschoedl_at_[hidden])
Date: 2008-12-31 05:41:49


> I have taken some time to evaluate alternative solutions, but I think the
> proposed patch is the best solution available. I am, with your permission,
> going to put this into the RangeEx code in the vault. This will, if all goes
> to plan, subsequently be an update of Boost.Range. It seems that this type
> of solution would be applicable to the mutable and reverse variants. Do you
> agree?

Feel free to put it in. The same principle applies to all templates exposing typedefs in their default implementation. I think this is a frequent pattern in Boost.Iterator, Boost.Range and Boost.MPL:

        template< class T >
        struct wrapper {
                typedef typename T::some_typedef type;
        };

You can always make it break like this:

        template< class T >
        typename wrapper<T>::type Func( T t ) {};

        template< class T >
        void Func( T t ) {};

        main () {
                struct {} empty_struct;
                func( empty_struct );
        }

and then fix it like this:

        BOOST_EXTRACT_OPTIONAL_TYPE( some_typedef );

        template< class T >
        struct wrapper
        : extract_some_typedef<T> {};

I already patched boost::range_mutable_iterator because I also use it as return type (see patch posted earlier). I am not sure how far we should drive this. We may not know all side effects yet, and whether my fix is really the best one. Maybe we should do it where immediately needed and otherwise wait for more evidence.

Arno

--
Dr. Arno Schoedl · aschoedl_at_[hidden] 
Technical Director 
 
think-cell Software GmbH · Invalidenstr. 34 · 10115 Berlin, Germany 
http://www.think-cell.com · phone +49-30-666473-10 · toll-free (US) +1-800-891-8091
Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl · Amtsgericht Charlottenburg, HRB 85229

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk