'Native' (no registration required) support for typeof for VC6, VC7.0 and VC7.1 implemented

[SVN r2562]
This commit is contained in:
Peder Holt
2005-04-04 10:38:55 +00:00
parent fd1038f002
commit 1854d10180
3 changed files with 168 additions and 15 deletions

View File

@@ -7,21 +7,28 @@
#include <boost/config.hpp>
#if !defined(BOOST_TYPEOF_COMPLIANT) && !defined(BOOST_TYPEOF_VINTAGE) && !defined(BOOST_TYPEOF_NATIVE)
#if !defined(BOOST_TYPEOF_COMPLIANT) &&\
!defined(BOOST_TYPEOF_VINTAGE) &&\
!defined(BOOST_TYPEOF_NATIVE) &&\
!defined(BOOST_TYPEOF_MSVC)
# if defined __GNUC__
# define BOOST_TYPEOF_NATIVE
# if defined __GNUC__
# define BOOST_TYPEOF_NATIVE
# elif defined __MWERKS__
# define BOOST_TYPEOF_NATIVE
# elif defined __MWERKS__
# define BOOST_TYPEOF_NATIVE
# elif defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
# define BOOST_TYPEOF_VINTAGE
# elif defined(BOOST_MSVC) && (BOOST_MSVC<1400)
//Doesn't require registration
# define BOOST_TYPEOF_NATIVE
# else
# define BOOST_TYPEOF_COMPLIANT
# elif defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
# define BOOST_TYPEOF_VINTAGE
# endif
# else
# define BOOST_TYPEOF_COMPLIANT
# endif
#endif

View File

@@ -0,0 +1,142 @@
// Copyright (C) 2005 Igor Chesnokov
// Copyright (C) 2005 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_MSVC_TYPEOF_IMPL_HPP_INCLUDED
# define BOOST_TYPEOF_MSVC_TYPEOF_IMPL_HPP_INCLUDED
# include <boost/config.hpp>
# include <boost/detail/workaround.hpp>
namespace boost
{
namespace type_of
{
//Compile time constant code
# if BOOST_WORKAROUND(BOOST_MSVC,>=1300) && defined(_MSC_EXTENSIONS)
template<int N> struct the_counter;
template<typename T,int N = 5/*for similarity*/>
struct encode_counter
{
__if_exists(the_counter<N + 256>)
{
BOOST_STATIC_CONSTANT(unsigned,count=(encode_counter<T,N + 257>::count));
}
__if_not_exists(the_counter<N + 256>)
{
__if_exists(the_counter<N + 64>)
{
BOOST_STATIC_CONSTANT(unsigned,count=(encode_counter<T,N + 65>::count));
}
__if_not_exists(the_counter<N + 64>)
{
__if_exists(the_counter<N + 16>)
{
BOOST_STATIC_CONSTANT(unsigned,count=(encode_counter<T,N + 17>::count));
}
__if_not_exists(the_counter<N + 16>)
{
__if_exists(the_counter<N + 4>)
{
BOOST_STATIC_CONSTANT(unsigned,count=(encode_counter<T,N + 5>::count));
}
__if_not_exists(the_counter<N + 4>)
{
__if_exists(the_counter<N>)
{
BOOST_STATIC_CONSTANT(unsigned,count=(encode_counter<T,N + 1>::count));
}
__if_not_exists(the_counter<N>)
{
BOOST_STATIC_CONSTANT(unsigned,count=N);
typedef the_counter<N> type;
}
}
}
}
}
};
# define BOOST_TYPEOF_INDEX(T) (encode_counter<T>::count)
# define BOOST_TYPEOF_NEXT_INDEX(next)
# else
template<int N> struct encode_counter : encode_counter<N - 1> {};
template<> struct encode_counter<0> {};
//Need to default to a larger value than 4, as due to MSVC's ETI errors. (sizeof(int)==4)
char (*encode_index(...))[5];
# define BOOST_TYPEOF_INDEX(T) (sizeof(*boost::type_of::encode_index((boost::type_of::encode_counter<1005>*)0)))
# define BOOST_TYPEOF_NEXT_INDEX(next) friend char (*encode_index(encode_counter<next>*))[next];
# endif
//Typeof code
# if BOOST_WORKAROUND(BOOST_MSVC,==1300)
template<int ID>
struct msvc_typeof_base
{
template<bool>
struct id2type_impl;
typedef id2type_impl<true> id2type;
};
template<typename T, int ID>
struct msvc_typeof : public msvc_typeof_base<ID>
{
template<>
struct id2type_impl<true>
{
typedef T type;
};
};
# else
template<int ID>
class msvc_typeof_base
{
public:
class id2type;
};
template<typename T, int ID>
class msvc_typeof : public msvc_typeof_base<ID>
{
public:
class msvc_typeof_base<ID>::id2type // This uses nice VC6-VC7 bugfeature
{
public:
typedef T type;
};
};
# endif
//Tie it all together
template<typename T>
struct encode_type
{
//Get the next available compile time constants index
BOOST_STATIC_CONSTANT(unsigned,value=BOOST_TYPEOF_INDEX(T));
//Instantiate the template
typedef typename msvc_typeof<T,value>::id2type type;
//Set the next compile time constants index
BOOST_STATIC_CONSTANT(unsigned,next=value+1);
//Increment the compile time constant (only needed when extensions are not active
BOOST_TYPEOF_NEXT_INDEX(next);
};
template<typename T>
char (*encode_start(T const&))[encode_type<T>::value];
}
}
# define BOOST_TYPEOF(expr) \
boost::type_of::msvc_typeof_base<sizeof(*boost::type_of::encode_start(expr))>::id2type::type
# define BOOST_TYPEOF_TPL(expr) typename BOOST_TYPEOF(expr)
#endif//BOOST_TYPEOF_MSVC_TYPEOF_IMPL_HPP_INCLUDED

