]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
msg/Message: add aliases for static_pointer_cast
authorKefu Chai <kchai@redhat.com>
Sun, 14 Apr 2019 06:03:28 +0000 (14:03 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 17 Apr 2019 22:59:41 +0000 (06:59 +0800)
strictly speaking, they are not "alias" of boost::static_pointer_cast,
but to avoid an extra conversion, instead of using
boost::static_pointer_cast<>, i am using std::static_cast<> directly for
creating boost::intrusive_ptr<> instance.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/msg/Message.h

index 75299e492615e7b52e8edd608403f5bc3964df71..e65cc6efc071b75324c6956c4a04ad80b0493dce 100644 (file)
@@ -573,10 +573,24 @@ template<typename... Args>
 };
 
 namespace ceph {
-template<typename T>
-using ref_t = boost::intrusive_ptr<T>;
-template<typename T>
-using cref_t = boost::intrusive_ptr<T const>;
+template<typename T> using ref_t = boost::intrusive_ptr<T>;
+template<typename T> using cref_t = boost::intrusive_ptr<const T>;
+template<class T, class U>
+boost::intrusive_ptr<T> ref_cast(const boost::intrusive_ptr<U>& r) noexcept {
+  return static_cast<T*>(r.get());
+}
+template<class T, class U>
+boost::intrusive_ptr<T> ref_cast(boost::intrusive_ptr<U>&& r) noexcept {
+  return {static_cast<T*>(r.detach()), false};
+}
+template<class T, class U>
+boost::intrusive_ptr<const T> ref_cast(const boost::intrusive_ptr<const U>& r) noexcept {
+  return static_cast<const T*>(r.get());
+}
+template<class T, class U>
+boost::intrusive_ptr<const T> ref_cast(const boost::intrusive_ptr<const U>&& r) noexcept {
+  return {static_cast<const T*>(r.detach()), false};
+}
 }
 
 #endif