= %s*(%s + %s) =", p1, p1, p2);
write(p1 * (p1 + p2)); // compare this to code without
operator overload:
}
```
Compare: ``p1 * (p1 + p2)`` to something with a structure like
``dot(p1,(add(p1,p2)).``
(With the Dlangs UFCS it might become: ``p1.dot(p1.add(p2))`` )
On Monday, 7 December 2020 at 06:18:33 UTC, mw wrote:
Now, how to convert it to a native array:
double[] row = record;
Error: cannot implicitly convert expression record of type
Tuple!(double, double, double, ..., double) to double[]
(I know for tuple, we can do: double[] arr = [record];)
On Monday, 7 December 2020 at 04:38:07 UTC, Paul Backus wrote:
On Monday, 7 December 2020 at 04:03:05 UTC, mw wrote:
So my next question: given N, how do I create a Tuple!(double,
double, ... n-double) type programmatically?
import std.meta: Repeat;
alias NDoubles = Tuple!(Repeat!(N, double))
On Monday, 7 December 2020 at 04:03:05 UTC, mw wrote:
So my next question: given N, how do I create a Tuple!(double,
double, ... n-double) type programmatically?
import std.meta: Repeat;
alias NDoubles = Tuple!(Repeat!(N, double));
Note that N must be a compile-time constant, since the number
On Monday, 7 December 2020 at 03:51:02 UTC, Paul Backus wrote:
On Monday, 7 December 2020 at 02:25:23 UTC, mw wrote:
onlineapp.d(8): Error: no [] operator overload for type
CsvRecord!(int, cast(Malformed)1, string, dchar)
should `r`'s type be integer array? and how do I access each
ele
On Monday, 7 December 2020 at 02:25:23 UTC, mw wrote:
onlineapp.d(8): Error: no [] operator overload for type
CsvRecord!(int, cast(Malformed)1, string, dchar)
should `r`'s type be integer array? and how do I access each
elelment of the row?
Thanks.
The docs [1] say that csvReader re
auto records = text.csvReader!int;
foreach(r; records) {writeln(r[0]);} // line 8
assert(records.equal!equal([
[76, 26, 22],
]));
}
but I got a compile error:
onlineapp.d(8): Error: no [] operator overload for type
CsvRecord!(int, cast(Malformed)1, string, dchar)
should `r`
On Monday, 17 February 2020 at 13:03:38 UTC, Basile B. wrote:
eg
Sh(echo) < "meh";
struct Sh
{
// you see the idea we have op overload for < here
}
You can't overload < separately - all the comparison operators
(<, <=, >, >=) are handled via opCmp. Even if you choose to go
down that
On Monday, 17 February 2020 at 13:03:38 UTC, Basile B. wrote:
Sh(echo) < "meh";
Not allowed in D - it only does a comparison overload which
covers < and > (and <= and >=).
Though we could do strings and stuff. especially with my string
interpolation dip
https://gist.github.com/adamdrupp
eg
Sh(echo) < "meh";
struct Sh
{
// you see the idea we have op overload for < here
}
On 5/30/18 5:41 PM, Malte wrote:
On Wednesday, 30 May 2018 at 21:27:44 UTC, Ali Çehreli wrote:
On 05/30/2018 02:19 PM, Malte wrote:
Why does this code complain at the last line about a missing []
operator overload?
auto buffer = new char[6];
auto chunked = buffer.chunks(3);
chunked[1][2
On Wednesday, 30 May 2018 at 21:27:44 UTC, Ali Çehreli wrote:
On 05/30/2018 02:19 PM, Malte wrote:
Why does this code complain at the last line about a missing
[] operator overload?
auto buffer = new char[6];
auto chunked = buffer.chunks(3);
chunked[1][2] = '!';
Same happens
On 05/30/2018 02:19 PM, Malte wrote:
Why does this code complain at the last line about a missing [] operator
overload?
auto buffer = new char[6];
auto chunked = buffer.chunks(3);
chunked[1][2] = '!';
Same happens with wchar.
Dchar and byte work as expected.
UTF-8 auto decodi
Why does this code complain at the last line about a missing []
operator overload?
auto buffer = new char[6];
auto chunked = buffer.chunks(3);
chunked[1][2] = '!';
Same happens with wchar.
Dchar and byte work as expected.
On Tuesday, 12 December 2017 at 17:13:55 UTC, Biotronic wrote:
On Tuesday, 12 December 2017 at 16:54:17 UTC, Biotronic wrote:
There is no way in C++ to set the format the way you want it.
If you want binary output, you need to call a function like
your binario function.
Of course this is not
On Tuesday, 12 December 2017 at 17:13:55 UTC, Biotronic wrote:
On Tuesday, 12 December 2017 at 16:54:17 UTC, Biotronic wrote:
There is no way in C++ to set the format the way you want it.
If you want binary output, you need to call a function like
your binario function.
Of course this is not
On Tuesday, 12 December 2017 at 16:54:17 UTC, Biotronic wrote:
There is no way in C++ to set the format the way you want it.
If you want binary output, you need to call a function like
your binario function.
Of course this is not entirely true - there is a way, but it's
ugly and probably not
On Tuesday, 12 December 2017 at 15:52:09 UTC, dark777 wrote:
I know that this community is not of c ++, but some time I have
been studying how to do overload of ostream operators in c ++
and I even managed to get to this result but the same is not
converting to binary only presents zeros as out
I know that this community is not of c ++, but some time I have
been studying how to do overload of ostream operators in c ++ and
I even managed to get to this result but the same is not
converting to binary only presents zeros as output to any number
already tried to pass parameter of variable
On 10.06.2016 13:02, Satoshi wrote:
Hello,
why operator overloading is not working as a static methods through the
UFCS?
...
It's an arbitrary limitation.
https://issues.dlang.org/show_bug.cgi?id=8062
(The specification has been updated in the meantime, it now documents
the limitation explici
Hello,
why operator overloading is not working as a static methods
through the UFCS?
I need overload a << operator in this way:
enum PlatformID {
None,
Trinix,
Unix,
MacOS,
Windows
}
PlatformID toPlatformID(string platform) {
switch (platform.to
On Thursday, 22 October 2015 at 05:17:29 UTC, Cauterite wrote:
On Thursday, 22 October 2015 at 04:25:01 UTC, MobPassenger
wrote:
On Thursday, 22 October 2015 at 04:01:16 UTC, Mike Parker
wrote:
On Thursday, 22 October 2015 at 03:19:49 UTC, MobPassenger
wrote:
code:
---
struct Foo
{
bool op
On Thursday, 22 October 2015 at 04:25:01 UTC, MobPassenger wrote:
On Thursday, 22 October 2015 at 04:01:16 UTC, Mike Parker wrote:
On Thursday, 22 October 2015 at 03:19:49 UTC, MobPassenger
wrote:
code:
---
struct Foo
{
bool opIn_r(T)(T t){return false;}
}
This needs to be marked with co
On Thursday, 22 October 2015 at 03:21:35 UTC, MobPassenger wrote:
On Thursday, 22 October 2015 at 03:18:25 UTC, MobPassenger
wrote:
code:
Plz don't reply, there's been a forum bug while posting.
What forum bug would that be?
On Thursday, 22 October 2015 at 04:01:16 UTC, Mike Parker wrote:
On Thursday, 22 October 2015 at 03:19:49 UTC, MobPassenger
wrote:
code:
---
struct Foo
{
bool opIn_r(T)(T t){return false;}
}
This needs to be marked with const:
struct Foo
{
bool opIn_r(T)(T t) const {return false;}
}
On Thursday, 22 October 2015 at 03:19:49 UTC, MobPassenger wrote:
code:
---
struct Foo
{
bool opIn_r(T)(T t){return false;}
}
This needs to be marked with const:
struct Foo
{
bool opIn_r(T)(T t) const {return false;}
}
On Thursday, 22 October 2015 at 03:18:25 UTC, MobPassenger wrote:
code:
Plz don't reply, there's been a forum bug while posting. Full
post is here:
http://forum.dlang.org/thread/kaqyeiakjunqoexos...@forum.dlang.org
code:
---
struct Foo
{
bool opIn_r(T)(T t){return false;}
}
static immutable Foo foo; // ouch
//static Foo foo; // OK
void main()
{
assert("a" !in foo);
}
code:
---
struct Foo
{
bool opIn_r(T)(T t){return false;}
}
static immutable Foo foo; // ouch
//static Foo foo; // OK
void main()
{
assert("a" !in foo);
}
---
output:
---
Error: template Foo.opIn_r cannot deduce function from argument
types !()(string) immutable, candidates are:
runna
On Saturday, 25 October 2014 at 18:38:12 UTC, John Colvin wrote:
On Saturday, 25 October 2014 at 17:14:51 UTC, Jkpl wrote:
Everything is in the Q. I ask this because those functions are
hidden behind symbols and keywords (+=, ~, in, etc.). It's not
that obvious for a user who would write a cust
On Saturday, 25 October 2014 at 17:14:51 UTC, Jkpl wrote:
Everything is in the Q. I ask this because those functions are
hidden behind symbols and keywords (+=, ~, in, etc.). It's not
that obvious for a user who would write a custom type.
e.g:
---
struct myType
{
@safe nothrow opIn
Everything is in the Q. I ask this because those functions are
hidden behind symbols and keywords (+=, ~, in, etc.). It's not
that obvious for a user who would write a custom type.
e.g:
---
struct myType
{
@safe nothrow opIndexAssign(t1 paramValue,t2 paramIndex){}
}
---
are
On Wednesday, 27 November 2013 at 18:40:09 UTC, Namespace wrote:
Too bad. Would have been really awesome.
It is pretty hard to define within common grammar rules because
of implicit nature of operators.
On Wednesday, 27 November 2013 at 17:47:13 UTC, bearophile wrote:
Namespace:
void main() {
A a;
a.opIndex!int(0); // [1]
a!int[0]; // [2]
}
[1] works, but [2] fails.
How can I call opIndex with bracket syntax and a typename? Or
is this not possible?
I think that
Namespace:
void main() {
A a;
a.opIndex!int(0); // [1]
a!int[0]; // [2]
}
[1] works, but [2] fails.
How can I call opIndex with bracket syntax and a typename? Or
is this not possible?
I think that's not supported by D syntax. So if you want that,
you need to use
On Wednesday, 27 November 2013 at 17:25:49 UTC, Shammah
Chancellor wrote:
On 2013-11-27 16:07:50 +, Namespace said:
Just out of curiosity: Is it possible to call an overloaded
operator with a template type?
import std.stdio;
struct A {
void opIndex(T)(size_t index) {
On 2013-11-27 16:07:50 +, Namespace said:
Just out of curiosity: Is it possible to call an overloaded operator
with a template type?
import std.stdio;
struct A {
void opIndex(T)(size_t index) {
}
}
void main() {
A a;
a.opIndex!int(0);
Just out of curiosity: Is it possible to call an overloaded
operator with a template type?
import std.stdio;
struct A {
void opIndex(T)(size_t index) {
}
}
void main() {
A a;
a.opIndex!int(0); // [1]
a!int[0]; // [2]
}
[1] work
On 9/1/13, Ali Çehreli wrote:
> This is the limitation of inner structs' not having an 'outer'
> reference, right?
Right, but this was just a workaround. Anyway I did just realize I can
use opDispatch for this:
-
class C
{
this()
{
this.opts["foo"] = 1;
}
private aut
On 08/31/2013 03:07 AM, Andrej Mitrovic wrote:
> I'm trying to achieve the syntax "opts[...] = 123", rather than using
> the more direct "this[...] = 123". I can use this code:
>
> -
> class C
> {
> this()
> {
> opts = Opts(this);
> opts["foo"] = 1;
> }
>
>
On 08/31/13 12:07, Andrej Mitrovic wrote:
> But this explicitly stores the 'this' reference in the struct, I was
> wondering if anyone knows of a trick to avoid having to do that. As
> you can tell I just want a more convenient operator-based syntax over
> calling the 'assign' method, but I don't w
I'm trying to achieve the syntax "opts[...] = 123", rather than using
the more direct "this[...] = 123". I can use this code:
-
class C
{
this()
{
opts = Opts(this);
opts["foo"] = 1;
}
struct Opts
{
C c;
void opIndexAssign(T)(T value, strin
On Sunday, 18 August 2013 at 21:23:05 UTC, Namespace wrote:
On Sunday, 18 August 2013 at 15:29:26 UTC, Ali Çehreli wrote:
On 08/18/2013 07:34 AM, Namespace wrote:
> In C++ you can declare operator overloads inside and outside
of classes
> (the latter is more popular)
The latter is popular beca
On Sunday, 18 August 2013 at 15:29:26 UTC, Ali Çehreli wrote:
On 08/18/2013 07:34 AM, Namespace wrote:
> In C++ you can declare operator overloads inside and outside
of classes
> (the latter is more popular)
The latter is popular because a global operator takes advantage
of implicit type conve
On Sunday, 18 August 2013 at 15:29:26 UTC, Ali Çehreli wrote:
On 08/18/2013 07:34 AM, Namespace wrote:
> In C++ you can declare operator overloads inside and outside
of classes
> (the latter is more popular)
The latter is popular because a global operator takes advantage
of implicit type conve
On 08/18/2013 07:34 AM, Namespace wrote:
> In C++ you can declare operator overloads inside and outside of classes
> (the latter is more popular)
The latter is popular because a global operator takes advantage of
implicit type conversions. A global operator+ allows using an int even
on the lef
I can't find anything so I ask here: what was the decision to
disallow static or global operator overloads?
In C++ you can declare operator overloads inside and outside of
classes (the latter is more popular), so why wasn't this
introduced in D also?
Thanks in advance. :)
On Wednesday, 1 December 2010 at 08:17:37 UTC, zusta wrote:
Hey guys,
I'm trying to read a JSON-formated file. The parsing of the
file seems to be
correct, but I always get the following error:
"Error: no [] operator overload for type JSONValue".
For testing purposes, I also
On Fri, Apr 20, 2012 at 07:12:41PM +0200, Mafi wrote:
> Am 20.04.2012 18:41, schrieb bearophile:
> >Dominic Jones:
> >
> >>I want to overload a primitive type operator so that I can do
> >>something like
> >>
> >>double a;
> >>myStruct b;
> >>writeln(a + b);
> >
> >You can't overload the operator o
Am 20.04.2012 18:41, schrieb bearophile:
Dominic Jones:
I want to overload a primitive type operator so that I can do
something like
double a;
myStruct b;
writeln(a + b);
You can't overload the operator of a primitive, but binary operators
come in left and right versions:
...
Bye,
bearoph
Dominic Jones:
I want to overload a primitive type operator so that I can do
something like
double a;
myStruct b;
writeln(a + b);
You can't overload the operator of a primitive, but binary
operators come in left and right versions:
http://dlang.org/operatoroverloading.html#Binary
a.opBina
Hello,
I want to overload a primitive type operator so that I can do
something like
double a;
myStruct b;
writeln(a + b);
but have no idea how to do it. Something similar(?) is already
implemented in the language, i.e.
double x;
double[] y;
writeln(x + y);
but after searching the dmd2/src
Hey guys,
I'm trying to read a JSON-formated file. The parsing of the file seems to be
correct, but I always get the following error:
"Error: no [] operator overload for type JSONValue".
For testing purposes, I also tried the code of
http://www.digitalmars.com/d/archive
53 matches
Mail list logo