Compiler hints, inlining and syntax consistency

Chris Cain clcain at uncg.edu
Sat Dec 28 10:47:50 PST 2013


On Saturday, 28 December 2013 at 18:38:55 UTC, Ola Fosheim 
Grøstad wrote:
> It is different in the sense that if your lengths are short you 
> either have to write your own container or your own algorithm 
> because the algorithm designer assumed that walkLength would be 
> too slow in all cases? In the case of phobos you probably could 
> just change the algorithm to use walkLength yourself and 
> include it with your source. In a more complex framework it 
> might be more difficult?

struct LengthWrapper(T) {
    T wrapped;
    size_t length() @property {
        return wrapped.walkLength();
    }
    alias wrapped this;
}

LengthWrapper!T assumeWalkLengthOK(T)(T thing) {
    return LengthWrapper!T(thing);
}

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.


More information about the Digitalmars-d mailing list