View File

@@ -15,10 +15,15 @@
// BOOST_TYPEOF, BOOST_TYPEOF_TPL
#if defined(BOOST_TYPEOF_COMPLIANT)
#if defined(BOOST_TYPEOF_NATIVE) && defined(BOOST_MSVC)
# define BOOST_TYPEOF_TEXT "using msvc 'native' imlementation"
# include <boost/typeof/message.hpp>
# include <boost/typeof/msvc/typeof_impl.hpp>
#elif defined(BOOST_TYPEOF_COMPLIANT)
# define BOOST_TYPEOF_TEXT "using compliant imlementation"
# include <boost/typeof/message.hpp>
# include <boost/typeof/compliant/typeof_impl.hpp>
# include <boost/typeof/compliant/typeof_impl.hpp>
#elif defined(BOOST_TYPEOF_VINTAGE)
# define BOOST_TYPEOF_TEXT "using vintage imlementation"
@@ -40,7 +45,7 @@
// lvalue typeof
#if defined(BOOST_TYPEOF_VINTAGE)
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
# include <boost/typeof/vintage/lvalue_typeof.hpp>
#else
# include <boost/typeof/compliant/lvalue_typeof.hpp>
@@ -54,7 +59,7 @@
#elif defined(BOOST_TYPEOF_VINTAGE)
# include <boost/typeof/vintage/type_encoding.hpp>
# include <boost/typeof/vintage/template_encoding.hpp>
#else//BOOST_TYPEOF_NATIVE
#else//BOOST_TYPEOF_NATIVE and BOOST_TYPEOF_MSVC
# define BOOST_TYPEOF_REGISTER_TYPE(x)
# define BOOST_TYPEOF_REGISTER_TEMPLATE(x, params)
#endif
@@ -66,7 +71,6 @@
<boost/typeof/increment_registration_group.hpp>
// register stuff
#include <boost/typeof/register_fundamental.hpp>
#if defined(BOOST_TYPEOF_COMPLIANT)