September 23, 2012
On Sun, Sep 23, 2012 at 1:54 AM, Jonathan M Davis <jmdavisProg@gmx.com> wrote:
> I'm trying to test whether a template argument is the type returned by takeExactly, and I haven't been able to sort out the template voodoo required yet. It would be a lot easier if I had a variable to work with, but I just have the type, and the fancy is expression required to pull it off is fancy enough that I haven't been able to sort it out yet.

Seeing that takeExactly returns itself when its input is a takeExactly, I used this:

import std.range;
import std.stdio;

template Hello(R)
{
    static if (is(typeof(R._input)) // Is using R._input OK?
              && is(typeof(takeExactly(typeof(R._input),0)) == R )) //
Does applying takeExactly on R gives R back?
        alias typeof(R._input) Hello; // Extract the original range type
    else
        alias void Hello;
}

void main()
{
    auto str = "hello";
    auto t = takeExactly(str, 3);

    writeln(t);
    writeln(Hello!(typeof(t)).stringof); // "string"
}

Transforming it into a predicate template is easy, I just wanted to
show that R._input is accessible.
Caution: takeExactly returns a slice when the range is slice-able. You
should test for hasSlicing on R first.

As for Voldemort (Nameless One, Dark Lord, whatever) types, I find them more annoying than useful, personally.

Philippe
September 23, 2012
On Sunday, September 23, 2012 13:55:04 Philippe Sigaud wrote:
> Transforming it into a predicate template is easy, I just wanted to show that R._input is accessible.

I was trying to test it without checking its internals (which should be possible IMHO), but if I have to check its internals, I have to check its internals. Actually, it hadn't occured to me to check its internals, but I would have wanted to avoid it (and still do), but this will work for now. Thanks.

> Caution: takeExactly returns a slice when the range is slice-able. You should test for hasSlicing on R first.

Actually, I'm messing with hasSlicing, so I have to be _very_ careful here. Per a discussion on github, I'm changing it to require that the return type of opSlice for finite ranges returns a type which can be assigned to the original type and that for infinite ranges it be the result of takeExactly. The changes to opSlice themselves seem straightforward enough but the side effects on take and takeExactly have gotten a bit hairy, since they reference hasSlicing. I don't think that it'll take many changes, but getting it right has been hard.

> As for Voldemort (Nameless One, Dark Lord, whatever) types, I find them more annoying than useful, personally.

Due to how they affect the init property and some other stuff, they may have to be axed (there's a bug report discussing some of those issues somewhere, but I don't remember it's number), but we still have them for the moment. The idea is cool, but the ultimate result is definitely problematic.

- Jonathan M Davis