Multiple alias this is coming.
IgorStepanov via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Thu Sep 18 16:16:32 PDT 2014
On Thursday, 18 September 2014 at 22:16:23 UTC, bearophile wrote:
> IgorStepanov:
>
>> Do you ask about alias this or about it multiple usage.
>> Multiple usage is similar to single, but multiple:)
>
> I meant the multiple usage. And none of your examples here are
> use cases :-( I'd like to see one use case, or more.
>
> Bye,
> bearophile
For example, you can define struct (value-type with automatic
storage class) which implements interfaces:
intarface InputStream
{
...
}
intarface OutputStream
{
...
}
struct File
{
this(string name, string options)
{
impl = new FileImpl(name, options);
}
~this()
{
impl.close();
}
@property InputStream inputStream()
{
return new class(impl) InputStream
{
//InputStream implementation
...
}
}
@property OutputStream outputStream()
{
return new class(impl) OutputStream
{
//OutputStream implementation
...
}
}
alias inputStream this;
alias seekable this;
FileImpl* impl;
}
Record[] readData(InputStream);
void storeData(OutputStream, Record[]);
Record[] extractRecords()
{
File f = File("records.bin", "rw");
auto data = readData(f);
///split to extracted and remaining
f.truncate();
writeData(f, remaining);
return extracted;
}
More information about the Digitalmars-d-announce
mailing list