reorganized the repository
This commit is contained in:
parent
b7622722e0
commit
9adf5c882f
6 changed files with 169 additions and 31 deletions
44
.gitignore
vendored
Normal file
44
.gitignore
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
### cpp gitignore ###
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
### CMake gitignore ###
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2016 - 2018 Terik23
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
34
README.md
Normal file
34
README.md
Normal file
|
@ -0,0 +1,34 @@
|
|||
# nameof(x) c++
|
||||
|
||||
Simple Example:
|
||||
```
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
#include <nameof.hpp>
|
||||
struct SomeStruct {
|
||||
int SomeField;
|
||||
void SomeMethod() { std::cout << "No called!" << std::endl; }
|
||||
};
|
||||
|
||||
int someVar = 0;
|
||||
|
||||
int main() {
|
||||
SomeStruct someVar{1};
|
||||
|
||||
constexpr auto a = nameof_variable(someVar.SomeField);
|
||||
constexpr auto b = nameof_variable((&someVar)->SomeField);
|
||||
constexpr auto c = nameof_variable(someVar);
|
||||
constexpr auto d = nameof_variable(::someVar);
|
||||
constexpr auto e = nameof_variable(&SomeStruct::SomeMethod);
|
||||
constexpr auto f = nameof_function(someVar.SomeMethod());
|
||||
constexpr auto g = nameof_type(SomeStruct);
|
||||
|
||||
std::cout << a << std::endl; // SomeField
|
||||
std::cout << b << std::endl; // SomeField
|
||||
std::cout << c << std::endl; // someVar
|
||||
std::cout << d << std::endl; // someVar
|
||||
std::cout << e << std::endl; // SomeMethod
|
||||
std::cout << f << std::endl; // SomeMethod()
|
||||
std::cout << g << std::endl; // SomeStruct
|
||||
}
|
||||
```
|
13
example/CMakeLists.txt
Normal file
13
example/CMakeLists.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
cmake_minimum_required(VERSION 3.6.4)
|
||||
project(nameof_example)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
include_directories(../src)
|
||||
|
||||
set(SRC
|
||||
example.cpp
|
||||
../src/nameof.hpp)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SRC})
|
54
example/example.cpp
Normal file
54
example/example.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
// MIT License
|
||||
//
|
||||
// Copyright(c) 2016 - 2018 Terik23
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files(the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions :
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
// Simple Example.
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
#include <nameof.hpp>
|
||||
|
||||
struct SomeStruct {
|
||||
int SomeField;
|
||||
void SomeMethod() { std::cout << "No called!" << std::endl; }
|
||||
};
|
||||
|
||||
int someVar = 0;
|
||||
|
||||
int main() {
|
||||
SomeStruct someVar{1};
|
||||
|
||||
constexpr auto a = nameof_variable(someVar.SomeField);
|
||||
constexpr auto b = nameof_variable((&someVar)->SomeField);
|
||||
constexpr auto c = nameof_variable(someVar);
|
||||
constexpr auto d = nameof_variable(::someVar);
|
||||
constexpr auto e = nameof_variable(&SomeStruct::SomeMethod);
|
||||
constexpr auto f = nameof_function(someVar.SomeMethod());
|
||||
constexpr auto g = nameof_type(SomeStruct);
|
||||
|
||||
std::cout << a << std::endl; // SomeField
|
||||
std::cout << b << std::endl; // SomeField
|
||||
std::cout << c << std::endl; // someVar
|
||||
std::cout << d << std::endl; // someVar
|
||||
std::cout << e << std::endl; // SomeMethod
|
||||
std::cout << f << std::endl; // SomeMethod()
|
||||
std::cout << g << std::endl; // SomeStruct
|
||||
}
|
|
@ -21,6 +21,8 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
|
||||
inline constexpr const char* template_nameof_(const char* name, size_t length) {
|
||||
return length == 0 ? name
|
||||
: (name[length - 1] == '.' || name[length - 1] == '>' || name[length - 1] == ':')
|
||||
|
@ -39,34 +41,4 @@ template <typename T> inline constexpr const char* template_nameof_type(const ch
|
|||
|
||||
// Used to obtain the string name of a function.
|
||||
#define nameof_function(function) template_nameof_function(#function, sizeof(#function) / sizeof(char) - 1); if (false) (void)(function);
|
||||
inline constexpr const char* template_nameof_function(const char* name, size_t length) { return template_nameof_(name, length); }
|
||||
|
||||
// Example.
|
||||
#include <iostream>
|
||||
|
||||
struct SomeStruct {
|
||||
int SomeField;
|
||||
void SomeMethod() { std::cout << "No called!" << std::endl; }
|
||||
};
|
||||
|
||||
int someVar = 0;
|
||||
|
||||
int main() {
|
||||
SomeStruct someVar{1};
|
||||
|
||||
constexpr auto a = nameof_variable(someVar.SomeField);
|
||||
constexpr auto b = nameof_variable((&someVar)->SomeField);
|
||||
constexpr auto c = nameof_variable(someVar);
|
||||
constexpr auto d = nameof_variable(::someVar);
|
||||
constexpr auto e = nameof_variable(&SomeStruct::SomeMethod);
|
||||
constexpr auto f = nameof_function(someVar.SomeMethod());
|
||||
constexpr auto g = nameof_type(SomeStruct);
|
||||
|
||||
std::cout << a << std::endl; // SomeField
|
||||
std::cout << b << std::endl; // SomeField
|
||||
std::cout << c << std::endl; // someVar
|
||||
std::cout << d << std::endl; // someVar
|
||||
std::cout << e << std::endl; // SomeMethod
|
||||
std::cout << f << std::endl; // SomeMethod()
|
||||
std::cout << g << std::endl; // SomeStruct
|
||||
}
|
||||
inline constexpr const char* template_nameof_function(const char* name, size_t length) { return template_nameof_(name, length); }
|
Loading…
Reference in a new issue