What is the case against a struct post-blit default constructor?
foobar
foo at bar.com
Wed Oct 10 04:40:06 PDT 2012
On Wednesday, 10 October 2012 at 11:23:11 UTC, Jonathan M Davis
wrote:
> On Wednesday, October 10, 2012 12:45:20 Don Clugston wrote:
>> Of course there would be no point.
>> You have not answered the question. The issue is, WHY can we
>> not
>> guarantee that that the struct default constructor is called?
>>
>> I have a vague memory that Walter mentioned a technical
>> difficulty once
>> but I don't remember anything about what it was.
>>
>> I can't imagine what it would be.
>
> I know that one of the issues was exceptions, though that could
> be solved by
> forcing them to be nothrow. There were others, but I don't
> remember the
> details. Certainly, from what I recall, the situation is such
> that you'd have
> to restrict a default construtor so thoroughly that it would be
> pretty much
> pointless to have one at all.
>
>> Even in the worst case, it would be
>> possible to run CTFE on the default constructor in order to
>> create
>> .init. This would limit the default constructor to things
>> which are
>> CTFEable, but even that would still be useful for templated
>> structs.
>
> Of what real value is a default construct that must be
> CTFEable? If you can
> construct everything at compile time, then you can directly
> initialize each of
> the member variables. It's being able to run a default
> constructor at runtime
> that's useful, and since init must be known at compile time,
> you get into the
> whole issue of needing init when you can't use a default
> constructor. For
> default constructors to be of any real value, it would have to
> be possible to
> replace all instances of init with a call to the default
> constructor _at
> runtime_. As long as you're restricted to CTFE, you might as
> well just
> directly initialize the member variables to set the values
> appropriately in
> the init property.
>
> - Jonathan M Davis
Can you please elaborate on where the .init property is being
relied on? This is an aspect of D I don't really understand.
What's the difference between a no-arg ctor and one with args in
relation to this requirement?
Is this used somewhere in template code? I vaguely remember the
clear() function is supposed to be related to this.
Personally, I don't agree with Walter's stance on default
initialization. An explicit init by the user is IMO better design
since it is _explicit_ and therefore documents the programmer's
intention in the code itself.
i.e.:
int x = 0; // this is explicit and states my intention
int x; // is it intentionally == 0? Did I forget to set a
meaningful value?
More information about the Digitalmars-d
mailing list