mirror of
https://github.com/boostorg/typeof.git
synced 2025-07-29 20:37:28 +02:00
Merge from trunk.
[SVN r39287]
This commit is contained in:
@ -644,12 +644,14 @@ that allows a nested class of base to be defined in a class derived from base:
|
||||
//Use the base class to access the type.
|
||||
typedef typeof_access::id2type::type type;
|
||||
|
||||
This method has also been adapted to VC7.0, where the nested class
|
||||
Peder Holt adapted this method to VC7.0, where the nested class
|
||||
is a template class that is specialized in the derived class.
|
||||
The loopholes have been fixed in VC8.0 though, so on this compiler
|
||||
this method doesn't work.
|
||||
|
||||
In VC8.0, it seemed that all the bug-featire had been fixed, but
|
||||
Steven Watanabe managed to implement a more rigorous version of the VC7.0 fix that
|
||||
enables 'typeof' to be supported 'natively' here as well.
|
||||
|
||||
For this and many other compilers neither native `typeof` support
|
||||
For many other compilers neither native `typeof` support
|
||||
nor the trick described above is an option. For such compilers
|
||||
the emulation method is the only way of implementing `typeof`.
|
||||
|
||||
|
100
include/boost/typeof/dmc/typeof_impl.hpp
Executable file
100
include/boost/typeof/dmc/typeof_impl.hpp
Executable file
@ -0,0 +1,100 @@
|
||||
// Copyright (C) 2007 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>
|
||||
# include <boost/mpl/int.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace type_of
|
||||
{
|
||||
|
||||
template<int N> struct encode_counter : encode_counter<N - 1> {};
|
||||
template<> struct encode_counter<0> {};
|
||||
|
||||
char (*encode_index(...))[1];
|
||||
|
||||
# define BOOST_TYPEOF_INDEX(T) (sizeof(*boost::type_of::encode_index((boost::type_of::encode_counter<1000>*)0)))
|
||||
# define BOOST_TYPEOF_NEXT_INDEX(next) friend char (*encode_index(encode_counter<next>*))[next];
|
||||
|
||||
|
||||
//Typeof code
|
||||
|
||||
template<typename ID>
|
||||
struct msvc_extract_type
|
||||
{
|
||||
struct id2type;
|
||||
};
|
||||
|
||||
template<typename T, typename ID>
|
||||
struct msvc_register_type : msvc_extract_type<ID>
|
||||
{
|
||||
typedef msvc_extract_type<ID> base_type;
|
||||
struct base_type::id2type // This uses nice VC6.5 and VC7.1 bugfeature, also works for Digital Mars
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template<int ID>
|
||||
struct msvc_typeid_wrapper {
|
||||
typedef typename msvc_extract_type<mpl::int_<ID> >::id2type id2type;
|
||||
typedef typename id2type::type type;
|
||||
};
|
||||
|
||||
//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_register_type<T,mpl::int_<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<class T>
|
||||
struct sizer
|
||||
{
|
||||
typedef char(*type)[encode_type<T>::value];
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
typename sizer<T>::type encode_start(T const&);
|
||||
|
||||
template<typename Organizer, typename T>
|
||||
msvc_register_type<T,Organizer> typeof_register_type(const T&,Organizer* =0);
|
||||
|
||||
# define BOOST_TYPEOF(expr) \
|
||||
boost::type_of::msvc_typeid_wrapper<sizeof(*boost::type_of::encode_start(expr))>::type
|
||||
|
||||
# define BOOST_TYPEOF_TPL(expr) typename BOOST_TYPEOF(expr)
|
||||
|
||||
# define BOOST_TYPEOF_NESTED_TYPEDEF_TPL(name,expr) \
|
||||
struct name {\
|
||||
BOOST_STATIC_CONSTANT(int,_typeof_register_value=sizeof(boost::type_of::typeof_register_type<name>(expr)));\
|
||||
typedef typename boost::type_of::msvc_extract_type<name>::id2type id2type;\
|
||||
typedef typename id2type::type type;\
|
||||
};
|
||||
|
||||
# define BOOST_TYPEOF_NESTED_TYPEDEF(name,expr) \
|
||||
struct name {\
|
||||
BOOST_STATIC_CONSTANT(int,_typeof_register_value=sizeof(boost::type_of::typeof_register_type<name>(expr)));\
|
||||
typedef boost::type_of::msvc_extract_type<name>::id2type id2type;\
|
||||
typedef id2type::type type;\
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif//BOOST_TYPEOF_MSVC_TYPEOF_IMPL_HPP_INCLUDED
|
@ -10,7 +10,7 @@
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_TYPEOF_EMULATION) && defined(BOOST_TYPEOF_NATIVE)
|
||||
# error both typeof emulation and native mode requested
|
||||
# error both typeof emulation and native mode requested
|
||||
#endif
|
||||
|
||||
#if defined(__COMO__)
|
||||
@ -76,6 +76,14 @@
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#elif defined __DMC__
|
||||
# ifndef BOOST_TYPEOF_EMULATION
|
||||
# ifndef BOOST_TYPEOF_NATIVE
|
||||
# define BOOST_TYPEOF_NATIVE
|
||||
# endif
|
||||
# include <boost/typeof/dmc/typeof_impl.hpp>
|
||||
# define MSVC_TYPEOF_HACK
|
||||
# endif
|
||||
#elif defined(_MSC_VER)
|
||||
# if (_MSC_VER <= 1300) // 6.5, 7.0
|
||||
# ifndef BOOST_TYPEOF_EMULATION
|
||||
|
Reference in New Issue
Block a user