Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LHCb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LHCb
LHCb
Commits
7d8cd17c
Commit
7d8cd17c
authored
1 year ago
by
Gerhard Raven
Browse files
Options
Downloads
Patches
Plain Diff
add type_name.h
parent
abcbd10d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!4193
add support for packing T::Selection, for classes T which are packable, if T::Selection is defined
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Event/EventPacker/src/component/type_name.h
+50
-0
50 additions, 0 deletions
Event/EventPacker/src/component/type_name.h
with
50 additions
and
0 deletions
Event/EventPacker/src/component/type_name.h
0 → 100644
+
50
−
0
View file @
7d8cd17c
#include
<string>
#include
<string_view>
#include
<array>
// std::array
#include
<utility>
// std::index_sequence
namespace
details
{
template
<
std
::
size_t
...
Is
>
constexpr
auto
as_array
(
std
::
string_view
str
,
std
::
index_sequence
<
Is
...
>
)
{
return
std
::
array
{
str
[
Is
]...};
}
template
<
typename
T
>
constexpr
auto
type_name_array
()
{
#if defined(__clang__)
constexpr
auto
prefix
=
std
::
string_view
{
"[T = "
};
constexpr
auto
suffix
=
std
::
string_view
{
"]"
};
constexpr
auto
function
=
std
::
string_view
{
__PRETTY_FUNCTION__
};
#elif defined(__GNUC__)
constexpr
auto
prefix
=
std
::
string_view
{
"with T = "
};
constexpr
auto
suffix
=
std
::
string_view
{
"]"
};
constexpr
auto
function
=
std
::
string_view
{
__PRETTY_FUNCTION__
};
#elif defined(_MSC_VER)
constexpr
auto
prefix
=
std
::
string_view
{
"type_name_array<"
};
constexpr
auto
suffix
=
std
::
string_view
{
">(void)"
};
constexpr
auto
function
=
std
::
string_view
{
__FUNCSIG__
};
#else
# error Unsupported compiler
#endif
constexpr
auto
start
=
function
.
find
(
prefix
)
+
prefix
.
size
();
constexpr
auto
end
=
function
.
rfind
(
suffix
);
static_assert
(
start
<
end
);
constexpr
auto
name
=
function
.
substr
(
start
,
(
end
-
start
));
return
as_array
(
name
,
std
::
make_index_sequence
<
name
.
size
()
>
{});
}
template
<
typename
T
>
struct
type_name_holder
{
static
inline
constexpr
auto
value
=
type_name_array
<
T
>
();
};
}
template
<
typename
T
>
constexpr
std
::
string_view
type_name
()
{
constexpr
auto
&
value
=
details
::
type_name_holder
<
T
>::
value
;
return
std
::
string_view
{
value
.
data
(),
value
.
size
()};
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment