From 7d33cf62a5d5108425c1bfd1f4ca45bdbaf55f7b Mon Sep 17 00:00:00 2001 From: Gleb Natapov Date: Thu, 2 Jul 2015 16:43:37 +0300 Subject: [PATCH] Add is_smart_ptr metafunction to detect know smart pointers objects --- core/sharded.hh | 4 ++++ core/shared_ptr.hh | 7 +++++++ util/is_smart_ptr.hh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 util/is_smart_ptr.hh diff --git a/core/sharded.hh b/core/sharded.hh index 89f85e7b4..d30bea043 100644 --- a/core/sharded.hh +++ b/core/sharded.hh @@ -23,6 +23,7 @@ #include "reactor.hh" #include "future-util.hh" +#include "util/is_smart_ptr.hh" namespace seastar { @@ -415,5 +416,8 @@ foreign_ptr make_foreign(T ptr) { return foreign_ptr(std::move(ptr)); } +template +struct is_smart_ptr<::foreign_ptr> : std::true_type {}; + /// @} diff --git a/core/shared_ptr.hh b/core/shared_ptr.hh index 56219a07e..49c5e0901 100644 --- a/core/shared_ptr.hh +++ b/core/shared_ptr.hh @@ -27,6 +27,7 @@ #include #include #include +#include "util/is_smart_ptr.hh" // This header defines two shared pointer facilities, lw_shared_ptr<> and // shared_ptr<>, both modeled after std::shared_ptr<>. @@ -719,4 +720,10 @@ struct hash<::shared_ptr> : private hash { } +template +struct is_smart_ptr<::shared_ptr> : std::true_type {}; + +template +struct is_smart_ptr<::lw_shared_ptr> : std::true_type {}; + #endif /* SHARED_PTR_HH_ */ diff --git a/util/is_smart_ptr.hh b/util/is_smart_ptr.hh new file mode 100644 index 000000000..9a45bc157 --- /dev/null +++ b/util/is_smart_ptr.hh @@ -0,0 +1,30 @@ +/* + * This file is open source software, licensed to you under the terms + * of the Apache License, Version 2.0 (the "License"). See the NOTICE file + * distributed with this work for additional information regarding copyright + * ownership. You may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/* + * Copyright (C) 2015 Cloudius Systems, Ltd. + */ + +#pragma once + +#include // for std::unique_ptr + +template +struct is_smart_ptr : std::false_type {}; + +template +struct is_smart_ptr> : std::true_type {};