June 05, 2015 Re: rvalue references | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | I start working on a Pull (https://github.com/D-Programming-Language/dmd/pull/4717), but it fails the first check. The reason seems to be this: https://github.com/D-Programming-Language/dmd/pull/4717/files#diff-ffafa03255a57832dd09031af6cb915dR5945 I guess that this error happens because I cannot distinguish between template and non template auto ref. Does anyone have an idea? |
June 05, 2015 Re: rvalue references | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | On Friday, 5 June 2015 at 21:31:22 UTC, Namespace wrote:
> I start working on a Pull (https://github.com/D-Programming-Language/dmd/pull/4717), but it fails the first check. The reason seems to be this: https://github.com/D-Programming-Language/dmd/pull/4717/files#diff-ffafa03255a57832dd09031af6cb915dR5945
> I guess that this error happens because I cannot distinguish between template and non template auto ref. Does anyone have an idea?
Hmm, the only problematic code is std.algorithm.mutation.swap on line 1956 - 1959 which calls doesPointTo from std.exception which is nothrow pure and @nogc, but shouldn't.
Without it, everything works.
|
June 06, 2015 Re: rvalue references | ||||
---|---|---|---|---|
| ||||
Posted in reply to bitwise | On Wednesday, 3 June 2015 at 01:57:21 UTC, bitwise wrote:
> 'in' is currently useless because scope is not defined properly, and const is too restrictive. Also, because of DIP25, it's now even more useless. It seems a pretty sure bet that it will either continue to be completely useless or be changed at some point anyways, so why not now?
> ...
> So why not re-brand this awesomely concise and convenient keyword to be the "non-template auto ref"?
I see the point in some sort of `auto ref`/`scope ref` parameters binding to rvalues in cases where one's not interested in a function's side effect applied to a non-escapable rvalue argument.
But what I need 99% of the time is some means to express my intention to pass an argument the most efficient way possible as the callee is only gonna read from it and won't let it escape. This is only relevant for non-primitive value types, i.e., structs. Like many others, I love the neat little `in` keyword, and would like for it to have exactly these semantics, for both templates and normal functions:
* the callee has read-only access to the parameter, i.e.,
it is const;
* since it's declared as normal function parameter (`in T arg`),
it cannot escape (`scope` or however we wanna call this);
* depending on type and hardware, value types are either passed
by value (POD type whose size <= [2*]size_t.sizeof) or by
reference (non-POD type and/or size > threshold);
reference types (class instances) are always passed by ref
* if a value type is passed by reference, an rvalue argument is
allowed to safely bind to the const, non-escapable reference.
This would be particularly useful for generic templates, e.g., containers, where primitive and small POD types T are ideally passed by value, and other Ts by reference.
|
June 06, 2015 Re: rvalue references | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | Finally all green! Now we need a review. |
June 07, 2015 Re: rvalue references | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | On Sat, 06 Jun 2015 14:05:54 -0400, Namespace <rswhite4@gmail.com> wrote:
> Finally all green! Now we need a review.
You're my hero.
Bit
|
June 08, 2015 Re: rvalue references | ||||
---|---|---|---|---|
| ||||
Posted in reply to bitwise | On Sunday, 7 June 2015 at 18:40:42 UTC, bitwise wrote:
> On Sat, 06 Jun 2015 14:05:54 -0400, Namespace <rswhite4@gmail.com> wrote:
>
>> Finally all green! Now we need a review.
>
> You're my hero.
>
> Bit
Sounds ironic. o.O
|
June 08, 2015 Re: rvalue references | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | On Mon, 08 Jun 2015 02:44:46 -0400, Namespace <rswhite4@gmail.com> wrote:
> On Sunday, 7 June 2015 at 18:40:42 UTC, bitwise wrote:
>> On Sat, 06 Jun 2015 14:05:54 -0400, Namespace <rswhite4@gmail.com> wrote:
>>
>>> Finally all green! Now we need a review.
>>
>> You're my hero.
>>
>> Bit
>
> Sounds ironic. o.O
Ironic or Sarcastic?
Neither.
Bit
|
June 08, 2015 Re: rvalue references | ||||
---|---|---|---|---|
| ||||
Posted in reply to bitwise | On Mon, 08 Jun 2015 11:29:56 -0400, bitwise <bitwise.pvt@gmail.com> wrote:
> On Mon, 08 Jun 2015 02:44:46 -0400, Namespace <rswhite4@gmail.com> wrote:
>
>> On Sunday, 7 June 2015 at 18:40:42 UTC, bitwise wrote:
>>> On Sat, 06 Jun 2015 14:05:54 -0400, Namespace <rswhite4@gmail.com> wrote:
>>>
>>>> Finally all green! Now we need a review.
>>>
>>> You're my hero.
>>>
>>> Bit
>>
>> Sounds ironic. o.O
>
>
> Ironic or Sarcastic?
> Neither.
>
> Bit
One useful case for me:
static Mat4 transform()(const auto ref Vec3 pos, const auto ref Vec3 scale, const auto ref Quat rot)
{
Mat4 m = Mat4(rot.matrix, 1);
m.m00 *= scale.x;
m.m01 *= scale.x;
m.m02 *= scale.x;
m.m10 *= scale.y;
m.m11 *= scale.y;
m.m12 *= scale.y;
m.m20 *= scale.z;
m.m21 *= scale.z;
m.m22 *= scale.z;
m.m30 = pos.x;
m.m31 = pos.y;
m.m32 = pos.z;
return m;
}
Currently, my choices are template bloat, or pointless copying.
Bit
|
June 08, 2015 Re: rvalue references | ||||
---|---|---|---|---|
| ||||
Posted in reply to bitwise | > One useful case for me:
>
> static Mat4 transform()(const auto ref Vec3 pos, const auto ref Vec3 scale, const auto ref Quat rot)
> {
> Mat4 m = Mat4(rot.matrix, 1);
>
> m.m00 *= scale.x;
> m.m01 *= scale.x;
> m.m02 *= scale.x;
>
> m.m10 *= scale.y;
> m.m11 *= scale.y;
> m.m12 *= scale.y;
>
> m.m20 *= scale.z;
> m.m21 *= scale.z;
> m.m22 *= scale.z;
>
> m.m30 = pos.x;
> m.m31 = pos.y;
> m.m32 = pos.z;
>
> return m;
> }
>
> Currently, my choices are template bloat, or pointless copying.
>
> Bit
Yes, the same goes for Dgame.
|
Copyright © 1999-2021 by the D Language Foundation