diff --git a/ostd/string.hh b/ostd/string.hh index 4d8e3ad..318e168 100644 --- a/ostd/string.hh +++ b/ostd/string.hh @@ -13,6 +13,7 @@ #include "ostd/range.hh" #include "ostd/vector.hh" #include "ostd/functional.hh" +#include "ostd/type_traits.hh" namespace ostd { static constexpr Size npos = -1; @@ -26,8 +27,18 @@ struct StringRangeBase: InputRange< StringRangeBase() = delete; StringRangeBase(T *beg, T *end): p_beg(beg), p_end(end) {} StringRangeBase(T *beg, Size n): p_beg(beg), p_end(beg + n) {} + /* TODO: traits for utf-16/utf-32 string lengths, for now assume char */ - StringRangeBase(T *beg): p_beg(beg), p_end(beg + strlen(beg)) {} + template + StringRangeBase(U beg, EnableIf< + IsConvertible::value && !IsArray::value, bool + > = true): p_beg(beg), p_end((T *)beg + strlen(beg)) { printf("ptr\n"); } + + template + StringRangeBase(U (&beg)[N], EnableIf< + IsConvertible::value, bool + > = true): p_beg(beg), + p_end(beg + N - (beg[N - 1] == '\0')) { printf("arr\n"); } template StringRangeBase(const StringBase &s): p_beg(s.data()),