Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66361 - sandbox/function/boost/function
From: dsaritz_at_[hidden]
Date: 2010-11-02 15:50:11


Author: psiha
Date: 2010-11-02 15:50:09 EDT (Tue, 02 Nov 2010)
New Revision: 66361
URL: http://svn.boost.org/trac/boost/changeset/66361

Log:
Refactored the has_empty_target() function(s) not to use SFINAE.
Moved the empty() member function to the function_base class.
Text files modified:
   sandbox/function/boost/function/function_base.hpp | 48 +++++++++++++++++++++++++---------------
   sandbox/function/boost/function/function_template.hpp | 3 --
   2 files changed, 30 insertions(+), 21 deletions(-)

Modified: sandbox/function/boost/function/function_base.hpp
==============================================================================
--- sandbox/function/boost/function/function_base.hpp (original)
+++ sandbox/function/boost/function/function_base.hpp 2010-11-02 15:50:09 EDT (Tue, 02 Nov 2010)
@@ -1200,6 +1200,10 @@
   template <class EmptyHandler>
   void swap( function_base & other, detail::function::vtable const & empty_handler_vtable );
 
+public:
+ /// Determine if the function is empty (i.e. has an empty target).
+ bool empty() const { return get_vtable().is_empty_handler_vtable(); }
+
 #ifndef BOOST_FUNCTION_NO_RTTI
 
   /// Retrieve the type of the stored function object.
@@ -1660,31 +1664,30 @@
 namespace detail {
   namespace function {
 
- BOOST_FUNCTION_ENABLE_IF_FUNCTION
- BF_FORCEINLINE has_empty_target( Function const * const f )
+ template <typename T>
+ BF_FORCEINLINE bool has_empty_target_aux( T const * const funcPtr, function_ptr_tag )
     {
- return f->empty();
+ return funcPtr == 0;
     }
 
- template <class FunctionPtr>
- typename enable_if_c
- <
- is_pointer <FunctionPtr>::value ||
- is_function <FunctionPtr>::value ||
- is_member_function_pointer<FunctionPtr>::value,
- bool
- >::type
- BF_FORCEINLINE has_empty_target( FunctionPtr const * const funcPtr )
+ template <typename T>
+ BF_FORCEINLINE bool has_empty_target_aux( T const * const funcPtr, member_ptr_tag )
     {
- return funcPtr == 0;
+ return has_empty_target_aux<T>( funcPtr, function_ptr_tag() );
+ }
+
+ BF_FORCEINLINE bool has_empty_target_aux( function_base const * const f, function_obj_tag )
+ {
+ BF_ASSUME( f != NULL );
+ return f->empty();
     }
 
     // Implementation note:
     // Even the best compilers seem unable to inline vararg functions
- // (e.g.MSVC 9.0 SP1 and GCC 4.6).
+ // (e.g. MSVC 9.0 SP1 and GCC 4.6).
     // (28.10.2010.) (Domagoj Saric)
- //inline bool has_empty_target(...)
- BF_FORCEINLINE bool has_empty_target( void const * )
+ //inline bool has_empty_target_aux(...)
+ BF_FORCEINLINE bool has_empty_target_aux( void const * /*f*/, function_obj_tag )
     {
         return false;
     }
@@ -1694,7 +1697,7 @@
     // compilers (e.g. GCC 4.2.1).
     // (28.10.2010.) (Domagoj Saric)
     template <class FunctionObj>
- BF_FORCEINLINE bool has_empty_target( reference_wrapper<FunctionObj> const * const f )
+ BF_FORCEINLINE bool has_empty_target_aux( reference_wrapper<FunctionObj> const * const f, function_obj_ref_tag )
     {
         // Implementation note:
         // We save/assign a reference to a boost::function even if it is empty
@@ -1704,9 +1707,18 @@
         BF_ASSUME( f->get_pointer() != 0 );
         return is_base_of<function_base, FunctionObj>::value
             ? ( f == 0 )
- : has_empty_target( f->get_pointer() );
+ : has_empty_target_aux( f->get_pointer(), function_obj_tag() );
     }
 
+
+ template <typename T>
+ BF_FORCEINLINE bool has_empty_target( T const * const f )
+ {
+ typedef typename get_function_tag<T>::type tag;
+ return has_empty_target_aux( f, tag() );
+ }
+
+
     /* Just an experiment to show how can the current boost::mem_fn implementation
     be 'hacked' to work with custom mem_fn pointer holders (in this case a static
     reference) and/to implement the above. See the assign template overload for

Modified: sandbox/function/boost/function/function_template.hpp
==============================================================================
--- sandbox/function/boost/function/function_template.hpp (original)
+++ sandbox/function/boost/function/function_template.hpp 2010-11-02 15:50:09 EDT (Tue, 02 Nov 2010)
@@ -305,9 +305,6 @@
         : function_base( static_cast<function_base const &>( f ) )
     {}
 
- /// Determine if the function is empty (i.e., has empty target).
- bool empty() const { return p_vtable_->is_empty_handler_vtable(); }
-
     /// Clear out a target (replace it with an empty handler), if there is one.
     void clear()
     {


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