From 52d4375b10d920a59f1309c272a2e525feb1c25d Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 1 Jan 2022 20:25:34 +0100 Subject: Separated out headers files; optimizations; type traits; better naming --- include/unicode/type_traits.h | 77 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 include/unicode/type_traits.h (limited to 'include/unicode/type_traits.h') diff --git a/include/unicode/type_traits.h b/include/unicode/type_traits.h new file mode 100644 index 0000000..3ee1d82 --- /dev/null +++ b/include/unicode/type_traits.h @@ -0,0 +1,77 @@ +#pragma once + +#include "utf.h" + +#include +#include + +namespace unicode { + + using namespace detail; + + // helper traits + + template + struct is_encoding + { + static const bool value{std::is_empty_v}; + }; + + template + inline constexpr bool is_encoding_v {is_encoding::value}; + + template + struct is_container + { + static const bool value{!std::is_empty_v}; + }; + + template + inline constexpr bool is_container_v {is_container::value}; + + template + struct is_char + { + static const bool value{std::is_trivial_v && std::is_scalar_v && !std::is_empty_v}; + }; + + template + inline constexpr bool is_char_v {is_char::value}; + + template + struct is_utf_encoding + { + static const bool value{std::is_same_v, utf_back_insert_iterator>>}; + }; + + template + inline constexpr bool is_utf_encoding_v {is_utf_encoding::value}; + + template + struct is_utf_8 + { + static const bool value{std::is_trivial_v && sizeof(T) == 1}; + }; + + template + inline constexpr bool is_utf_8_v {is_utf_8::value}; + + template + struct is_utf_16 + { + static const bool value{std::is_trivial_v && sizeof(T) == 2}; + }; + + template + inline constexpr bool is_utf_16_v {is_utf_16::value}; + + template + struct is_utf_32 + { + static const bool value{std::is_trivial_v && sizeof(T) == 4}; + }; + + template + inline constexpr bool is_utf_32_v {is_utf_32::value}; + +} // namespace unicode -- cgit v1.2.3