From 07c77b45ba9f74cfe1bed547bea1eeb705f0582b Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 13 Feb 2021 12:47:39 +0100 Subject: Support G++, support string type as template argument for convert() --- include/unicode.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/unicode.h b/include/unicode.h index d6f8e51..171496e 100644 --- a/include/unicode.h +++ b/include/unicode.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #ifdef __cpp_char8_t @@ -526,7 +527,7 @@ namespace unicode { typedef UTF, utf_back_insert_iterator> UTF_32; // From and To are facets - template + template::value && std::is_empty::value, bool> = true> std::basic_string convert(const std::basic_string& s) { std::basic_string result; @@ -561,7 +562,9 @@ namespace unicode { }; // From and To are from: utf8_t, char16_t and char32_t - template + template::value && std::is_trivial::value, bool> = true + > std::basic_string convert(const std::basic_string& s) { typedef UTF, utf_back_insert_iterator> UTF_Trait; @@ -573,6 +576,20 @@ namespace unicode { return result; } + template::value && !std::is_empty::value, bool> = true + > + ToContainer convert(const FromContainer& s) + { + typedef UTF, utf_back_insert_iterator> UTF_Trait; + + ToContainer result; + + std::copy(UTF_Trait::begin(s), UTF_Trait::end(s), UTF_Trait::back_inserter(result)); + + return result; + } + // basic type version template bool is_valid_utf(const std::basic_string& s) -- cgit v1.2.3