2019-07-27 16:53:03 +00:00
|
|
|
#include <nameof.hpp>
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
struct SomeStruct {};
|
|
|
|
|
|
|
|
SomeStruct structvar;
|
2019-07-30 18:44:48 +00:00
|
|
|
|
2019-07-27 16:53:03 +00:00
|
|
|
int main() {
|
|
|
|
// Compile-time.
|
|
|
|
constexpr auto name = NAMEOF(structvar);
|
|
|
|
static_assert("structvar" == name);
|
|
|
|
|
|
|
|
// Nameof.
|
|
|
|
std::string_view res1 = NAMEOF(structvar);
|
|
|
|
std::string_view res2 = NAMEOF(::structvar);
|
2019-07-30 18:44:48 +00:00
|
|
|
|
2019-07-27 16:53:03 +00:00
|
|
|
std::cout << res1 << '\n' << res2 << '\n';
|
2019-07-30 18:44:48 +00:00
|
|
|
|
|
|
|
using std::literals::string_view_literals::operator""sv;
|
|
|
|
|
|
|
|
bool success = (res1 == "structvar"sv) && (res2 == "structvar"sv);
|
|
|
|
|
2019-07-27 16:53:03 +00:00
|
|
|
return success ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|