about const and immutable (again)

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Thu Oct 6 07:56:43 PDT 2011


Hi, guys.

I just made my handy parsing struct take an arbitrary range, instead
of a dstring and immediately rain head-first into a brick wall of
errors.

There's this function:
    bool next(bool function(ElementType!InputType) pred)

, where InputType is bound to be dstring and which gets called like this:
    parser.next(&isAlpha)

, where isAlpha is from std.uni.
When i do that, i get this error:
    Error: cannot implicitly convert expression (& isAlpha) of type
bool function(dchar c) pure nothrow @safe to bool
function(immutable(dchar))

Yes, I understand why do i get this error.
What i don't understand is: does the dchar being immutable really
change anything?
I would, if dchar was indirected type, but it's not. isAlpha has no
way to change my original dchar, that i passed it.
What's the point of disallowing this?
And by `this` i mean, initializing mutable cariables of non-indirected
types with immutable values of those types?

Cheers,
Gor.


More information about the Digitalmars-d mailing list