I posted an enhancement request for this:
http://d.puremagic.com/issues/show_bug.cgi?id=10527
Yet one small observation: This optimization would mean that a
lot of the use cases of "auto ref const MyType" parameters (the
upcoming non-templated auto ref feature... although I don't know
if that's the syntax for it) could be replaced by using "const
MyType" parameters.
Or, if you look at
To take the full advantage of this optimization, a change in
lambda function parameter type inference might be necessary,
which sadly would be a breaking change:
struct S
{
int get()
{
return 11;
}
int get() const
{
return 22;
}
}
void main()
{
S s;
On Sunday, 30 June 2013 at 09:38:49 UTC, TommiT wrote:
[..] So, in order to elide postblit when a const variable is
passed by value as a const argument, the function would not
only need to be pure, but also all of its parameters would have
to be either const or immutable.
All along I've bee
On Sunday, 30 June 2013 at 10:21:12 UTC, TommiT wrote:
Perhaps an interesting observation about this is that while in
C++ const correctness literally never improves performance [1],
in D (if these optimizations were implemented) const
correctness could potentially increase performance considera
Perhaps an interesting observation about this is that while in
C++ const correctness literally never improves performance [1],
in D (if these optimizations were implemented) const correctness
could potentially increase performance considerably (if there are
expensive postblits). Thus, functions
On Sunday, 30 June 2013 at 09:24:28 UTC, Diggory wrote:
[..]
Also, the function needs to be strongly pure, not just weakly
pure, otherwise the calling code could pass in both the const
variable and a non-const reference to that variable. If the
callee modifies the non-const reference it would
If this is indeed Diggory's point, it's not very pointy
(sorry). The compiler should be able to safely omit the
postblit on 's' when it passes it to foo (and the possible
destructor of foo's argument inside foo when foo exits).
If the postblit is omitted, and the function or code it calls
acc
On Sunday, 30 June 2013 at 08:59:14 UTC, anonymous wrote:
void foo(const S s)
{
data[0] = 42;
assert(s.values[0] == 1);
}
With the postblit, the assert holds. Without it, it would fail.
Isn't that problematic?
Ok, I see your point now. The function needs to be pure to elide
postblit
On Sunday, 30 June 2013 at 08:34:20 UTC, TommiT wrote:
On Sunday, 30 June 2013 at 08:16:44 UTC, anonymous wrote:
On Sunday, 30 June 2013 at 07:27:06 UTC, TommiT wrote:
On Sunday, 30 June 2013 at 02:20:24 UTC, Diggory wrote:
On Saturday, 29 June 2013 at 17:57:33 UTC, TommiT wrote:
On Saturday,
On Sunday, 30 June 2013 at 08:16:44 UTC, anonymous wrote:
On Sunday, 30 June 2013 at 07:27:06 UTC, TommiT wrote:
On Sunday, 30 June 2013 at 02:20:24 UTC, Diggory wrote:
On Saturday, 29 June 2013 at 17:57:33 UTC, TommiT wrote:
On Saturday, 29 June 2013 at 13:47:36 UTC, TommiT wrote:
[..]
Exam
On Sunday, 30 June 2013 at 07:27:06 UTC, TommiT wrote:
On Sunday, 30 June 2013 at 02:20:24 UTC, Diggory wrote:
On Saturday, 29 June 2013 at 17:57:33 UTC, TommiT wrote:
On Saturday, 29 June 2013 at 13:47:36 UTC, TommiT wrote:
[..]
Example:
struct S
{
int[] values;
this(this)
{
v
On Sunday, 30 June 2013 at 07:27:06 UTC, TommiT wrote:
[..]
case 1:
void foo(const S s)
{
S m = cast(S) s;
s.values[0] = 42;
}
A typo. It should be:
case 1:
void foo(const S s)
{
S m = cast(S) s;
m.values[0] = 42;
}
On Sunday, 30 June 2013 at 02:20:24 UTC, Diggory wrote:
Un
On Sunday, 30 June 2013 at 02:20:24 UTC, Diggory wrote:
On Saturday, 29 June 2013 at 17:57:33 UTC, TommiT wrote:
On Saturday, 29 June 2013 at 13:47:36 UTC, TommiT wrote:
[..]
Example:
struct S
{
int[] values;
this(this)
{
values = values.dup;
}
}
void foo(const S) { }
vo
On Saturday, 29 June 2013 at 17:57:33 UTC, TommiT wrote:
On Saturday, 29 June 2013 at 13:47:36 UTC, TommiT wrote:
[..]
Example:
struct S
{
int[] values;
this(this)
{
values = values.dup;
}
}
void foo(const S) { }
void main()
{
const S s;
foo(s); // No need to c
On Saturday, 29 June 2013 at 13:47:36 UTC, TommiT wrote:
[..]
Example:
struct S
{
int[] values;
this(this)
{
values = values.dup;
}
}
void foo(const S) { }
void main()
{
const S s;
foo(s); // No need to call postblit
}
One important related detail:
If t
Disclaimer: The "discovery" I'm about to describe here seems so
obvious that I'm inclined to think that I've made some mistake.
The sole purpose of postblit constructors is to provide value
semantics to structs which have mutable indirection (variables
which have only immutable indirection hav
17 matches
Mail list logo