//remove_reference.h ![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
#ifndef _REMOVE_REFERENCE_H_
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
#define _REMOVE_REFERENCE_H_
namespace boost {
namespace type_traits {
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
template <
class T>
struct wrap {};
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
typedef
char yes_type;
struct no_type
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
{
char padding[8];
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
};
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
}
// namespace boost::type_traits
namespace detail {
using ::boost::type_traits::yes_type;
using ::boost::type_traits::no_type;
using ::boost::type_traits::wrap;
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
#define BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(trait,sp,C) \
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
template<>
struct trait##_impl< sp > \
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
{ \
enum {value = (C)}; \
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
};
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
template <
class T> T&(* is_reference_helper1(wrap<T>) )(wrap<T>);
char is_reference_helper1(...);
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
template <
class T> no_type is_reference_helper2(T&(*)(wrap<T>));
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
yes_type is_reference_helper2(...);
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
template <typename T>
struct is_reference_impl
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
{
enum{
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
value =
sizeof(
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
::boost::detail::is_reference_helper2(
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
::boost::detail::is_reference_helper1(::boost::type_traits::wrap<T>()))) == 1
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
};
// BOOST_STATIC_CONSTANT(
// bool, value = sizeof(
// ::boost::detail::is_reference_helper2(
// ::boost::detail::is_reference_helper1(::boost::type_traits::wrap<T>()))) == 1
// ); ![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
};
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_reference,
void,
false)
// VC6用这一个就可以了,void const等也解决了
// #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
// BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_reference,void const,false)
// BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_reference,void volatile,false)
// BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_reference,void const volatile,false)
// #endif
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
}
// namespace detail
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
template <typename T>
struct is_reference
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
{
enum{
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
value = detail::is_reference_impl<T>::value
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
};
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
};
namespace detail {
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
template<typename ID>
struct msvc_extract_type
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
{
struct id2type;
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
};
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
template<typename T, typename ID>
struct msvc_register_type : msvc_extract_type<ID>
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
{
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
typedef msvc_extract_type<ID> base_type;
struct base_type::id2type
// This uses nice VC6.5 and VC7.1 bugfeature ![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
{
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
typedef T type;
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
};
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
};
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
template<
bool IsReference>
struct remove_reference_impl_typeof {
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
template<typename T,typename ID>
struct inner {
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
typedef T type;
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
};
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
};
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
template<>
struct remove_reference_impl_typeof<
true> {
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
template<typename T,typename ID>
struct inner {
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
template<typename U>
static msvc_register_type<U,ID> test(U&(*)());
static msvc_register_type<T,ID> test(...);
//BOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (T(*)())(NULL) ) ));
enum {register_test=
sizeof(test( (T(*)())(NULL) ) )};
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
typedef typename msvc_extract_type<ID>::id2type::type type;
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
};
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
};
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
}
//namespace detail
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
template<typename T>
struct remove_reference {
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
typedef typename detail::remove_reference_impl_typeof<
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
boost::is_reference<T>::value
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
>::template inner<T,remove_reference<T> >::type type;
//BOOST_MPL_AUX_LAMBDA_SUPPORT(1,remove_reference,T) ![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
};
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
}
![InBlock.gif](http://sinojelly.blog.51cto.com/images/editer/InBlock.gif)
#endif