++Phobos
Meta
jared771 at gmail.com
Fri Oct 18 15:12:45 UTC 2019
On Friday, 18 October 2019 at 00:19:08 UTC, rikki cattermole
wrote:
>> Correct me if I'm wrong, but would using this with std.range
>> be as simple as:
>>
>> import std.range;
>>
>> @implements!(MyCoolRange, InputRange)
>> struct MyCoolRange(T)
>> {
>> ....
>> }
>>
>> long sum(R)(R range)
>> if (implements!(R, InputRange))
>> {
>> ....
>> }
>
> This unfortunately still ties the implementation itself to the
> interface. Which goes against DbI.
Not necessarily. I haven't tried this myself, but I think you
could get pretty far with UDAs and some template magic. What I'm
thinking:
//Unfortunately this is necessary so that R is in scope for the
UDAs.
//Maybe it can be avoided with std.traits.TemplateArgsOf /
TemplateOf?
template MapResult(R)
{
//MapResult is always at least an input range
@implements!(MapResult, InputRange)
//If the wrapped type is a forward range, MapResult
//is also a forward range and will forward to its
implementation
@given!(implements!(R, ForwardRange),
implements!(inheritImpl!(ForwardRange, MapResult, R),
ForwardRange))
//etc.
struct MapResult
{
R store;
mixin forwardTo!(ForwardRange, store);
//Input range primitives defined down here
}
}
More information about the Digitalmars-d
mailing list