On Thursday, 30 December 2021 at 01:04:10 UTC, Ali Çehreli wrote:
The second item in the documentation mentions "any number of
default parameters" when describing copy constructor syntax:
https://dlang.org/spec/struct.html#struct-copy-constructor
1) I can't figure out how to use those extra
On Thursday, 30 December 2021 at 04:42:06 UTC, Tejas wrote:
On Thursday, 30 December 2021 at 01:04:10 UTC, Ali Çehreli
wrote:
The second item in the documentation mentions "any number of
default parameters" when describing copy constructor syntax:
On Thursday, 30 December 2021 at 01:04:10 UTC, Ali Çehreli wrote:
The second item in the documentation mentions "any number of
default parameters" when describing copy constructor syntax:
https://dlang.org/spec/struct.html#struct-copy-constructor
1) I can't figure out how to use those extra
On Thursday, 30 December 2021 at 02:04:30 UTC, Ali Çehreli wrote:
On 12/29/21 5:14 PM, Paul Backus wrote:
Therefore, when you write your own copy constructors, you
should always use `inout` if possible, so that
compiler-generated copy constructors will be able to copy
instances of your
On 12/29/21 5:14 PM, Paul Backus wrote:
Therefore, when you write your own copy constructors, you should always
use `inout` if possible, so that compiler-generated copy constructors
will be able to copy instances of your struct that appear as members of
other structs.
Excellent point. I
On Thursday, 30 December 2021 at 01:04:10 UTC, Ali Çehreli wrote:
2) Unlike the examples there, I think the parameter should most
usefully be defined as 'const' unless there is a special reason:
struct S {
// const(S) instead of S:
this(ref const(S) that) {
}
}
Do you agree?
When the
The second item in the documentation mentions "any number of default
parameters" when describing copy constructor syntax:
https://dlang.org/spec/struct.html#struct-copy-constructor
1) I can't figure out how to use those extra parameters. For example, I
can't find a special function name to
On Wednesday, 29 December 2021 at 01:11:13 UTC, Stanislav Blinov
wrote:
Because opIndexAssign cannot distinguish at compile time
between initialization and assignment:
```d
Stuff[Key] aa;
aa[key] = Stuff(args); // ostensibly, initialization
aa[key] = otherStuff; // assignment to existing
On Wednesday, 29 December 2021 at 17:20:59 UTC, max haughton
wrote:
This is handled by the compiler backend. The simplest way it
can do this kind of optimization is by "inlining" the function.
This is done by transplanting the function body into the place
it's used. At this point the compiler
On Wednesday, 29 December 2021 at 16:51:47 UTC, rempas wrote:
On Wednesday, 29 December 2021 at 16:27:22 UTC, max haughton
wrote:
Inlining + constant propagation. Fancier iterations on those
exist too but 90% of the speedup will come from those since
for it to matter they likely would've been
On Wednesday, 29 December 2021 at 16:27:22 UTC, max haughton
wrote:
Inlining + constant propagation. Fancier iterations on those
exist too but 90% of the speedup will come from those since for
it to matter they likely would've been used in first place.
Sounds like black magic? So If I write
On Wednesday, 29 December 2021 at 15:53:38 UTC, rempas wrote:
On Wednesday, 29 December 2021 at 11:09:04 UTC, max haughton
wrote:
If the value is known at compile time the compiler can pretty
easily do that for you unless you're really unlucky.
How is this even possible?
Inlining + constant
On Wednesday, 29 December 2021 at 14:49:40 UTC, Steven
Schveighoffer wrote:
On 12/29/21 3:55 AM, rempas wrote:
Thanks! That's cool but I don't want this to be this way. Or
at least I want it to be able to take a default value so we
don't have to get passed all the time.
OK:
```
extern (C)
On Wednesday, 29 December 2021 at 11:09:04 UTC, max haughton
wrote:
If the value is known at compile time the compiler can pretty
easily do that for you unless you're really unlucky.
How is this even possible?
On Wednesday, 29 December 2021 at 10:14:13 UTC, Tobias Pankrath
wrote:
How do I mixin a function only if it is not already present?
This is the default behavior of template mixins.
On 12/29/21 3:56 AM, rempas wrote:
On Tuesday, 28 December 2021 at 22:26:33 UTC, max haughton wrote:
Why do you need this? What's wrong with a normal branch in this case.
Runtime performance. I want the value to get checked at compile time and
use "static if" with it
Oof, just let the
On 12/29/21 3:55 AM, rempas wrote:
Thanks! That's cool but I don't want this to be this way. Or at least I
want it to be able to take a default value so we don't have to get
passed all the time.
OK:
```
extern (C) void main() {
void print_num(int mul = 100)(int num) {
static if
On Wednesday, 29 December 2021 at 08:56:47 UTC, rempas wrote:
On Tuesday, 28 December 2021 at 22:26:33 UTC, max haughton
wrote:
Why do you need this? What's wrong with a normal branch in
this case.
Runtime performance. I want the value to get checked at compile
time and use "static if" with
On Wednesday, 29 December 2021 at 10:21:07 UTC, Stanislav Blinov
wrote:
On Wednesday, 29 December 2021 at 10:14:13 UTC, Tobias Pankrath
wrote:
How do I mixin a function only if it is not already present?
Perhaps use opDispatch?
That's a great idea and I'll look into it.
On Wednesday, 29 December 2021 at 10:14:13 UTC, Tobias Pankrath
wrote:
How do I mixin a function only if it is not already present?
Perhaps use opDispatch?
I am trying to implement the builder pattern for some structs.
Currently I am auto implementing all methods by mixing them into
the builder, but now I need some custom logic for some of the
fields and I figured I just write them down by hand and mixin the
rest.
I tried checking if it is
On Wednesday, 29 December 2021 at 01:34:22 UTC, Stanislav Blinov
wrote:
One can also do this kind of stuff:
```d
import core.stdc.stdio;
struct Literal(alias val)
{
enum value = val;
}
enum lit(alias val) = Literal!val.init;
void print_num(Arg)(int num, Arg mul)
{
static if (is(Arg
On Tuesday, 28 December 2021 at 22:26:33 UTC, max haughton wrote:
Why do you need this? What's wrong with a normal branch in this
case.
Runtime performance. I want the value to get checked at compile
time and use "static if" with it
On Tuesday, 28 December 2021 at 22:06:50 UTC, Steven
Schveighoffer wrote:
On 12/28/21 4:19 PM, rempas wrote:
Here:
```
extern (C) void main() {
void print_num(int mul)(int num) {
static if (is(mul == ten)) {
printf("%d\n", num * 10);
} else static if (is(mul == three)) {
On Wednesday, 29 December 2021 at 01:00:53 UTC, Tejas wrote:
On Tuesday, 28 December 2021 at 18:27:36 UTC, vit wrote:
[...]
Since a destructor ignores `const`, I think adding the `~this`
to Foo manually is somehow making the compiler have to actually
cast away const, which it is doing via
25 matches
Mail list logo