9 #ifndef __NODAMUSHI_CONST_STRING_HPP__ 10 #define __NODAMUSHI_CONST_STRING_HPP__ 16 # if __cplusplus >= 201703 17 # include <string_view> 23 # ifndef _ENABLE_GNU_TEMPLATE_STRING_ 24 # define _ENABLE_GNU_TEMPLATE_STRING_ 26 # pragma GCC diagnostic ignored "-Wgnu-string-literal-operator-template" 36 # if __cplusplus >= 201703 38 using optional = std::optional<T>;
39 constexpr
inline bool is_empty(
const std::string_view& v){
return v.empty();}
42 constexpr
inline bool is_empty(
const char* v){
return !v || *v ==
'\0';}
43 inline bool is_empty(
const std::string& v){
return v.empty();}
50 template<
char... chars>
56 template<
char... chars>
58 if(
sizeof...(chars) <= index){
return '\0';}
59 char TEXT[] = {chars...};
63 constexpr
char at(
const char (&array)[N],
size_t index)
65 return index < N?array[index]:
'\0';
67 template<
size_t MAX_SIZE,
size_t N>
68 constexpr
char at0(
const char (&array)[N])
70 static_assert(N <= MAX_SIZE,
"N<=MAX_SIZE.");
71 return N != 0?array[0]:
'\0';
75 template<
char... chars>
81 # if __cplusplus >= 201703 82 # define NODAMUSHI_LOCAL_CONST_STRING(CHARS,varname) std::string_view varname =::nodamushi::details::template_text<CHARS...>::TEXT 84 # define NODAMUSHI_LOCAL_CONST_STRING(CHARS,varname) constexpr char varname[] = {CHARS...,'\0'} 89 template<
char... chars>
106 template<
char... chars>
107 struct template_char_length{
109 static constexpr
size_t count(){
110 char TEXT[] = {chars...,
'\0'};
111 for(
size_t i=0;i<
sizeof...(chars);i++){
112 if(TEXT[i] ==
'\0')
return i;
114 return sizeof...(chars);
118 static constexpr
size_t value = count();
123 # if __cplusplus >= 201703 125 static inline constexpr
char arr[] = {chars...};
127 static inline constexpr std::string_view
TEXT = std::string_view(
130 static constexpr
char TEXT[] = {chars...,
'\0'};
138 #endif // __NODAMUSHI_CONST_STRING_HPP__ std::ostream & print_const_string(std::ostream &o)
constexpr char at0(const char(&array)[N])
constexpr char at_const_string(size_t index)
constexpr size_t get_const_string_length()
const char * const_string
constexpr const_string get_const_string()
#define NODAMUSHI_LOCAL_CONST_STRING(CHARS, varname)
static constexpr size_t value
constexpr bool is_empty(const char *v)
constexpr char at(const char(&array)[N], size_t index)
static constexpr char TEXT[]