container.string: Add missing postblit

This commit is contained in:
Eugen Wissner 2017-10-08 15:53:29 +02:00
parent 17005e4ac9
commit 87bfd77373

View File

@ -26,7 +26,6 @@
*/ */
module tanya.container.string; module tanya.container.string;
import core.exception;
import std.algorithm.comparison; import std.algorithm.comparison;
import std.algorithm.mutation; import std.algorithm.mutation;
import std.algorithm.searching; import std.algorithm.searching;
@ -501,6 +500,14 @@ struct String
assert(s.length == 0); assert(s.length == 0);
} }
this(this) @nogc nothrow @trusted
{
auto buf = this.data[0 .. this.length_];
this.length_ = capacity_ = 0;
this.data = null;
insertBack(buf);
}
/** /**
* Destroys the string. * Destroys the string.
*/ */
@ -1112,15 +1119,13 @@ struct String
} }
/// ///
@safe @nogc unittest @nogc @safe unittest
{ {
auto s = String("Высоцкий"); auto s = String("Мне есть, что спеть, представ перед Всевышним.");
auto cp = s.byCodePoint(); auto cp = s.byCodePoint();
assert(cp.front == 'В'); assert(cp.front == 'М');
cp.popFront(); cp.popFront();
assert(cp.front == 'ы'); assert(cp.front == 'н');
cp.popFront();
assert(cp.front == 'с');
s = String("€"); s = String("€");
cp = s.byCodePoint(); cp = s.byCodePoint();
@ -1133,6 +1138,24 @@ struct String
assert(s.length == 4); assert(s.length == 4);
} }
///
@nogc @safe unittest
{
auto s = const String("Высоцкий");
auto cp1 = s.byCodePoint();
assert(cp1.front == 'В');
auto cp2 = cp1[];
cp1.popFront();
assert(cp1.front == 'ы');
assert(cp2.front == 'В');
cp2 = cp1.save();
cp1.popFront();
assert(cp1.front == 'с');
assert(cp2.front == 'ы');
}
/** /**
* Returns: $(D_KEYWORD true) if the string is empty. * Returns: $(D_KEYWORD true) if the string is empty.
*/ */
@ -1594,3 +1617,23 @@ struct String
mixin DefaultAllocator; mixin DefaultAllocator;
} }
// Postblit works.
@nogc @safe unittest
{
void internFunc(String arg)
{
}
void middleFunc(S...)(S args)
{
foreach (arg; args)
{
internFunc(arg);
}
}
void topFunc(String args)
{
middleFunc(args);
}
topFunc(String("asdf"));
}