Skip to content

Commit

Permalink
Merge pull request #343 from elbeno/dedup-type-to-string
Browse files Browse the repository at this point in the history
  • Loading branch information
lukevalenty authored Aug 20, 2023
2 parents f8b1693 + 8c19626 commit 78215ff
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 45 deletions.
26 changes: 3 additions & 23 deletions include/cib/detail/set_details.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <cib/detail/compiler.hpp>
#include <sc/detail/conversions.hpp>

#include <algorithm>
#include <array>
Expand Down Expand Up @@ -28,33 +29,12 @@ struct typename_map_entry {
}
};

template <typename Tag> CIB_CONSTEVAL static auto name() -> std::string_view {
#if defined(__clang__)
constexpr std::string_view function_name = __PRETTY_FUNCTION__;
constexpr auto lhs = 44;
constexpr auto rhs = function_name.size() - 2;

#elif defined(__GNUC__) || defined(__GNUG__)
constexpr std::string_view function_name = __PRETTY_FUNCTION__;
constexpr auto lhs = 59;
constexpr auto rhs = function_name.size() - 51;

#elif defined(_MSC_VER)
constexpr std::string_view function_name = __FUNCSIG__;
constexpr auto lhs = 0;
constexpr auto rhs = function_name.size();
#else
static_assert(false, "Unknown compiler, can't build cib::tuple name.");
#endif

return function_name.substr(lhs, rhs - lhs + 1);
}

template <template <typename> typename MetaFunc, typename... Types>
CIB_CONSTEVAL static auto create_type_names([[maybe_unused]] std::size_t src) {
auto i = std::size_t{};
std::array<typename_map_entry, sizeof...(Types)> names = {
typename_map_entry{name<MetaFunc<Types>>(), i++, src}...};
typename_map_entry{sc::detail::type_as_string<MetaFunc<Types>>(), i++,
src}...};
std::sort(std::begin(names), std::end(names));
return names;
}
Expand Down
9 changes: 1 addition & 8 deletions include/sc/detail/conversions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@ constexpr static auto type_as_string() -> std::string_view {
static_assert(false, "Unknown compiler, can't build type name.");
#endif

constexpr auto lhs = [&]() -> std::string_view::size_type {
for (auto i = std::size_t{}; i < function_name.size(); i++) {
if (function_name[i] == '=') {
return i + 2;
}
}
return 0;
}();
constexpr auto lhs = function_name.rfind('=', rhs) + 2;

return function_name.substr(lhs, rhs - lhs + 1);
}
Expand Down
1 change: 0 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ add_unit_test(
cib_test
CATCH2
FILES
cib/detail/type_to_string_view.cpp
cib/builder_meta.cpp
cib/callback.cpp
cib/nexus.cpp
Expand Down
13 changes: 0 additions & 13 deletions test/cib/detail/type_to_string_view.cpp

This file was deleted.

0 comments on commit 78215ff

Please sign in to comment.