Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 41 additions & 15 deletions std/range/primitives.d
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ $(BOOKTABLE ,
))
)

$(B NEW:) `version(NoAutoDecode)` allows to use Phobos ranges without
auto-decoding. This is an experimental option to test the feasibility
of disabling auto-decoding by default. You have been warned.

Source: $(PHOBOSSRC std/range/_primitives.d)

License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
Expand Down Expand Up @@ -2325,14 +2329,25 @@ if (!isNarrowString!(T[]) && !is(T[] == void[]))
assert(c.front == 1);
}

/// ditto
@property dchar front(T)(T[] a) @safe pure
if (isNarrowString!(T[]))
version(NoAutoDecode)
{
import std.utf : decode;
assert(a.length, "Attempting to fetch the front of an empty array of " ~ T.stringof);
size_t i = 0;
return decode(a, i);
@property auto front(T)(T[] a) @safe pure
if (isNarrowString!(T[]))
{
return a[0];
}
}
else
{
/// ditto
@property dchar front(T)(T[] a) @safe pure
if (isNarrowString!(T[]))
{
import std.utf : decode;
assert(a.length, "Attempting to fetch the front of an empty array of " ~ T.stringof);
size_t i = 0;
return decode(a, i);
}
}

/**
Expand Down Expand Up @@ -2368,13 +2383,24 @@ if (!isNarrowString!(T[]) && !is(T[] == void[]))
assert(c.back == 3);
}

/// ditto
// Specialization for strings
@property dchar back(T)(T[] a) @safe pure
if (isNarrowString!(T[]))
version(NoAutoDecode)
{
import std.utf : decode, strideBack;
assert(a.length, "Attempting to fetch the back of an empty array of " ~ T.stringof);
size_t i = a.length - strideBack(a, a.length);
return decode(a, i);
@property auto back(T)(T[] a) @safe pure
if (isNarrowString!(T[]))
{
return a[$ - 1];
}
}
else
{
/// ditto
// Specialization for strings
@property dchar back(T)(T[] a) @safe pure
if (isNarrowString!(T[]))
{
import std.utf : decode, strideBack;
assert(a.length, "Attempting to fetch the back of an empty array of " ~ T.stringof);
size_t i = a.length - strideBack(a, a.length);
return decode(a, i);
}
}