C++ Utilities
Loading...
Searching...
No Matches
type.h
Go to the documentation of this file.
1#pragma once
2// SPDX-FileCopyrightText: 2025 Nessan Fitzmaurice <nzznfitz+gh@icloud.com>
3// SPDX-License-Identifier: MIT
4
8
9#include <string>
10#include <iostream>
11
12namespace utilities {
13
15template<typename T>
16constexpr auto
18{
19#ifdef __clang__
20 std::string_view m_name = __PRETTY_FUNCTION__;
21 std::string_view m_prefix = "auto utilities::type() [T = ";
22 std::string_view m_suffix = "]";
23#elif defined(__GNUC__)
24 std::string_view m_name = __PRETTY_FUNCTION__;
25 std::string_view m_prefix = "constexpr auto utilities::type() [with T = ";
26 std::string_view m_suffix = "]";
27#elif defined(_MSC_VER)
28 std::string_view m_name = __FUNCSIG__;
29 std::string_view m_prefix = "auto __cdecl utilities::type<";
30 std::string_view m_suffix = ">(void)";
31#endif
32
33 m_name.remove_prefix(m_prefix.size());
34 m_name.remove_suffix(m_suffix.size());
35 return m_name;
36}
37
39template<typename T>
40constexpr auto
41type(const T&)
42{
43 return type<T>();
44}
45
46} // namespace utilities
The namespace for the utilities library.
Definition formatter.h:14
constexpr auto type()
Returns a string representing an object's "type" as the compiler/preprocessor sees.
Definition type.h:17