xcal
基于 C++23 的现代图形渲染引擎
载入中...
搜索中...
未找到
compiling.hpp
浏览该文件的文档.
1// compiling.hpp
2#pragma once
3#ifndef COMPILING_H
4#define COMPILING_H
5#include <cstddef>
6#include <string_view>
7
8namespace xcmath {
9template <char... args>
11 static constexpr const char str[] = {args...};
12 constexpr operator const char*() const { return static_string::str; }
13};
14template <size_t N, const char (&str)[N]>
15struct MyStr {};
16#ifdef __unix
17template <class _Tp>
18constexpr auto TypeName = []<class _FTp = _Tp>() -> const char* {
19 constexpr std::string_view full_name(__PRETTY_FUNCTION__);
20 constexpr auto start = full_name.find("=") + 2;
21 constexpr auto end = full_name.find("]");
22 return [&]<size_t... idx>(std::index_sequence<idx...>) {
23 return static_string<full_name[idx + start]..., '\0'>{};
24 }(std::make_index_sequence<end - start>{});
25}();
26#else
27template <typename Object>
28constexpr auto TypeName = []<class _Obj = Object>() {
29
30#ifdef _MSC_VER
31 constexpr std::string_view fully_name = __FUNCSIG__;
32#else
33 constexpr std::string_view fully_name = __PRETTY_FUNCTION__;
34#endif
35#ifdef __clang__
36 constexpr size_t begin = sizeof(
37 "auto __cdecl xcmath::(anonymous "
38 "class)::operator()(void) const [_Obj = ") -
39 1;
40 constexpr size_t end = fully_name.rfind("]");
41#elif defined(__GNUC__)
42 constexpr size_t begin = sizeof("<lambda()> [with _Obj =");
43 constexpr size_t end = fully_name.rfind("]");
44#else
45 constexpr size_t begin = fully_name.find("<") + 1;
46 constexpr size_t end = fully_name.rfind(">");
47#endif
48
49 constexpr auto type_name_view = fully_name.substr(begin, end - begin);
50 return [&]<size_t... index>(std::index_sequence<index...>) {
51 return static_string<type_name_view[index]..., '\0'>{};
52 }((std::make_index_sequence<end - begin>{}));
53}();
54#endif
55} // namespace xcmath
56
57#endif // COMPILING_H
Compiler-specific type information handling for MSVC
Definition complex.hpp:12
constexpr auto TypeName
Definition compiling.hpp:28
static constexpr const char str[]
Definition compiling.hpp:11