// -*- begin of type_info.hpp -*-
#ifndef _type_info_hpp_
#define _type_info_hpp_
namespace rtti
{
namespace detail
{
struct identity {};
template < typename >
struct type_info_impl
{ static identity impl_; };
template < typename T >
identity type_info_impl< T >::impl_;
template < typename >
struct type_forwarding {};
} // namespace detail
struct type_info_
{
private:
const detail::identity *id_ptr_;
template < typename T >
friend type_info_
typeid_( void );
template < typename T >
explicit inline
type_info_( detail::type_forwarding< T > )
: id_ptr_( &detail::type_info_impl< T >::impl_ ) {}
public:
inline bool
operator==( const type_info_ &ti ) const
{ return this->id_ptr_ == ti.id_ptr_; }
inline bool
operator!=( const type_info_ &ti ) const
{ return !( *this == ti ); }
};
template < typename T >
inline type_info_
typeid_( void )
{ return type_info_( detail::type_forwarding< T >() ); }
} // namespace rtti
#endif // _type_info_hpp_
// -*- end of type_info.hpp -*-
// -*- begin of test.cpp -*-
//#include "type_info.hpp"
namespace
{
rtti::type_info_ int_info = rtti::typeid_< int >();
}
bool
test( rtti::type_info_ ti )
{ return int_info == ti; }
// -*- end of test.cpp
// -*- begin of main.cpp
#include <iostream>
//#include "type_info.hpp"
bool
test( rtti::type_info_ );
template < typename T >
void
hoge( void )
{
std::cout << std::boolalpha
<< test( rtti::typeid_< T >() )
<< std::endl;
}
int
main( void )
{
std::cout << "int: ";
hoge< int >();
std::cout << "float: ";
hoge< float >();
}
// -*- end of main.cpp -*-