www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15926] New: Peculiar behavior of 'inout'


          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 puremagic.com
          Reporter: bugzilla digitalmars.com



Use case:


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?

Apr 14 2016