Boost logo

Boost :

From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2005-05-21 11:51:07


"Eric Niebler" <eric_at_[hidden]> wrote

> Arkadiy Vertleyb wrote:
> > Here is the minimal example:
> >
> > // ----
> > #include "boost/mpl/vector.hpp"
> > #include "boost/mpl/size_t.hpp"
> >
> > template<class T> T make();
> >
> > template<class T>
> > struct et
> > {
> > typedef boost::mpl::vector1<int> type;
> > };
> >
> > template<class T>
> > char(&sz(const T&))[
> > boost::mpl::size<
> > typename et<T>::type
> > >::value
> > ];
> >
> > template<class T, class U>
> > struct add
> > {
> > typedef boost::mpl::vector1<
> > boost::mpl::size_t<sizeof(sz(make<T>() + make<U>()))>
> > //boost::mpl::size_t<sizeof(sz(T() + U()))> -- doesn't help here
> > > type;
> > };
> >
> > int main()
> > {
> > return 0;
> > }
> > // ----
> >
> > This example compiles fine with GCC, but both MS compilers choke on it.
>
>
>
> I have experienced this problem before, and the fix is to calculate the
> return type of the sz() function as a separate step:
>
> #include "boost/mpl/vector.hpp"
> #include "boost/mpl/size_t.hpp"
>
> template<class T> T make();
>
> template<class T>
> struct et
> {
> typedef boost::mpl::vector1<int> type;
> };
>
> template<class T>
> struct sizer
> {
> typedef char(&type)[
> boost::mpl::size<
> typename et<T>::type
> >::value
> ];
> };
>
> template<class T>
> typename sizer<T>::type sz(const T&);
>
> template<class T, class U>
> struct add
> {
> typedef boost::mpl::vector1<
> boost::mpl::size_t<sizeof(sz(make<T>() + make<U>()))>
> > type;
> };
>
>
>
> This compiles with VC7.1 and with gcc. I don't have VC8 beta installed.

Hi Eric,

Your example does compile on VC8 beta -- thanks a lot. Now I'll try to aply
it to typeof...

As far as "Microsoft bug" is conserned, my testing wasn't accurate. After I
#include "boost/mpl/size.hpp", which I use, VC7 is fine and VC8 is fine with
T() + U(). It still can't handle make<T>() + make<U>(), though...

Regards,
Arkadiy


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