Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
May 27, 2015 Null argument and function resolution | ||||
---|---|---|---|---|
| ||||
Check this example: http://dpaste.dzfl.pl/53f85bae4382 Calling with null, both c-tor match. Is there a way to solve this? Something like: this(in ubyte* data) if( ??? ) { } Andrea |
May 27, 2015 Re: Null argument and function resolution | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrea Fontana | Two options: 1) add an overload that takes typeof(null) this(typeof(null)) { /* handles the null literal specially */ } 2) Cast null to a specific type when making it: new YourClass(cast(ubyte*) null); |
May 27, 2015 Re: Null argument and function resolution | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | The first answer is the one I was looking for. Very useful.
You should add to next "this week in d" tips.
On Wednesday, 27 May 2015 at 14:09:48 UTC, Adam D. Ruppe wrote:
> Two options:
>
> 1) add an overload that takes typeof(null)
>
> this(typeof(null)) { /* handles the null literal specially */ }
>
> 2) Cast null to a specific type when making it:
>
> new YourClass(cast(ubyte*) null);
|
May 27, 2015 Re: Null argument and function resolution | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe Attachments: | On Wed, 27 May 2015 14:09:47 +0000, Adam D. Ruppe wrote:
> Two options:
>
> 1) add an overload that takes typeof(null)
>
> this(typeof(null)) { /* handles the null literal specially */ }
you keep breaking my "box of thinking". ;-) never thought about such declaration.
|
May 27, 2015 Re: Null argument and function resolution | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Wednesday, 27 May 2015 at 19:38:16 UTC, ketmar wrote:
> On Wed, 27 May 2015 14:09:47 +0000, Adam D. Ruppe wrote:
>
>> Two options:
>>
>> 1) add an overload that takes typeof(null)
>>
>> this(typeof(null)) { /* handles the null literal specially */ }
>
> you keep breaking my "box of thinking". ;-) never thought about such
> declaration.
Unfortunately, there is no equivalent way to disable assignment of [] at compile time.
struct ArrayWrapper(T)
{
T[] a;
this(T[] arr) { a = arr; }
//Doesn't work; Conflicts with this(T[] arr)
//@disable this(typeof(this)[]);
//Doesn't work; hijacked by this(T[] arr)
//@disable this(typeof([]));
}
|
May 27, 2015 Re: Null argument and function resolution | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On 05/27/2015 10:09 PM, Meta wrote: > On Wednesday, 27 May 2015 at 19:38:16 UTC, ketmar wrote: >> On Wed, 27 May 2015 14:09:47 +0000, Adam D. Ruppe wrote: >> >>> Two options: >>> >>> 1) add an overload that takes typeof(null) >>> >>> this(typeof(null)) { /* handles the null literal specially */ } >> >> you keep breaking my "box of thinking". ;-) never thought about such >> declaration. > > Unfortunately, there is no equivalent way to disable assignment of [] at > compile time. > > struct ArrayWrapper(T) > { > T[] a; > > this(T[] arr) { a = arr; } > > //Doesn't work; Conflicts with this(T[] arr) > //@disable this(typeof(this)[]); > > //Doesn't work; hijacked by this(T[] arr) > //@disable this(typeof([])); > } https://issues.dlang.org/show_bug.cgi?id=7007 |
Copyright © 1999-2021 by the D Language Foundation