From e740a1a736180b2d32a640e9380712b051a4895a Mon Sep 17 00:00:00 2001 From: Tao He Date: Thu, 4 Nov 2021 21:44:22 +0800 Subject: [PATCH] Remove the `__::1` part in the type signature for libc++. Signed-off-by: Tao He --- src/common/util/typename.h | 71 ++++++++++---------------------------- test/typename_test.cc | 15 ++++++++ 2 files changed, 33 insertions(+), 53 deletions(-) diff --git a/src/common/util/typename.h b/src/common/util/typename.h index 2b7c42f9..e7e51349 100644 --- a/src/common/util/typename.h +++ b/src/common/util/typename.h @@ -37,18 +37,18 @@ limitations under the License. namespace vineyard { template -inline const std::string type_name(); +inline const std::string __type_name(); namespace detail { template inline const std::string typename_unpack_args() { - return type_name(); + return __type_name(); } template inline const std::string typename_unpack_args() { - return type_name() + "," + typename_unpack_args(); + return __type_name() + "," + typename_unpack_args(); } #if defined(__VINEYARD_GCC_VERSION) && __VINEYARD_GCC_VERSION <= 90100 @@ -128,10 +128,24 @@ struct typename_t { }; template -inline const std::string type_name() { +inline const std::string __type_name() { return typename_t::name(); } +template +inline const std::string type_name() { + std::string name = __type_name(); + // drop the `std::__1::` namespace for libc++ + // erase std::__1:: and std:: difference: to make the object can be get by + // clients that linked against different STL libraries. + const std::string marker = "std::__1::"; + for (std::string::size_type p = name.find(marker); p != std::string::npos; + p = name.find(marker)) { + name.replace(p, marker.size(), "std::"); + } + return name; +} + template <> struct typename_t { inline static const std::string name() { return "std::string"; } @@ -157,55 +171,6 @@ struct typename_t { inline static const std::string name() { return "uint64"; } }; -template -struct typename_t> { - inline static const std::string name() { - return "std::hash<" + type_name() + ">"; - } -}; - -template -struct typename_t> { - inline static const std::string name() { - return "std::equal_to<" + type_name() + ">"; - } -}; - -template -struct typename_t> { - inline static const std::string name() { - return "std::not_equal_to<" + type_name() + ">"; - } -}; - -template -struct typename_t> { - inline static const std::string name() { - return "std::less<" + type_name() + ">"; - } -}; - -template -struct typename_t> { - inline static const std::string name() { - return "std::less_equal<" + type_name() + ">"; - } -}; - -template -struct typename_t> { - inline static const std::string name() { - return "std::greater<" + type_name() + ">"; - } -}; - -template -struct typename_t> { - inline static const std::string name() { - return "std::greater_equal<" + type_name() + ">"; - } -}; - } // namespace vineyard // for backwards compatiblity. diff --git a/test/typename_test.cc b/test/typename_test.cc index 944b011d..11b34b8a 100644 --- a/test/typename_test.cc +++ b/test/typename_test.cc @@ -64,6 +64,21 @@ int main(int, const char**) { "vineyard::Hashmap,std::equal_to<" "int64>>"); } + + { + const auto type = type_name::Entry>>(); + CHECK_EQ(type, + "vineyard::Array>>"); + } + + { + const auto type = type_name::Entry>>(); + CHECK_EQ(type, + "vineyard::Array>>"); + } + { const auto type = type_name>(); CHECK_EQ(type,