This commit is contained in:
Neargye 2018-04-03 00:19:22 +05:00
parent 0016e037b4
commit 425046ecb6
4 changed files with 6 additions and 10 deletions

View file

@ -2,9 +2,9 @@
C++ alternative to [nameof](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/nameof) operator in C#.
Linux/OSX | Windows
-----------|---------
[![Build Status](https://travis-ci.org/Neargye/nameof.svg?branch=master)](https://travis-ci.org/Neargye/nameof)|[![Build status](https://ci.appveyor.com/api/projects/status/yq5fk0d9mwljbubt/branch/master?svg=true)](https://ci.appveyor.com/project/Neargye/nameof/branch/master)
Branch | Linux/OSX | Windows
-------|-----------|---------
master |[![Build Status](https://travis-ci.org/Neargye/nameof.svg?branch=master)](https://travis-ci.org/Neargye/nameof)|[![Build status](https://ci.appveyor.com/api/projects/status/yq5fk0d9mwljbubt/branch/master?svg=true)](https://ci.appveyor.com/project/Neargye/nameof/branch/master)
Used to obtain the simple name of a variable, type, member or function and etc.
Before, you had to use string literals to refer to definitions, which is brittle when renaming code elements because tools do not know to check these string literals.

View file

@ -1,7 +1,5 @@
include_directories(${CMAKE_SOURCE_DIR}/src)
set(SRC
example.cpp
${CMAKE_SOURCE_DIR}/src/nameof.hpp)
set(SRC example.cpp)
add_executable(${PROJECT_NAME}_example ${SRC})

View file

@ -31,6 +31,7 @@ inline constexpr bool IsLexeme(const char s) {
return (s == '.' || s == '>' || s == ':' || s == '&' || s == '*' ||
s == '+' || s == '~' || s == '-' || s == '!');
}
template <typename T, std::size_t N>
inline constexpr const char* Nameof(const char(&name)[N], const std::size_t length = N) {
return length == 0 ? name : IsLexeme(name[length - 1])

View file

@ -1,10 +1,7 @@
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(3rdparty/Catch2)
set(SRC
test.cpp
3rdparty/Catch2/catch.hpp
${CMAKE_SOURCE_DIR}/src/nameof.hpp)
set(SRC test.cpp)
add_executable(${PROJECT_NAME}_test ${SRC})