What is Base64 part in Base64.encode

Moritz Maxeiner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 14 14:55:51 PDT 2017


On Sunday, 14 May 2017 at 21:34:35 UTC, zabruk70 wrote:
> On Sunday, 14 May 2017 at 21:22:20 UTC, Moritz Maxeiner wrote:
>> The full line is `alias Base64 = Base64Impl!('+', '/');`
>
> Yes. When we use it like this:
>
>   const(char)[] encoded = Base64.encode(data);
>
> then template instantiated and produce ... what?

Have you read the language specification I linked to?
Base64 refers to a (fully) parametrized template. If you use the 
symbol Base64, you will access its instantiation; '.encode' then 
accesses the member "encode" in the scope of that template 
instance, which happens to be a function. That function then gets 
called with "data" as its argument and returns the encoded data.

>
>> I don't understand what you're trying to express here.
>
> What kind of symbols (class name, structure name, type)
> can be used with dot in D language?

Pretty much any symbol. Any type (or alias to one) will at least 
have properties[1] and any variable will be open to UFCS[2].

>
> What produced by template instantiation `Base64Impl!('+', '/')`
> then i use alias `Base64`?

I'm sorry, but I have no idea what you're trying to convey here.

>
>> You can create a base32 encoder however you like, D has lots 
>> of different ways you could approach this; you can even do it 
>> in a
>
> But i want mimic std.base64 syntax.
> I want to write something like
>
>   string encoded = Base32.encode(data);
>
> And i don't want to use template.

Then use a struct with static member functions:

struct Base32
{
     static [...] encode([...]) { [...] }
     static [...] decode([...]) { [...] }
}

[1] https://dlang.org/spec/property.html
[2] 
https://tour.dlang.org/tour/en/gems/uniform-function-call-syntax-ufcs


More information about the Digitalmars-d-learn mailing list