// Copyright (C) 2004 Peder Holt // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_TYPEOF_VECTOR_CTC_HPP_INCLUDED #define BOOST_TYPEOF_VECTOR_CTC_HPP_INCLUDED #include #include #include #include namespace boost { namespace mpl { #define CTC_INDEX() sizeof(boost::mpl::ctc_index((boost::mpl::aux::ctc_counter<64>*)NULL)) #define CTC_VALUE(index,pos) sizeof(boost::mpl::ctc_value((boost::mpl::aux::ctc_counter*)NULL,(boost::mpl::aux::ctc_size*)NULL)) namespace aux { template struct ctc_size { BOOST_STATIC_CONSTANT(unsigned,value=N); typedef char type[value]; }; template struct ctc_counter : ctc_counter {}; template<> struct ctc_counter<0> {}; struct ctc_vector_tag {}; template struct ctc_vector_impl { typedef ctc_vector_tag tag; BOOST_STATIC_CONSTANT(unsigned,index=Index); BOOST_STATIC_CONSTANT(unsigned,pos=Pos); }; } aux::ctc_size<1>::type &ctc_index(...); template struct ctc_vector : aux::ctc_vector_impl { BOOST_STATIC_CONSTANT(unsigned,value=Index); BOOST_STATIC_CONSTANT(unsigned,next=value+1); typedef aux::ctc_vector_tag tag; friend typename aux::ctc_size::type &ctc_index(aux::ctc_counter*); }; template struct ctc_iterator { BOOST_STATIC_CONSTANT(unsigned,value=CTC_VALUE(Index,Pos)); typedef ctc_iterator next; typedef mpl::size_t type; }; template<> struct push_back_impl< aux::ctc_vector_tag > { template< typename Vector, typename T > struct apply { BOOST_STATIC_CONSTANT(unsigned,index=Vector::index); BOOST_STATIC_CONSTANT(unsigned,pos=Vector::pos); friend typename aux::ctc_size::type &ctc_value(aux::ctc_counter*,aux::ctc_size*); typedef aux::ctc_vector_impl type; }; }; template<> struct begin_impl< aux::ctc_vector_tag > { template< typename Vector > struct apply { BOOST_STATIC_CONSTANT(unsigned,index=Vector::index); typedef ctc_iterator type; }; }; }} #endif