// Copyright (C) 2004, 2005 Arkadiy Vertleyb // Copyright (C) 2005 Peder Holt // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_TYPEOF_TYPEOF_IMPL_HPP_INCLUDED #define BOOST_TYPEOF_TYPEOF_IMPL_HPP_INCLUDED #include #include #include #include #include #include #define BOOST_TYPEOF_VECTOR(n) BOOST_PP_CAT(boost::type_of::vector, n) #define BOOST_TYPEOF_sizer_item(z, n, _)\ char item ## n[V::item ## n ::value]; namespace boost { namespace type_of { template struct sizer { // char item0[V::item0::value]; // char item1[V::item1::value]; // ... BOOST_PP_REPEAT(BOOST_TYPEOF_LIMIT_SIZE, BOOST_TYPEOF_sizer_item, ~) }; }} #undef BOOST_TYPEOF_sizer_item // namespace boost { namespace type_of { # ifdef BOOST_NO_SFINAE template sizer::type> encode(const T&); # else template typename enable_if< typename is_function::type, sizer::type> >::type encode(T&); template typename disable_if< typename is_function::type, sizer::type> >::type encode(const T&); # endif }} // namespace boost { namespace type_of { template struct decode_begin { typedef typename decode_type::type type; }; }} #define BOOST_TYPEOF_TYPEITEM(z, n, expr)\ boost::mpl::size_t >(expr).item ## n)> #define BOOST_TYPEOF_ENCODED_VECTOR(Expr) \ BOOST_TYPEOF_VECTOR(BOOST_TYPEOF_LIMIT_SIZE)< \ BOOST_PP_ENUM(BOOST_TYPEOF_LIMIT_SIZE, BOOST_TYPEOF_TYPEITEM, Expr) \ > #define BOOST_TYPEOF(Expr)\ boost::type_of::decode_begin::type #define BOOST_TYPEOF_TPL typename BOOST_TYPEOF //offset_vector is used to delay the insertion of data into the vector in order to allow //encoding to be done in many steps namespace boost { namespace type_of { template struct offset_vector { }; template struct push_back,T> { typedef offset_vector type; }; template struct push_back >,T> { typedef typename push_back::type type; }; }} #define BOOST_TYPEOF_NESTED_TYPEITEM(z, n, expr)\ BOOST_STATIC_CONSTANT(int,BOOST_PP_CAT(value,n) = sizeof(boost::type_of::encode<_typeof_start_vector>(expr).item ## n));\ typedef boost::mpl::size_t BOOST_PP_CAT(item,n); #ifdef __DMC__ #define BOOST_TYPEOF_NESTED_TYPEITEM_2(z,n,expr)\ typedef typename _typeof_encode_fraction::BOOST_PP_CAT(item,n) BOOST_PP_CAT(item,n); #define BOOST_TYPEOF_FRACTIONTYPE()\ BOOST_PP_REPEAT(BOOST_TYPEOF_LIMIT_SIZE,BOOST_TYPEOF_NESTED_TYPEITEM_2,_)\ typedef _typeof_fraction_iter fraction_type; #else #define BOOST_TYPEOF_FRACTIONTYPE()\ typedef _typeof_encode_fraction fraction_type; #endif #ifdef __BORLANDC__ namespace boost { namespace type_of { template struct generic_typeof_fraction_iter { typedef generic_typeof_fraction_iter self_t; static const int pos=(Pos::value); static const int iteration=(pos/5); static const int where=pos%5; typedef typename Iter::template _apply_next::type fraction_type; typedef generic_typeof_fraction_iter next; typedef typename v_iter >::type type; }; }} #define BOOST_TYPEOF_NESTED_TYPEDEF_IMPL(expr) \ template\ struct _typeof_encode_fraction {\ typedef _typeof_encode_fraction<_Typeof_Iteration> self_t;\ BOOST_STATIC_CONSTANT(int,_typeof_encode_offset = (_Typeof_Iteration*BOOST_TYPEOF_LIMIT_SIZE));\ typedef boost::type_of::offset_vector,boost::mpl::size_t > _typeof_start_vector;\ BOOST_PP_REPEAT(BOOST_TYPEOF_LIMIT_SIZE,BOOST_TYPEOF_NESTED_TYPEITEM,expr)\ template\ struct _apply_next {\ typedef _typeof_encode_fraction type;\ };\ };\ template\ struct _typeof_fraction_iter {\ typedef boost::type_of::generic_typeof_fraction_iter > self_t;\ typedef typename self_t::next next;\ typedef typename self_t::type type;\ }; #else #define BOOST_TYPEOF_NESTED_TYPEDEF_IMPL(expr) \ template\ struct _typeof_encode_fraction {\ typedef _typeof_encode_fraction<_Typeof_Iteration> self_t;\ BOOST_STATIC_CONSTANT(int,_typeof_encode_offset = (_Typeof_Iteration*BOOST_TYPEOF_LIMIT_SIZE));\ typedef boost::type_of::offset_vector,boost::mpl::size_t > _typeof_start_vector;\ BOOST_PP_REPEAT(BOOST_TYPEOF_LIMIT_SIZE,BOOST_TYPEOF_NESTED_TYPEITEM,expr)\ };\ template\ struct _typeof_fraction_iter {\ typedef _typeof_fraction_iter self_t;\ BOOST_STATIC_CONSTANT(int,pos=(Pos::value));\ BOOST_STATIC_CONSTANT(int,iteration=(pos/BOOST_TYPEOF_LIMIT_SIZE));\ BOOST_STATIC_CONSTANT(int,where=pos%BOOST_TYPEOF_LIMIT_SIZE);\ BOOST_TYPEOF_FRACTIONTYPE()\ typedef typename boost::type_of::v_iter >::type type;\ typedef _typeof_fraction_iter next;\ }; #endif #ifdef __MWERKS__ # define BOOST_TYPEOF_NESTED_TYPEDEF(name,expr) \ template\ struct BOOST_PP_CAT(_typeof_template_,name) {\ BOOST_TYPEOF_NESTED_TYPEDEF_IMPL(expr)\ typedef typename boost::type_of::decode_type<_typeof_fraction_iter > >::type type;\ };\ typedef BOOST_PP_CAT(_typeof_template_,name) name; # define BOOST_TYPEOF_NESTED_TYPEDEF_TPL(name,expr) BOOST_TYPEOF_NESTED_TYPEDEF(name,expr) #else # define BOOST_TYPEOF_NESTED_TYPEDEF_TPL(name,expr) \ struct name {\ BOOST_TYPEOF_NESTED_TYPEDEF_IMPL(expr)\ typedef typename boost::type_of::decode_type<_typeof_fraction_iter > >::type type;\ }; # define BOOST_TYPEOF_NESTED_TYPEDEF(name,expr) \ struct name {\ BOOST_TYPEOF_NESTED_TYPEDEF_IMPL(expr)\ typedef boost::type_of::decode_type<_typeof_fraction_iter > >::type type;\ }; #endif #endif//BOOST_TYPEOF_COMPLIANT_TYPEOF_IMPL_HPP_INCLUDED