Boost logo

Boost Users :

From: alex solovyov (alex.solovyov_at_[hidden])
Date: 2007-05-14 04:33:00


Hi all,

It is not possible to use the macro BOOST_CLASS_EXPORT_GUID or
BOOST_IS_ABSTRACT etc. with a template class. You can certainly
redefine the macro to use the template classes as follows:

#define BOOST_TEMPLATE_CLASS_IS_ABSTRACT(CLASS_NAME, TYPENAME_ARG_1 …,
TYPENAME_ARG_n) \
  namespace boost \
  { \
    namespace serialization \
    { \
      template<> \
            struct is_abstract<CLASS_NAME<TYPENAME_ARG_1, …, TYPENAME_ARG_n> > \
      { \
            typedef mpl::bool_<true> type; \
            BOOST_STATIC_CONSTANT(bool, value = true); \
      }; \
    } \
  }

But here we have the following problem:
 1. How many definitions are written?
 2. What happens with the following template class: Class1<int,
Class2<int, char> >; it defines another new macro (:

The answer for this problem I found in MPL library. We need a wrapper (traits):

struct abstract_class
{
   typedef Class1<int, Class2<int, char> > type;
};

and the macro:

#define BOOST_TEMPLATE_CLASS_IS_ABSTRACT(CLASS_WRAPPER) \
namespace boost \
{ \
  namespace serialization \
  { \
    template<> \
    struct is_abstract< CLASS_WRAPPER::type > \
    { \
      typedef mpl::bool_<true> type; \
      BOOST_STATIC_CONSTANT(bool, value = true); \
    }; \
  } \
}

It is not an optimal solution, but reduces the source code.

Best regards

Alex Solovyov


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net