I was a little surprised the subclassing syntax didn't do
structural concatenation for struct's. That is,
```d
import std.stdio : writeln;
struct A {
int a;
void printA() {
println(this.a);
}
}
struct B : A {
int b;
void printAB() {
this.printA();
println(this.b);
}
}
void an_A_fu
On Monday, June 23, 2025 9:56:15 PM Mountain Daylight Time Andy Valencia via
Digitalmars-d-learn wrote:
> I was a little surprised the subclassing syntax didn't do
> structural concatenation for struct's. That is,
>
> ```d
> import std.stdio : writeln;
>
> struct A {
> int a;
> void printA()
arguments about it in the past).
I think everyone agrees that pointers can be abused, misused, and
used to make things blow up. Yet nobody argues they should be
removed, because it's up to the programmer to do things that make
sense. The restrictions on operator overloading reflect the us
On Monday, 23 June 2025 at 19:00:34 UTC, matheus wrote:
In fact this restriction is good in fact.
Stockholm syndrome
On Monday, 23 June 2025 at 15:27:46 UTC, Nick Treleaven wrote:
...
One reason is that it would be hard to reason about what the
operator means - for example if there is one operator overload
in module `a` and another one in `b`, that have compatible
operand types, and both imports are used in
On Monday, 23 June 2025 at 15:27:46 UTC, Nick Treleaven wrote:
One reason is that it would be hard to reason about what the
operator means - for example if there is one operator overload
in module `a` and another one in `b`, that have compatible
operand types, and both imports are used in the s
On Sunday, 22 June 2025 at 15:04:27 UTC, matheus wrote:
Hi, could someone please tell me why operador overloading
(https://dlang.org/spec/operatoroverloading.html) is relegated
only to classes and structs?
One reason is that it would be hard to reason about what the
operator means - for
On Monday, 23 June 2025 at 10:14:25 UTC, Jonathan M Davis wrote:
...
Overloaded operators are considered to be part of the type just
like constructors are part of the type, and D has done a number
of things with overloaded operators to try to minimize the
ability to do what many consider to b
On Sunday, 22 June 2025 at 15:04:27 UTC, matheus wrote:
Hi, could someone please tell me why operador overloading
(https://dlang.org/spec/operatoroverloading.html) is relegated
only to classes and structs?
"1 Operator overloading is accomplished by rewriting operators
whose operand
On Sunday, June 22, 2025 9:04:27 AM Mountain Daylight Time matheus via
Digitalmars-d-learn wrote:
> Hi, could someone please tell me why operador overloading
> (https://dlang.org/spec/operatoroverloading.html) is relegated
> only to classes and structs?
>
> "1 Operator overloa
Hi, could someone please tell me why operador overloading
(https://dlang.org/spec/operatoroverloading.html) is relegated
only to classes and structs?
"1 Operator overloading is accomplished by rewriting operators
whose operands are class or struct objects into calls to
specially
On Sunday, 15 June 2025 at 16:14:28 UTC, Manfred Nowak wrote:
On Sunday, 15 June 2025 at 10:51:37 UTC, Nick Treleaven wrote:
An untyped parameter does make the literal an actual template:
```d
pragma(msg, __traits(isTemplate, (x) {})); // true
```
It can be instantiated with a type parameter.
On Sunday, 15 June 2025 at 10:51:37 UTC, Nick Treleaven wrote:
An untyped parameter does make the literal an actual template:
```d
pragma(msg, __traits(isTemplate, (x) {})); // true
```
It can be instantiated with a type parameter.
Therefore in the case discussed, the code `(_){}' declares a
On Sunday, 15 June 2025 at 10:51:37 UTC, Nick Treleaven wrote:
So I think there must be another reason why your unary literals
work.
Given it's specifically void return, and top level and it acts
like it matches the first return, I expect that void is
incorrectly being considered a invalid
On Saturday, 14 June 2025 at 23:49:19 UTC, Steven Schveighoffer
wrote:
A lambda is a shortened syntax for a function literal or
delegate literal.
HOWEVER, when you do not give the parameters types, the lambda
becomes a template! Well, not actually a template, but a
quasi-template.
An untype
On Saturday, 14 June 2025 at 23:49:19 UTC, Steven Schveighoffer
wrote:
If I had to guess, I think the compiler is not able to exactly
deduce what form your lambda should be instantiated with. I
think it's picking the first form it sees.
I think if anything, the error message is really weird.
On Saturday, 14 June 2025 at 00:02:32 UTC, Andrey Zherikov wrote:
The simplest code that shows the issue:
```d
struct S{}
template f(void function(S) F) {}
template f(int function(S) F) {}
mixin f!((_) {});
mixin f!((_) => 0); // Error: cannot return non-void from
`void` function
On Saturday, 14 June 2025 at 03:17:09 UTC, monkyyy wrote:
```d
import std;
mixin template f(int function(int) F){}
mixin template f(void function(int)
F){unittest{"void".writeln;}}
//mixin f!((_){}); //FAILS
mixin template g(void function(int)
F){unittest{"void".writeln;}}
mixin template
On Saturday, 14 June 2025 at 02:16:58 UTC, Andrey Zherikov wrote:
On Saturday, 14 June 2025 at 02:10:03 UTC, monkyyy wrote:
On Saturday, 14 June 2025 at 01:46:31 UTC, Andrey Zherikov
wrote:
On Saturday, 14 June 2025 at 00:02:32 UTC, Andrey Zherikov
wrote:
Simplified test case a bit more.
This
On Saturday, 14 June 2025 at 02:10:03 UTC, monkyyy wrote:
On Saturday, 14 June 2025 at 01:46:31 UTC, Andrey Zherikov
wrote:
On Saturday, 14 June 2025 at 00:02:32 UTC, Andrey Zherikov
wrote:
Simplified test case a bit more.
This works:
```d
template f(void function(int) F) {}
template f(int func
On Saturday, 14 June 2025 at 00:26:27 UTC, monkyyy wrote:
I believe every change in compilation from (top level)
declaration order is considered a compiler bug
However, I see Allot of issues with this code, Id want to
see something near functional code around this subject; its
worth pokin
On Saturday, 14 June 2025 at 01:46:31 UTC, Andrey Zherikov wrote:
On Saturday, 14 June 2025 at 00:02:32 UTC, Andrey Zherikov
wrote:
Simplified test case a bit more.
This works:
```d
template f(void function(int) F) {}
template f(int function(int) F) {}
mixin f!((int _) {});
mixin f!((int _) =>
On Saturday, 14 June 2025 at 00:02:32 UTC, Andrey Zherikov wrote:
Simplified test case a bit more.
This works:
```d
template f(void function(int) F) {}
template f(int function(int) F) {}
mixin f!((int _) {});
mixin f!((int _) => 0);
mixin f!((int) {});
mixin f!((int) => 0);
mixin f!((_) {});
mi
On Saturday, 14 June 2025 at 00:02:32 UTC, Andrey Zherikov wrote:
The simplest code that shows the issue:
```d
struct S{}
template f(void function(S) F) {}
template f(int function(S) F) {}
mixin f!((_) {});
mixin f!((_) => 0); // Error: cannot return non-void from
`void` function
The simplest code that shows the issue:
```d
struct S{}
template f(void function(S) F) {}
template f(int function(S) F) {}
mixin f!((_) {});
mixin f!((_) => 0); // Error: cannot return non-void from `void`
function
// mixin f!((_) => 0);
//
On Wednesday, 20 December 2023 at 02:56:24 UTC, Steven
Schveighoffer wrote:
Instead you are trying to reassign the `this` reference, which
is a local (and also forbidden). Think about it a second, your
`this + rhs` is going to allocate a *new* object. Then if the
assignment to the local `this`
auto opOpAssign(string op)(Value rhs)
{
this = this + rhs;
return this;
}
// Error: `this` is not an lvalue and cannot be modified
```
Assigning an object is like copying a pointer. You may think you
can try overloading the assignment, but it is
[forbidden](https:/
On Sunday, 17 December 2023 at 04:13:20 UTC, Ki Rill wrote:
I am trying to overload `opOpAssign` for my class. The code
compiles, but it does not seem to be working.
```d
// binary operations have already been implemented for Value
// i need +=, -=, *=, /=
auto opOpAssign(string op)(Value rhs)
On Monday, 18 December 2023 at 04:49:53 UTC, novice2 wrote:
On Monday, 18 December 2023 at 03:39:16 UTC, Ki Rill wrote:
On Sunday, 17 December 2023 at 07:05:12 UTC, Adam D. Ruppe
wrote:
On Sunday, 17 December 2023 at 04:13:20 UTC, Ki Rill wrote:
[...]
check what `op` is. pretty sure it is "+
On Monday, 18 December 2023 at 03:39:16 UTC, Ki Rill wrote:
On Sunday, 17 December 2023 at 07:05:12 UTC, Adam D. Ruppe
wrote:
On Sunday, 17 December 2023 at 04:13:20 UTC, Ki Rill wrote:
[...]
check what `op` is. pretty sure it is "+" not "+=" so your
element isnt' saved anywhere. also a bit
On Sunday, 17 December 2023 at 07:05:12 UTC, Adam D. Ruppe wrote:
On Sunday, 17 December 2023 at 04:13:20 UTC, Ki Rill wrote:
[...]
check what `op` is. pretty sure it is "+" not "+=" so your
element isnt' saved anywhere. also a bit iffy there isn't a
member here to work on
Yes, op is '+'.
On Sunday, 17 December 2023 at 04:13:20 UTC, Ki Rill wrote:
auto opOpAssign(string op)(in ElementType rhs)
{
mixin("return this" ~ op ~ "rhs;");
}
```
check what `op` is. pretty sure it is "+" not "+=" so your
element isnt' saved anywhere. also a bit iffy there isn't a
member here to work
On Sunday, 17 December 2023 at 04:15:02 UTC, Ki Rill wrote:
On Sunday, 17 December 2023 at 04:13:20 UTC, Ki Rill wrote:
I am trying to overload `opOpAssign` for my class. The code
[...]
I forgot to mention, it is relevant to
[`Value`](https://github.com/rillki/tiny-grad/blob/main/source/rk/
On Sunday, 17 December 2023 at 04:13:20 UTC, Ki Rill wrote:
I am trying to overload `opOpAssign` for my class. The code
[...]
I forgot to mention, it is relevant to
[`Value`](https://github.com/rillki/tiny-grad/blob/main/source/rk/tgrad/core/value.d) class only.
I am trying to overload `opOpAssign` for my class. The code
compiles, but it does not seem to be working.
```d
// binary operations have already been implemented for Value
// i need +=, -=, *=, /=
auto opOpAssign(string op)(Value rhs)
{
mixin("return this" ~ op ~ "rhs;");
}
auto opOpAssign(
c.add(2);
c.writeln; // x + 2 +
// with constructor:
c = Calculate("x");
c.add(2);
c.writeln; // x + 2 +
}
```
There is a simple struct like the one above that is not related
to reality. There can be more than 2 function overloading in
it, but in our example there
On Thursday, 2 November 2023 at 11:17:42 UTC, Salih Dincer wrote:
On Wednesday, 1 November 2023 at 20:04:52 UTC, Basile B. wrote:
Yes. D constructors are not named but the current
implementation adds a name that is `__ctor`, so add
```d
alias add = __ctor;
```
to you struct.
Yeah, it wor
On Wednesday, 1 November 2023 at 20:04:52 UTC, Basile B. wrote:
Yes. D constructors are not named but the current
implementation adds a name that is `__ctor`, so add
```d
alias add = __ctor;
```
to you struct.
Yeah, it works! Thanks...:)
SDB@79
On Tuesday, 31 October 2023 at 20:09:44 UTC, Salih Dincer wrote:
[...]
is it possible to do something like `alias add = this;`?
```d
struct Calculate
{
int memory;
string result;
auto toString() => result;
// alias add = this;
import std.string : format;
this(stri
c = Calculate("x");
c.add(2);
c.writeln; // x + 2 +
}
```
There is a simple struct like the one above that is not related
to reality. There can be more than 2 function overloading in it,
but in our example there are only 2. Without implementing a
similar function again for each c
On Sunday, 30 October 2022 at 23:43:03 UTC, NonNull wrote:
On Sunday, 30 October 2022 at 18:24:22 UTC, Adam D Ruppe wrote:
[...]
Ah, makes sense to limit the possible low level error messages
with separate compilation because of the linker not knowing D
signatures. Thanks for the intuition.
On Sunday, 30 October 2022 at 18:24:22 UTC, Adam D Ruppe wrote:
it prolly just to keep newbs from making confusing mistakes and
getting weird behavior at startup. If there's two mains, which
one is the expected entry? Perhaps it could just be the one
that matches the permitted signature, and if
On Sunday, 30 October 2022 at 17:41:07 UTC, Imperatorn wrote:
On Sunday, 30 October 2022 at 17:29:25 UTC, NonNull wrote:
On Sunday, 30 October 2022 at 16:31:45 UTC, Imperatorn wrote:
You should not have multiple mains. Rename it and call it
Doesn't answer my questions. I wasn't asking for pra
On Sunday, 30 October 2022 at 16:09:54 UTC, NonNull wrote:
I am linking to a C project with some C already automatically
translated into D including the C main function `int main(int
argc, char** argv){/* ... */}` which I wanted to call from a D
main function in a new module.
did you put exte
On Sunday, 30 October 2022 at 17:29:25 UTC, NonNull wrote:
On Sunday, 30 October 2022 at 16:31:45 UTC, Imperatorn wrote:
You should not have multiple mains. Rename it and call it
Doesn't answer my questions. I wasn't asking for practical,
moral or esthetic advice.
Try to phrase your questio
On Sunday, 30 October 2022 at 16:31:45 UTC, Imperatorn wrote:
You should not have multiple mains. Rename it and call it
Doesn't answer my questions. I wasn't asking for practical, moral
or esthetic advice.
On Sunday, 30 October 2022 at 16:09:54 UTC, NonNull wrote:
I am linking to a C project with some C already automatically
translated into D including the C main function `int main(int
argc, char** argv){/* ... */}` which I wanted to call from a D
main function in a new module. But then I found t
I am linking to a C project with some C already automatically
translated into D including the C main function `int main(int
argc, char** argv){/* ... */}` which I wanted to call from a D
main function in a new module. But then I found that the former C
main in D will not compile! ldc2 complains
On Wednesday, 22 June 2022 at 12:42:48 UTC, Steven Schveighoffer
wrote:
On 6/22/22 2:05 AM, monkyyy wrote:
On Monday, 20 June 2022 at 13:20:51 UTC, Steven Schveighoffer
wrote:
And you can also use an inner struct to define overloaded
functions.
I believe templates make a better bandaid
```d
v
On 6/22/22 2:05 AM, monkyyy wrote:
On Monday, 20 June 2022 at 13:20:51 UTC, Steven Schveighoffer wrote:
And you can also use an inner struct to define overloaded functions.
I believe templates make a better bandaid
```d
void main(){
template bar(){
void bar_(int){}
void
On Monday, 20 June 2022 at 13:20:51 UTC, Steven Schveighoffer
wrote:
And you can also use an inner struct to define overloaded
functions.
I believe templates make a better bandaid
```d
void main(){
template bar(){
void bar_(int){}
void bar_(float){}
On 6/17/22 8:09 AM, Chris Katko wrote:
I don't need this functionality, but I wanted to be sure.
Does function overloading not work with nested functions? I got a
compiler error (something like "function already defined") when I tried it.
Correct, it's not allowed.
Howev
On Friday, 17 June 2022 at 13:04:47 UTC, Chris Katko wrote:
On Friday, 17 June 2022 at 12:19:33 UTC, bauss wrote:
On Friday, 17 June 2022 at 12:09:33 UTC, Chris Katko wrote:
I don't need this functionality, but I wanted to be sure.
Does function overloading not work with nested functio
On Friday, 17 June 2022 at 12:19:33 UTC, bauss wrote:
On Friday, 17 June 2022 at 12:09:33 UTC, Chris Katko wrote:
I don't need this functionality, but I wanted to be sure.
Does function overloading not work with nested functions? I
got a compiler error (something like "functi
On Friday, 17 June 2022 at 12:09:33 UTC, Chris Katko wrote:
I don't need this functionality, but I wanted to be sure.
Does function overloading not work with nested functions? I got
a compiler error (something like "function already defined")
when I tried it.
According t
I don't need this functionality, but I wanted to be sure.
Does function overloading not work with nested functions? I got a
compiler error (something like "function already defined") when I
tried it.
On 1/19/22 3:47 AM, Enjoys Math wrote:
```
module expr;
import dots;
import operator;
import equation;
import var;
import var_expr;
import zz_const;
class Expr
{
public:
void opBinary(string op)(string s) const
{
static if (op == "+")
{
Expr right = null;
On Wednesday, 19 January 2022 at 08:47:27 UTC, Enjoys Math wrote:
```
module expr;
import dots;
import operator;
import equation;
import var;
import var_expr;
import zz_const;
class Expr
{
public:
void opBinary(string op)(string s) const
{
static if (op == "+")
{
Expr
On Wednesday, 19 January 2022 at 08:47:27 UTC, Enjoys Math wrote:
```
module expr;
import dots;
import operator;
import equation;
import var;
import var_expr;
import zz_const;
class Expr
{
public:
void opBinary(string op)(string s) const
{
static if (op == "+")
{
Expr
```
module expr;
import dots;
import operator;
import equation;
import var;
import var_expr;
import zz_const;
class Expr
{
public:
void opBinary(string op)(string s) const
{
static if (op == "+")
{
Expr right = null;
if (s == ".." || s == "..." || s == ""
On Monday, 8 February 2021 at 15:56:24 UTC, Michael Brown wrote:
Hi all,
Is it possible to operator overload on enums? I'd like to do a
opCmp()
Kind regards,
Mike
You can create custom struct type with opCmp() and create enum
with that type. Example: https://run.dlang.io/is/m7DN66
Hi all,
Is it possible to operator overload on enums? I'd like to do a
opCmp()
Kind regards,
Mike
On Monday, 8 February 2021 at 15:56:24 UTC, Michael Brown wrote:
Hi all,
Is it possible to operator overload on enums? I'd like to do a
opCmp()
Kind regards,
Mike
No, it isn't. Only structs and classes can have overloaded
operators.
On Monday, 11 January 2021 at 18:51:04 UTC, Jack wrote:
alias Callback = void function(const C, int);
void main()
{
auto l = SList!Callback();
auto a = (C c, int d) { };
auto b = (C c, int d) { };
auto c = (const C c, int d) { };
l.insert(a);
l.insert(b);
l.insert(c);
On Monday, 11 January 2021 at 18:51:04 UTC, Jack wrote:
Here's what I'm trying to make to work:
import std.container : SList;
class C
{
static immutable Foo = new C();
//
}
alias Callback = void function(const C, int);
void main()
{
auto l = SList!Callback();
auto a = (C c
On Monday, 11 January 2021 at 18:37:58 UTC, ag0aep6g wrote:
On Monday, 11 January 2021 at 18:12:17 UTC, Jack wrote:
thanks! now, how would I add const here?
import std.container : SList;
auto l = SList!Callabck();
doesn't work:
auto l = SList!(const(Callabck()));
auto l = SList!(const Callabc
On Monday, 11 January 2021 at 18:12:17 UTC, Jack wrote:
thanks! now, how would I add const here?
import std.container : SList;
auto l = SList!Callabck();
doesn't work:
auto l = SList!(const(Callabck()));
auto l = SList!(const Callabck());
You said you want the callbacks to accept both mutabl
On Monday, 11 January 2021 at 16:56:05 UTC, ag0aep6g wrote:
On Monday, 11 January 2021 at 16:40:01 UTC, Jack wrote:
let's say a I have this:
void f(X foo) { }
but I'd like to make f() accept immutable X too so instead of
cast away everywhere in the code where immutable(X) is passed
to f() or
On Monday, 11 January 2021 at 16:40:01 UTC, Jack wrote:
let's say a I have this:
void f(X foo) { }
but I'd like to make f() accept immutable X too so instead of
cast away everywhere in the code where immutable(X) is passed
to f() or make a overload for this, are there any way to accept
both
let's say a I have this:
void f(X foo) { }
but I'd like to make f() accept immutable X too so instead of
cast away everywhere in the code where immutable(X) is passed to
f() or make a overload for this, are there any way to accept both
in same function? those function are callback-like functi
On 1/10/21 7:27 PM, Paul wrote:
> On Monday, 11 January 2021 at 02:37:24 UTC, Ali Çehreli wrote:
>> >> T opCast(T)() const if (is(T : Vec!(size, S2), S2)) {
>
>> The is expression can be so complicated that I used a different
>> approach below.
>
>> if (isInstanceOfVec!T &&
>> T.init.
On Monday, 11 January 2021 at 03:40:41 UTC, Paul wrote:
On Monday, 11 January 2021 at 00:48:49 UTC, Steven
Schveighoffer wrote:
I would think though, that this should work:
T opCast(T : Vec!(vecsize, S), S)()
Oh wouw, this seems to work perfectly! Awesome thanks ^^
Any Idea why
T opCast(T,
On Monday, 11 January 2021 at 00:48:49 UTC, Steven Schveighoffer
wrote:
I would think though, that this should work:
T opCast(T : Vec!(vecsize, S), S)()
Oh wouw, this seems to work perfectly! Awesome thanks ^^
Any Idea why
T opCast(T, S)() const if (is(T : Vec!(grootte, S))) {
yields the er
On Monday, 11 January 2021 at 02:37:24 UTC, Ali Çehreli wrote:
>> T opCast(T)() const if (is(T : Vec!(size, S2), S2)) {
The is expression can be so complicated that I used a different
approach below.
if (isInstanceOfVec!T &&
T.init.content.length == size) {
// ADDED:
ali
On 1/10/21 6:37 PM, Ali Çehreli wrote:
>// OBSERVATION: Should the cast below be S?
>converted.content[i] = cast(S2) content[i];
I take that back. Yes, it should be S2. (I've been off lately. :) )
Ali
On 1/10/21 5:09 PM, Paul wrote:
> I'll paste more of my file, I hope that's ok.
Not only ok but much appreciated. :)
>> T opCast(T)() const if (is(T : Vec!(size, S2), S2)) {
The is expression can be so complicated that I used a different approach
below. I left notes in capital letters bel
On Monday, 11 January 2021 at 00:25:36 UTC, Ali Çehreli wrote:
You don't show complete code; so, I hope I came up with
something that reflects your case.
Thank you, sadly S (S2 now) is not any specific type, sorry I'll
paste more of my file, I hope that's ok. (Sidenote, I'm not sure
it's the
On 1/10/21 7:09 PM, Paul wrote:
Is there a way to have additional template arguments in operator overloads?
The problem I'm having is mostly caused by casting a templated struct to
other templated structs. I had the following code;
T opCast(T)() const if (is(T : Vec!(vecsize, S), S)) {
T
On 1/10/21 4:09 PM, Paul wrote:
> Is there a way to have additional template arguments in operator
overloads?
I haven't tried that but the following method seems to work for you. You
don't show complete code; so, I hope I came up with something that
reflects your case.
import std;
struct
Is there a way to have additional template arguments in operator
overloads?
The problem I'm having is mostly caused by casting a templated
struct to other templated structs. I had the following code;
T opCast(T)() const if (is(T : Vec!(vecsize, S), S)) {
T converted;
static for
On Saturday, 12 December 2020 at 20:25:48 UTC, Adam D. Ruppe
wrote:
On Saturday, 12 December 2020 at 18:14:31 UTC, Paul Backus
wrote:
IMO this is one of the stupider design decisions in D, but
it's unlikely it will ever be fixed.
It is useful in several other contexts though, including user
o
On Saturday, 12 December 2020 at 20:26:00 UTC, Dennis wrote:
If issue 19365 got fixed
eeek I thought that was fixed but apparently not :(
so yeah alias won't work for operator overloads. Does work for
other functions so good technique to know but not here.
So for op prolly go with the strin
On Saturday, 12 December 2020 at 18:14:31 UTC, Paul Backus wrote:
IMO this is one of the stupider design decisions in D, but it's
unlikely it will ever be fixed.
It is useful in several other contexts though, including user
overriding and private data stores for the mixin.
The easiest workar
On Saturday, 12 December 2020 at 18:14:31 UTC, Paul Backus wrote:
IMO this is one of the stupider design decisions in D, but it's
unlikely it will ever be fixed. The easiest workaround is to
use string mixins instead, which work the way you'd expect them
to.
If issue 19365 got fixed, it could
On Saturday, 12 December 2020 at 18:14:31 UTC, Paul Backus wrote:
Functions from different mixin templates can't overload each
other. The reason for this is that, when you mix in a mixin
template, it does not *actually* add the declarations inside it
to a current scope: instead, it adds them to
On Saturday, 12 December 2020 at 17:36:57 UTC, Tobias Pankrath
wrote:
I want to wrap e.g. an int and implement basic arithmetic. In
the provided example [1] I use two mixin templates to
separately implement scaling (multiplication with int/double)
and addition and subtraction with the type its
I want to wrap e.g. an int and implement basic arithmetic. In the
provided example [1] I use two mixin templates to separately
implement scaling (multiplication with int/double) and addition
and subtraction with the type itself.
In the end I want to have several distinct wrappers and allow
s
ave a geomentry object and in one case I get x0,y0,x1,y1
and in the other case x,y,w,h
IMO that would make a lot of sense.
D doesn't do overloading based on return type.
You can do some things like return an item that alias this'd to one of
the two, and then use an accessor for the
It is easy. You can make both types as children of common parent
class myT, and when return myT.
Wouldn't it make a lot of sense to allow different opIndex
implementations based on return type?
class myC {
myT1 opIndex(int x)
myT2 opIndex(int x)
}
Depending on the types involved myC[1] woudl return myT1 or myT2.
Use-case: I have a geomentry object and in one case I get x0,
On Tuesday, 21 January 2020 at 20:48:44 UTC, Enjoys Math wrote:
I have an Integer class in integer.d. A RationalNumber class
in rational_number.d, and they each import each other (so that
could be the issue). However, this is not working:
Symbol opBinary(string op : "/")(const Integer z)
On 1/21/20 3:48 PM, Enjoys Math wrote:
I have an Integer class in integer.d. A RationalNumber class in
rational_number.d, and they each import each other (so that could be the
issue). However, this is not working:
Symbol opBinary(string op : "/")(const Integer z) const
{
retu
I have an Integer class in integer.d. A RationalNumber class in
rational_number.d, and they each import each other (so that could
be the issue). However, this is not working:
Symbol opBinary(string op : "/")(const Integer z) const
{
return new RationalNumber(this, z);
}
Getti
On Friday, 11 October 2019 at 13:13:46 UTC, Dennis wrote:
On Friday, 11 October 2019 at 12:45:59 UTC, Boyan Lazov wrote:
Any ideas what I'm doing wrong?
Nothing, it's a bug.
https://issues.dlang.org/show_bug.cgi?id=19476
Alright, I see
Well, the alias workaround works, so that seems just as
On Friday, 11 October 2019 at 12:45:59 UTC, Boyan Lazov wrote:
Any ideas what I'm doing wrong?
Nothing, it's a bug.
https://issues.dlang.org/show_bug.cgi?id=19476
Hello,
I seem to have a problem when I use a template mixin and then try
to overload operators both in the mixin and in a struct from
where it's instantiated.
So the idea is that I have a few operators defined in the mixin,
then a few more in the struct, and I want to forward all
operations n
On Sunday, 21 April 2019 at 18:17:00 UTC, Adam D. Ruppe wrote:
On Sunday, 21 April 2019 at 18:07:08 UTC, Ferhat Kurtulmuş
wrote:
I am writing an opencv binding and need something like: Mat m
= another_mat > 5;
D does not support that. The comparison operators are always
just true or false (as
On Sunday, 21 April 2019 at 18:07:08 UTC, Ferhat Kurtulmuş wrote:
I am writing an opencv binding and need something like: Mat m =
another_mat > 5;
D does not support that. The comparison operators are always just
true or false (as determined by the int opCmp or the bool
opEquals returns), the
I am writing an opencv binding and need something like: Mat m =
another_mat > 5;
Docs does not cover this sitiuation:
https://dlang.org/spec/operatoroverloading.html#compare
opBinary does not support those operators, and Section
"Overloading <, <=, >, and >=" descr
On Fri, Mar 15, 2019 at 04:29:22PM -0700, Ali Çehreli via Digitalmars-d-learn
wrote:
> On 03/15/2019 03:48 PM, H. S. Teoh wrote:
[...]
> > Ali's example was unfortunately deceptively formatted.
>
> My editor did that. :)
This is why I don't trust auto-formatters. ;-)
> On my work computer, I'v
1 - 100 of 602 matches
Mail list logo