Re: interface opEquals

2023-11-27 Thread Alexandru Ermicioi via Digitalmars-d-learn

On Monday, 27 November 2023 at 09:53:48 UTC, Antonio wrote:

...but why?


All classes (and interfaces I think), at root of inheritance have 
`Object` class, this class defines couple of generic methods, you 
can find this class in object.d btw. One of those methods is 
`bool opEquals(const Object rhs) const`, therefore if you try to 
call opEquals, it could be possible that in some cricumstances 
instead of your overload, one defined on Object is picked up, 
which checks only if rhs is same object as the one invoked upon.


Btw, dunno how the rules for overload set resolution on opEquals 
work, so someone else should check whther this is a bug or 
expected behavior.


Best regards,
Alexandru.


Re: D Phobos Library Documentation: What is the Internal API for?

2023-11-27 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, November 27, 2023 6:03:22 AM MST BoQsc via Digitalmars-d-learn 
wrote:
> This is pretty basic question.
> If you open [D Library
> Reference](https://dlang.org/phobos/index.html) you are bound to
> see the **Internal API** section in the table of content.
>
> What is the **Internal API** (internal.core, dmd, rt) for and
> when, how and where to use it?
>
> ![](https://i.imgur.com/WyemZsG.png)

They're modules that are supposed to be internal to the implementation. They
should not be accessible to anyone outside of those projects. So, it's
pretty weird that it's up on the website, but my guess is that someone put
it there so that the folks working on the code base could see the rendered
ddoc comments for that code. For instance, I could believe that the dmd
section there is there just to make it easier for some of the folks working
on the compiler to more easily get an overview of the public symbols within
those modules. But if you're not contributing to those projects, there
really isn't any reason to see those modules.

- Jonathan M Davis





Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-27 Thread Nick Treleaven via Digitalmars-d-learn

On Monday, 27 November 2023 at 12:34:30 UTC, Nick Treleaven wrote:

On Friday, 24 November 2023 at 09:35:00 UTC, BoQsc wrote:
You can use std.conv.toChars:

```d
void main() @nogc
{
int n = 515;

import std.conv;
char[10] s = 0;
auto r = n.toChars();
assert(r.length < s.length);
size_t i;
foreach (c; r)
s[i++] = c;

import core.stdc.stdio;
puts(s.ptr);
}
```


Or, using std.experimental.allocator:

```d
void main() @nogc
{
int n = 515;

import std.conv;
import std.experimental.allocator;
import std.experimental.allocator.mallocator;
alias a = Mallocator.instance;
auto s = a.makeArray(n.toChars);
assert(s == "515");
a.dispose(s);
}
```


D Phobos Library Documentation: What is the Internal API for?

2023-11-27 Thread BoQsc via Digitalmars-d-learn

This is pretty basic question.
If you open [D Library 
Reference](https://dlang.org/phobos/index.html) you are bound to 
see the **Internal API** section in the table of content.


What is the **Internal API** (internal.core, dmd, rt) for and 
when, how and where to use it?


![](https://i.imgur.com/WyemZsG.png)


Re: D: Convert/parse uint integer to string. (@nogc)

2023-11-27 Thread Nick Treleaven via Digitalmars-d-learn

On Friday, 24 November 2023 at 09:35:00 UTC, BoQsc wrote:

I tried to look into https://dlang.org/phobos/std_conv.html

Most of the functions inside `std.conv` seem to be dependant on 
[Garbage Collection](https://dlang.org/spec/garbage.html).


And I couldn't find a straightforward way to produce a `string` 
value out of `uint` value.


How to convert or parse `uint` value to a `string` in `@nogc` 
way?


You can use std.conv.toChars:

```d
void main() @nogc
{
int n = 515;

import std.conv;
char[10] s = 0;
auto r = n.toChars();
assert(r.length < s.length);
size_t i;
foreach (c; r)
s[i++] = c;

import core.stdc.stdio;
puts(s.ptr);
}
```


Re: interface opEquals

2023-11-27 Thread Antonio via Digitalmars-d-learn
On Saturday, 25 November 2023 at 01:15:34 UTC, Alexandru Ermicioi 
wrote:

On Friday, 24 November 2023 at 17:39:10 UTC, Antonio wrote:

...


Dunno if this might help, but I noticed that `==` sometimes 
calls `opEquals(const Object) const` instead of overload 
defined on class/interface, you might try and override it as 
well, and delegate to your overload that deals directly with 
`IOpt`.


Best regards,
Alexandru.


Thangs Alexandru,

It works.

...but why?