string encryption
Basile B. via Digitalmars-d
digitalmars-d at puremagic.com
Fri Jul 1 17:39:57 PDT 2016
On Saturday, 2 July 2016 at 00:05:14 UTC, Hiemlick Hiemlicker
wrote:
> On Friday, 1 July 2016 at 23:55:08 UTC, Adam D. Ruppe wrote:
>> On Friday, 1 July 2016 at 23:23:19 UTC, Hiemlick Hiemlicker
>> wrote:
>
> I've tried playing with opCall, opAssign, alias this, @property
> but writeln(s) never calls what I thought it should.
>
> I thought s was short for s() if s was a property. having alias
> this decrypt and decrypt being a @property should allow this to
> work?
I think the best you can do is this:
========================
import std.stdio;
struct KryptedString(string value)
{
alias get this;
string get() @property
{
return "decrypt \"" ~ value ~ "\" here";
}
}
template krypt(string value)
{
string process()
{
return "crypted"; // encrypt the template param
}
enum krypt = KryptedString!process();
}
enum string1 = krypt!"blablabla";
enum string2 = krypt!"blablablabla";
void main()
{
writeln(string1);
writeln(string2);
}
========================
The syntax is not so bad.
enum KryptedString string1 = "blablabla";
is impossible or maybe I don't know the trick yet.
More information about the Digitalmars-d
mailing list