Compare commits
15 commits
Author | SHA1 | Date | |
---|---|---|---|
ad4ba073a3 | |||
![]() |
6c8e87da57 | ||
![]() |
3f1664327a | ||
![]() |
174b23d76e | ||
![]() |
3d4c9820fc | ||
![]() |
72a9659576 | ||
![]() |
72ce6c9ae0 | ||
![]() |
4d097b9da0 | ||
![]() |
e86b94cb8d | ||
![]() |
c9ae9a57c3 | ||
![]() |
5443409085 | ||
![]() |
8aeb677413 | ||
![]() |
f2522c2cc0 | ||
![]() |
8a6813f242 | ||
![]() |
31ac2b3273 |
17 changed files with 783 additions and 575 deletions
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
|
@ -1,2 +0,0 @@
|
|||
custom: ["paypal.me/Neargye", "btc.com/btc/address/bc1qzevldln8tqz5xf4lyufu9msgl7t97xstth9zq8", "etherscan.io/address/0xbb42fdef9204fa6f3d535d202b088dee35fcbd31"]
|
||||
liberapay: neargye
|
16
.github/workflows/macos.yml
vendored
16
.github/workflows/macos.yml
vendored
|
@ -2,19 +2,21 @@ name: macos
|
|||
|
||||
on: [push, pull_request]
|
||||
|
||||
permissions: read-all
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{matrix.config.os}}
|
||||
runs-on: ${{ matrix.config.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
config:
|
||||
- { os: macos-11 } # https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md#xcode
|
||||
- { os: macos-12 } # https://github.com/actions/virtual-environments/blob/main/images/macos/macos-12-Readme.md#xcode
|
||||
- { os: macos-13 } # https://github.com/actions/virtual-environments/blob/main/images/macos/macos-13-Readme.md#xcode
|
||||
- { os: macos-14 } # https://github.com/actions/virtual-environments/blob/main/images/macos/macos-14-Readme.md#xcode
|
||||
|
||||
name: "${{matrix.config.os}}"
|
||||
name: "${{ matrix.config.os }}"
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Build Release
|
||||
run: |
|
||||
|
@ -22,7 +24,7 @@ jobs:
|
|||
mkdir build
|
||||
cd build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build . --config Release
|
||||
cmake --build . -j 4 --config Release
|
||||
ctest --output-on-failure -C Release
|
||||
|
||||
- name: Build Debug
|
||||
|
@ -31,5 +33,5 @@ jobs:
|
|||
mkdir build
|
||||
cd build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Debug
|
||||
cmake --build . --config Debug
|
||||
cmake --build . -j 4 --config Debug
|
||||
ctest --output-on-failure -C Debug
|
||||
|
|
51
.github/workflows/ubuntu.yml
vendored
51
.github/workflows/ubuntu.yml
vendored
|
@ -2,32 +2,39 @@ name: ubuntu
|
|||
|
||||
on: [push, pull_request]
|
||||
|
||||
permissions: read-all
|
||||
|
||||
jobs:
|
||||
ubuntu:
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
compiler:
|
||||
- { cc: "gcc-9", cxx: "g++-9" }
|
||||
- { cc: "gcc-10", cxx: "g++-10" }
|
||||
- { cc: "gcc-11", cxx: "g++-11" }
|
||||
- { cc: "clang-9", cxx: "clang++-9" }
|
||||
- { cc: "clang-10", cxx: "clang++-10" }
|
||||
- { cc: "clang-11", cxx: "clang++-11" }
|
||||
- { cc: "clang-12", cxx: "clang++-12" }
|
||||
- { cc: "clang-13", cxx: "clang++-13" }
|
||||
- { cc: "clang-14", cxx: "clang++-14" }
|
||||
- { cc: "clang-15", cxx: "clang++-15" }
|
||||
- { cc: "clang-16", cxx: "clang++-16" }
|
||||
- { cc: "gcc-9", cxx: "g++-9", os: "ubuntu-20.04" }
|
||||
- { cc: "gcc-10", cxx: "g++-10", os: "ubuntu-20.04" }
|
||||
- { cc: "gcc-10", cxx: "g++-10", os: "ubuntu-20.04" }
|
||||
- { cc: "gcc-11", cxx: "g++-11", os: "ubuntu-20.04" }
|
||||
- { cc: "gcc-11", cxx: "g++-11", os: "ubuntu-20.04" }
|
||||
- { cc: "gcc-12", cxx: "g++-12", os: "ubuntu-22.04" }
|
||||
- { cc: "gcc-13", cxx: "g++-12", os: "ubuntu-22.04" }
|
||||
- { cc: "gcc-14", cxx: "g++-12", os: "ubuntu-22.04" }
|
||||
- { cc: "clang-9", cxx: "clang++-9", os: "ubuntu-20.04" }
|
||||
- { cc: "clang-10", cxx: "clang++-10", os: "ubuntu-20.04" }
|
||||
- { cc: "clang-11", cxx: "clang++-11", os: "ubuntu-20.04" }
|
||||
- { cc: "clang-12", cxx: "clang++-12", os: "ubuntu-20.04" }
|
||||
- { cc: "clang-13", cxx: "clang++-13", os: "ubuntu-20.04" }
|
||||
- { cc: "clang-14", cxx: "clang++-14", os: "ubuntu-20.04" }
|
||||
- { cc: "clang-15", cxx: "clang++-15", os: "ubuntu-20.04" }
|
||||
- { cc: "clang-16", cxx: "clang++-16", os: "ubuntu-20.04" }
|
||||
|
||||
name: "${{matrix.compiler.cc}}"
|
||||
name: "${{ matrix.compiler.cc }}"
|
||||
runs-on: ${{ matrix.compiler.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Configure clang
|
||||
run: |
|
||||
if [[ "${{matrix.compiler.cc}}" == "clang"* ]]; then
|
||||
if [[ "${{ matrix.compiler.cc }}" == "clang"* ]]; then
|
||||
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
|
||||
sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-9 main"
|
||||
sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-10 main"
|
||||
|
@ -39,15 +46,15 @@ jobs:
|
|||
sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-16 main"
|
||||
sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal main"
|
||||
sudo apt update
|
||||
sudo apt install ${{matrix.compiler.cc}} -y
|
||||
sudo apt install ${{ matrix.compiler.cc }} -y
|
||||
fi
|
||||
|
||||
- name: Configure gcc
|
||||
run: |
|
||||
if [[ "${{matrix.compiler.cc}}" == "gcc"* ]]; then
|
||||
if [[ "${{ matrix.compiler.cc }}" == "gcc"* ]]; then
|
||||
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
|
||||
sudo apt update
|
||||
sudo apt install ${{matrix.compiler.cxx}} -y
|
||||
sudo apt install ${{ matrix.compiler.cxx }} -y
|
||||
fi
|
||||
|
||||
- name: Build Release
|
||||
|
@ -55,8 +62,8 @@ jobs:
|
|||
rm -rf build
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
|
||||
cmake --build . --config Release
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=${{ matrix.compiler.cxx }}
|
||||
cmake --build . -j 4 --config Release
|
||||
ctest --output-on-failure -C Release
|
||||
|
||||
- name: Build Debug
|
||||
|
@ -64,6 +71,6 @@ jobs:
|
|||
rm -rf build
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=${{matrix.compiler.cxx}}
|
||||
cmake --build . --config Debug
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=${{ matrix.compiler.cxx }}
|
||||
cmake --build . -j 4 --config Debug
|
||||
ctest --output-on-failure -C Debug
|
||||
|
|
17
.github/workflows/windows.yml
vendored
17
.github/workflows/windows.yml
vendored
|
@ -2,9 +2,11 @@ name: windows
|
|||
|
||||
on: [push, pull_request]
|
||||
|
||||
permissions: read-all
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{matrix.config.os}}
|
||||
runs-on: ${{ matrix.config.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
|
@ -12,9 +14,9 @@ jobs:
|
|||
- { os: windows-2019, vs: "Visual Studio 2019" } # https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md#visual-studio-enterprise-2019
|
||||
- { os: windows-2022, vs: "Visual Studio 2022" } # https://github.com/actions/virtual-environments/blob/main/images/win/Windows2022-Readme.md#visual-studio-enterprise-2022
|
||||
|
||||
name: "${{matrix.config.vs}}"
|
||||
name: "${{ matrix.config.vs }}"
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Build Win32
|
||||
shell: bash
|
||||
|
@ -23,9 +25,9 @@ jobs:
|
|||
mkdir build
|
||||
cd build
|
||||
cmake .. -A Win32
|
||||
cmake --build . --config Release
|
||||
cmake --build . -j 4 --config Release
|
||||
ctest --output-on-failure -C Release
|
||||
cmake --build . --config Debug
|
||||
cmake --build . -j 4 --config Debug
|
||||
ctest --output-on-failure -C Debug
|
||||
|
||||
- name: Build x64
|
||||
|
@ -35,8 +37,7 @@ jobs:
|
|||
mkdir build
|
||||
cd build
|
||||
cmake .. -A x64
|
||||
cmake --build . --config Release
|
||||
cmake --build . -j 4 --config Release
|
||||
ctest --output-on-failure -C Release
|
||||
cmake --build . --config Debug
|
||||
cmake --build . -j 4 --config Debug
|
||||
ctest --output-on-failure -C Debug
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
cmake_minimum_required(VERSION 3.14)
|
||||
cmake_minimum_required(VERSION 3.30)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
|
@ -6,7 +6,7 @@ set(ADDITIONAL_MODULES_DIR "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
|||
list(APPEND CMAKE_MODULE_PATH "${ADDITIONAL_MODULES_DIR}")
|
||||
|
||||
project(nameof
|
||||
VERSION "0.10.3"
|
||||
VERSION "0.10.4"
|
||||
HOMEPAGE_URL "https://github.com/Neargye/nameof"
|
||||
DESCRIPTION "A library that provides nameof macros and functions to simply obtain the name of a variable, type, function, macro, and enum."
|
||||
LANGUAGES CXX
|
||||
|
@ -22,6 +22,7 @@ endif()
|
|||
option(NAMEOF_OPT_BUILD_EXAMPLES "Build nameof examples" ${IS_TOPLEVEL_PROJECT})
|
||||
option(NAMEOF_OPT_BUILD_TESTS "Build and perform nameof tests" ${IS_TOPLEVEL_PROJECT})
|
||||
option(NAMEOF_OPT_INSTALL "Generate and install nameof target" ${IS_TOPLEVEL_PROJECT})
|
||||
option(NAMEOF_MODULE "Build nameof module" OFF)
|
||||
|
||||
if(NAMEOF_OPT_BUILD_EXAMPLES)
|
||||
add_subdirectory(example)
|
||||
|
@ -36,14 +37,34 @@ include(CMakePackageConfigHelpers)
|
|||
|
||||
set(EXPORT_NAMESPACE "${PROJECT_NAME}::")
|
||||
|
||||
add_library("${PROJECT_NAME}" INTERFACE)
|
||||
add_library("${EXPORT_NAMESPACE}${PROJECT_NAME}" ALIAS "${PROJECT_NAME}")
|
||||
|
||||
set(INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
if(NAMEOF_MODULE)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
add_library(${PROJECT_NAME})
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${INCLUDES}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE NAMEOF_MODULE)
|
||||
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
|
||||
|
||||
target_sources(${PROJECT_NAME} PUBLIC FILE_SET nameofModules TYPE CXX_MODULES
|
||||
FILES src/nameof.cpp)
|
||||
else()
|
||||
add_library("${PROJECT_NAME}" INTERFACE)
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
INTERFACE
|
||||
$<BUILD_INTERFACE:${INCLUDES}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
endif()
|
||||
|
||||
add_library("${EXPORT_NAMESPACE}${PROJECT_NAME}" ALIAS "${PROJECT_NAME}")
|
||||
|
||||
|
||||
|
||||
|
||||
if(NAMEOF_OPT_INSTALL)
|
||||
list(APPEND CMAKE_MODULE_PATH "${ADDITIONAL_MODULES_DIR}/GenPkgConfig")
|
||||
|
@ -54,6 +75,10 @@ if(NAMEOF_OPT_INSTALL)
|
|||
string(REPLACE "/${CMAKE_LIBRARY_ARCHITECTURE}" "" CMAKE_INSTALL_LIBDIR_ARCHIND "${CMAKE_INSTALL_LIBDIR}")
|
||||
install(TARGETS "${PROJECT_NAME}"
|
||||
EXPORT ${PROJECT_NAME}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
FILE_SET nameofModules DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
INCLUDES
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||
# COMPONENT "${SDK_COMPONENT_NAME}" # component is not allowed for includes! Headers are installed separately! Includes only marks the headers for export
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2016 - 2023 Daniil Goncharov
|
||||
Copyright (c) 2016 - 2024 Daniil Goncharov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
70
README.md
70
README.md
|
@ -1,38 +1,15 @@
|
|||
[](https://bit.ly/3OMysM8)
|
||||
|
||||
```text
|
||||
_ _ __ _____
|
||||
| \ | | / _| / ____|_ _
|
||||
| \| | __ _ _ __ ___ ___ ___ | |_ | | _| |_ _| |_
|
||||
| . ` |/ _` | '_ ` _ \ / _ \/ _ \| _| | | |_ _|_ _|
|
||||
| |\ | (_| | | | | | | __/ (_) | | | |____|_| |_|
|
||||
|_| \_|\__,_|_| |_| |_|\___|\___/|_| \_____|
|
||||
```
|
||||
|
||||
[](https://github.com/Neargye/nameof/releases)
|
||||
[](https://conan.io/center/nameof)
|
||||
[](https://conan.io/center/recipes/nameof)
|
||||
[](https://github.com/microsoft/vcpkg/tree/master/ports/nameof)
|
||||
[](LICENSE)
|
||||
[](https://wandbox.org/permlink/PBBzVKlbMIfC3WOk)
|
||||
[](https://godbolt.org/z/s_ecko)
|
||||
[](https://stand-with-ukraine.pp.ua)
|
||||
|
||||
# Nameof C++
|
||||
|
||||
Header-only C++17 library provides nameof macros and functions to simply obtain the name of a variable, type, function, macro, and enum.
|
||||
|
||||
## Features
|
||||
|
||||
* C++17
|
||||
* Header-only
|
||||
* Dependency-free
|
||||
* Compile-time
|
||||
* Name of variable, member variable
|
||||
* Name of type, variable type
|
||||
* Name of member, pointer
|
||||
* Name of function, member function
|
||||
* Name of enum, enum variable
|
||||
* Name of macro
|
||||
* Enum to string
|
||||
If you like this project, please consider donating to one of the funds that help victims of the war in Ukraine: https://u24.gov.ua.
|
||||
|
||||
## Documentation
|
||||
|
||||
|
@ -40,7 +17,7 @@ Header-only C++17 library provides nameof macros and functions to simply obtain
|
|||
* [Limitations](doc/limitations.md)
|
||||
* [Integration](#Integration)
|
||||
|
||||
## [Examples](example/example.cpp)
|
||||
## [Features & Examples](example/example.cpp)
|
||||
|
||||
* Nameof
|
||||
|
||||
|
@ -61,6 +38,12 @@ Header-only C++17 library provides nameof macros and functions to simply obtain
|
|||
// Name of macro.
|
||||
NAMEOF(__LINE__) -> "__LINE__"
|
||||
NAMEOF(NAMEOF(structvar)) -> "NAMEOF"
|
||||
|
||||
// Obtains full name of variable, function, macro.
|
||||
NAMEOF_FULL(somevar.some_method<int>()) -> "some_method<int>"
|
||||
|
||||
// Obtains raw name of variable, function, macro.
|
||||
NAMEOF_RAW(somevar.some_method<int>()) -> "somevar.some_method<int>()"
|
||||
```
|
||||
|
||||
* Nameof enum
|
||||
|
@ -78,9 +61,13 @@ Header-only C++17 library provides nameof macros and functions to simply obtain
|
|||
NAMEOF_ENUM_CONST(Color::GREEN) -> "GREEN"
|
||||
nameof::nameof_enum<Color::GREEN>() -> "GREEN"
|
||||
|
||||
// Enum flag variable to string.
|
||||
// Enum flags variable to string.
|
||||
NAMEOF_ENUM_FLAG(Color::GREEN | Color::BLUE) -> "GREEN|BLUE"
|
||||
nameof::nameof_enum_flag<Color::GREEN>() -> "GREEN|BLUE"
|
||||
nameof::nameof_enum_flag<Color::GREEN | Color::BLUE>() -> "GREEN|BLUE"
|
||||
|
||||
// Obtains name of enum variable or default value if enum variable out of range.
|
||||
NAMEOF_ENUM_OR(Color::GREEN) -> "GREEN"
|
||||
NAMEOF_ENUM_OR((Color)0, "none") -> "none"
|
||||
```
|
||||
|
||||
* Nameof type
|
||||
|
@ -109,19 +96,22 @@ Header-only C++17 library provides nameof macros and functions to simply obtain
|
|||
NAMEOF_TYPE_RTTI(*ptr) -> "my::detail::Derived"
|
||||
NAMEOF_FULL_TYPE_RTTI(*ptr) -> "volatile const my::detail::Derived&"
|
||||
NAMEOF_SHORT_TYPE_RTTI(*ptr) -> "Derived"
|
||||
```
|
||||
|
||||
* Compile-time
|
||||
struct A {
|
||||
int this_is_the_name;
|
||||
};
|
||||
// Obtains name of member.
|
||||
NAMEOF_MEMBER(&A::this_is_the_name) -> "this_is_the_name"
|
||||
nameof::nameof_member(&A::this_is_the_name) -> "this_is_the_name"
|
||||
|
||||
```cpp
|
||||
constexpr auto somevar_name = NAMEOF(somevar);
|
||||
// somevar_name -> "somevar"
|
||||
constexpr auto color_name = NAMEOF_ENUM(Color::BLUE); // or nameof::nameof_enum(Color::BLUE)
|
||||
// color_name -> "BLUE"
|
||||
constexpr auto var_type_name = NAMEOF_TYPE_EXPR(var); // or nameof::nameof_type<decltype(var)>()
|
||||
// var_type_name -> "int"
|
||||
constexpr auto type_name = NAMEOF_TYPE(T); // or nameof::nameof_type<T>()
|
||||
// type_name -> "int"
|
||||
int someglobalvariable = 0;
|
||||
// Obtains name of a function, a global or class static variable.
|
||||
NAMEOF_POINTER(&someglobalconstvariable) == "someglobalconstvariable"
|
||||
nameof::nameof_pointer(&someglobalconstvariable) == "someglobalconstvariable"
|
||||
|
||||
constexpr auto global_ptr = &someglobalvariable;
|
||||
NAMEOF_POINTER(global_ptr) == "someglobalconstvariable"
|
||||
nameof::nameof_pointer(global_ptr) == "someglobalconstvariable"
|
||||
```
|
||||
|
||||
## Remarks
|
||||
|
|
|
@ -211,6 +211,7 @@
|
|||
flag = AnimalFlags::CanFly | AnimalFlags::Endangered;
|
||||
NAMEOF_ENUM_FLAG(flag) -> "CanFly|Endangered"
|
||||
nameof_enum_flag(flag) -> "CanFly|Endangered"
|
||||
nameof_enum_flag(flag, '$') -> "CanFly$Endangered"
|
||||
|
||||
NAMEOF_ENUM(HasClaws | CanFly) -> ""
|
||||
nameof_enum(HasClaws | CanFly) -> ""
|
||||
|
|
|
@ -12,10 +12,12 @@ endif()
|
|||
function(make_example target)
|
||||
add_executable(${target} ${target}.cpp)
|
||||
set_target_properties(${target} PROPERTIES CXX_EXTENSIONS OFF)
|
||||
target_compile_features(${target} PRIVATE cxx_std_17)
|
||||
target_compile_options(${target} PRIVATE ${OPTIONS})
|
||||
target_link_libraries(${target} PRIVATE ${CMAKE_PROJECT_NAME})
|
||||
endfunction()
|
||||
|
||||
make_example(example)
|
||||
make_example(example_custom_name)
|
||||
if(NAMEOF_MODULE)
|
||||
make_example(example_module)
|
||||
endif()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2018 - 2023 Daniil Goncharov <neargye@gmail.com>.
|
||||
// Copyright (c) 2018 - 2024 Daniil Goncharov <neargye@gmail.com>.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2020 - 2023 Daniil Goncharov <neargye@gmail.com>.
|
||||
// Copyright (c) 2020 - 2024 Daniil Goncharov <neargye@gmail.com>.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
11
example/example_module.cpp
Normal file
11
example/example_module.cpp
Normal file
|
@ -0,0 +1,11 @@
|
|||
import nameof;
|
||||
#include <nameof_macro.hpp>
|
||||
|
||||
struct Test {};
|
||||
|
||||
auto main() -> int {
|
||||
auto _ = nameof::nameof_type<Test>();
|
||||
{
|
||||
auto _ = NAMEOF_TYPE(Test);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
149
include/nameof_macro.hpp
Normal file
149
include/nameof_macro.hpp
Normal file
|
@ -0,0 +1,149 @@
|
|||
#ifndef NEARGYE_NAMEOF_MACRO_HPP
|
||||
#define NEARGYE_NAMEOF_MACRO_HPP
|
||||
|
||||
// Checks nameof_type compiler compatibility.
|
||||
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 7 || defined(_MSC_VER) && _MSC_VER >= 1910
|
||||
#undef NAMEOF_TYPE_SUPPORTED
|
||||
#define NAMEOF_TYPE_SUPPORTED 1
|
||||
#endif
|
||||
|
||||
// Checks nameof_type_rtti compiler compatibility.
|
||||
#if defined(__clang__)
|
||||
#if __has_feature(cxx_rtti)
|
||||
#undef NAMEOF_TYPE_RTTI_SUPPORTED
|
||||
#define NAMEOF_TYPE_RTTI_SUPPORTED 1
|
||||
#endif
|
||||
#elif defined(__GNUC__)
|
||||
#if defined(__GXX_RTTI)
|
||||
#undef NAMEOF_TYPE_RTTI_SUPPORTED
|
||||
#define NAMEOF_TYPE_RTTI_SUPPORTED 1
|
||||
#endif
|
||||
#elif defined(_MSC_VER)
|
||||
#if defined(_CPPRTTI)
|
||||
#undef NAMEOF_TYPE_RTTI_SUPPORTED
|
||||
#define NAMEOF_TYPE_RTTI_SUPPORTED 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Checks nameof_member compiler compatibility.
|
||||
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 7 || \
|
||||
defined(_MSC_VER) && defined(_MSVC_LANG) && _MSVC_LANG >= 202002L
|
||||
#undef NAMEOF_MEMBER_SUPPORTED
|
||||
#define NAMEOF_MEMBER_SUPPORTED 1
|
||||
#endif
|
||||
|
||||
// Checks nameof_pointer compiler compatibility.
|
||||
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 7 || \
|
||||
defined(_MSC_VER) && defined(_MSVC_LANG) && _MSVC_LANG >= 202002L
|
||||
#undef NAMEOF_POINTER_SUPPORTED
|
||||
#define NAMEOF_POINTER_SUPPORTED 1
|
||||
#endif
|
||||
|
||||
// Checks nameof_enum compiler compatibility.
|
||||
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 9 || defined(_MSC_VER) && _MSC_VER >= 1910
|
||||
#undef NAMEOF_ENUM_SUPPORTED
|
||||
#define NAMEOF_ENUM_SUPPORTED 1
|
||||
#endif
|
||||
|
||||
// Checks nameof_enum compiler aliases compatibility.
|
||||
#if defined(__clang__) && __clang_major__ >= 5 || defined(__GNUC__) && __GNUC__ >= 9 || defined(_MSC_VER) && _MSC_VER >= 1920
|
||||
#undef NAMEOF_ENUM_SUPPORTED_ALIASES
|
||||
#define NAMEOF_ENUM_SUPPORTED_ALIASES 1
|
||||
#endif
|
||||
|
||||
// Enum value must be greater or equals than NAMEOF_ENUM_RANGE_MIN. By default NAMEOF_ENUM_RANGE_MIN = -128.
|
||||
// If need another min range for all enum types by default, redefine the macro NAMEOF_ENUM_RANGE_MIN.
|
||||
#if !defined(NAMEOF_ENUM_RANGE_MIN)
|
||||
#define NAMEOF_ENUM_RANGE_MIN -128
|
||||
#endif
|
||||
|
||||
// Enum value must be less or equals than NAMEOF_ENUM_RANGE_MAX. By default NAMEOF_ENUM_RANGE_MAX = 128.
|
||||
// If need another max range for all enum types by default, redefine the macro NAMEOF_ENUM_RANGE_MAX.
|
||||
#if !defined(NAMEOF_ENUM_RANGE_MAX)
|
||||
#define NAMEOF_ENUM_RANGE_MAX 128
|
||||
#endif
|
||||
|
||||
#define NAMEOF_VERSION_MAJOR 0
|
||||
#define NAMEOF_VERSION_MINOR 10
|
||||
#define NAMEOF_VERSION_PATCH 4
|
||||
|
||||
// Obtains name of variable, function, macro.
|
||||
#define NAMEOF(...) \
|
||||
[]() constexpr noexcept { \
|
||||
::std::void_t<decltype(__VA_ARGS__)>(); \
|
||||
constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__); \
|
||||
static_assert(!_name.empty(), "Expression does not have a name."); \
|
||||
constexpr auto _size = _name.size(); \
|
||||
constexpr auto _nameof = ::nameof::cstring<_size>{_name}; \
|
||||
return _nameof; \
|
||||
}()
|
||||
|
||||
// Obtains full name of variable, function, macro.
|
||||
#define NAMEOF_FULL(...) \
|
||||
[]() constexpr noexcept { \
|
||||
::std::void_t<decltype(__VA_ARGS__)>(); \
|
||||
constexpr auto _name = ::nameof::detail::pretty_name(#__VA_ARGS__, false); \
|
||||
static_assert(!_name.empty(), "Expression does not have a name."); \
|
||||
constexpr auto _size = _name.size(); \
|
||||
constexpr auto _nameof_full = ::nameof::cstring<_size>{_name}; \
|
||||
return _nameof_full; \
|
||||
}()
|
||||
|
||||
// Obtains raw name of variable, function, macro.
|
||||
#define NAMEOF_RAW(...) \
|
||||
[]() constexpr noexcept { \
|
||||
::std::void_t<decltype(__VA_ARGS__)>(); \
|
||||
constexpr auto _name = ::nameof::string_view{#__VA_ARGS__}; \
|
||||
static_assert(!_name.empty(), "Expression does not have a name."); \
|
||||
constexpr auto _size = _name.size(); \
|
||||
constexpr auto _nameof_raw = ::nameof::cstring<_size>{_name}; \
|
||||
return _nameof_raw; \
|
||||
}()
|
||||
|
||||
// Obtains name of enum variable.
|
||||
#define NAMEOF_ENUM(...) ::nameof::nameof_enum<::std::decay_t<decltype(__VA_ARGS__)>>(__VA_ARGS__)
|
||||
|
||||
// Obtains name of enum variable or default value if enum variable out of range.
|
||||
#define NAMEOF_ENUM_OR(...) ::nameof::nameof_enum_or(__VA_ARGS__)
|
||||
|
||||
// Obtains name of static storage enum variable.
|
||||
// This version is much lighter on the compile times and is not restricted to the enum_range limitation.
|
||||
#define NAMEOF_ENUM_CONST(...) ::nameof::nameof_enum<__VA_ARGS__>()
|
||||
|
||||
// Obtains name of enum-flags variable.
|
||||
#define NAMEOF_ENUM_FLAG(...) ::nameof::nameof_enum_flag<::std::decay_t<decltype(__VA_ARGS__)>>(__VA_ARGS__)
|
||||
|
||||
// Obtains type name, reference and cv-qualifiers are ignored.
|
||||
#define NAMEOF_TYPE(...) ::nameof::nameof_type<__VA_ARGS__>()
|
||||
|
||||
// Obtains full type name, with reference and cv-qualifiers.
|
||||
#define NAMEOF_FULL_TYPE(...) ::nameof::nameof_full_type<__VA_ARGS__>()
|
||||
|
||||
// Obtains short type name.
|
||||
#define NAMEOF_SHORT_TYPE(...) ::nameof::nameof_short_type<__VA_ARGS__>()
|
||||
|
||||
// Obtains type name of expression, reference and cv-qualifiers are ignored.
|
||||
#define NAMEOF_TYPE_EXPR(...) ::nameof::nameof_type<decltype(__VA_ARGS__)>()
|
||||
|
||||
// Obtains full type name of expression, with reference and cv-qualifiers.
|
||||
#define NAMEOF_FULL_TYPE_EXPR(...) ::nameof::nameof_full_type<decltype(__VA_ARGS__)>()
|
||||
|
||||
// Obtains short type name of expression.
|
||||
#define NAMEOF_SHORT_TYPE_EXPR(...) ::nameof::nameof_short_type<decltype(__VA_ARGS__)>()
|
||||
|
||||
// Obtains type name, with reference and cv-qualifiers, using RTTI.
|
||||
#define NAMEOF_TYPE_RTTI(...) ::nameof::detail::nameof_type_rtti<::std::void_t<decltype(__VA_ARGS__)>>(typeid(__VA_ARGS__).name())
|
||||
|
||||
// Obtains full type name, using RTTI.
|
||||
#define NAMEOF_FULL_TYPE_RTTI(...) ::nameof::detail::nameof_full_type_rtti<decltype(__VA_ARGS__)>(typeid(__VA_ARGS__).name())
|
||||
|
||||
// Obtains short type name, using RTTI.
|
||||
#define NAMEOF_SHORT_TYPE_RTTI(...) ::nameof::detail::nameof_short_type_rtti<decltype(__VA_ARGS__)>(typeid(__VA_ARGS__).name())
|
||||
|
||||
// Obtains name of member.
|
||||
#define NAMEOF_MEMBER(...) ::nameof::nameof_member<__VA_ARGS__>()
|
||||
|
||||
// Obtains name of a function, a global or class static variable.
|
||||
#define NAMEOF_POINTER(...) ::nameof::nameof_pointer<__VA_ARGS__>()
|
||||
|
||||
#endif
|
46
src/nameof.cpp
Normal file
46
src/nameof.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
module;
|
||||
|
||||
#ifndef NAMEOF_IMPORT_STD
|
||||
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <iosfwd>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#if !defined(NAMEOF_USING_ALIAS_STRING)
|
||||
#include <string>
|
||||
#endif
|
||||
#if !defined(NAMEOF_USING_ALIAS_STRING_VIEW)
|
||||
#include <string_view>
|
||||
#endif
|
||||
|
||||
#if __has_include(<cxxabi.h>)
|
||||
#include <cxxabi.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
export module nameof;
|
||||
|
||||
#ifdef NAMEOF_IMPORT_STD
|
||||
|
||||
import std;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef NAMEOF_ATTACH_TO_GLOBAL_MODULE
|
||||
extern "C++" {
|
||||
#endif
|
||||
|
||||
#include <nameof.hpp>
|
||||
|
||||
#ifdef NAMEOF_ATTACH_TO_GLOBAL_MODULE
|
||||
} // extern "C++"
|
||||
#endif
|
|
@ -1,6 +1,6 @@
|
|||
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2018 - 2023 Daniil Goncharov <neargye@gmail.com>.
|
||||
// Copyright (c) 2018 - 2024 Daniil Goncharov <neargye@gmail.com>.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2019 - 2023 Daniil Goncharov <neargye@gmail.com>.
|
||||
// Copyright (c) 2019 - 2024 Daniil Goncharov <neargye@gmail.com>.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -32,7 +32,7 @@ struct MyString {
|
|||
MyString(const char* s, std::size_t l) : str{s, l} {} // required
|
||||
bool empty() const { return str.empty(); } // required
|
||||
MyString& append(std::size_t count, char c) { str.append(count, c); return *this; } // required
|
||||
MyString& append(const char* s) { str.append(s); return *this; } // required
|
||||
MyString& append(const char* s, std::size_t count) { str.append(s, count); return *this; } // required
|
||||
MyString& append(const MyString& s) { str.append(s.str); return *this; } // required
|
||||
|
||||
std::size_t size() const { return str.size(); }
|
||||
|
|
Loading…
Reference in a new issue