2018-04-10 19:32:51 +00:00
|
|
|
// _ _ __ _____
|
|
|
|
// | \ | | / _| / ____|_ _
|
|
|
|
// | \| | __ _ _ __ ___ ___ ___ | |_ | | _| |_ _| |_
|
|
|
|
// | . ` |/ _` | '_ ` _ \ / _ \/ _ \| _| | | |_ _|_ _|
|
|
|
|
// | |\ | (_| | | | | | | __/ (_) | | | |____|_| |_|
|
|
|
|
// |_| \_|\__,_|_| |_| |_|\___|\___/|_| \_____|
|
|
|
|
// https://github.com/Neargye/nameof
|
2018-08-02 14:51:44 +00:00
|
|
|
// vesion 0.5.0
|
2018-03-17 03:09:49 +00:00
|
|
|
//
|
2018-03-18 16:34:09 +00:00
|
|
|
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
2018-04-02 11:49:15 +00:00
|
|
|
// Copyright (c) 2016, 2018 Daniil Goncharov <neargye@gmail.com>.
|
2018-03-17 03:09:49 +00:00
|
|
|
//
|
2018-03-24 08:58:08 +00:00
|
|
|
// 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:
|
2018-03-17 03:09:49 +00:00
|
|
|
//
|
2018-03-24 08:58:08 +00:00
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
2018-03-17 03:27:47 +00:00
|
|
|
// copies or substantial portions of the Software.
|
2018-03-17 03:09:49 +00:00
|
|
|
//
|
2018-03-24 08:58:08 +00:00
|
|
|
// 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
|
2018-03-17 03:27:47 +00:00
|
|
|
// SOFTWARE.
|
|
|
|
|
2018-03-17 04:31:59 +00:00
|
|
|
#pragma once
|
2018-04-10 18:09:23 +00:00
|
|
|
|
2018-03-17 05:06:38 +00:00
|
|
|
#include <cstddef>
|
2018-07-13 15:18:52 +00:00
|
|
|
#include <type_traits>
|
2018-08-06 14:53:58 +00:00
|
|
|
#include <string>
|
2018-08-02 14:51:44 +00:00
|
|
|
#include <ostream>
|
2018-03-17 04:31:59 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201304L
|
|
|
|
# define NAMEOF_HAS_CONSTEXPR14 1
|
2018-08-03 12:34:46 +00:00
|
|
|
#endif
|
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
#if defined(__clang__) || defined(_MSC_VER)
|
|
|
|
# define NAMEOF_TYPE_CONSTEXPR constexpr
|
|
|
|
# define NAMEOF_TYPE_HAS_CONSTEXPR 1
|
|
|
|
#else
|
|
|
|
# define NAMEOF_TYPE_CONSTEXPR inline
|
|
|
|
#endif
|
|
|
|
|
2018-04-04 12:19:02 +00:00
|
|
|
namespace nameof {
|
2018-04-10 18:09:23 +00:00
|
|
|
|
2018-04-04 12:19:02 +00:00
|
|
|
namespace detail {
|
2018-04-04 16:36:18 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
namespace nstd {
|
|
|
|
|
2018-08-02 14:51:44 +00:00
|
|
|
template <typename T>
|
|
|
|
struct identity {
|
|
|
|
using type = T;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
2018-08-26 20:30:16 +00:00
|
|
|
using identity_t = typename identity<T>::type;
|
|
|
|
|
|
|
|
// Removes all pointer from the given type.
|
|
|
|
template <typename T>
|
|
|
|
struct remove_all_p
|
2018-08-02 16:01:25 +00:00
|
|
|
: std::conditional<std::is_pointer<T>::value,
|
2018-08-26 20:30:16 +00:00
|
|
|
remove_all_p<typename std::remove_pointer<T>::type>,
|
|
|
|
identity<T>
|
|
|
|
>::type {};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
using remove_all_p_t = typename remove_all_p<T>::type;
|
|
|
|
|
|
|
|
// Removes const, volatile, reference specifiers from the given type.
|
|
|
|
template <typename T>
|
|
|
|
struct remove_cvr {
|
|
|
|
using type = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
using remove_cvr_t = typename remove_cvr<T>::type;
|
|
|
|
|
|
|
|
// Removes all const, volatile, reference, pointer specifiers from the given type.
|
|
|
|
template <typename T>
|
|
|
|
struct remove_all_cvrp {
|
|
|
|
using type = typename remove_cvr<typename remove_all_p<typename remove_cvr<T>::type>::type>::type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
using remove_all_cvrp_t = typename remove_all_cvrp<T>::type;
|
|
|
|
|
|
|
|
// Removes all const, volatile, reference, pointer, array extents specifiers from the given type.
|
|
|
|
template <typename T, typename U = typename remove_all_cvrp<T>::type>
|
|
|
|
struct remove_all_cvrpe
|
|
|
|
: std::conditional<std::is_array<U>::value,
|
|
|
|
remove_all_cvrpe<typename std::remove_all_extents<U>::type>,
|
|
|
|
identity<U>
|
|
|
|
>::type {};
|
2018-08-03 12:34:46 +00:00
|
|
|
|
2018-08-06 11:01:40 +00:00
|
|
|
template <typename T>
|
2018-08-26 20:30:16 +00:00
|
|
|
using remove_all_cvrpe_t = typename remove_all_cvrpe<T>::type;
|
2018-08-06 11:01:40 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
} // namespace nstd
|
|
|
|
|
|
|
|
constexpr bool StrEquals(const char* lhs, const char* rhs, std::size_t size) {
|
|
|
|
#if defined(NAMEOF_HAS_CONSTEXPR14)
|
|
|
|
for (std::size_t i = 0; i < size; ++i) {
|
|
|
|
if (lhs[i] != rhs[i]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
#else
|
2018-08-07 16:13:40 +00:00
|
|
|
return (size == 0) ? (lhs[0] == rhs[0]) : ((lhs[size - 1] == rhs[size - 1]) && StrEquals(lhs, rhs, size - 1));
|
2018-08-26 20:30:16 +00:00
|
|
|
#endif
|
2018-08-06 14:53:58 +00:00
|
|
|
}
|
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr std::size_t StrLen(const char* str, std::size_t size = 0) {
|
|
|
|
#if defined(NAMEOF_HAS_CONSTEXPR14)
|
|
|
|
for (; str != nullptr; ++size) {
|
|
|
|
if (str[size] == '\0') {
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
#else
|
|
|
|
return (str[size] == '\0') ? size : StrLen(str, size + 1);
|
|
|
|
#endif
|
2018-08-07 16:13:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// STD like compile-time const char* string.
|
2018-08-02 14:51:44 +00:00
|
|
|
class cstring final {
|
|
|
|
const char* str_;
|
2018-08-26 20:30:16 +00:00
|
|
|
std::size_t size_;
|
2018-08-02 14:51:44 +00:00
|
|
|
|
|
|
|
public:
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr cstring(const char* str, std::size_t size, std::size_t prefix = 0, std::size_t suffix = 0) noexcept
|
2018-08-07 16:13:40 +00:00
|
|
|
: str_{str + prefix},
|
2018-08-26 20:30:16 +00:00
|
|
|
size_{size - prefix - suffix} {}
|
2018-08-02 14:51:44 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr cstring() noexcept : cstring{nullptr, 0, 0, 0} {}
|
2018-08-07 16:13:40 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr cstring(const char* str) noexcept : cstring{str, StrLen(str), 0, 0} {}
|
2018-08-02 14:51:44 +00:00
|
|
|
|
|
|
|
cstring(const cstring&) = default;
|
|
|
|
|
|
|
|
cstring(cstring&&) = default;
|
|
|
|
|
|
|
|
cstring& operator=(const cstring&) = default;
|
|
|
|
|
|
|
|
cstring& operator=(cstring&&) = default;
|
|
|
|
|
|
|
|
~cstring() = default;
|
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr std::size_t size() const noexcept { return size_; }
|
2018-08-02 14:51:44 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr std::size_t length() const noexcept { return size_; }
|
2018-08-02 14:51:44 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr bool empty() const noexcept { return size_ == 0; }
|
2018-08-02 14:51:44 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr const char* begin() const noexcept { return str_; }
|
2018-08-02 14:51:44 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr const char* end() const noexcept { return str_ + size_; }
|
2018-08-02 14:51:44 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr const char* cbegin() const noexcept { return begin(); }
|
2018-08-02 14:51:44 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr const char* cend() const noexcept { return end(); }
|
2018-08-02 14:51:44 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr const char& operator[](std::size_t i) const { return str_[i]; }
|
2018-08-02 14:51:44 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr const char& front() const { return str_[0]; }
|
2018-08-03 12:19:51 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr const char& back() const { return str_[size_ - 1]; }
|
2018-08-03 12:19:51 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr const char* data() const noexcept { return str_; }
|
2018-08-03 12:19:51 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr cstring remove_prefix(std::size_t n) const {
|
2018-08-03 12:34:46 +00:00
|
|
|
return {str_ + n, size_ - n};
|
2018-08-03 12:19:51 +00:00
|
|
|
}
|
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr cstring add_prefix(std::size_t n) const {
|
|
|
|
return {str_ - n, size_ + n};
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr cstring remove_suffix(std::size_t n) const {
|
2018-08-03 12:34:46 +00:00
|
|
|
return {str_, size_ - n};
|
2018-08-03 12:19:51 +00:00
|
|
|
}
|
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr cstring add_suffix(std::size_t n) const {
|
|
|
|
return {str_, size_ + n};
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr cstring substr(std::size_t pos, std::size_t n) const {
|
2018-08-03 12:19:51 +00:00
|
|
|
return {str_ + pos, n};
|
|
|
|
}
|
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
friend constexpr bool operator==(cstring lhs, cstring rhs) noexcept {
|
2018-08-26 20:30:16 +00:00
|
|
|
return (lhs.size_ == rhs.size_) && StrEquals(lhs.str_, rhs.str_, lhs.size_);
|
2018-08-03 12:19:51 +00:00
|
|
|
}
|
2018-08-02 14:51:44 +00:00
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
friend constexpr bool operator!=(cstring lhs, cstring rhs) noexcept {
|
2018-08-03 12:34:46 +00:00
|
|
|
return !(lhs == rhs);
|
2018-08-02 14:51:44 +00:00
|
|
|
}
|
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
friend std::ostream& operator<<(std::ostream& os, cstring str) {
|
2018-08-26 20:30:16 +00:00
|
|
|
os.write(str.str_, str.size_);
|
2018-08-03 12:34:46 +00:00
|
|
|
return os;
|
|
|
|
}
|
2018-08-02 14:51:44 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
operator std::string() const { return std::string(str_, size_); }
|
2018-08-03 12:34:46 +00:00
|
|
|
};
|
2018-08-02 14:51:44 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
constexpr bool IsLexeme(char s) noexcept {
|
2018-08-06 11:01:40 +00:00
|
|
|
return !((s >= '0' && s <= '9') || (s >= 'a' && s <= 'z') || (s >= 'A' && s <= 'Z') || s == '_');
|
2018-08-02 14:51:44 +00:00
|
|
|
}
|
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
#if defined(NAMEOF_HAS_CONSTEXPR14)
|
2018-08-26 23:57:25 +00:00
|
|
|
constexpr cstring NameofPretty(cstring name, bool with_suffix) noexcept {
|
2018-08-26 20:30:16 +00:00
|
|
|
std::size_t s = 0;
|
|
|
|
for (std::size_t i = name.size(), h = 0; i > 0; --i) {
|
|
|
|
if (name[i - 1] == '>') {
|
|
|
|
++h;
|
|
|
|
++s;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name[i - 1] == '<') {
|
|
|
|
--h;
|
|
|
|
++s;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (h == 0) {
|
|
|
|
break;
|
2018-08-26 23:57:25 +00:00
|
|
|
} else {
|
|
|
|
++s;
|
|
|
|
continue;
|
2018-08-02 14:51:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
for (std::size_t i = name.size() - s; i > 0; --i) {
|
|
|
|
if (IsLexeme(name[i - 1])) {
|
|
|
|
return name.remove_prefix(i).remove_suffix(with_suffix ? 0 : s);
|
2018-08-06 11:01:40 +00:00
|
|
|
}
|
2018-08-26 20:30:16 +00:00
|
|
|
}
|
2018-08-26 23:57:25 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
return name.remove_suffix(with_suffix ? 0 : s);
|
|
|
|
}
|
|
|
|
#else
|
2018-08-26 23:57:25 +00:00
|
|
|
constexpr std::size_t NameofBaseImpl1(cstring name, std::size_t h = 0, std::size_t s = 0) noexcept {
|
2018-08-26 20:30:16 +00:00
|
|
|
return name[name.size() - 1 - s] == '>'
|
|
|
|
? NameofBaseImpl1(name, h + 1, s + 1)
|
|
|
|
: name[name.size() - 1 - s] == '<'
|
|
|
|
? NameofBaseImpl1(name, h - 1, s + 1)
|
|
|
|
: h == 0 ? s : NameofBaseImpl1(name, h, s + 1);
|
|
|
|
}
|
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
constexpr cstring NameofBaseImpl2(cstring name, const std::size_t p = 0) noexcept {
|
2018-08-26 20:30:16 +00:00
|
|
|
return p == name.size() ? name : IsLexeme(name[name.size() - 1 - p])
|
|
|
|
? name.remove_prefix(name.size() - p)
|
|
|
|
: NameofBaseImpl2(name, p + 1);
|
|
|
|
}
|
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
constexpr cstring NameofBaseImpl3(cstring name, std::size_t s, bool with_suffix) noexcept {
|
2018-08-26 20:30:16 +00:00
|
|
|
return NameofBaseImpl2(name.remove_suffix(s)).add_suffix(with_suffix ? s : 0);
|
|
|
|
}
|
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
constexpr cstring NameofPretty(cstring name, bool with_suffix) noexcept {
|
2018-08-26 20:30:16 +00:00
|
|
|
return NameofBaseImpl3(name, NameofBaseImpl1(name), with_suffix);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
constexpr cstring RemoveSpace(cstring name) noexcept {
|
2018-08-26 20:30:16 +00:00
|
|
|
return name.back() == ' ' ? RemoveSpace(name.remove_suffix(1)) : name;
|
|
|
|
}
|
2018-08-06 11:01:40 +00:00
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
constexpr cstring RemoveClassPrefix(cstring name) noexcept {
|
2018-08-26 20:30:16 +00:00
|
|
|
return (name.size() > sizeof("class") && name[0] == 'c' && name[1] == 'l' &&
|
|
|
|
name[2] == 'a' && name[3] == 's' && name[4] == 's' && name[5] == ' ')
|
|
|
|
? name.remove_prefix(sizeof("class"))
|
|
|
|
: name;
|
2018-08-02 14:51:44 +00:00
|
|
|
}
|
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
constexpr cstring RemoveEnumPrefix(cstring name) noexcept {
|
2018-08-26 20:30:16 +00:00
|
|
|
return (name.size() > sizeof("enum") && name[0] == 'e' && name[1] == 'n' &&
|
|
|
|
name[2] == 'u' && name[3] == 'm' && name[4] == ' ')
|
|
|
|
? name.remove_prefix(sizeof("enum"))
|
|
|
|
: name;
|
|
|
|
}
|
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
constexpr cstring RemoveStructPrefix(cstring name) noexcept {
|
2018-08-26 20:30:16 +00:00
|
|
|
return (name.size() > sizeof("struct") && name[0] == 's' && name[1] == 't' &&
|
|
|
|
name[2] == 'r' && name[3] == 'u' && name[4] == 'c' && name[5] == 't' && name[6] == ' ')
|
|
|
|
? name.remove_prefix(sizeof("struct"))
|
|
|
|
: name;
|
|
|
|
}
|
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
constexpr cstring NameofTypeRawPretty(cstring name) noexcept {
|
|
|
|
return RemoveClassPrefix(RemoveStructPrefix(RemoveEnumPrefix(RemoveSpace(name))));
|
2018-08-02 14:51:44 +00:00
|
|
|
}
|
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
template <typename T>
|
|
|
|
NAMEOF_TYPE_CONSTEXPR cstring NameofTypeRaw() noexcept {
|
|
|
|
#if defined(__clang__)
|
|
|
|
return {__PRETTY_FUNCTION__,
|
|
|
|
sizeof(__PRETTY_FUNCTION__) - 1,
|
|
|
|
sizeof("nameof::detail::cstring nameof::detail::NameofTypeRaw() [T = nameof::detail::nstd::identity<") - 1,
|
|
|
|
sizeof(">]") - 1};
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
return {__PRETTY_FUNCTION__,
|
|
|
|
sizeof(__PRETTY_FUNCTION__) - 1,
|
|
|
|
sizeof("nameof::detail::cstring nameof::detail::NameofTypeRaw() [with T = nameof::detail::nstd::identity<") - 1,
|
|
|
|
sizeof(">]") - 1};
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
return {__FUNCSIG__,
|
|
|
|
sizeof(__FUNCSIG__) - 1,
|
|
|
|
sizeof("class nameof::detail::cstring __cdecl nameof::detail::NameofTypeRaw<struct nameof::detail::nstd::identity<") - 1,
|
|
|
|
sizeof(">>(void) noexcept") - 1};
|
|
|
|
#else
|
|
|
|
return {};
|
|
|
|
#endif
|
|
|
|
}
|
2018-08-02 14:51:44 +00:00
|
|
|
|
2018-07-13 15:18:52 +00:00
|
|
|
template <typename T,
|
2018-08-02 14:51:44 +00:00
|
|
|
typename = typename std::enable_if<!std::is_reference<T>::value &&
|
|
|
|
!std::is_void<T>::value>::type>
|
2018-08-26 23:57:25 +00:00
|
|
|
constexpr cstring Nameof(const T&, const char* name, std::size_t size, bool with_suffix) noexcept {
|
|
|
|
return NameofPretty({name, size}, with_suffix);
|
2018-07-13 15:18:52 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 14:51:44 +00:00
|
|
|
template <typename T,
|
|
|
|
typename = typename std::enable_if<!std::is_enum<T>::value &&
|
|
|
|
!std::is_function<T>::value &&
|
|
|
|
!std::is_member_function_pointer<T>::value>::type>
|
2018-08-26 23:57:25 +00:00
|
|
|
constexpr cstring Nameof(T&&, const char*, std::size_t, bool) = delete;
|
2018-08-26 20:30:16 +00:00
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
constexpr cstring NameofRaw(const char* name, std::size_t size) noexcept {
|
2018-08-26 20:30:16 +00:00
|
|
|
return {name, size};
|
|
|
|
}
|
2018-08-02 14:51:44 +00:00
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
} // namespace detail
|
2018-08-02 14:51:44 +00:00
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
template <typename T, typename H = detail::nstd::identity<T>>
|
|
|
|
NAMEOF_TYPE_CONSTEXPR detail::cstring NameofType(bool pretty = true) noexcept {
|
|
|
|
return pretty ? detail::NameofTypeRawPretty(detail::NameofTypeRaw<H>()) : detail::NameofTypeRaw<H>();
|
2018-08-02 14:51:44 +00:00
|
|
|
}
|
2018-07-13 15:18:52 +00:00
|
|
|
|
2018-04-04 16:36:18 +00:00
|
|
|
} // namespace nameof
|
2018-03-22 14:09:55 +00:00
|
|
|
|
2018-08-26 20:30:16 +00:00
|
|
|
#if defined(__clang__)
|
|
|
|
# if __has_feature(cxx_rtti)
|
|
|
|
# define NAMEOF_HAS_RTTI 1
|
|
|
|
# endif
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
# if defined(__GXX_RTTI)
|
|
|
|
# define NAMEOF_HAS_RTTI 1
|
|
|
|
# endif
|
|
|
|
#elif defined(_MSC_VER) && defined(_CPPRTTI)
|
|
|
|
# if defined(_CPPRTTI)
|
|
|
|
# define NAMEOF_HAS_RTTI 1
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(NAMEOF_HAS_RTTI) || defined(_MSC_VER)
|
|
|
|
#include <typeinfo>
|
|
|
|
|
2018-08-02 14:51:44 +00:00
|
|
|
// Used to obtain the raw string name of a variable, type, member, function, macros.
|
2018-08-26 23:57:25 +00:00
|
|
|
# define NAMEOF_RAW(name) ::nameof::detail::NameofRaw(#name, ((sizeof(#name) / sizeof(char)) - 1) + (0 * sizeof(typeid(name))))
|
2018-08-26 20:30:16 +00:00
|
|
|
#elif defined(__clang__) || defined(__GNUC__)
|
2018-08-02 14:51:44 +00:00
|
|
|
// Used to obtain the raw string name of a variable, type, member, function, macros.
|
2018-08-26 23:57:25 +00:00
|
|
|
# define NAMEOF_RAW(name) ::nameof::detail::NameofRaw(#name, ((sizeof(#name) / sizeof(char)) - 1) + (0 * sizeof(void(*)(__typeof__(name)))))
|
2018-04-04 12:19:02 +00:00
|
|
|
#endif
|
2018-07-13 15:18:52 +00:00
|
|
|
|
2018-08-02 14:51:44 +00:00
|
|
|
// Used to obtain the simple (unqualified) string name of a variable, member, function.
|
2018-08-26 23:57:25 +00:00
|
|
|
#define NAMEOF(name) ::nameof::detail::Nameof<decltype(name)>(name, #name, (sizeof(#name) / sizeof(char)) - 1, false)
|
2018-08-02 15:18:59 +00:00
|
|
|
|
2018-08-06 11:01:40 +00:00
|
|
|
// Used to obtain the full string name of a variable, member, function.
|
2018-08-26 23:57:25 +00:00
|
|
|
#define NAMEOF_FULL(name) ::nameof::detail::Nameof<decltype(name)>(name, #name, (sizeof(#name) / sizeof(char)) - 1, true)
|
2018-08-02 15:18:59 +00:00
|
|
|
|
2018-08-26 23:57:25 +00:00
|
|
|
// Used to obtain the string name of a type.
|
|
|
|
#define NAMEOF_TYPE(var) ::nameof::NameofType<decltype(var)>(true)
|
|
|
|
#define NAMEOF_TYPE_T(type) ::nameof::NameofType<type>(true)
|