50void demo_basic_usage()
52 std::cout <<
"[1] Construction, concat, substr, at, flatten\n";
55 Rope<char> greeting{std::string_view(
"Hello, ")};
64 std::cout <<
"size: " <<
message.size() <<
"\n";
65 std::cout <<
"char at 7: '" <<
message.at(7) <<
"' (expect 'w')\n";
71 std::cout <<
"substr(7, 5): \"" << just_name.
to_string() <<
"\" (expect \"world\")\n\n";
74void demo_structural_sharing()
76 std::cout <<
"[2] Structural sharing: a copy is O(1) and independent\n";
79 Rope<char> original{std::string_view(
"immutable")};
85 std::cout <<
"original: \"" << original.
to_string() <<
"\"\n";
86 std::cout <<
"copy: \"" <<
copy.to_string() <<
"\"\n";
87 std::cout <<
"derived: \"" << derived.
to_string() <<
"\"\n";
88 std::cout <<
"original == copy (same content): " << std::boolalpha
89 << (original ==
copy) <<
"\n\n";
92void demo_text_editing()
94 std::cout <<
"[3] Text-editing style usage: insert and erase\n";
97 Rope<char> doc{std::string_view(
"The fox jumps over the dog.")};
98 std::cout <<
"original: \"" <<
doc.
to_string() <<
"\"\n";
104 std::cout <<
"after insert: \"" << with_adjective.
to_string() <<
"\"\n";
109 std::cout <<
"after erase: \"" << without_adjective.
to_string()
110 <<
"\" (back to the original text)\n";
111 std::cout <<
"doc unchanged by either edit: \"" <<
doc.to_string() <<
"\"\n\n";
117 std::cout <<
"\n=== Aleph::Rope: immutable, structurally-shared string ===\n\n";
120 demo_structural_sharing();
123 std::cout <<
"Done.\n";
Immutable, structurally-shared rope over a sequence of Char.
Rope erase(const size_t pos, const size_t len) const
Return a new rope with [pos, pos+len) removed.
Rope insert(const size_t pos, const Rope &other) const
Return a new rope with other inserted at pos.
Rope concat(const Rope &other) const
Return a new rope that is *this followed by other.
std::basic_string< Char > to_string() const
Return every character of this rope as a std::basic_string.
Rope substr(const size_t pos, const size_t len) const
Return a new rope holding [pos, pos+len) of *this.
Main namespace for Aleph-w library functions.
void message(const char *file, int line, const char *format,...)
Print an informational message with file and line info.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
void print_rule()
Prints a horizontal rule for example output separation.
Immutable, structurally-shared rope (Aleph::Rope) for large character sequences.