clean-up
This commit is contained in:
parent
1e3f53ba5f
commit
713a504d5f
2 changed files with 3 additions and 11 deletions
|
@ -70,7 +70,6 @@ SomeStruct somevar;
|
||||||
Long othervar;
|
Long othervar;
|
||||||
int intvar = 0;
|
int intvar = 0;
|
||||||
SomeStruct* ptrvar = &somevar;
|
SomeStruct* ptrvar = &somevar;
|
||||||
SomeStruct** ptrptrvar = &ptrvar;
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// constexpr
|
// constexpr
|
||||||
|
@ -90,13 +89,6 @@ int main() {
|
||||||
std::cout << NAMEOF((&somevar)->somefield) << std::endl; // somefield
|
std::cout << NAMEOF((&somevar)->somefield) << std::endl; // somefield
|
||||||
std::cout << NAMEOF(othervar.ll.field) << std::endl; // field
|
std::cout << NAMEOF(othervar.ll.field) << std::endl; // field
|
||||||
|
|
||||||
// variable
|
|
||||||
std::cout << NAMEOF(ptrvar) << std::endl; // ptrvar
|
|
||||||
std::cout << NAMEOF(*ptrvar) << std::endl; // ptrvar
|
|
||||||
std::cout << NAMEOF(ptrptrvar) << std::endl; // ptrptrvar
|
|
||||||
std::cout << NAMEOF(*ptrptrvar) << std::endl; // ptrptrvar
|
|
||||||
std::cout << NAMEOF(**ptrptrvar) << std::endl; // ptrptrvar
|
|
||||||
|
|
||||||
// function
|
// function
|
||||||
std::cout << NAMEOF(&SomeStruct::SomeMethod2) << std::endl; // SomeMethod2
|
std::cout << NAMEOF(&SomeStruct::SomeMethod2) << std::endl; // SomeMethod2
|
||||||
std::cout << NAMEOF(SomeMethod3) << std::endl; // SomeMethod3
|
std::cout << NAMEOF(SomeMethod3) << std::endl; // SomeMethod3
|
||||||
|
@ -115,7 +107,6 @@ int main() {
|
||||||
std::cout << NAMEOF_FULL(somevar.somefield) << std::endl; // somevar.somefield
|
std::cout << NAMEOF_FULL(somevar.somefield) << std::endl; // somevar.somefield
|
||||||
std::cout << NAMEOF_FULL(&SomeStruct::SomeMethod2) << std::endl; // &SomeStruct::SomeMethod2
|
std::cout << NAMEOF_FULL(&SomeStruct::SomeMethod2) << std::endl; // &SomeStruct::SomeMethod2
|
||||||
std::cout << NAMEOF_FULL(Long::LL) << std::endl; // Long::LL
|
std::cout << NAMEOF_FULL(Long::LL) << std::endl; // Long::LL
|
||||||
std::cout << NAMEOF_FULL(std::string) << std::endl; // std::string
|
|
||||||
|
|
||||||
const auto div = [](int x, int y) -> int {
|
const auto div = [](int x, int y) -> int {
|
||||||
if (y == 0) {
|
if (y == 0) {
|
||||||
|
@ -156,6 +147,7 @@ int main() {
|
||||||
std::cout << NAMEOF(std::cout << intvar << std::endl) << std::endl; // 'endl'
|
std::cout << NAMEOF(std::cout << intvar << std::endl) << std::endl; // 'endl'
|
||||||
std::cout << NAMEOF(decltype(intvar)) << std::endl; // 'decltype(intvar)'
|
std::cout << NAMEOF(decltype(intvar)) << std::endl; // 'decltype(intvar)'
|
||||||
std::cout << NAMEOF(typeid(intvar)) << std::endl; // 'typeid(intvar)'
|
std::cout << NAMEOF(typeid(intvar)) << std::endl; // 'typeid(intvar)'
|
||||||
|
std::cout << NAMEOF((intvar)) << std::endl; // '(intvar)'
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,14 +37,14 @@ namespace nameof {
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
inline constexpr bool IsLexeme(const char s) noexcept {
|
inline constexpr bool IsLexeme(char s) noexcept {
|
||||||
return (s == '.' || s == '>' || s == ':' || s == '&' || s == '*' ||
|
return (s == '.' || s == '>' || s == ':' || s == '&' || s == '*' ||
|
||||||
s == '+' || s == '~' || s == '-' || s == '!');
|
s == '+' || s == '~' || s == '-' || s == '!');
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
inline constexpr const char* Nameof(const char* name, const std::size_t length) noexcept {
|
inline constexpr const char* Nameof(const char* name, std::size_t length) noexcept {
|
||||||
return ((length == 0) ? name : (detail::IsLexeme(name[length - 1])
|
return ((length == 0) ? name : (detail::IsLexeme(name[length - 1])
|
||||||
? &name[length]
|
? &name[length]
|
||||||
: Nameof(name, length - 1)));
|
: Nameof(name, length - 1)));
|
||||||
|
|
Loading…
Reference in a new issue