www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13016] New: Can't create std.typecons.Nullable!int from the

https://issues.dlang.org/show_bug.cgi?id=13016

          Issue ID: 13016
           Summary: Can't create std.typecons.Nullable!int from the index
                    variable of a foreach loop
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: monkeyworks12 hotmail.com

import std.typecons: Nullable;

Nullable!int IndexOf(int[] arr, int val)
{
    foreach (i, n; arr)
    {
        if (n == val)
        {
            //Error: inout method
                        //std.typecons.Nullable!int.Nullable.this 
                        //is not callable using a mutable object
            return Nullable!int(i);
        }
    }

    return Nullable!int();
}

--
Jul 01 2014