Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58127 - in trunk: boost/detail boost/exception/detail libs/smart_ptr/test
From: pdimov_at_[hidden]
Date: 2009-12-03 15:31:01


Author: pdimov
Date: 2009-12-03 15:31:01 EST (Thu, 03 Dec 2009)
New Revision: 58127
URL: http://svn.boost.org/trac/boost/changeset/58127

Log:
Fix sp_typeinfo to match the interface of std::type_info.
Added:
   trunk/libs/smart_ptr/test/sp_typeinfo_test.cpp (contents, props changed)
Text files modified:
   trunk/boost/detail/sp_typeinfo.hpp | 54 +++++++++++++++++++++++++++++++++++++--
   trunk/boost/exception/detail/type_info.hpp | 10 +++---
   trunk/libs/smart_ptr/test/Jamfile.v2 | 1
   3 files changed, 56 insertions(+), 9 deletions(-)

Modified: trunk/boost/detail/sp_typeinfo.hpp
==============================================================================
--- trunk/boost/detail/sp_typeinfo.hpp (original)
+++ trunk/boost/detail/sp_typeinfo.hpp 2009-12-03 15:31:01 EST (Thu, 03 Dec 2009)
@@ -19,20 +19,66 @@
 
 #if defined( BOOST_NO_TYPEID )
 
+#include <boost/current_function.hpp>
+#include <functional>
+
 namespace boost
 {
 
 namespace detail
 {
 
-typedef void* sp_typeinfo;
+class sp_typeinfo
+{
+private:
+
+ sp_typeinfo( sp_typeinfo const& );
+ sp_typeinfo& operator=( sp_typeinfo const& );
+
+ char const * name_;
+
+public:
+
+ explicit sp_typeinfo( char const * name ): name_( name )
+ {
+ }
+
+ bool operator==( sp_typeinfo const& rhs ) const
+ {
+ return this == &rhs;
+ }
+
+ bool operator!=( sp_typeinfo const& rhs ) const
+ {
+ return this != &rhs;
+ }
+
+ bool before( sp_typeinfo const& rhs ) const
+ {
+ return std::less< sp_typeinfo const* >()( this, &rhs );
+ }
+
+ char const* name() const
+ {
+ return name_;
+ }
+};
 
 template<class T> struct sp_typeid_
 {
- static char v_;
+ static sp_typeinfo ti_;
+
+ static char const * name()
+ {
+ return BOOST_CURRENT_FUNCTION;
+ }
 };
 
-template<class T> char sp_typeid_< T >::v_;
+template<class T> sp_typeinfo sp_typeid_< T >::ti_( sp_typeid_< T >::name() );
+
+template<class T> struct sp_typeid_< T & >: sp_typeid_< T >
+{
+};
 
 template<class T> struct sp_typeid_< T const >: sp_typeid_< T >
 {
@@ -50,7 +96,7 @@
 
 } // namespace boost
 
-#define BOOST_SP_TYPEID(T) (&boost::detail::sp_typeid_<T>::v_)
+#define BOOST_SP_TYPEID(T) (boost::detail::sp_typeid_<T>::ti_)
 
 #else
 

Modified: trunk/boost/exception/detail/type_info.hpp
==============================================================================
--- trunk/boost/exception/detail/type_info.hpp (original)
+++ trunk/boost/exception/detail/type_info.hpp 2009-12-03 15:31:01 EST (Thu, 03 Dec 2009)
@@ -48,12 +48,12 @@
         struct
         type_info_
             {
- detail::sp_typeinfo type_;
+ detail::sp_typeinfo const * type_;
             char const * name_;
 
             explicit
- type_info_( detail::sp_typeinfo type, char const * name ):
- type_(type),
+ type_info_( detail::sp_typeinfo const & type, char const * name ):
+ type_(&type),
                 name_(name)
                 {
                 }
@@ -62,14 +62,14 @@
             bool
             operator==( type_info_ const & a, type_info_ const & b )
                 {
- return a.type_==b.type_;
+ return (*a.type_)==(*b.type_);
                 }
 
             friend
             bool
             operator<( type_info_ const & a, type_info_ const & b )
                 {
- return a.type_<b.type_;
+ return 0!=(a.type_->before(*b.type_));
                 }
 
             char const *

Modified: trunk/libs/smart_ptr/test/Jamfile.v2
==============================================================================
--- trunk/libs/smart_ptr/test/Jamfile.v2 (original)
+++ trunk/libs/smart_ptr/test/Jamfile.v2 2009-12-03 15:31:01 EST (Thu, 03 Dec 2009)
@@ -63,5 +63,6 @@
           [ run enable_shared_from_raw_test.cpp ]
           [ compile-fail auto_ptr_lv_fail.cpp ]
           [ run atomic_count_test2.cpp ]
+ [ run sp_typeinfo_test.cpp ]
         ;
 }

Added: trunk/libs/smart_ptr/test/sp_typeinfo_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/smart_ptr/test/sp_typeinfo_test.cpp 2009-12-03 15:31:01 EST (Thu, 03 Dec 2009)
@@ -0,0 +1,51 @@
+//
+// sp_typeinfo_test.cpp
+//
+// Copyright (c) 2009 Peter Dimov
+//
+// Distributed under the Boost Software License, Version 1.0.
+// See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+//
+
+#include <boost/detail/sp_typeinfo.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <iostream>
+
+int main()
+{
+ BOOST_TEST( BOOST_SP_TYPEID( int ) == BOOST_SP_TYPEID( int ) );
+ BOOST_TEST( BOOST_SP_TYPEID( int ) != BOOST_SP_TYPEID( long ) );
+ BOOST_TEST( BOOST_SP_TYPEID( int ) != BOOST_SP_TYPEID( void ) );
+
+ boost::detail::sp_typeinfo const & ti = BOOST_SP_TYPEID( int );
+
+ boost::detail::sp_typeinfo const * pti = &BOOST_SP_TYPEID( int );
+ BOOST_TEST( *pti == ti );
+
+ BOOST_TEST( ti == ti );
+ BOOST_TEST( !( ti != ti ) );
+ BOOST_TEST( !ti.before( ti ) );
+
+ char const * nti = ti.name();
+ std::cout << nti << std::endl;
+
+ boost::detail::sp_typeinfo const & tv = BOOST_SP_TYPEID( void );
+
+ boost::detail::sp_typeinfo const * ptv = &BOOST_SP_TYPEID( void );
+ BOOST_TEST( *ptv == tv );
+
+ BOOST_TEST( tv == tv );
+ BOOST_TEST( !( tv != tv ) );
+ BOOST_TEST( !tv.before( tv ) );
+
+ char const * ntv = tv.name();
+ std::cout << ntv << std::endl;
+
+ BOOST_TEST( ti != tv );
+ BOOST_TEST( !( ti == tv ) );
+
+ BOOST_TEST( ti.before( tv ) != tv.before( ti ) );
+
+ return boost::report_errors();
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk