Thread overview | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 27, 2014 Re: DConf Day 1 Panel with Walter Bright and Andrei Alexandrescu | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | http://youtu.be/TNvUIWFy02I |
June 27, 2014 Re: DConf Day 1 Panel with Walter Bright and Andrei Alexandrescu | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot | On 6/27/2014 12:53 PM, Dicebot wrote:
> http://youtu.be/TNvUIWFy02I
Ack, need to work on my posture :-(
|
June 27, 2014 Re: DConf Day 1 Panel with Walter Bright and Andrei Alexandrescu | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | I have two questions that I've come upon lately: 1) How was it decided that there should be implicit conversion between signed and unsigned integers in arithmetic operations, and why prefer unsigned numbers? E.g. Signed / Unsigned = Unsigned Is this simply compatibility with C or is there something greater behind this decision. 2) With regard to reducing template instantiations: I've been using a technique similar to the one mentioned in the video: separating functions out of templates to reduce bloat. My question is: does a template such as: T foo(T)(T x) if (isIntegral!T) { return x; } Get instantiated multiple times for const, immutable, etc. qualifiers on the input? |
June 28, 2014 Re: DConf Day 1 Panel with Walter Bright and Andrei Alexandrescu | ||||
---|---|---|---|---|
| ||||
Posted in reply to safety0ff | On Friday, 27 June 2014 at 23:30:39 UTC, safety0ff wrote:
> 2) With regard to reducing template instantiations:
> I've been using a technique similar to the one mentioned in the video: separating functions out of templates to reduce bloat.
> My question is: does a template such as:
> T foo(T)(T x)
> if (isIntegral!T) { return x; }
>
> Get instantiated multiple times for const, immutable, etc. qualifiers on the input?
Yes, but bear in mind that those qualifiers are often stripped
with IFTI, e.g.:
int a;
const int b;
immutable int c;
foo(a);
foo(b);
foo(c);
These all call foo!int
|
June 28, 2014 Re: DConf Day 1 Panel with Walter Bright and Andrei Alexandrescu | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Alexander | On Saturday, 28 June 2014 at 02:02:28 UTC, Peter Alexander wrote:
> On Friday, 27 June 2014 at 23:30:39 UTC, safety0ff wrote:
>> 2) With regard to reducing template instantiations:
>> I've been using a technique similar to the one mentioned in the video: separating functions out of templates to reduce bloat.
>> My question is: does a template such as:
>> T foo(T)(T x)
>> if (isIntegral!T) { return x; }
>>
>> Get instantiated multiple times for const, immutable, etc. qualifiers on the input?
>
> Yes, but bear in mind that those qualifiers are often stripped
> with IFTI, e.g.:
>
> int a;
> const int b;
> immutable int c;
> foo(a);
> foo(b);
> foo(c);
>
> These all call foo!int
Awesome, thanks!
|
June 28, 2014 Re: DConf Day 1 Panel with Walter Bright and Andrei Alexandrescu | ||||
---|---|---|---|---|
| ||||
Posted in reply to safety0ff | On Saturday, 28 June 2014 at 02:46:25 UTC, safety0ff wrote:
> On Saturday, 28 June 2014 at 02:02:28 UTC, Peter Alexander
>> int a;
>> const int b;
>> immutable int c;
>> foo(a);
>> foo(b);
>> foo(c);
>>
>> These all call foo!int
>
> Awesome, thanks!
... I just tried this and I'm wrong. The qualifier isn't stripped. Gah! Three different versions!
I could have sworn D did this for primitive types. This makes me sad :-(
|
June 28, 2014 Re: DConf Day 1 Panel with Walter Bright and Andrei Alexandrescu | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Alexander | On Saturday, 28 June 2014 at 03:33:37 UTC, Peter Alexander wrote:
>
> ... I just tried this and I'm wrong. The qualifier isn't stripped. Gah! Three different versions!
>
> I could have sworn D did this for primitive types. This makes me sad :-(
I guess you can make all kinds of code that depends on the qualifier.
I tried using ld.gold to play with icf (identical code folding,) but I did not manage to get a working binary out of gold (regardless of icf.)
|
June 28, 2014 Re: DConf Day 1 Panel with Walter Bright and Andrei Alexandrescu | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Alexander | Am 28.06.2014 05:33, schrieb Peter Alexander:
> On Saturday, 28 June 2014 at 02:46:25 UTC, safety0ff wrote:
>> On Saturday, 28 June 2014 at 02:02:28 UTC, Peter Alexander
>>> int a;
>>> const int b;
>>> immutable int c;
>>> foo(a);
>>> foo(b);
>>> foo(c);
>>>
>>> These all call foo!int
>>
>> Awesome, thanks!
>
> ... I just tried this and I'm wrong. The qualifier isn't stripped. Gah!
> Three different versions!
>
> I could have sworn D did this for primitive types. This makes me sad :-(
I *think* it does this if you define foo as "foo(T)(const(T) arg)", though.
|
June 28, 2014 Re: DConf Day 1 Panel with Walter Bright and Andrei Alexandrescu | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sönke Ludwig | On Saturday, 28 June 2014 at 16:51:56 UTC, Sönke Ludwig wrote:
> Am 28.06.2014 05:33, schrieb Peter Alexander:
>> On Saturday, 28 June 2014 at 02:46:25 UTC, safety0ff wrote:
>>> On Saturday, 28 June 2014 at 02:02:28 UTC, Peter Alexander
>>>> int a;
>>>> const int b;
>>>> immutable int c;
>>>> foo(a);
>>>> foo(b);
>>>> foo(c);
>>>>
>>>> These all call foo!int
>>>
>>> Awesome, thanks!
>>
>> ... I just tried this and I'm wrong. The qualifier isn't stripped. Gah!
>> Three different versions!
>>
>> I could have sworn D did this for primitive types. This makes me sad :-(
>
> I *think* it does this if you define foo as "foo(T)(const(T) arg)", though.
Thanks, that works.
std.math doesn't do this for its templated functions, should it?
Is there an easy way to shared-strip primitive types?
Perhaps passing non-ref/non-pointer primitive data to const(T) should implicitly strip shared.
Reading of the shared data occurs at the call site.
Are there any use cases where passing on the shared-ness of a primitive type to non-ref const(T) is useful?
|
Copyright © 1999-2021 by the D Language Foundation