Struct default constructor - need some kind of solution for C++ interop

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 8 02:33:01 PDT 2016


On Wednesday, 7 September 2016 at 12:28:41 UTC, Ethan Watson 
wrote:
> On Wednesday, 7 September 2016 at 12:14:46 UTC, rikki 
> cattermole wrote:
>> http://dlang.org/phobos/std_typecons.html#.scoped
>
> This is the kind of hackaround I'd need to do if it were a 
> class... And it would require more hacking around than the 
> standard library supports. And it's a spiraling-out-of-control 
> hack, which would effectively mean every C++ matching class 
> will need to define a class and then an alias with the scoped 
> type, and then that means the pattern matching I've been 
> creating for function linkups won't work any more...
>
> static opCall() and a static alloc function for allocating on 
> the heap are still looking like the simplest options here.

They aren't. It won't also be used if you declare new instance on 
stack via `S s`. Staic opCall is 100% identical to any other 
static factory method in its semantics (i.e. static S create()).

What I am trying to say is thta prohibiting struct default 
constructors is an intentional language design decision in D, 
with a lot of consequences. There is literally no chance it can 
be tricked.

Instead, it would be much more constructive (pun unintended) to 
focus on language changes to extern(c++) class bindings to make 
them suitable for the task - those won't affect anyone but C++ 
interop users.


More information about the Digitalmars-d mailing list