On Saturday, 28 December 2013 at 18:47:52 UTC, Chris Cain wrote:
...snip...

There you go. Use it like:

```
someGenericAlgorithm(assumeWalkLengthOK(myContainer));
```

Squelches the error message and documents the intent. Could be better, but it saves us writing a language feature for it.

I keep forgetting to use voldemort types, and in this case it really makes sense:

    import std.range;
    auto assumeWalkLengthOK(T)(T thing)
    if(isInputRange!T)
    {
        struct Result
        {
            T wrapped;
            size_t length()
            {
                return wrapped.walkLength();
            }
            alias wrapped this;
        }
        return Result(thing);
    }

Same usage, `someGenericAlgorithm(assumeWalkLengthOK(myContainer));` (I didn't actually run this through dmd, but it should work in theory)

Reply via email to