diff --git a/include/rexy/string_base.hpp b/include/rexy/string_base.hpp index ba4f028..dd11dc4 100644 --- a/include/rexy/string_base.hpp +++ b/include/rexy/string_base.hpp @@ -405,6 +405,9 @@ namespace rexy{ REXY_CPP20_CONSTEXPR pointer release(void)noexcept(noexcept(this->allocate(0))); using detail::hasallocator::allocator; + + constexpr basic_string_view create_view(void)const noexcept; + constexpr basic_string_view create_view(const_iterator start, const_iterator fin)const noexcept; }; //Like an expression template but not really @@ -592,11 +595,11 @@ namespace rexy{ #define HAS_MEMFUN_WITH_RET(type, ret, fun, ...) \ template \ struct has_##fun##_f{ \ - std::false_type check(...); \ + static std::false_type check(...); \ template \ - auto check(type* u) -> std::enable_if().fun(__VA_ARGS__),ret>,std::true_type>; \ + static auto check(type* u) -> std::enable_if_t().fun(__VA_ARGS__)),ret>,std::true_type>; \ \ - static constexpr bool value = decltype(check(std::declval()))::value; \ + static constexpr bool value = decltype(check(std::declval*>()))::value; \ }; \ template \ static constexpr bool has_##fun##_f_v = has_##fun##_f::value @@ -604,11 +607,11 @@ namespace rexy{ #define HAS_MEMOP_WITH_RET(type, ret, opname, op, ...) \ template \ struct has_##opname##_f{ \ - std::false_type check(...); \ + static std::false_type check(...); \ template \ - auto check(type* u) -> std::enable_if().operator op(__VA_ARGS__),ret>,std::true_type>; \ + static auto check(type* u) -> std::enable_if_t().operator op(__VA_ARGS__)),ret>,std::true_type>; \ \ - static constexpr bool value = decltype(check(std::declval()))::value; \ + static constexpr bool value = decltype(check(std::declval*>()))::value; \ }; \ template \ static constexpr bool has_##opname##_f_v = has_##opname##_f::value @@ -629,6 +632,10 @@ namespace rexy{ }; template static constexpr bool is_string_v = is_string::value; + + static_assert(is_string_v>); + + template struct are_strings{ static constexpr bool value = (is_string::value && ...); @@ -701,12 +708,14 @@ namespace rexy{ { return string_cat_expr(std::forward(l), std::forward(r)); } + //String + char pointer template::value,int> = 0> constexpr auto operator+(typename std::decay_t::const_pointer left, Right&& right) noexcept(noexcept(::new (nullptr) string_cat_expr(rexy::basic_string_view(left), std::forward(right)))) { return string_cat_expr(rexy::basic_string_view(left), std::forward(right)); } + //Char pointer + string template::value,int> = 0> constexpr auto operator+(Left&& left, typename std::decay_t::const_pointer right) noexcept(noexcept(::new (nullptr) string_cat_expr(std::forward(left), rexy::basic_string_view(right)))) @@ -720,10 +729,26 @@ namespace rexy{ constexpr auto operator+(Left&& left, Right&& right){ return string_cat_expr(std::forward(left), std::forward(right)); } + //Expr + string template::value && is_string::value,int> = 0> constexpr auto operator+(Left&& left, Right&& right){ return string_cat_expr(std::forward(left), std::forward(right)); } + //Expr + expr + template::value,int> = 0> + constexpr auto operator+(Left&& left, Right&& right){ + return string_cat_expr(std::forward(left), std::forward(right)); + } + //Expr + char pointer + template::value,int> = 0> + constexpr auto operator+(Left&& left, typename std::decay_t::const_pointer right){ + return string_cat_expr(std::forward(left), rexy::basic_string_view(right)); + } + //char pointer + Expr + template::value,int> = 0> + constexpr auto operator+(typename std::decay_t::const_pointer left, Right&& right){ + return string_cat_expr(rexy::basic_string_view(left), std::forward(right)); + } //String concat assignment template::value,int> = 0> diff --git a/include/rexy/string_base.tpp b/include/rexy/string_base.tpp index 54cbe09..3244873 100644 --- a/include/rexy/string_base.tpp +++ b/include/rexy/string_base.tpp @@ -336,6 +336,15 @@ namespace rexy{ this->set_short_length(0); return retval; } + template + constexpr auto basic_string::create_view(void)const noexcept -> basic_string_view{ + const auto ptr = this->get_pointer(); + return basic_string_view(ptr, ptr + this->length()); + } + template + constexpr auto basic_string::create_view(const_iterator start, const_iterator fin)const noexcept -> basic_string_view{ + return basic_string_view(start, fin); + } template REXY_CPP20_CONSTEXPR basic_string& basic_string::_copy_string(const_pointer s, size_type len)