Skip to content

Commit 9238fb6

Browse files
authored
Merge pull request #929 from niermann999/fix-type-printing
fix: type printing version 2
2 parents afc4ef8 + 73f8a97 commit 9238fb6

File tree

4 files changed

+57
-40
lines changed

4 files changed

+57
-40
lines changed

core/include/detray/geometry/shapes/unbounded.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "detray/definitions/containers.hpp"
1313
#include "detray/definitions/detail/qualifiers.hpp"
1414
#include "detray/definitions/indexing.hpp"
15-
#include "detray/utils/string_view_concat.hpp"
15+
#include "detray/utils/string_helpers.hpp"
1616

1717
// System include(s)
1818
#include <limits>
@@ -37,7 +37,7 @@ class unbounded {
3737
static constexpr std::string_view name_prefix = "unbounded ";
3838

3939
/// The name for this shape
40-
static constexpr string_view_concat2 name{name_prefix, shape::name};
40+
static constexpr utils::string_view_concat2 name{name_prefix, shape::name};
4141

4242
/// Local coordinate frame for boundary checks
4343
template <concepts::algebra algebra_t>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/** Detray library, part of the ACTS project (R&D line)
2+
*
3+
* (c) 2022-2024 CERN for the benefit of the ACTS project
4+
*
5+
* Mozilla Public License Version 2.0
6+
*/
7+
8+
#pragma once
9+
10+
// Project include(s)
11+
#include "detray/definitions/containers.hpp"
12+
13+
// System include(s)
14+
#include <ranges>
15+
#include <string>
16+
#include <string_view>
17+
18+
namespace detray::utils {
19+
20+
/// @brief Convenience class to statically concatenate two string views.
21+
struct string_view_concat2 {
22+
std::string_view s1;
23+
std::string_view s2;
24+
25+
explicit operator std::string() const {
26+
return std::string(s1) + std::string(s2);
27+
}
28+
};
29+
30+
/// Split string @param input at every occurence of @param delim
31+
inline dvector<std::string> split_at_delim(const std::string &input,
32+
const char delim) {
33+
dvector<std::string> tokens{};
34+
35+
for (const auto char_range : std::views::split(input, delim)) {
36+
std::string s{""};
37+
// TODO: Remove when range constructor becomes available in c++23
38+
for (const char c : char_range) {
39+
s.push_back(c);
40+
}
41+
tokens.push_back(std::move(s));
42+
}
43+
44+
return tokens;
45+
}
46+
47+
} // namespace detray::utils

core/include/detray/utils/string_view_concat.hpp

-23
This file was deleted.

core/include/detray/utils/type_list.hpp

+8-15
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
#pragma once
99

1010
// Project include(s)
11+
#include "detray/utils/string_helpers.hpp"
1112
#include "detray/utils/tuple.hpp"
1213
#include "detray/utils/type_traits.hpp"
1314

1415
// System include(s)
15-
#include <ranges>
1616
#include <string>
1717
#include <string_view>
1818
#include <type_traits>
@@ -162,23 +162,16 @@ std::string get_name(bool full = false) {
162162
return tp_str;
163163
}
164164

165-
// Remove the template argument list
166-
dvector<std::string> tokens{};
167-
for (const auto t : std::views::split(tp_str, '<')) {
168-
// The std::string constructor does not work with std::sentinel_t
169-
tokens.emplace_back(std::string_view(t.begin(), t.end()));
170-
}
171-
172-
// Split a the first ocurrence of '<'
165+
// Remove template parameter list by removing everything behind the first
166+
// occurrence of '<'
167+
auto tokens = detray::utils::split_at_delim(tp_str, '<');
173168
tp_str = tokens.front();
174-
tokens.clear();
175169

176-
// Strip the namespaces and qualifiers
177-
for (const auto t : std::views::split(tp_str, ':')) {
178-
tokens.emplace_back(std::string_view(t.begin(), t.end()));
179-
}
170+
tokens.clear();
180171

181-
// Split at the last occurrence of ':'
172+
// Strip the namespaces by removing everything before the last occurrence of
173+
// ':'
174+
tokens = detray::utils::split_at_delim(tp_str, ':');
182175
return tokens.back();
183176
}
184177

0 commit comments

Comments
 (0)