Boost logo

Boost :

From: Mat Marcus (mmarcus_at_[hidden])
Date: 2001-12-15 18:10:31


At 5:59 PM -0500 12/15/01, David Abrahams wrote:
>Mat, could you describe this technique in a patch for
>
>www.boost.org/more/microsoft_vcpp.html
>
>??
>
>I will be very glad to be able to check it into CVS.

Sure, although it might take some time for me to get to it. If it's
any help, here is a snippet describing the technique from
<http://groups.yahoo.com/group/boost/message/20944>

Mat

--- Snip ---

At 12:18 AM -0800 11/30/01, Mat Marcus wrote:

This brings us to the second porting problem. This code still won't
compile. The heinous VC "typedef dependent template parameter"
bug. This bug is difficult to describe but I will give it a brief
try. The code above:

      MetaFunctionWrapper::template Result<AtomicType>::type

fails to compile. But other similar expressions succeed. Success seems
to occur in the cases when the outer class is not a template
parameter. There are a couple of workarounds for this but they are not
legal C++. Aleksey has encapsulated one of these in ::boost::mpl as
the BOOST_MPL_DEPENDENT_TEMPLATE_TYPEDEF macro. (Actually, the macro
needs a slight modification to work here: the last parameter must be
eliminated.). So we replace the above line of code with:

      BOOST_MPL_DEPENDENT_TEMPLATE_TYPEDEF(MetaFunctionWrapper, \
        Result, AtomicType)

This is admittedly ugly, but at least it only appears in the
implementation, not the client code. Many of us don't like macros too
much. We can do a little better by burying this hack away inside
another metafunction, let's call it Apply. That is:

template <class MetaFunctionWrapper, class T>
struct Apply
{
#ifdef BOOST_MSVC
  // based on the (non-conforming) MSVC trick from MPL

  template<bool>
  struct MetaFunctionWrapper_VC : MetaFunctionWrapper {};

  //illegal C++ which causes VC to admit that MetaFunctionWrapper_VC
  //can have a nested template:

  template<>
  struct MetaFunctionWrapper_VC<true>
  {template<class> struct Result; };

  typedef typename MetaFunctionWrapper_VC<
    ::boost::mpl::detail::msvc_never_true<MetaFunctionWrapper>::value
>::template Result<T>::type type;
  };
#else
   typedef typename MetaFunctionWrapper::template Result<T>::type type;
#endif
};

Then the offending code:

template <class AtomicType, class MetaFunctionWrapper>
class GenScatterHierarchy : public
       MetaFunctionWrapper::template Result<AtomicType>::type
{
};

becomes:

template <class AtomicType, class MetaFunctionWrapper>
class GenScatterHierarchy : public
   typename Apply<MetaFunctionWrapper, AtomicType>::type
{
};


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