From fbab44816a808041037eb39c265126bda42e5bc6 Mon Sep 17 00:00:00 2001 From: Terik23 Date: Thu, 22 Mar 2018 10:26:19 +0500 Subject: [PATCH] Add namespace --- src/nameof.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/nameof.hpp b/src/nameof.hpp index 1484a65..b14ec5b 100644 --- a/src/nameof.hpp +++ b/src/nameof.hpp @@ -26,9 +26,11 @@ #pragma once #include +namespace nameof { + #define NAMEOF_RAW(x) (#x) -inline constexpr const char* nameof(const char* name, const size_t length) { +inline constexpr const char* Nameof(const char* name, const size_t length) { return length == 0 ? name : (name[length - 1] == ' ' || name[length - 1] == '.' || name[length - 1] == '>' || name[length - 1] == ':' || @@ -36,13 +38,13 @@ inline constexpr const char* nameof(const char* name, const size_t length) { name[length - 1] == '+' || name[length - 1] == '~' || name[length - 1] == '-' || name[length - 1] == '!') ? &name[length] - : nameof(name, length - 1); + : Nameof(name, length - 1); } // Used to obtain the string name of a variable, function and etc. template -inline constexpr const char* template_nameof(const char* name, const size_t length) { return nameof(name, length); } -#define NAMEOF(name) template_nameof(NAMEOF_RAW(name), sizeof(NAMEOF_RAW(name)) / sizeof(char) - 1) +inline constexpr const char* Nameof(const char* name, const size_t length) { return Nameof(name, length); } +#define NAMEOF(name) nameof::Nameof(NAMEOF_RAW(name), sizeof(NAMEOF_RAW(name)) / sizeof(char) - 1) #define NAMEOF_VARIABLE(variable) NAMEOF(variable) #define NAMEOF_VAR(var) NAMEOF_VARIABLE(var) @@ -51,4 +53,6 @@ inline constexpr const char* template_nameof(const char* name, const size_t leng #define NAMEOF_FUN(fun) NAMEOF_FUNCTION(fun) // Used to obtain the string name of a type. -#define NAMEOF_TYPE(type) template_nameof(NAMEOF_RAW(type), sizeof(NAMEOF_RAW(type)) / sizeof(char) - 1) +#define NAMEOF_TYPE(type) nameof::Nameof(NAMEOF_RAW(type), sizeof(NAMEOF_RAW(type)) / sizeof(char) - 1) + +} \ No newline at end of file