repr 0.1
Reconstructable string representations and more
Loading...
Searching...
No Matches
ctvi/ctvi.h
Go to the documentation of this file.
1#pragma once
2#include <cstddef>
3#include <string_view>
4
8
9namespace librepr::ctvi {
10
11#if USING(LIBREPR_COMPILER_CLANG) && __has_warning("-Wenum-constexpr-conversion")
13// https://github.com/llvm/llvm-project/issues/68489
14LIBREPR_WARNING_DISABLE_CLANG("-Wenum-constexpr-conversion")
15#endif
16
17namespace detail {
18template <auto V>
19[[nodiscard]] constexpr auto get_ctvi() noexcept {
20#if USING(LIBREPR_COMPILER_MSVC)
21 constexpr auto prefix = std::string_view{"get_ctvi<"};
22 constexpr auto suffix = std::string_view{">(void)"};
23#else
24 constexpr auto prefix = std::string_view{"V = "};
25 constexpr auto suffix = std::string_view{"]"};
26#endif
27
29 constexpr std::size_t start = signature.find(prefix) + prefix.size();
30 constexpr std::size_t end = signature.find(suffix, start);
31
32 constexpr auto value = signature.substr(start, end - start);
33 return const_string<value.size()>(value);
34}
35
36template <typename T, auto M>
37constexpr auto name_from_subobject() {
39
40#if USING(LIBREPR_COMPILER_CLANG)
41 constexpr auto start_marker = std::string_view{"."};
42 constexpr auto end_marker = std::string_view{"}]"};
43#elif USING(LIBREPR_COMPILER_MSVC)
44 constexpr auto start_marker = std::string_view{"->"};
45 constexpr auto end_marker = std::string_view{">(void)"};
46#else
47 constexpr auto start_marker = std::string_view{"::"};
48 constexpr auto end_marker = std::string_view{")]"};
49#endif
50
51 constexpr auto name =
52 std::string_view{raw.begin() + raw.rfind(start_marker) + start_marker.length(), raw.end() - end_marker.size()};
53 return librepr::const_string<name.length()>(name);
54}
55
56#if !USING(LIBREPR_COMPILER_MSVC)
57template <auto P>
58consteval auto name_from_member_ptr() {
60 constexpr auto start_marker = std::string_view{"::"};
61 constexpr auto end_marker = std::string_view{"]"};
62
63 constexpr auto name = std::string_view{raw.begin() + raw.rfind(start_marker) + start_marker.length(),
64 raw.end() - end_marker.size()};
65
66 return librepr::const_string<name.length()>(name);
67}
68#endif
69} // namespace detail
70
71template <auto V>
72constexpr inline auto value = detail::get_ctvi<V>();
73
74#if USING(LIBREPR_COMPILER_CLANG) && __has_warning("-Wenum-constexpr-conversion")
76#endif
77
78} // namespace librepr::ctvi
constexpr auto name_from_subobject()
Definition ctvi/ctvi.h:37
consteval auto name_from_member_ptr()
Definition ctvi/ctvi.h:58
constexpr auto get_ctvi() noexcept
Definition ctvi/ctvi.h:19
Definition ctvi/ctvi.h:9
constexpr auto value
Definition ctvi/ctvi.h:72
std::string code_for()
Definition repr:39
#define LIBREPR_FUNCTION_NAME
Definition platform.h:80
Definition const_string.h:9
static constexpr auto size
Definition const_string.h:11
#define LIBREPR_WARNING_DISABLE_CLANG(...)
Definition warning.h:24