Jump to page: 1 2
Thread overview
Re: Named template constraints
Apr 22, 2014
Andrej Mitrovic
Apr 22, 2014
monarch_dodra
Apr 22, 2014
monarch_dodra
Apr 22, 2014
monarch_dodra
Apr 22, 2014
Andrej Mitrovic
Apr 22, 2014
Tim Holzschuh
April 22, 2014
On 4/22/14, Tim Holzschuh via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote:
> What does (inout int = 0) mean/affect here?

This was asked recently, see my reponse here: http://forum.dlang.org/post/mailman.102.1396007039.25518.digitalmars-d-learn@puremagic.com
April 22, 2014
On Tue, 22 Apr 2014 10:58:41 -0400, Andrej Mitrovic via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote:

> On 4/22/14, Tim Holzschuh via Digitalmars-d-learn
> <digitalmars-d-learn@puremagic.com> wrote:
>> What does (inout int = 0) mean/affect here?
>
> This was asked recently, see my reponse here:
> http://forum.dlang.org/post/mailman.102.1396007039.25518.digitalmars-d-learn@puremagic.com

I think this can be fixed a different way:

template isInputRange(R)
{
enum bool isInputRange = is(typeof(
(R r)
{
R r2 = R.init; // 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
}));
}


Note, is the r2 = R.init needed? Not sure.

-Steve
April 22, 2014
On Tuesday, 22 April 2014 at 15:06:34 UTC, Steven Schveighoffer wrote:
> Note, is the r2 = R.init needed? Not sure.

Yes: It R2 has no default init, or is an immutable, then that line will fail to compile.
April 22, 2014
Not sure what InputRange is defined as atm, but I don't think anything should have to define init to be a valid inputrange.
April 22, 2014
On Tue, 22 Apr 2014 11:15:14 -0400, monarch_dodra <monarchdodra@gmail.com> wrote:

> On Tuesday, 22 April 2014 at 15:06:34 UTC, Steven Schveighoffer wrote:
>> Note, is the r2 = R.init needed? Not sure.
>
> Yes: It R2 has no default init, or is an immutable, then that line will fail to compile.

I don't believe it's possible to have no 'init'.

I think the reason it says '= R.init' is for ranges that have @disable this().

Also, an immutable can be initialized that way:

immutable int[] = int[].init;

Of course, it wouldn't pass the rest of isInputRange.

-Steve
April 22, 2014
On Tuesday, 22 April 2014 at 15:30:36 UTC, Steven Schveighoffer wrote:
> On Tue, 22 Apr 2014 11:15:14 -0400, monarch_dodra <monarchdodra@gmail.com> wrote:
>
>> On Tuesday, 22 April 2014 at 15:06:34 UTC, Steven Schveighoffer wrote:
>>> Note, is the r2 = R.init needed? Not sure.
>>
>> Yes: It R2 has no default init, or is an immutable, then that line will fail to compile.
>
> I don't believe it's possible to have no 'init'.
>
> I think the reason it says '= R.init' is for ranges that have @disable this().

Yes, that's what I meant by "no default init". Guess I got my terms wrong. Sorry.

> Also, an immutable can be initialized that way:
>
> immutable int[] = int[].init;

Isn't that exactly "R.init" ?

> Of course, it wouldn't pass the rest of isInputRange.
>
> -Steve

In this particular case, probably not (except for, maybe "repeat"?) In any case, it's become the "generic" way of initializing a generic type.
April 22, 2014
On 4/22/14, Steven Schveighoffer via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> > I think this can be fixed a different way.

Feel free to file a bug / make a pull. :>
April 22, 2014
Am 22.04.2014 16:58, schrieb Andrej Mitrovic via Digitalmars-d-learn:
> On 4/22/14, Tim Holzschuh via Digitalmars-d-learn
> <digitalmars-d-learn@puremagic.com> wrote:
>> What does (inout int = 0) mean/affect here?
> This was asked recently, see my reponse here:
> http://forum.dlang.org/post/mailman.102.1396007039.25518.digitalmars-d-learn@puremagic.com
>
Aargh, I'm sorry.
Didn't see that one.

- Tim
April 22, 2014
On Tue, 22 Apr 2014 11:36:07 -0400, monarch_dodra <monarchdodra@gmail.com> wrote:

> On Tuesday, 22 April 2014 at 15:30:36 UTC, Steven Schveighoffer wrote:
>> Also, an immutable can be initialized that way:
>>
>> immutable int[] = int[].init;
>
> Isn't that exactly "R.init" ?

Yes, you said if it's an immutable it would fail to compile. I think this is not true.

-Steve
April 22, 2014
On Tuesday, 22 April 2014 at 18:35:58 UTC, Steven Schveighoffer wrote:
> On Tue, 22 Apr 2014 11:36:07 -0400, monarch_dodra <monarchdodra@gmail.com> wrote:
>
>> On Tuesday, 22 April 2014 at 15:30:36 UTC, Steven Schveighoffer wrote:
>>> Also, an immutable can be initialized that way:
>>>
>>> immutable int[] = int[].init;
>>
>> Isn't that exactly "R.init" ?
>
> Yes, you said if it's an immutable it would fail to compile. I think this is not true.
>
> -Steve


Ah... you said:

> Note, is the r2 = R.init needed? Not sure.

To whitch I replied:

> Yes: It R2 has no default init, or is an immutable,
> then that line will fail to compile.

I meant that if you *don't* add the R.init, then the code will *not* compile. EG => R.init is necessary.

Sorry for the mixup :/
« First   ‹ Prev
1 2