Boost logo

Boost :

Subject: Re: [boost] [heap] typedef T gets prevalence over template parameter
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2012-09-07 05:34:55


On Friday 07 September 2012 10:27:55 Alex Hagen-Zanker wrote:
> On 07/09/2012 08:40, Tim Blechmann wrote:
> >> The d_ary_heap does not compile (in VS2010) when the Comparison class
> >> contains a typedef T. The typedef takes prevalence over the template
> >> parameter T when the heap is derived from the Comparison class.
> >>
> >> I.e. the following pattern occurs:
> >>
> >> template<class T, class Cmp> struct heap_base : Cmp
> >> {
> >>
> >> typedef T value_type; // value_type = Cmp::T
> >>
> >> }
> >>
> >> I don't know if this is a bug, a user issue, or a compiler issue. But it
> >> caused me a lot of headache when I was trying to apply Jeremiah's
> >> indirect_cmp with Boost.Heap.
> >
> > hm ... this code works with gcc and with clang ... afaict, msvc does not
> > resolve T correctly.
> >
> > not sure what is the best way to work around this, as every identifier
> > that we can use instead of T could also clash with a declaration in Cmp :/
> >
> > tim
>
> You could have a workaround like this:
>
> template<typename T, typename U, typename Parent>
> struct B_args
> {
> typedef T T;
> typedef U U;
> typedef Parent Parent;
> };
>
> template<typename T, typename U, typename Parent>
> struct B : B_args<T, U, Parent> , Parent
> {
> typedef typename B_args::T value_type;
> };
>
> as a replacement for:
>
> template<typename T, typename U, typename Parent>
> struct B : Parent
> {
> typedef T value_type;
> };

... or keep Cmp as a member, if possible. Although this would defeat EBO.


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