String.this - multiple declarations

Function String.this

Constructs the string from a stringish range.

this(S) (
  const S str,
  shared Allocator allocator = defaultAllocator
)
if (!isInfinite!S && isInputRange!S && isSomeChar!(ElementType!S));

Parameters

NameDescription
S String type.
str Initial string.
allocator Allocator.

Throws

UTFException.

Precondition

allocator is null.

Example

auto s = String("\u10437"w);
assert(s == "\u10437");

Example

auto s = String("Отказаться от вина - в этом страшная вина."d);
assert(s == "Отказаться от вина - в этом страшная вина.");

Function String.this

Initializes this string from another one.

this(S) (
  S init,
  shared Allocator allocator = defaultAllocator
) @trusted
if (is(S == String));

this(S) (
  ref S init,
  shared Allocator allocator = defaultAllocator
) @trusted
if (is(Unqual!S == String));

ref this (
  shared(tanya.memory.allocator.Allocator) allocator
) pure nothrow @nogc @safe;

If init is passed by value, it won't be copied, but moved. If the allocator of ($D_PARAM init) matches allocator, this will just take the ownership over init's storage, otherwise, the storage will be allocated with allocator. init will be destroyed at the end.

If init is passed by reference, it will be copied.

Parameters

NameDescription
S Source string type.
init Source string.
allocator Allocator.

Precondition

allocator is null.

Function String.this

Fills the string with n consecutive copies of character chr.

this(C) (
  const size_t n,
  const C chr,
  shared Allocator allocator = defaultAllocator
) @trusted
if (isSomeChar!C);

Parameters

NameDescription
C Type of the character to fill the string with.
n Number of characters to copy.
chr Character to fill the string with.
allocator Allocator.

Example

{
    auto s = String(1, 'О');
    assert(s.length == 2);
}
{
    auto s = String(3, 'О');
    assert(s.length == 6);
}
{
    auto s = String(8, 'О');
    assert(s.length == 16);
}