popFront with input variables
Jonathan M Davis
jmdavisProg at gmx.com
Fri Aug 31 09:51:27 PDT 2012
On Friday, August 31, 2012 15:56:32 Joseph Rushton Wakeling wrote:
> Hello all,
>
> Is it considered legit in any circumstances for popFront to take an input
> variable (e.g. a random number generator)? Or is it required always to have
> no input variables?
Don't do it. Technically speaking, as long as it's callable with no arguments,
you should be able to do it. isInputRange just checks that it's callable with
no arguments:
template isInputRange(R)
{
enum bool isInputRange = 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
}));
}
but no range-based anything is going to call popFront with any arguments, and
it goes against how popFront works. If you want a function which takes an
argument and pops of the front as well, then create a new one. Don't use
popFront for that. I have no idea why you'd ever _want_ to do that though. You
have a highly abnormal use case if it makes any sense for you to be declaring
a popFront which takes an argument.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list