[Issue 15926] New: Peculiar behavior of 'inout'
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Apr 14 23:47:42 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=15926
Issue ID: 15926
Summary: Peculiar behavior of 'inout'
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: bugzilla at digitalmars.com
Discussion:
http://www.digitalmars.com/d/archives/digitalmars/D/So_what_does_inout_int_0_do_283407.html
Use case:
https://github.com/D-Programming-Language/phobos/blob/master/std/range/primitives.d#L152
Given the code:
template isInputRange(R)
{
enum bool isInputRange = is(typeof(
(inout int = 0)
{
R r = R.init; // can define a range object
if (r.empty) {} // can test for empty
r.popFront(); // can invoke popFront()
auto h = r.front; // can get the front of the range
}));
}
///
@safe unittest
{
struct A {}
struct B
{
void popFront();
@property bool empty();
@property int front();
}
static assert(!isInputRange!A);
static assert( isInputRange!B);
static assert( isInputRange!(int[]));
static assert( isInputRange!(char[]));
static assert(!isInputRange!(char[4]));
static assert( isInputRange!(inout(int)[]));
}
What is the 'inout int = 0' doing there and why does 'static assert(
isInputRange!(inout(int)[]));' fail when it is removed? There seems to be some
sort of undocumented behavior going on?
--
More information about the Digitalmars-d-bugs
mailing list