Boost logo

Boost :

From: Peder Holt (peder.holt_at_[hidden])
Date: 2004-09-17 01:27:06


> > 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.
>
> Sorry, I don't see any recursion here.
>

Here is a simplified example from my implementation:
template<>
struct encode_impl<POINTER_ID>
{
   template<typename T,unsigned Index>
   struct encoder {
       enum(instantiate=sizeof(encode_modifier<T,Index+1>::type)); <- Recursion
   }
};

template<typename T,unsigned Index>
encode_impl<POINTER_ID>::encoder<T,Index>
encode(void(*)(mpl::int_<POINTER_ID>,T*,mpl::int_<Index>));

where
template<typename T,unsigned Index>
struct encode_modifier {
  enum(instantiate=sizeof(encode(select_modifier<T>::type,T,mpl::int_<Index>)));
<-Recursion
};

Here:

encode_modifier is instantiated with a type T. After analyzing the
type, type deduction is done through the encode function.
The encode function (or the sizeof operation) instantiates an
encode_impl<N>::encoder<...> struct, which in turn instantiate one or
more encode_modifier<...> structs which in turn ...

What I fear is that some compiler will want to optimalize away the
instantiate enums, as it is never referred to in the source.

--
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