Skip to content

Commit 93a6816

Browse files
committed
Properly handling Char * arguments to addition
1 parent c1a3c3a commit 93a6816

2 files changed

Lines changed: 24 additions & 18 deletions

File tree

lib/inc/sys_string/impl/addition.h

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ namespace sysstr::util
127127
class addend<Storage, addition<Storage, First, Second>>
128128
{
129129
public:
130-
addend(const addition<Storage, First, Second> & val) noexcept:
131-
m_val(val)
130+
addend(addition<Storage, First, Second> && val) noexcept:
131+
m_val(std::move(val))
132132
{}
133133

134134
auto storage_size() const -> typename sys_string_t<Storage>::size_type
@@ -137,7 +137,7 @@ namespace sysstr::util
137137
auto append_to(sys_string_builder_t<Storage> & builder) const -> void
138138
{ this->m_val.append_to(builder); }
139139
private:
140-
const addition<Storage, First, Second> & m_val;
140+
addition<Storage, First, Second> && m_val;
141141
};
142142

143143
template<class Storage, class First, class Second>
@@ -148,22 +148,26 @@ namespace sysstr::util
148148
m_first{left},
149149
m_second{right}
150150
{}
151+
addition(First && left, const Second & right) noexcept:
152+
m_first{std::move(left)},
153+
m_second{right}
154+
{}
155+
addition(const First & left, Second && right) noexcept:
156+
m_first{left},
157+
m_second{std::move(right)}
158+
{}
159+
addition(First && left, Second && right) noexcept:
160+
m_first{std::move(left)},
161+
m_second{std::move(right)}
162+
{}
163+
164+
template <addable<Storage> T>
165+
friend auto operator+(addition && lhs, const T & rhs) noexcept
166+
{ return addition<Storage, addition, T>(std::move(lhs), rhs); }
151167

152-
friend auto operator+(addition && lhs, const sys_string_t<Storage> & rhs) noexcept
153-
{ return addition<Storage, addition, sys_string_t<Storage>>(std::move(lhs), rhs); }
154-
friend auto operator+(addition && lhs, char32_t rhs) noexcept
155-
{ return addition<Storage, addition, char32_t>(std::move(lhs), rhs); }
156-
template <std::ranges::forward_range Range>
157-
friend auto operator+(addition && lhs, const Range & rhs) noexcept
158-
{ return addition<Storage, addition, Range>(std::move(lhs), rhs); }
159-
160-
friend auto operator+(const sys_string_t<Storage> & lhs, addition && rhs) noexcept
161-
{ return addition<Storage, sys_string_t<Storage>, addition>(lhs, std::move(rhs)); }
162-
friend auto operator+(char32_t lhs, addition && rhs) noexcept
163-
{ return addition<Storage, char32_t, addition>(lhs, std::move(rhs)); }
164-
template <std::ranges::forward_range Range>
165-
friend auto operator+(const Range & lhs, addition && rhs) noexcept
166-
{ return addition<Storage, Range, addition>(lhs, std::move(rhs)); }
168+
template <addable<Storage> T>
169+
friend auto operator+(const T & lhs, addition && rhs) noexcept
170+
{ return addition<Storage, T, addition>(lhs, std::move(rhs)); }
167171

168172
template<class RHSFirst, class RHSSecond>
169173
friend auto operator+(addition && lhs, addition<Storage, RHSFirst, RHSSecond> && rhs) noexcept

test/test_general.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,8 @@ TEST_CASE( "Addition" ) {
749749

750750
const char * foo = "abc";
751751
CHECK(S("x") + foo == "xabc");
752+
753+
CHECK((S("x") + S("y")) + foo == "xyabc");
752754
}
753755

754756
TEST_CASE( "c_str" ) {

0 commit comments

Comments
 (0)