]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/polymorphic_cast.hpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / boost / polymorphic_cast.hpp
index 70afa6be2eee4cc73c9cf311a14a1d83a2b67018..3592506003250f5f6cf16b39ac19cd98f2956e42 100644 (file)
 #define BOOST_POLYMORPHIC_CAST_HPP
 
 # include <boost/config.hpp>
-# include <boost/assert.hpp>
-# include <boost/throw_exception.hpp>
-# include <typeinfo>
 
 #ifdef BOOST_HAS_PRAGMA_ONCE
 #   pragma once
 #endif
 
+# include <boost/assert.hpp>
+# include <boost/core/addressof.hpp>
+# include <boost/core/enable_if.hpp>
+# include <boost/throw_exception.hpp>
+# include <boost/type_traits/is_reference.hpp> 
+# include <boost/type_traits/remove_reference.hpp>
+
+# include <typeinfo>
+
 namespace boost
 {
 //  See the documentation for descriptions of how to choose between
@@ -79,7 +85,7 @@ namespace boost
 
 //  polymorphic_downcast  ----------------------------------------------------//
 
-    //  BOOST_ASSERT() checked polymorphic downcast.  Crosscasts prohibited.
+    //  BOOST_ASSERT() checked raw pointer polymorphic downcast.  Crosscasts prohibited.
 
     //  WARNING: Because this cast uses BOOST_ASSERT(), it violates
     //  the One Definition Rule if used in multiple translation units
@@ -95,6 +101,26 @@ namespace boost
         return static_cast<Target>(x);
     }
 
+    //  BOOST_ASSERT() checked reference polymorphic downcast.  Crosscasts prohibited.
+
+    //  WARNING: Because this cast uses BOOST_ASSERT(), it violates
+    //  the One Definition Rule if used in multiple translation units
+    //  where BOOST_DISABLE_ASSERTS, BOOST_ENABLE_ASSERT_HANDLER
+    //  NDEBUG are defined inconsistently.
+
+    //  Contributed by Julien Delacroix
+
+    template <class Target, class Source>
+    inline typename boost::enable_if_c<
+        boost::is_reference<Target>::value, Target
+    >::type polymorphic_downcast(Source& x)
+    {
+        typedef typename boost::remove_reference<Target>::type* target_pointer_type;
+        return *boost::polymorphic_downcast<target_pointer_type>(
+            boost::addressof(x)
+        );
+    }
+
 } // namespace boost
 
 #endif  // BOOST_POLYMORPHIC_CAST_HPP