Boost logo

Boost :

From: Yitzhak Sapir (yitzhaks_at_[hidden])
Date: 2002-09-05 14:34:13


> -----Original Message-----
> From: David Abrahams [mailto:dave_at_[hidden]]
> Sent: Thursday, September 05, 2002 8:05 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] iterator adaptors and operator[]

> I've been using a trick in the Boost.Python library which
> might apply here:
>
> template <class T, class Result>
> struct dependent {
> typedef Result type;
> };
>
> now you can use dependent<T,X>::type to declare a return type
> of X which is
> dependent on a template parameter of the function, e.g.:
>
> typename dependent<Policies,value_type>::type
> operator[](difference_type
> n) {
> ...
> }
>
> This trick is also nice for breaking #include dependencies, since the
> definition of X isn't needed in order to use it.
>
> If OP tries this and it works for his problem I'd be happy to accept a
> patch.

It doesn't work. I suppose that is because when it gets to operator[] it already knows what Policies and value_type both are. Maybe it would work in a templated function, but I can't see why any other parameter other than Policies would make it work in this case.

The attached patch solves it using inheritance (operator[] is inherited, with the inherited class chosen based on Category), but is much more complex than the above trick would have been.

In testing this against cvs, I had problems that the preprocessor lib was including stuff from preprocessor/detail in, for example, inc.hpp, and those were being used in alignment_traits.hpp. The cvs didn't have a preprocessor/detail however.




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