CPP-AP 3.0.1
Command-line argument parser for C++20
Loading...
Searching...
No Matches
typing.hpp
Go to the documentation of this file.
1// Copyright (c) 2023-2025 Jakub MusiaƂ
2// This file is part of the CPP-AP project (https://github.com/SpectraL519/cpp-ap).
3// Licensed under the MIT License. See the LICENSE file in the project root for full license information.
4
10#pragma once
11
12#include <functional>
13#include <memory>
14#include <optional>
15#include <source_location>
16#include <string_view>
17
18namespace ap::util {
19
28template <typename T>
29constexpr std::string_view get_demangled_type_name() {
30#if defined(__clang__) || defined(__GNUC__)
31 constexpr std::string_view func_name = __PRETTY_FUNCTION__;
32 constexpr std::string_view begin_key = "T = ";
33 constexpr std::string_view end_key = ";]";
34
35 auto start_pos = func_name.find(begin_key) + begin_key.size();
36 auto end_pos = func_name.find_first_of(end_key, start_pos);
37 return func_name.substr(start_pos, end_pos - start_pos);
38#elif defined(_MSC_VER)
39 constexpr std::string_view func_name = __FUNCSIG__;
40 constexpr std::string_view begin_key = "type_name<";
41 constexpr char end_key = '>';
42
43 auto start_pos = func_name.find(begin_key) + begin_key.size();
44 auto end_pos = func_name.find(end_key, start_pos);
45 return func_name.substr(start_pos, end_pos - start_pos);
46#else
47 return typeid(T).name();
48#endif
49}
50
51} // namespace ap::util
constexpr std::string_view get_demangled_type_name()
Retrieves the demangled name of a type T.
Definition typing.hpp:29