Boost logo

Boost :

From: Peder Holt (peder.holt_at_[hidden])
Date: 2004-09-16 01:58:48


On Wed, 15 Sep 2004 09:14:02 -0400, David Abrahams
<dave_at_[hidden]> wrote:
> Peder Holt <peder.holt_at_[hidden]> writes:
>
> >>From a quick search in boost/config, the compilers supported by boost
> > that does not support partial template specialization, are:
> > VC 6.5 and 7.0
> > Sunpro 5.2 and earler
> > MPW
> >
> > VC 6.5 and 7.0 are covered by my compile time constants implementation.
> > The question is whether the other two compilers are compilant enough
> > to have implemented ADL correctly :)
>
> Definitely not. But I'm not sure which parts of the ADL rules you're
> interested in here.
>

I am not familiar with the full set of ADL rules, so I'll examplify instead.
I'll list the most important concepts I rely on:

As Daniel pointed out, the following construct is rather essential:

template<int N> struct encode_counter : encode_counter<N - 1> {};
template<> struct encode_counter<1> {};

The template recursion should be reasonably large (eg. 64 or above)
This limits the number of typeofs that can be used per compilation units

This limit is not absolute. I have a method of getting around this limit.

template<unsigned N>
struct sizer {
    BOOST_STATIC_CONSTANT(unsigned,value=N);
    typedef char(&type)[value];
};

sizer<1>::type encode_value(...);
sizer<1>::type encode_index(...);

#define BOOST_TYPEOF_INDEX()
(sizeof(encode_index((encode_counter<MAX_RECURSION_DEPTH>*)0)))

template<typename T>
struct encode_type {
   BOOST_STATIC_CONSTANT(unsigned,value=BOOST_TYPEOF_INDEX());

   BOOST_STATIC_CONSTANT(unsigned,next=value+1);
   friend sizer<next> encode_index(encode_counter<next>*);
   sizer<value>::type resize;
};

template<typename T>
encode_type<T> encode_start(T const&);

void main() {
    int index_before=BOOST_TYPEOF_INDEX() //should return 1
    double* a;
    int index=sizeof(encode_start(a)); //should install a new
encode_index function
    int index_after=BOOST_TYPEOF_INDEX() //should return 2, hence it
must find the encode_index function embedded in the encode_type
struct.
}

That is, Instantiating a template class with a friend function, should
expose this function uncritically.

In addition to the above requirements, I expect the compiler to
recursively instantiate template types, as in the dummy-example below:

template<typename T,unsigned Index,unsigned Position>
struct dummy_encode2 {
      sizer<DOUBLE_ID>::type encode_value(sizer<Index>
const*,sizer<Position>*);
};

template<typename T,unsigned Index,unsigned Position=1>
struct dummy_encode1 {
BOOST_STATIC_CONSTANT(unsigned,instantiate=sizeof(dummy_encode2<T,Index,Position+1>));
      sizer<POINTER_ID>::type encode_value(sizer<Index>
const*,sizer<Position>*);
};

Then the expression
sizeof(dummy_encode1<double*,1>) should install two encode_value functions.

--
Peder Holt
> 
> 
> --
> Dave Abrahams
> Boost Consulting
> http://www.boost-consulting.com
> 
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>

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