On Thursday, 5 October 2023 at 12:00:22 UTC, Timon Gehr wrote:
void opIndexAssign(int value, int index){ i[index] = value; }
In this case I need to define many operator overloads. For
example (+=), this won't work without returns ref:
```d
s[1] += 3;
assert(s.i == [2, 45]);
//
On 10/3/23 00:11, Salih Dincer wrote:
Hi,
opIndexAssign, which is void, cannot compromise with opIndex, which is a
ref! Solution: Using opSliceAssign. Could this be a bug? Because
there is no problem in older versions (e.g. v2.0.83).
```d
struct S
{
int[] i;
ref opIndex(size_t
Hi,
opIndexAssign, which is void, cannot compromise with opIndex,
which is a ref! Solution: Using opSliceAssign. Could this be a
bug? Because there is no problem in older versions (e.g.
v2.0.83).
```d
struct S
{
int[] i;
ref opIndex(size_t index) => i[index];
auto opSliceAss
On Monday, 18 October 2021 at 03:42:35 UTC, Paul Backus wrote:
What happens here is, the compiler first tries the D2-style
rewrite:
```d
s.opIndexAssign(arr[1..4], s.opSlice!0(0, 3))
```
However, that rewrite fails to compile, because your `opSlice`
does not take a template argument specifyin
On Monday, 18 October 2021 at 04:11:18 UTC, Paul Backus wrote:
On Monday, 18 October 2021 at 03:42:35 UTC, Paul Backus wrote:
My guess is that you got into this situation by trying to
follow the example in the spec's section on ["Slice Assignment
Operator Overloading"][2]. Unfortunately, that e
On Monday, 18 October 2021 at 03:42:35 UTC, Paul Backus wrote:
My guess is that you got into this situation by trying to
follow the example in the spec's section on ["Slice Assignment
Operator Overloading"][2]. Unfortunately, that example is
incorrect.
[2]:
https://dlang.org/spec/operatorove
On Sunday, 17 October 2021 at 22:52:27 UTC, Elmar wrote:
Hello Dear community.
I'd like to overload `opIndexAssign` for a struct which wraps
around a generic array (so that it can't support `opIndex` due
to unknown return type).
Broken down as much as possible this is the code:
Btw, I should have written:
`s.opIndexAssign(arr[1..4], s.opSlice(0,3));`
But it compiles the same way.
Hello Dear community.
I'd like to overload `opIndexAssign` for a struct which wraps
around a generic array (so that it can't support `opIndex` due to
unknown return type).
Broken down as much as possible this is the code:
```
import std.stdio : writeln;
import std.range : E
On Monday, 16 August 2021 at 10:48:19 UTC, Alexandru Ermicioi
wrote:
On Monday, 16 August 2021 at 06:36:02 UTC, james.p.leblanc
wrote:
To be honest, I am not exactly sure what is happening here. I
am unfamiliar with the "(T : T[])" syntax ... need to read
That is template argument secializatio
On Monday, 16 August 2021 at 06:36:02 UTC, james.p.leblanc wrote:
To be honest, I am not exactly sure what is happening here. I
am unfamiliar with the "(T : T[])" syntax ... need to read
That is template argument secialization. You're saying that T can
be accept only types that are arrays of T
On Monday, 16 August 2021 at 06:49:08 UTC, james.p.leblanc wrote:
On Monday, 16 August 2021 at 06:42:48 UTC, Tejas wrote:
If the code works, what's the problem?
Hej Again,
I was able to construct the working code shown above from help I
obtained here in the forum and other resources.
My ori
On Monday, 16 August 2021 at 06:42:48 UTC, Tejas wrote:
If the code works, what's the problem?
Hej Again,
I was able to construct the working code shown above from help I
obtained here in the forum and other resources.
My original code was not working ... but updated code is working
fine ...
On Monday, 16 August 2021 at 06:36:02 UTC, james.p.leblanc wrote:
On Monday, 16 August 2021 at 06:20:11 UTC, Tejas wrote:
Maybe just write `T[]` in code rather than making it happen
via the colon?
I also have similar troubles, removing the default value
always helped me.
Can you show the c
On Monday, 16 August 2021 at 06:20:11 UTC, Tejas wrote:
Maybe just write `T[]` in code rather than making it happen via
the colon?
I also have similar troubles, removing the default value always
helped me.
Can you show the code where you're trying to apply this?
Hej Tejas,
Sure, here is
On Monday, 16 August 2021 at 06:12:42 UTC, james.p.leblanc wrote:
On Monday, 16 August 2021 at 05:26:00 UTC, Tejas wrote:
If you're finding the spec too hard, please try Ali's book.
I'm sharing the part on operator overloading below:
http://ddili.org/ders/d.en/operator_overloading.html
Pleas
On Monday, 16 August 2021 at 05:26:00 UTC, Tejas wrote:
If you're finding the spec too hard, please try Ali's book. I'm
sharing the part on operator overloading below:
http://ddili.org/ders/d.en/operator_overloading.html
Please ping if you still have problems; I'll then write a full
program.
On Sunday, 15 August 2021 at 20:41:51 UTC, james.p.leblanc wrote:
Greetings,
I have been trying to get a working example of slice assignment
operator
overloading ... and am befuddled. From the spec (section
20.6.2), the
code below appears:
struct A
{
int opIndexAssign(int v
On Sunday, 15 August 2021 at 21:28:53 UTC, james.p.leblanc wrote:
On Sunday, 15 August 2021 at 21:15:02 UTC, Bastiaan Veelo wrote:
On Sunday, 15 August 2021 at 20:41:51 UTC, james.p.leblanc
— Bastiaan.
Bastiaan,
Thanks once again,
James
On Sunday, 15 August 2021 at 21:28:53 UTC, james.p
the last couple of details regarding
an array member? I attempted but the values always remain zero
even when I set v=4.
import std;
struct A
{
int[5] a;
int opIndexAssign(int v) // overloads a[] = v
{
writeln(__FUNCTION__);
return 42
There is an example here:
http://www.rosettacode.org/wiki/Multi-dimensional_array#D
Look at the Matrix struct
On Sunday, 15 August 2021 at 20:41:51 UTC, james.p.leblanc wrote:
I have been trying to get a working example of slice assignment
operator
overloading ... and am befuddled. From the spec (section
20.6.2), the
code below appears:
struct A
{
int opIndexAssign(int v
On Sunday, 15 August 2021 at 20:41:51 UTC, james.p.leblanc wrote:
struct A
{
int opIndexAssign(int v); // overloads a[] = v
int opIndexAssign(int v, size_t[2] x); // overloads
a[i .. j] = v
int[2] opSlice(size_t x, size_t y); // overloads i
.. j
Greetings,
I have been trying to get a working example of slice assignment
operator
overloading ... and am befuddled. From the spec (section
20.6.2), the
code below appears:
struct A
{
int opIndexAssign(int v); // overloads a[] = v
int opIndexAssign(int v, size_t[2
On Tuesday, 25 February 2020 at 15:30:19 UTC, Ali Çehreli wrote:
On 2/25/20 3:02 AM, wjoe wrote:> Lets say I've got 3 overloads
of opIndexAssign:
>
> auto opIndexAssign(T t);
> an internet search which didn't find any useful
> information.
I have examples for non-te
On 2/25/20 3:02 AM, wjoe wrote:> Lets say I've got 3 overloads of
opIndexAssign:
>
> auto opIndexAssign(T t);
> an internet search which didn't find any useful
> information.
I have examples for non-templatized and templatized versions of
opIndexAssign here:
h
On Tuesday, 25 February 2020 at 11:49:50 UTC, Petar Kirov
[ZombineDev] wrote:
On Tuesday, 25 February 2020 at 11:02:40 UTC, wjoe wrote:
[...]
opIndexAssign is the operator used in the following code:
arr[1] = 8;
It returns the element at index 1 (so 8 in this case) by
reference.
This
On Tuesday, 25 February 2020 at 11:02:40 UTC, wjoe wrote:
Lets say I've got 3 overloads of opIndexAssign:
auto opIndexAssign(T t);
auto opIndexAssign(T t, size_t i); and
auto opIndexAssign(T t, size_t[2] i);
I would assume to return what I would return with opIndex but
I'd rather no
Lets say I've got 3 overloads of opIndexAssign:
auto opIndexAssign(T t);
auto opIndexAssign(T t, size_t i); and
auto opIndexAssign(T t, size_t[2] i);
I would assume to return what I would return with opIndex but I'd
rather not act upon assumptions.
But if yes is it supposed to be
void main() {
auto s = S();
s["b", "c"] = s["a"];
}
Prints
a
["b", "c"]
Ali
I thought about this too, thanks!
opIndexAssign(int value, string[] indexes...) {
writeln(indexes);
}
}
void main() {
auto s = S();
s["b", "c"] = s["a"];
}
Prints
a
["b", "c"]
Ali
On Monday, 18 September 2017 at 15:14:20 UTC, Moritz Maxeiner
wrote:
On Monday, 18 September 2017 at 15:11:34 UTC, Moritz Maxeiner
wrote:
gets rewritten to
---
t.opIndex("b").opIndexAssign(t["a"].value, "c");
---
Sorry, forgot one level of rewriting:
--
On Monday, 18 September 2017 at 15:11:34 UTC, Moritz Maxeiner
wrote:
gets rewritten to
---
t.opIndex("b").opIndexAssign(t["a"].value, "c");
---
Sorry, forgot one level of rewriting:
---
t.opIndex("b").opIndexAssign(t.opIndex("a").value, "c");
---
On Sunday, 17 September 2017 at 18:52:39 UTC, SrMordred wrote:
struct Test{ [...] }
Test t;
As described in the spec [1]
t["a"] = 100;
gets rewritten to
---
t.opIndexAssign(100, "a");
---
, while
t["b"]["c"] = t["a"].value;
gets r
Should I report this as a bug?
I tried a C++ equivalent code and it execute in the expected
order.
struct Test{
@property int value(){
writeln("property value : ", _value);
return _value;
}
int _value;
Test opIndex( string index )
{
writeln( "opIndex : index : ", index );
return this;
}
Test opIndexAssign(int
The Anh Tran:
> No offense, but for a beginner like me, those mixin are similar to C
> macro hacks years ago. :)
They share part of the same purposes. But D string mixing are scoped, while C
macros cut across scopes. This makes mixins quite safer to use.
Bye,
bearophile
downs wrote:
Take a look at tools.behave_as (for phobos).
It only works properly with built-in types though.
http://dsource.org/projects/scrapple/browser/trunk/tools/tools/behave_as.d
It should let you implement a HashMap that supports += and similar, at least
for built-ins.
Many thanks.
No of
345; // error not lvalue
> hm[123]++;// error
>
> D document says current opIndexAssign does not work as lvalue. But why
> can builtin AA can that? How can i copy builtin AA behaviour?
>
Take a look at tools.behave_as (for phobos).
It only works properly with built-in typ
Daniel Keep wrote:
You could try the Tango IRC channel:
That, or the Tango forums:
http://dsource.org/projects/tango/forums
You can report problems with Tango via the ticket system:
http://dsource.org/projects/tango/report ("New Ticket" is down the
bottom of the page.)
I tried to register. Bu
] += 12345; // error not lvalue
hm[123]++; // error
D document says current opIndexAssign does not work as lvalue. But why
can builtin AA can that? How can i copy builtin AA behaviour?
--
Forgive my noob, where is the place to ask question, report bug for
Tango?
1. I
23] += 12345; // error not lvalue
> hm[123]++;// error
>
> D document says current opIndexAssign does not work as lvalue. But why
> can builtin AA can that? How can i copy builtin AA behaviour?
You can't. This is a hole in the language at the moment, hopefully
solved by the intr
]++; // error
D document says current opIndexAssign does not work as lvalue. But why
can builtin AA can that? How can i copy builtin AA behaviour?
--
Forgive my noob, where is the place to ask question, report bug for Tango?
1. I can't compile D code using tango hashmap in debug
43 matches
Mail list logo