C++ Essence Library 0.1.0
A Utility Library for Modern C++ Programming
Loading...
Searching...
No Matches
identifier.hpp
1/*
2 * Copyright (c) 2024 The RefValue Project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include "../../char8_t_remediation.hpp"
26#include "parse_qualified_function_name.hpp"
27#include "parse_raw_identifier_name.hpp"
28
29#include <type_traits>
30
31/*
32 * With GCC 11, __PRETTY_FUNCTION__ provides more detailed information than
33 * std::source_location::current().function_name().
34 */
35#ifdef _MSC_VER
36#define ES_UNIFORM_FUNCSIG __FUNCSIG__
37#elif defined(__GNUC__) || defined(__clang__)
38#define ES_UNIFORM_FUNCSIG __PRETTY_FUNCTION__
39#else
40#error "Unsupported compiler."
41#endif
42
43namespace essence::meta::detail {
50 template <typename T, identifier_param Param = identifier_param{}>
51 consteval auto get_literal_string() noexcept {
52 return parse_raw_identifier_name(U8("essence::meta::detail::get_literal_string<"), ES_UNIFORM_FUNCSIG,
53 identifier_param{
54 .ensure_correctness = Param.ensure_correctness,
55 .preview_first_character = Param.preview_first_character,
56 });
57 }
58
66 template <auto Value, typename T, identifier_param Param = identifier_param{}>
67 consteval auto get_literal_string() noexcept {
68 return parse_raw_identifier_name(U8("essence::meta::detail::get_literal_string<"), ES_UNIFORM_FUNCSIG,
69 identifier_param{
70 .type = false,
71 .ensure_correctness = Param.ensure_correctness,
72 .preview_first_character = Param.preview_first_character,
73 });
74 }
75
82 template <typename T, identifier_param Param = identifier_param{}>
83 consteval auto get_short_literal_string() noexcept {
84 return parse_raw_identifier_name(U8("essence::meta::detail::get_short_literal_string<"), ES_UNIFORM_FUNCSIG,
85 identifier_param{
86 .shortened = true,
87 .ensure_correctness = Param.ensure_correctness,
88 .preview_first_character = Param.preview_first_character,
89 });
90 }
91
99 template <auto Value, typename T, identifier_param Param = identifier_param{}>
100 consteval auto get_short_literal_string() noexcept {
101 return parse_raw_identifier_name(U8("essence::meta::detail::get_short_literal_string<"), ES_UNIFORM_FUNCSIG,
102 identifier_param{
103 .type = false,
104 .shortened = true,
105 .ensure_correctness = Param.ensure_correctness,
106 .preview_first_character = Param.preview_first_character,
107 });
108 }
109
116 template <auto Value, identifier_param Param = identifier_param{}>
117 requires(std::is_pointer_v<decltype(Value)> && std::is_function_v<std::remove_pointer_t<decltype(Value)>>)
118 consteval auto get_function_name() noexcept {
119 return parse_qualified_function_name(
120 parse_raw_identifier_name(U8("essence::meta::detail::get_function_name<"), ES_UNIFORM_FUNCSIG,
121 identifier_param{
122 .type = false,
123 .ensure_correctness = Param.ensure_correctness,
124 .preview_first_character = Param.preview_first_character,
125 }));
126 }
127
134 template <auto Value, identifier_param Param = identifier_param{}>
135 requires(std::is_pointer_v<decltype(Value)> && std::is_function_v<std::remove_pointer_t<decltype(Value)>>)
136 consteval auto get_short_function_name() noexcept {
137 return get_short_identifier_name(get_function_name<Value, Param>());
138 }
139} // namespace essence::meta::detail