On 11/9/12, H. S. Teoh <[email protected]> wrote:
> Then all input ranges will have to explicitly declare they are an input
> range thus:

Or:

Change definition of isInputRange to:

---
template isInputRange(T)
{
    enum bool isInputRange = (__attributes(T, RequiresInputRangeCheck)
                              && __attributes(T, IsInputRangeAttr))
        || is(typeof(
        (inout int _dummy=0)
        {
            R r = void;       // can define a range object
            if (r.empty) {}   // can test for empty
            r.popFront();     // can invoke popFront()
            auto h = r.front; // can get the front of the range
        }));
}
---

and in your user module:

---
module foo;
@RequiresInputRangeCheck:  // apply attribute to all declarations in this module

@IsInputRangeAttr struct MyRange { /* front/popFront/empty */ }
struct NotARange { /* front/popFront/empty defined but not designed to
be a range */ }
---

---
static assert(isInputRange!MyRange);
static assert(!(isInputRange!NotARange));
---

That way you keep compatibility with existing ranges and introduce
extra safety check for new types which want to be checked.

Reply via email to