an extremely overload draw function that
eventually calls some set of these functions, but Im pretty sure
that "named arguments dont survive T..." is causing problems for
me, and I'm unsure how to work around it as I make more complex
versions.
https://github.com/crazymonkyyy/raylib
and more obfuscated for
which cases there is an overload and for which not.
A good (?!?) example of how bad this can get is the "to" template.
On Sat, May 27, 2023 at 05:49:27PM +, vushu via Digitalmars-d-learn wrote:
> On Saturday, 27 May 2023 at 16:38:43 UTC, Steven Schveighoffer wrote:
[...]
> > void make_lava(T)(ref T lava) if (hasMagma!T) {
> > lava.magma();
> > }
> >
> > void make_lava(T)(ref T lava_thing) if
lava();
}
```
-Steve
I see thanks for the example :), I think this probably the
closest equivalent i dlang.
I feel like overload in that case make things harder to read
My example has less context switch, and hte logic is correctly
understandable at first sight
Only one make_lava func
mple :), I think this probably the
closest equivalent i dlang.
I feel like overload in that case make things harder to read
My example has less context switch, and hte logic is correctly
understandable at first sight
Only one make_lava function
On Saturday, 27 May 2023 at 16:38:43 UTC, Steven Schveighoffer
wrote:
On 5/27/23 9:50 AM, vushu wrote:
On Saturday, 27 May 2023 at 13:42:29 UTC, Basile B. wrote:
[...]
Yes I know there is template constraint, but not with
specialized overloading right?
so you need to use static if for
On 5/27/23 9:50 AM, vushu wrote:
On Saturday, 27 May 2023 at 13:42:29 UTC, Basile B. wrote:
On Saturday, 27 May 2023 at 13:23:38 UTC, vushu wrote:
[...]
Is there something equivalent in dlang, doesn't seem like d support
specialized overload?
D solution is called [template
constraints
On Saturday, 27 May 2023 at 13:23:38 UTC, vushu wrote:
you can use: ``static if (__traits(hasMember, T, "magma"))``
```D
import std;
struct LavaMan {
void magma() { writeln(" LavaMan is throwing LAVA"); }
}
struct FakeVulcano {
void try_making_lava() { writeln( " Making fake lava"); }
}
On Saturday, 27 May 2023 at 13:42:29 UTC, Basile B. wrote:
On Saturday, 27 May 2023 at 13:23:38 UTC, vushu wrote:
[...]
Is there something equivalent in dlang, doesn't seem like d
support specialized overload?
D solution is called [template
constraints](https://dlang.org/spec/template.html
On Saturday, 27 May 2023 at 13:23:38 UTC, vushu wrote:
[...]
Is there something equivalent in dlang, doesn't seem like d
support specialized overload?
D solution is called [template
constraints](https://dlang.org/spec/template.html#template_constraints).
ing LAVA
```
Is there something equivalent in dlang, doesn't seem like d
support specialized overload?
Hi,
for the source code below, the compiler says:
app.d(26): constructor `app.TObject.this` hides base class
function `app.DelphiObject.this`
app.d(26): add `alias this = app.DelphiObject.this` to
`app.TObject`'s body to merge the overload sets
But if I add `alias
On Sunday, 11 September 2022 at 09:47:34 UTC, solidstate1991
wrote:
Here's this code:
This should be allowed, but also the way you're supposed to write
it now is a no-argument opIndex.
Here's this code:
```d
auto opSlice()
{
struct Range
{
Attr currentAttr;
auto front() { return currentAttr; }
void popFront() { currentAttr = currentAttr._nextAttr; }
bool empty() { return currentAttr is null; }
}
return Range(firstAttr);
}
```
On Monday, 1 August 2022 at 00:23:21 UTC, Hipreme wrote:
On Sunday, 31 July 2022 at 19:25:51 UTC, Hipreme wrote:
[...]
Seems that is how it should be checked:
```d
enum hasOverload(T, string member, FuncType)()
{
bool ret;
static foreach(overload; __traits
On Sunday, 31 July 2022 at 19:25:51 UTC, Hipreme wrote:
I wish to generate some functions using mixin template and I
wish to check if the current class already has an specific
overload with parameters (A, B).
What I'm currently trying is doing `__traits(getOverloads, T,
&quo
I wish to generate some functions using mixin template and I wish
to check if the current class already has an specific overload
with parameters (A, B).
What I'm currently trying is doing `__traits(getOverloads, T,
"foo")`, and then checking if its type are equal. But it seems
hack
On Tue, Feb 15, 2022 at 06:37:44PM +, meta via Digitalmars-d-learn wrote:
> A trick i use often:
>
> ```D
> import std;
>
> void main()
> {
> import uni = std.uni;
> writeln("Learning D is fun".split!(uni.isWhite));
> }
>
> ```
>
> Under-rated way of importing things, you don't
A trick i use often:
```D
import std;
void main()
{
import uni = std.uni;
writeln("Learning D is fun".split!(uni.isWhite));
}
```
Under-rated way of importing things, you don't bloat your scope
anymore
f it doesn't
for any reason, then it doesn't match.
Now, the symbol `isWhite` is an overload set, which is in error
(ambiguous). So I'm not sure how to test this better.
Note, if I copy the entire definition of split locally, it explains the
problem correctly (though still not as clear as it could be):
On Monday, 14 February 2022 at 11:37:38 UTC, ag0aep6g wrote:
On 14.02.22 12:14, forkit wrote:
However, if I uncomment the //import std.uni : isWhite;
then it will compile.
I don't understand. I thought 'import std;' would be
sufficient here??
"isWhite" is ambiguous. There's std.uni.isWhite
On 14.02.22 12:14, forkit wrote:
However, if I uncomment the //import std.uni : isWhite;
then it will compile.
I don't understand. I thought 'import std;' would be sufficient here??
"isWhite" is ambiguous. There's std.uni.isWhite and std.ascii.isWhite.
`import std;` can't know which one you
This code will not compile.
Error: no overload matches for `split`
However, if I uncomment the //import std.uni : isWhite;
then it will compile.
I don't understand. I thought 'import std;' would be sufficient
here??
//
module test;
@safe:
import std;
void main()
{
//import
On Tuesday, 14 December 2021 at 14:40:00 UTC, RazvanN wrote:
On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote:
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(ref scope typeof(this) rhs){
}
}
struct Bar{
On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote:
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(ref scope typeof(this) rhs){
}
}
struct Bar{
Foo!int foo;
}
void main(){
}
```
error: Segmentation
On Tuesday, 14 December 2021 at 13:02:16 UTC, Tejas wrote:
On Tuesday, 14 December 2021 at 12:04:36 UTC, RazvanN wrote:
[...]
Then why did my modification work?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(scope Foo!(T)* rhs){ //replaced typeof(this) with
is templated it is impossible for the compiler to
issue this error before actually instantiating the constructor.
I see 2 possible fixes for this: (1) either we rename the copy
constructor symbol to __cpCtor so that it does not clash with
the normal constructor overload set or (2) when a templated
2 possible fixes for this: (1) either we rename the copy
constructor symbol to __cpCtor so that it does not clash with the
normal constructor overload set or (2) when a templated
constructor is instantiated, we can check whether it is an rvalue
constructor and issue an error if a copy
On Sunday, 12 December 2021 at 19:17:53 UTC, vit wrote:
On Sunday, 12 December 2021 at 18:32:28 UTC, Imperatorn wrote:
On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote:
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote:
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(ref scope typeof(this) rhs){
}
}
struct Bar{
Foo!int foo;
}
void main(){
}
```
error: Segmentation
On Sunday, 12 December 2021 at 18:32:28 UTC, Imperatorn wrote:
On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote:
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(ref scope typeof(this) rhs){
}
}
struct Bar{
On Sunday, 12 December 2021 at 11:57:43 UTC, vit wrote:
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(ref scope typeof(this) rhs){
}
}
struct Bar{
Foo!int foo;
}
void main(){
}
```
error: Segmentation
Hello, why does this code fail to compile?
```d
struct Foo(T){
this(Rhs, this This)(scope Rhs rhs){
}
this(ref scope typeof(this) rhs){
}
}
struct Bar{
Foo!int foo;
}
void main(){
}
```
error: Segmentation fault (core dumped)
= %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 Tuesday, 24 August 2021 at 05:34:08 UTC, Ali Çehreli wrote:
On 8/23/21 10:25 PM, james.p.leblanc wrote:
So, you need a "property". Easy... :)
1) Rename the member e.g. as a_.
2) Write setter and getter functions named 'a'.
struct Foo{
int a_;
int a() const {
return a_;
}
On 8/23/21 10:25 PM, james.p.leblanc wrote:
So, you need a "property". Easy... :)
1) Rename the member e.g. as a_.
2) Write setter and getter functions named 'a'.
struct Foo{
int a_;
int a() const {
return a_;
}
void a(int value) {
a_ = value;
}
}
void main(){
auto x =
Greetings,
With a struct, there are many overload possibilities available.
However, I haven't been able to find how to overload assignment
of **selected fields** of a struct.
For example, suppose:
struct Foo{
int a;
int b;
...
}
void main(){
auto x = Foo
On Tuesday, 20 July 2021 at 18:32:26 UTC, Ali Çehreli wrote:
On 7/19/21 11:20 PM, Tejas wrote:
> trying to create the spaceship operator of C++
Just to make sure, D's opCmp returns an int. That new C++
operator was added to provide the same semantics.
Ali
I know. As I already mentioned,
On 7/20/21 11:49 AM, H. S. Teoh wrote:
> On Tue, Jul 20, 2021 at 11:32:26AM -0700, Ali Çehreli via
Digitalmars-d-learn wrote:
>> On 7/19/21 11:20 PM, Tejas wrote:
>>
>>> trying to create the spaceship operator of C++
>>
>> Just to make sure, D's opCmp returns an int. That new C++ operator was
On Tuesday, 20 July 2021 at 18:49:07 UTC, H. S. Teoh wrote:
On Tue, Jul 20, 2021 at 11:32:26AM -0700, Ali Çehreli via
Digitalmars-d-learn wrote:
On 7/19/21 11:20 PM, Tejas wrote:
> trying to create the spaceship operator of C++
Just to make sure, D's opCmp returns an int. That new C++
On Tue, Jul 20, 2021 at 11:32:26AM -0700, Ali Çehreli via Digitalmars-d-learn
wrote:
> On 7/19/21 11:20 PM, Tejas wrote:
>
> > trying to create the spaceship operator of C++
>
> Just to make sure, D's opCmp returns an int. That new C++ operator was
> added to provide the same semantics.
[...]
On 7/19/21 11:20 PM, Tejas wrote:
> trying to create the spaceship operator of C++
Just to make sure, D's opCmp returns an int. That new C++ operator was
added to provide the same semantics.
Ali
On Tuesday, 20 July 2021 at 06:34:45 UTC, vit wrote:
On Tuesday, 20 July 2021 at 06:20:34 UTC, Tejas wrote:
...
Initially, I was trying to create the spaceship operator of
C++, but we aren't allowed to create new operators
...
D has spaceship operator: opCmp
to verify whether we can even overload an
operator globally, but even that seems to be failing, atleast
for me.
From the docs:
Operator overloading is accomplished by rewriting operators
whose operands are class or struct objects into calls to
specially named members.
https://dlang.org/spec
On Tuesday, 20 July 2021 at 06:20:34 UTC, Tejas wrote:
Why isn't it working by default?
Initially, I was trying to create the spaceship operator of
C++, but we aren't allowed to create new operators, it seems.
Then I just wanted to verify whether we can even overload an
operator globally
On Tuesday, 20 July 2021 at 06:20:34 UTC, Tejas wrote:
...
Initially, I was trying to create the spaceship operator of
C++, but we aren't allowed to create new operators
...
D has spaceship operator: opCmp
(https://dlang.org/spec/operatoroverloading.html#compare).
ry!"+"(1,5);
```
It works as expected.
Why isn't it working by default?
Initially, I was trying to create the spaceship operator of C++,
but we aren't allowed to create new operators, it seems. Then I
just wanted to verify whether we can even overload an operator
globally, but even that
On Saturday, 3 April 2021 at 13:46:17 UTC, kdevel wrote:
Why does this code
[...]
```d
ec.opAssign (bar (1)); // okay
// ec = bar (1); // Error: expression bar(1) is void and has
no value
```
[...]
compile with the abovementioned error?
This is a compiler bug. You're not allowed to
On Monday, 5 April 2021 at 20:59:34 UTC, tsbockman wrote:
However, `=` and `~=` should not treat `lazy void` parameters
differently. They should either both work, or neither. I
checked and this is actually a very old regression; both worked
way back in DMD 2.061. So, I've filed a front-end bug
On Monday, 5 April 2021 at 05:22:22 UTC, frame wrote:
On Sunday, 4 April 2021 at 18:05:04 UTC, tsbockman wrote:
Thus, the solution is to use an explicit `delegate` instead of
`lazy`:
Yes, I forgot to mention that.
Could you please explain why you set 'scope' here? Isn't it
wanted to keep
On Monday, 5 April 2021 at 15:05:24 UTC, kdevel wrote:
You changed the definition of ``bar`` while the exception
collector (``EC``) is meant to catch and collect an exception
thrown from the *unmodified* function.
My point was that the code will work if you do explicitly what
`lazy` does
On Monday, 5 April 2021 at 15:05:24 UTC, kdevel wrote:
On Sunday, 4 April 2021 at 18:05:04 UTC, tsbockman wrote:
```
[...]
[...]
[...]
[...]
```
[...]
Nice, is this documented somewhere? 樂
Maybe we could add a better error message or smth.
On Sunday, 4 April 2021 at 18:05:04 UTC, tsbockman wrote:
```
[...]
You cannot assign void returned from bar() as parameter to
opAssign(). The lazy keyword creates some internal delegate,
thus opAssign() works instead.
[...]
auto bar (int i) {
return () {
if (i == 1)
On Sunday, 4 April 2021 at 18:05:04 UTC, tsbockman wrote:
Thus, the solution is to use an explicit `delegate` instead of
`lazy`:
Yes, I forgot to mention that.
Could you please explain why you set 'scope' here? Isn't it
wanted to keep references here?
On Sunday, 4 April 2021 at 16:38:10 UTC, frame wrote:
On Saturday, 3 April 2021 at 13:46:17 UTC, kdevel wrote:
Why does this code
ec.opAssign (bar (1)); // okay
// ec = bar (1); // Error: expression bar(1) is void and has
no value
compile with the abovementioned error?
You cannot
On Saturday, 3 April 2021 at 13:46:17 UTC, kdevel wrote:
Why does this code
ec.opAssign (bar (1)); // okay
// ec = bar (1); // Error: expression bar(1) is void and has
no value
compile with the abovementioned error?
You cannot assign void returned from bar() as parameter to
Why does this code
```d
import std.stdio,std.typecons;
struct EC {
Exception [] ex;
auto opAssign (X: void) (lazy X f)
{
writeln (__PRETTY_FUNCTION__);
try return f (); catch (Exception e) ex ~= e;
}
}
class E : Exception { this (string s) { super (s); } }
void bar (int
On Monday, 25 January 2021 at 17:09:22 UTC, Jack wrote:
I'd like to make this work s += 10 where s is a struct. How can
I do that?
You have your answer, but someone else might come upon this in
the future, so here's a link to the clearest explanation of
operator overloading for someone new
On Monday, 25 January 2021 at 21:53:15 UTC, Jack wrote:
That naming is confusing
op: it is an operator method
Op: it takes an operator as a parameter
Assign: kinda obvious.
As an example, there are opIndex, opIndexAssign and
opIndexOpAssign.
opIndex overloads obj[i].
opIndexAssign overloads
On Monday, 25 January 2021 at 17:12:47 UTC, Paul Backus wrote:
On Monday, 25 January 2021 at 17:09:22 UTC, Jack wrote:
I'd like to make this work s += 10 where s is a struct. How
can I do that?
+=, -=, *=, and other compound assignment operators can be
overloaded by defining `opOpAssign`:
On Monday, 25 January 2021 at 17:11:41 UTC, Adam D. Ruppe wrote:
On Monday, 25 January 2021 at 17:09:22 UTC, Jack wrote:
auto ref opAssign(string op, T)(T value)
try
opOpAssign instead
opAssign is for =
opOpAssign is for +=, -=, etc.
It might be some variation but I think it works if
On Monday, 25 January 2021 at 17:09:22 UTC, Jack wrote:
I'd like to make this work s += 10 where s is a struct. How can
I do that?
+=, -=, *=, and other compound assignment operators can be
overloaded by defining `opOpAssign`:
https://dlang.org/spec/operatoroverloading.html#op-assign
On Monday, 25 January 2021 at 17:09:22 UTC, Jack wrote:
auto ref opAssign(string op, T)(T value)
try
opOpAssign instead
opAssign is for =
opOpAssign is for +=, -=, etc.
It might be some variation but I think it works if you just
rename it.
I'd like to make this work s += 10 where s is a struct. How can I
do that?
this isn't working:
auto ref opAssign(string op, T)(T value)
if(op == "+")
{
m += value;
return this;
}
the compiler didn't consider that overload and return:
d.d(34)
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,
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
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
elelment
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 returns
to 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`'s type
Now my slice works fine.
// Tipo Nulo.
class None {}
// Função slice()
auto slice(T1, T2, T3 = None)(T1 conteudo, T2 inicio, T3 fim =
T3.init) {
int start, end, startlen;
static if (is(T2 == int)) {inicio = inicio < 0 ? conteudo.length
+ inicio : inicio;}
static if (is(T3 == int))
On Sunday, 29 November 2020 at 02:55:02 UTC, Ali Çehreli wrote:
On 11/28/20 6:40 PM, Marcone wrote:
void a(T1, T2)(T1 b, T2 c){
// I need parameter "c" optional, but only (String or
int). How can I make it without overload function?
}
Since it's optional, T2 must have a defau
On 11/28/20 6:40 PM, Marcone wrote:
void a(T1, T2)(T1 b, T2 c){
// I need parameter "c" optional, but only (String or int). How can
I make it without overload function?
}
Since it's optional, T2 must have a default type. I made it 'int' below.
void a(T1, T2 = int)(T1 b, T2 c
void a(T1, T2)(T1 b, T2 c){
// I need parameter "c" optional, but only (String or int). How
can I make it without overload function?
}
On Monday, 9 November 2020 at 22:04:55 UTC, kdevel wrote:
It appears to me that the overload resolution may depend on the
/value/ of the function argument. According to [1] the type of
1 is int and that of 1L is long. Thus I would have expected
foo!int and foo!long being called in those cases
On Monday, 9 November 2020 at 22:04:55 UTC, kdevel wrote:
It appears to me that the overload resolution may depend on the
/value/ of the function argument. According to [1] the type of
1 is int and that of 1L is long.
That's not exactly true because of value range propagation. It is
weird
(id (1L));
foo (0x1_);
foo (0x1_L);
return 0;
}
~~~
Output:
$ ./id
short id.foo(short s)
short id.foo(short s)
int id.foo!int.foo(int s)
long id.foo!long.foo(long s)
int id.foo!int.foo(int s)
long id.foo!long.foo(long s)
It appears to me that the overload resolution may depend
On Friday, 25 September 2020 at 18:58:54 UTC, H. S. Teoh wrote:
You probably need to use the long-form of templates, with
separate function declarations, to accomplish this. E.g.:
...
Alright, but your example still contains shouldReturnByRef which
presumably I need to implement myself. But
On Fri, Sep 25, 2020 at 05:58:08PM +, 60rntogo via Digitalmars-d-learn
wrote:
> On Friday, 25 September 2020 at 15:21:22 UTC, Steven Schveighoffer wrote:
> > If the input is not ref, you should not return by ref, because then
> > you would be returning a reference to local stack data that is
On Friday, 25 September 2020 at 15:21:22 UTC, Steven
Schveighoffer wrote:
If the input is not ref, you should not return by ref, because
then you would be returning a reference to local stack data
that is about to be destroyed.
Yes, I understand that. What I'm really after at this point is
On 9/25/20 11:21 AM, Steven Schveighoffer wrote:
I wouldn't depend on that mechanism yes.
*yet*.
-Steve
there is a way of saying "just figure out
if it's more optimal to return by value or const reference".
If the input is not ref, you should not return by ref, because then you
would be returning a reference to local stack data that is about to be
destroyed.
The only way to say "mak
On Friday, 25 September 2020 at 14:21:59 UTC, Steven
Schveighoffer wrote:
in does not mean "take by reference", it means "scope const"
I'm not sure that I really understand scope, but I read
https://dlang.org/spec/function.html#param-storage as saying "in
means take by value or reference
On 9/25/20 10:12 AM, 60rntogo wrote:
On Friday, 25 September 2020 at 13:15:27 UTC, Steven Schveighoffer wrote:
ou can use auto ref to alleviate that:
int x()(auto ref Foo f) // needs to be a template for auto ref to work
That's a good point, thanks. Since we are on that topic, how would
On Friday, 25 September 2020 at 13:15:27 UTC, Steven
Schveighoffer wrote:
I don't know, you can search for and report it here:
https://issues.dlang.org
I find it quite hard to search for anything here, but I couldn't
find anything similar so I submitted a bug report.
You can use auto ref
On 9/25/20 3:43 AM, 60rntogo wrote:
On Wednesday, 23 September 2020 at 19:27:13 UTC, Steven Schveighoffer
wrote:
This is a bug in the language.
Is this a known bug? If not, it should be reported.
I don't know, you can search for and report it here:
https://issues.dlang.org
I came up
On Wednesday, 23 September 2020 at 19:27:13 UTC, Steven
Schveighoffer wrote:
This is a bug in the language.
Is this a known bug? If not, it should be reported.
I came up with an answer to my original question that sort of
works:
---
module foo;
struct Foo
{
private int x;
}
int x(Foo
On Wednesday, 23 September 2020 at 19:26:43 UTC, aliak wrote:
Yeah, you can make a property setter:
private void x(int newValue) { _x = newValue }
I'm aware of this, but it does not achieve what I asked for. It
only allows me to assign to _x, it doesn't give me a reference to
x, so I cannot
. Is the behavior that allows me to call the private method intended?
This is such a blatant violation of encapsulation that it feels like a
bug either in the language or the implementation.
This is a bug in the language. Either varying ONLY by visibility of an
overload should be disallowed, or you shouldn't
On Wednesday, 23 September 2020 at 19:27:13 UTC, Steven
Schveighoffer wrote:
This is a bug in the language.
勞
On Wednesday, 23 September 2020 at 18:38:53 UTC, 60rntogo wrote:
There are really two questions here, one that I intended to ask
and one that came out while I was trying to figure out the
answer. Consider this simple code:
[...]
Yeah, you can make a property setter:
private void x(int
;
private ref int x() return
{
writeln("ref int");
return _x;
}
int x() const
{
writeln("int");
return _x;
}
---
At first I didn't even expect this to compile, but it does and I
can call these methods. I believe an overload is chosen based on
the type qualifier of a Foo ins
On Thursday, 30 July 2020 at 14:52:17 UTC, H. S. Teoh wrote:
On Thu, Jul 30, 2020 at 01:41:05PM +, Oleg B via
Digitalmars-d-learn wrote: [...]
Logically we can compare versions, but what must return
`opCmp` if one of versions has 'not comparible' state?
[...]
opCmp is allowed to return
On Thu, Jul 30, 2020 at 01:41:05PM +, Oleg B via Digitalmars-d-learn wrote:
[...]
> Logically we can compare versions, but what must return `opCmp` if one of
> versions has 'not comparible' state?
[...]
opCmp is allowed to return float; so you could return float.nan in this
case.
T
--
mparible' state before `a <= b` is not
intuitive too.
`opBinary` can't overload comparison.
We have same type of problem if wrap simple `double` into struct
and try overload comparison (double.nan has own behavior).
Problem can be solved if we add new `opCmpEx` into language spec
that ret
On 5/25/20 1:20 AM, John Chapman wrote:
void foo(T)(T[] a) {}
void foo(T)(T[][] a) {}
auto ra = new int[][](5, 5);
ra.foo(); // matches both
import std.traits;
void foo(T)(T[] a)
if (!isArray!T) {}
void foo(T)(T[] a)
if (isArray!T) {}
Or you can take T as parameter and check ElementType!T:
Is it possible to overload a function template for rectangular
arrays? Is there any way to tell them apart from normal ones?
void foo(T)(T[] a) {}
void foo(T)(T[][] a) {}
auto ra = new int[][](5, 5);
ra.foo(); // matches both
Thanks for any hints.
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.
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
eg
Sh(echo) < "meh";
struct Sh
{
// you see the idea we have op overload for < here
}
1 - 100 of 346 matches
Mail list logo