Thread overview | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
October 26, 2011 Own type for null? | ||||
---|---|---|---|---|
| ||||
I recently tried to replace the deprecated overloading of new and delete and came across a serious issue. You can not use std.conv.emplace with null. If you pass null to it, null loses it's implicit casting cabablities and just becomes a void*. This issue pretty much exists with every template. As soon as you pass null to a template (compile time) information gets lost. Besides fixing std.conv.emplace it could be really handy to be able to check for a null-type at compile time for example with non-nullable types. There is already a enhancement reqeust in bugzilla since January but it didn't get much attention yet: http://d.puremagic.com/issues/show_bug.cgi?id=5416 Would this be a worthwile improvement for the langauge? -- Kind Regards Benjamin Thaut |
October 26, 2011 Re: Own type for null? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Benjamin Thaut | I agree. Null is a very common special-case value and overloading may be necessary based on that special-case value. Currently doing so means accepting any kind of typeless pointer (which is certainly not desirable).
On Wed, Oct 26, 2011 at 9:49 AM, Benjamin Thaut <code@benjamin-thaut.de> wrote:
> I recently tried to replace the deprecated overloading of new and delete and
> came across a serious issue. You can not use std.conv.emplace with null. If
> you pass null to it, null loses it's implicit casting cabablities and just
> becomes a void*.
> This issue pretty much exists with every template. As soon as you pass null
> to a template (compile time) information gets lost.
>
> Besides fixing std.conv.emplace it could be really handy to be able to check for a null-type at compile time for example with non-nullable types.
>
> There is already a enhancement reqeust in bugzilla since January but it didn't get much attention yet: http://d.puremagic.com/issues/show_bug.cgi?id=5416
>
> Would this be a worthwile improvement for the langauge?
> --
> Kind Regards
> Benjamin Thaut
>
|
October 26, 2011 Re: Own type for null? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Benjamin Thaut | On 10/26/2011 07:49 AM, Benjamin Thaut wrote:
> I recently tried to replace the deprecated overloading of new and delete
> and came across a serious issue. You can not use std.conv.emplace with
> null. If you pass null to it, null loses it's implicit casting
> cabablities and just becomes a void*.
> This issue pretty much exists with every template. As soon as you pass
> null to a template (compile time) information gets lost.
>
> Besides fixing std.conv.emplace it could be really handy to be able to
> check for a null-type at compile time for example with non-nullable types.
>
> There is already a enhancement reqeust in bugzilla since January but it
> didn't get much attention yet:
> http://d.puremagic.com/issues/show_bug.cgi?id=5416
>
> Would this be a worthwile improvement for the langauge?
++vote.
We also need an own type for the empty array literal '[]' btw.
|
October 26, 2011 Re: Own type for null? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | Yes! Empty array is also a special-case value, which can be interpreted in a special way, which is completely different from any other array.
On Wed, Oct 26, 2011 at 12:56 PM, Timon Gehr <timon.gehr@gmx.ch> wrote:
> On 10/26/2011 07:49 AM, Benjamin Thaut wrote:
>>
>> I recently tried to replace the deprecated overloading of new and delete
>> and came across a serious issue. You can not use std.conv.emplace with
>> null. If you pass null to it, null loses it's implicit casting
>> cabablities and just becomes a void*.
>> This issue pretty much exists with every template. As soon as you pass
>> null to a template (compile time) information gets lost.
>>
>> Besides fixing std.conv.emplace it could be really handy to be able to check for a null-type at compile time for example with non-nullable types.
>>
>> There is already a enhancement reqeust in bugzilla since January but it didn't get much attention yet: http://d.puremagic.com/issues/show_bug.cgi?id=5416
>>
>> Would this be a worthwile improvement for the langauge?
>
> ++vote.
>
> We also need an own type for the empty array literal '[]' btw.
>
|
October 26, 2011 Re: Own type for null? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | Am 26.10.2011 10:56, schrieb Timon Gehr: > On 10/26/2011 07:49 AM, Benjamin Thaut wrote: >> I recently tried to replace the deprecated overloading of new and delete >> and came across a serious issue. You can not use std.conv.emplace with >> null. If you pass null to it, null loses it's implicit casting >> cabablities and just becomes a void*. >> This issue pretty much exists with every template. As soon as you pass >> null to a template (compile time) information gets lost. >> >> Besides fixing std.conv.emplace it could be really handy to be able to >> check for a null-type at compile time for example with non-nullable >> types. >> >> There is already a enhancement reqeust in bugzilla since January but it >> didn't get much attention yet: >> http://d.puremagic.com/issues/show_bug.cgi?id=5416 >> >> Would this be a worthwile improvement for the langauge? > > ++vote. > > We also need an own type for the empty array literal '[]' btw. Do you have an example where a own type for [] would be usefull? -- Kind Regards Benjamin Thaut |
October 26, 2011 Re: Own type for null? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Benjamin Thaut | Functions, overladed on different types of arrays will always fail with empty arrays unless empty arrays have their own type.
On Wed, Oct 26, 2011 at 7:55 PM, Benjamin Thaut <code@benjamin-thaut.de> wrote:
> Am 26.10.2011 10:56, schrieb Timon Gehr:
>>
>> On 10/26/2011 07:49 AM, Benjamin Thaut wrote:
>>>
>>> I recently tried to replace the deprecated overloading of new and delete
>>> and came across a serious issue. You can not use std.conv.emplace with
>>> null. If you pass null to it, null loses it's implicit casting
>>> cabablities and just becomes a void*.
>>> This issue pretty much exists with every template. As soon as you pass
>>> null to a template (compile time) information gets lost.
>>>
>>> Besides fixing std.conv.emplace it could be really handy to be able to check for a null-type at compile time for example with non-nullable types.
>>>
>>> There is already a enhancement reqeust in bugzilla since January but it didn't get much attention yet: http://d.puremagic.com/issues/show_bug.cgi?id=5416
>>>
>>> Would this be a worthwile improvement for the langauge?
>>
>> ++vote.
>>
>> We also need an own type for the empty array literal '[]' btw.
>
> Do you have an example where a own type for [] would be usefull?
>
> --
> Kind Regards
> Benjamin Thaut
>
|
October 26, 2011 Re: Own type for null? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Benjamin Thaut | On 10/26/2011 05:55 PM, Benjamin Thaut wrote:
> Am 26.10.2011 10:56, schrieb Timon Gehr:
>> On 10/26/2011 07:49 AM, Benjamin Thaut wrote:
>>> I recently tried to replace the deprecated overloading of new and delete
>>> and came across a serious issue. You can not use std.conv.emplace with
>>> null. If you pass null to it, null loses it's implicit casting
>>> cabablities and just becomes a void*.
>>> This issue pretty much exists with every template. As soon as you pass
>>> null to a template (compile time) information gets lost.
>>>
>>> Besides fixing std.conv.emplace it could be really handy to be able to
>>> check for a null-type at compile time for example with non-nullable
>>> types.
>>>
>>> There is already a enhancement reqeust in bugzilla since January but it
>>> didn't get much attention yet:
>>> http://d.puremagic.com/issues/show_bug.cgi?id=5416
>>>
>>> Would this be a worthwile improvement for the langauge?
>>
>> ++vote.
>>
>> We also need an own type for the empty array literal '[]' btw.
>
> Do you have an example where a own type for [] would be usefull?
>
It is the same rationale as the one for null
Eg:
class Class{
this(int,string,double[]) {}
}
auto New(T,A...)(A args) {
return new T(args);
}
void main(){
auto a = new Class(1,"hi",[]); // fine
auto b = New!Class(1,"hi",[]); // would require an own type
}
|
October 26, 2011 Re: Own type for null? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gor Gyolchanyan | Le 26/10/2011 09:20, Gor Gyolchanyan a écrit :
> I agree. Null is a very common special-case value and overloading may
> be necessary based on that special-case value. Currently doing so
> means accepting any kind of typeless pointer (which is certainly not
> desirable).
>
+1 for me ! And +1 for non nullable types.
|
October 27, 2011 Re: Own type for null? | ||||
---|---|---|---|---|
| ||||
+1
I think 5899 is related issue.
Kenji Hara
2011/10/26 Gor Gyolchanyan <gor.f.gyolchanyan@gmail.com>:
> I agree. Null is a very common special-case value and overloading may be necessary based on that special-case value. Currently doing so means accepting any kind of typeless pointer (which is certainly not desirable).
>
> On Wed, Oct 26, 2011 at 9:49 AM, Benjamin Thaut <code@benjamin-thaut.de> wrote:
>> I recently tried to replace the deprecated overloading of new and delete and
>> came across a serious issue. You can not use std.conv.emplace with null. If
>> you pass null to it, null loses it's implicit casting cabablities and just
>> becomes a void*.
>> This issue pretty much exists with every template. As soon as you pass null
>> to a template (compile time) information gets lost.
>>
>> Besides fixing std.conv.emplace it could be really handy to be able to check for a null-type at compile time for example with non-nullable types.
>>
>> There is already a enhancement reqeust in bugzilla since January but it didn't get much attention yet: http://d.puremagic.com/issues/show_bug.cgi?id=5416
>>
>> Would this be a worthwile improvement for the langauge?
>> --
>> Kind Regards
>> Benjamin Thaut
>>
>
|
October 27, 2011 Re: Own type for null? | ||||
---|---|---|---|---|
| ||||
https://github.com/D-Programming-Language/dmd/pull/476 The pull request implementing that enhancement. Kenji Hara 2011/10/27 kenji hara <k.hara.pg@gmail.com>: > +1 > I think 5899 is related issue. > > Kenji Hara > > 2011/10/26 Gor Gyolchanyan <gor.f.gyolchanyan@gmail.com>: >> I agree. Null is a very common special-case value and overloading may be necessary based on that special-case value. Currently doing so means accepting any kind of typeless pointer (which is certainly not desirable). >> >> On Wed, Oct 26, 2011 at 9:49 AM, Benjamin Thaut <code@benjamin-thaut.de> wrote: >>> I recently tried to replace the deprecated overloading of new and delete and >>> came across a serious issue. You can not use std.conv.emplace with null. If >>> you pass null to it, null loses it's implicit casting cabablities and just >>> becomes a void*. >>> This issue pretty much exists with every template. As soon as you pass null >>> to a template (compile time) information gets lost. >>> >>> Besides fixing std.conv.emplace it could be really handy to be able to check for a null-type at compile time for example with non-nullable types. >>> >>> There is already a enhancement reqeust in bugzilla since January but it didn't get much attention yet: http://d.puremagic.com/issues/show_bug.cgi?id=5416 >>> >>> Would this be a worthwile improvement for the langauge? >>> -- >>> Kind Regards >>> Benjamin Thaut >>> >> > |
Copyright © 1999-2021 by the D Language Foundation