Massively overengineered logger to support different character types.
This commit is contained in:
57
source/mijin/internal/helpers.hpp
Normal file
57
source/mijin/internal/helpers.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(MIJIN_INTERNAL_HELPERS_HPP_INCLUDED)
|
||||
#define MIJIN_INTERNAL_HELPERS_HPP_INCLUDED 1
|
||||
|
||||
#include <type_traits>
|
||||
#include "../util/traits.hpp"
|
||||
|
||||
#define MIJIN_IDENTITY(what) what
|
||||
#define MIJIN_NULLIFY(what)
|
||||
|
||||
#define MIJIN_SMART_QUOTE(chr_type, text) \
|
||||
[]<typename TChar__>(TChar__) consteval \
|
||||
{ \
|
||||
if constexpr (std::is_same_v<TChar__, char>) \
|
||||
{ \
|
||||
return text; \
|
||||
} \
|
||||
else if constexpr (std::is_same_v<TChar__, wchar_t>) \
|
||||
{ \
|
||||
return L ## text; \
|
||||
} \
|
||||
else if constexpr (std::is_same_v<TChar__, char8_t>) \
|
||||
{ \
|
||||
return u8 ## text; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
static_assert(::mijin::always_false_v<TChar__>, "Invalid char type."); \
|
||||
} \
|
||||
}(chr_type())
|
||||
|
||||
#define MIJIN_SMART_STRINGIFY(chr_type, text) MIJIN_SMART_QUOTE(chr_type, #text)
|
||||
|
||||
#define MIJIN_DEFINE_CHAR_VERSIONS_IMPL(type_name, prefix_a, prefix_b, prefix_c, set_args) \
|
||||
prefix_a prefix_b(char) prefix_c \
|
||||
using C ## type_name = Base ## type_name <set_args(char)>; \
|
||||
\
|
||||
prefix_a prefix_b(wchar_t) prefix_c \
|
||||
using W ## type_name = Base ## type_name <set_args(wchar_t)>; \
|
||||
\
|
||||
prefix_a prefix_b(char8_t) prefix_c \
|
||||
using U ## type_name = Base ## type_name <set_args(char8_t)>; \
|
||||
\
|
||||
using type_name = Base ## type_name<>;
|
||||
|
||||
#define MIJIN_DEFINE_CHAR_VERSIONS_TMPL(type_name, remaining_args, set_args) \
|
||||
MIJIN_DEFINE_CHAR_VERSIONS_IMPL(type_name, template<, remaining_args, >, set_args)
|
||||
|
||||
#define MIJIN_DEFINE_CHAR_VERSIONS_CUSTOM(type_name, set_args) \
|
||||
MIJIN_DEFINE_CHAR_VERSIONS_IMPL(type_name, , MIJIN_NULLIFY, , set_args)
|
||||
|
||||
#define MIJIN_DEFINE_CHAR_VERSIONS(type_name) \
|
||||
MIJIN_DEFINE_CHAR_VERSIONS_CUSTOM(type_name, MIJIN_IDENTITY)
|
||||
|
||||
#endif // !defined(MIJIN_INTERNAL_HELPERS_HPP_INCLUDED)
|
||||
Reference in New Issue
Block a user