Elegant D
Kagamin
spam at here.lot
Tue Nov 25 10:52:59 UTC 2025
Hybrid reference/value type:
```
/// Buffered output stream
struct OutputStream
{
/// Reference type
package Instance* I;
/// Implicitly convertible to value type
pure ref Instance Forward(){ debug assert(!!I); return *I; }
/// ditto
alias Forward this;
/// Null check
const pure bool opCast(){ return !!I; }
/// Use this to store `OutputStream` as value type
struct Instance
{
/// Implicitly convertible to reference type
pure OutputStream Reference(){ return OutputStream(&this); }
/// ditto
alias Reference this;
...other methods
@disable this(this); //not copyable
}
}
/**
Text interface for `OutputStream`.
Examples:
---
OutputStream ostr;
auto wr=TextWriter(ostr);
wr.Write("text string");
---
*/
struct TextWriter
{
OutputStream Output;
void Write(in char[] txt)
{
Output.Write(cast(const byte[])txt); //trust.bytes;
}
void Write(in char[][] txts...)
{
foreach(txt;txts)Write(txt);
}
}
```
More information about the Digitalmars-d
mailing list