std_exception.html#enforce: example does not compile

kdevel kdevel at vogtner.de
Sat Jan 27 17:57:54 UTC 2018


On Saturday, 27 January 2018 at 16:10:29 UTC, Jonathan M Davis 
wrote:
> On Saturday, January 27, 2018 13:29:00 kdevel via 
> Digitalmars-d-learn wrote:
>> What's wrong here? And why is the "selective import" of 
>> enforce necessary?
>
> Because you named your module enforce. As such, by default, 
> referring to enforce inside of the module refers to the module. 
> Having the selective import overrides that.

Okay. But what about that persisting error message:

zz.d
---
import core.stdc.stdio : fopen;
import std.stdio : readln, writeln;
import std.exception; // : enforce;

void main ()
{
    auto f = enforce(fopen("data.txt", "r"));
    auto line = readln(f);
    enforce(line.length, "Expected a non-empty line.");
}
---

$ dmd zz
zz.d(8): Error: template std.stdio.readln cannot deduce function 
from argument types !()(shared(_IO_FILE)*), candidates are:
/.../dmd2/linux/bin64/../../src/phobos/std/stdio.d(3921):        
std.stdio.readln(S = string)(dchar terminator = '\x0a') if 
(isSomeString!S)
/.../dmd2/linux/bin64/../../src/phobos/std/stdio.d(3955):        
std.stdio.readln(C)(ref C[] buf, dchar terminator = '\x0a') if 
(isSomeChar!C && is(Unqual!C == C) && !is(C == enum))
/.../dmd2/linux/bin64/../../src/phobos/std/stdio.d(3962):        
std.stdio.readln(C, R)(ref C[] buf, R terminator) if 
(isSomeChar!C && is(Unqual!C == C) && !is(C == enum) && 
isBidirectionalRange!R && is(typeof(terminator.front == 
(dchar).init)))

The example still does not compile.


More information about the Digitalmars-d-learn mailing list