Как вы используете диапазоны в D?

Всякий раз, когда я пытаюсь использовать диапазоны в D, я терплю неудачу.

Как правильно использовать диапазоны в D? (См. встроенные комментарии для моей путаницы.)

void print(R)(/* ref? auto ref? neither? */ R r)
{
    foreach (x; r)
    {
        writeln(x);
    }

    // Million $$$ question:
    //
    // Will I get back the same things as last time?
    // Do I have to check for this every time?

    foreach (x; r)
    {
        writeln(x);
    }
}

void test2(alias F, R)(/* ref/auto ref? */ R items)
{
    // Will it consume items?
    // _Should_ it consume items?
    // Will the caller be affected? How do I know?
    // Am I supposed to?
    F(items);
}
7
задан Mehrdad 25 June 2012 в 15:28
поделиться