diff --git a/octa/string.h b/octa/string.h index bbba350..5d65502 100644 --- a/octa/string.h +++ b/octa/string.h @@ -173,8 +173,16 @@ namespace octa { typedef StringBase String; + template + struct __OctaIsRangeTest { + template static char __octa_test(typename U::Category *); + template static int __octa_test(...); + static constexpr bool value = (sizeof(__octa_test(0)) == sizeof(char)); + }; + template - String concat(R range, String sep, F func) { + String __octa_concat(R range, const String &sep, F func, + EnableIf<__OctaIsRangeTest::value, bool> = true) { String ret; if (range.empty()) return move(ret); for (;;) { @@ -186,8 +194,15 @@ namespace octa { return move(ret); } + template + String __octa_concat(const T &v, const String &sep, F func, + EnableIf::value, bool> = true) { + return __octa_concat(each(v), sep, func); + } + template - String concat(R range, String sep = " ") { + String __octa_concat(R range, const String &sep, + EnableIf<__OctaIsRangeTest::value, bool> = true) { String ret; if (range.empty()) return move(ret); for (;;) { @@ -199,14 +214,30 @@ namespace octa { return move(ret); } + template + String __octa_concat(const T &v, const String &sep, + EnableIf::value, bool> = true) { + return __octa_concat(each(v), sep); + } + template - String concat(initializer_list il, String sep, F func) { - return concat(each(il), sep, func); + String concat(const T &v, const String &sep, F func) { + return __octa_concat(v, sep, func); } template - String concat(initializer_list il, String sep = " ") { - return concat(each(il), sep); + String concat(const T &v, const String &sep = " ") { + return __octa_concat(v, sep); + } + + template + String concat(initializer_list v, const String &sep, F func) { + return __octa_concat(each(v), sep, func); + } + + template + String concat(initializer_list v, const String &sep = " ") { + return __octa_concat(each(v), sep); } template