Skip to content

Commit 2e124dd

Browse files
committed
Rope fixes
* empty Rope can now be be stored * ropeAppend now declares no return type
1 parent 96c1d70 commit 2e124dd

File tree

6 files changed

+19
-9
lines changed

6 files changed

+19
-9
lines changed

src/string19.lib/string19/Rope.Decimal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ template<size_t N> constexpr auto ropeCount(ADL*, Decimal<N>*) -> size_t {
1616
return c;
1717
}
1818

19-
template<size_t N> constexpr auto ropeAppend(ADL*, char*& data, Decimal<N>*) {
19+
template<size_t N> constexpr void ropeAppend(ADL*, char*& data, Decimal<N>*) {
2020
auto c = ropeCount(adl, decimal<N>);
2121
auto n = N;
2222
for (int o = c - 1; o >= 0; o--, n /= 10) data[o] = n % 10 + '0';

src/string19.lib/string19/Rope.Rope.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44

55
namespace string19 {
66

7-
template<class... Ts> constexpr auto ropeAppend(ADL*, char*& data, const Rope<Ts...>& rope) {
8-
rope.parts.visitAll([&](const auto& p) { ropeAppend(adl, data, p); });
9-
}
10-
117
template<class... Ts> constexpr auto ropeCount(ADL*, const Rope<Ts...>& rope) -> size_t {
128
auto result = size_t{};
139
rope.parts.visitAll([&](const auto& p) { result += ropeCount(adl, p); });
1410
return result;
1511
}
12+
template<> constexpr auto ropeCount(ADL*, const Rope<>&) -> size_t { return {}; }
13+
14+
template<class... Ts> constexpr void ropeAppend(ADL*, char*& data, const Rope<Ts...>& rope) {
15+
rope.parts.visitAll([&](const auto& p) { ropeAppend(adl, data, p); });
16+
}
17+
template<> constexpr void ropeAppend(ADL*, char*&, const Rope<>&) {}
1618

1719
} // namespace string19

src/string19.lib/string19/Rope.StringStore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace string19 {
66

77
template<size_t N> constexpr auto ropeCount(ADL*, const StringStore<N>&) -> size_t { return N; }
88

9-
template<size_t N> constexpr auto ropeAppend(ADL*, char*& data, const StringStore<N>& s) {
9+
template<size_t N> constexpr void ropeAppend(ADL*, char*& data, const StringStore<N>& s) {
1010
for (auto i = 0u; i < N; ++i) *data++ = s[i];
1111
}
1212

src/string19.lib/string19/Rope.StringView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace string19 {
66

77
constexpr auto ropeCount(ADL*, StringView sv) -> size_t { return sv.count; }
88

9-
constexpr auto ropeAppend(ADL*, char*& data, StringView sv) {
9+
constexpr void ropeAppend(ADL*, char*& data, StringView sv) {
1010
for (auto i = 0u; i < sv.count; ++i) *data++ = sv[i];
1111
}
1212

src/string19.lib/string19/Rope.char.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ namespace string19 {
55

66
constexpr auto ropeCount(ADL*, char) -> size_t { return 1; }
77

8-
constexpr auto ropeAppend(ADL*, char*& data, char c) { *data++ = c; }
8+
constexpr void ropeAppend(ADL*, char*& data, char c) { *data++ = c; }
99

1010
} // namespace string19

src/string19.lib/string19/Rope.join.test.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111

1212
using namespace string19;
1313

14+
TEST(Rope, joinEmpty) {
15+
constexpr auto rope = Seperator{','}.join();
16+
constexpr auto N = ropeCount(rope);
17+
constexpr auto store = ropeStore<N>(rope);
18+
static_assert(viewStore(store) == viewLiteral(""));
19+
EXPECT_EQ(store, storeLiteral(""));
20+
}
21+
1422
TEST(Rope, joinChar) {
1523
constexpr auto rope = Seperator{','}.join('1', '2', '3');
1624
constexpr auto N = ropeCount(rope);
@@ -20,7 +28,7 @@ TEST(Rope, joinChar) {
2028
}
2129

2230
TEST(Rope, joinView) {
23-
constexpr auto rope = Seperator{viewLiteral(", ")}.join('1', '2', '3');
31+
constexpr auto rope = Seperator{viewLiteral(", ")}.join(viewLiteral("1"), '2', '3');
2432
constexpr auto N = ropeCount(rope);
2533
constexpr auto store = ropeStore<N>(rope);
2634
static_assert(viewStore(store) == viewLiteral("1, 2, 3"));

0 commit comments

Comments
 (0)