Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the __::1 part in the type signature for libc++. #573

Merged
merged 1 commit into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 18 additions & 53 deletions src/common/util/typename.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ limitations under the License.
namespace vineyard {

template <typename T>
inline const std::string type_name();
inline const std::string __type_name();

namespace detail {

template <typename Arg>
inline const std::string typename_unpack_args() {
return type_name<Arg>();
return __type_name<Arg>();
}

template <typename T, typename U, typename... Args>
inline const std::string typename_unpack_args() {
return type_name<T>() + "," + typename_unpack_args<U, Args...>();
return __type_name<T>() + "," + typename_unpack_args<U, Args...>();
}

#if defined(__VINEYARD_GCC_VERSION) && __VINEYARD_GCC_VERSION <= 90100
Expand Down Expand Up @@ -128,10 +128,24 @@ struct typename_t {
};

template <typename T>
inline const std::string type_name() {
inline const std::string __type_name() {
return typename_t<T>::name();
}

template <typename T>
inline const std::string type_name() {
std::string name = __type_name<T>();
// 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<std::string> {
inline static const std::string name() { return "std::string"; }
Expand All @@ -157,55 +171,6 @@ struct typename_t<uint64_t> {
inline static const std::string name() { return "uint64"; }
};

template <typename T>
struct typename_t<std::hash<T>> {
inline static const std::string name() {
return "std::hash<" + type_name<T>() + ">";
}
};

template <typename T>
struct typename_t<std::equal_to<T>> {
inline static const std::string name() {
return "std::equal_to<" + type_name<T>() + ">";
}
};

template <typename T>
struct typename_t<std::not_equal_to<T>> {
inline static const std::string name() {
return "std::not_equal_to<" + type_name<T>() + ">";
}
};

template <typename T>
struct typename_t<std::less<T>> {
inline static const std::string name() {
return "std::less<" + type_name<T>() + ">";
}
};

template <typename T>
struct typename_t<std::less_equal<T>> {
inline static const std::string name() {
return "std::less_equal<" + type_name<T>() + ">";
}
};

template <typename T>
struct typename_t<std::greater<T>> {
inline static const std::string name() {
return "std::greater<" + type_name<T>() + ">";
}
};

template <typename T>
struct typename_t<std::greater_equal<T>> {
inline static const std::string name() {
return "std::greater_equal<" + type_name<T>() + ">";
}
};

} // namespace vineyard

// for backwards compatiblity.
Expand Down
15 changes: 15 additions & 0 deletions test/typename_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ int main(int, const char**) {
"vineyard::Hashmap<int64,double,std::hash<int64>,std::equal_to<"
"int64>>");
}

{
const auto type = type_name<Array<Hashmap<int64_t, double>::Entry>>();
CHECK_EQ(type,
"vineyard::Array<ska::detailv3::sherwood_v3_entry<std::pair<int64,"
"double>>>");
}

{
const auto type = type_name<Array<Hashmap<int64_t, uint64_t>::Entry>>();
CHECK_EQ(type,
"vineyard::Array<ska::detailv3::sherwood_v3_entry<std::pair<int64,"
"uint64>>>");
}

{
const auto type = type_name<my_hashmap<int64_t, double>>();
CHECK_EQ(type,
Expand Down