|
Boost : |
From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2005-12-22 15:31:18
"Arkadiy Vertleyb" <vertleyb_at_[hidden]> wrote
> I will try to implement such registrations for mpl::vector[n], as an
> example. However, I think it's ultimately up to the library authors do
> decide whether or not to make their libraries typeof-enabled (I would be
> happy to provide any help on the subject).
Here it is (tested only with vc71, BOOST_TYPEOF_COMPLIANT mode). I will
have to add one macro to the typeof lib (marked in the source below):
============================
#define BOOST_TYPEOF_COMPLIANT
#include <boost/typeof/typeof.hpp>
#include <boost/mpl/vector.hpp>
// this is to be added to the typeof lib
#define BOOST_TYPEOF_REGISTER_TEMPLATE_EXPLICIT_ID(Name, Params, Id)\
BOOST_TYPEOF_REGISTER_TEMPLATE_IMPL(\
Name,\
BOOST_TYPEOF_MAKE_OBJS(BOOST_TYPEOF_TOSEQ(Params)),\
BOOST_PP_SEQ_SIZE(BOOST_TYPEOF_TOSEQ(Params)),\
Id)
//////////////////
#define REGISTER_ONE(z, n, Group)\
BOOST_TYPEOF_REGISTER_TEMPLATE_EXPLICIT_ID(\
boost::mpl::vector, n, Group + n - 1)
#define REGISTER_ONE_NUMBERED(z, n, Group)\
BOOST_TYPEOF_REGISTER_TEMPLATE_EXPLICIT_ID(\
boost::mpl::vector ## n, n, Group + n - 1)
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
// to minimize the size of encoding vector,
// register with every possible number of parameters (0 - 10)
BOOST_TYPEOF_REGISTER_TYPE(boost::mpl::vector<>)
BOOST_PP_REPEAT_FROM_TO(1, 10,
REGISTER_ONE, BOOST_TYPEOF_UNIQUE_ID())
// since we registered more than one template in one line,
// UNIQUE_ID is no longer valid with this registration group
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
BOOST_TYPEOF_REGISTER_TYPE(boost::mpl::vector0<>)
BOOST_PP_REPEAT_FROM_TO(1, 10,
REGISTER_ONE_NUMBERED, BOOST_TYPEOF_UNIQUE_ID())
int main()
{
boost::mpl::vector1<boost::mpl::vector<int, boost::mpl::vector0<> > > v;
typedef BOOST_TYPEOF(v) v_type;
return 0;
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk