Nameof fork with modules for modern C++, simply obtain the name of a variable, type, function, macro, and enum
Find a file
2018-03-17 13:18:42 +05:00
example Add new case 2018-03-17 13:04:35 +05:00
src Add new case 2018-03-17 13:04:35 +05:00
.gitignore reorganized the repository 2018-03-17 09:31:59 +05:00
LICENSE reorganized the repository 2018-03-17 09:31:59 +05:00
README.md Edit README 2018-03-17 13:18:42 +05:00

nameof(x) c++

C++ alternative to nameOf operator.

Simple Example:

#include <iostream>
#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_VAR(someVar.SomeField);
  constexpr auto b = NAMEOF_VAR((&someVar)->SomeField);
  constexpr auto c = NAMEOF_VAR(someVar);
  constexpr auto d = NAMEOF_VAR(::someVar);
  constexpr auto e = NAMEOF_VAR(&SomeStruct::SomeMethod);
  constexpr auto f = NAMEOF_FUN(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
}