Problem with taking inout, const references
Uranuz
neuranuz at gmail.com
Tue Mar 25 12:20:09 PDT 2014
I have problem with understanding of work of modifiers const,
inout, immutable modifiers. As I understand inout keyword is
intended to consume const, immutable and data without modifiers.
It's how I expect it to work otherwise I don't understand what is
the purpose of inout. In current implementation of language it
looks like (it's just my feeling) that it's completly other
modifier that connects badly with const and immutable. In this
case I don't understand sense of it. Also I have strange feelings
about shared, because it's not widely used in code that I'm
experienced to see and lacks of good usage examples.
May main question is that I don't understand sense of this error:
Error: cannot implicitly convert expression (&c) of type
const(Cookie)* to inout(Cookie)*
It occured in the following code. Can someone understand what I'm
doing wrong? Or is it a bug or something?
struct Cookie
{ string name;
string value;
string domain;
string path;
string expires;
bool isHTTPOnly;
bool isSecure;
void opAssign(string rhs)
{ value = rhs; }
string toString()
{ string result = `Set-Cookie: ` ~ name ~ `=` ~ value;
if( domain.length > 0 )
result ~= `; Domain=` ~ domain;
if( path.length > 0 )
result ~= `; Path=` ~ path;
if( expires.length > 0 )
result ~= `; Expires=` ~ expires;
if( isHTTPOnly )
result ~= `; HttpOnly`;
if( isSecure )
result ~= `; Secure`;
return result;
}
}
class ResponseCookies
{
Cookie[] _cookies;
//.....
inout(Cookie)* opBinaryRight(string op)(string name) inout if(op
== "in")
{ foreach( ref inout(Cookie) c; _cookies )
if( c.name == name )
return &c; //Error is here
return null;
}
}
More information about the Digitalmars-d-learn
mailing list