On 6/17/21 5:01 PM, Ali Çehreli wrote:
What's the difference? In both cases an int is being converted to a Foo.
I think the "working" case is against the design of D.
Likely there is a subtlety that I am missing...
The difference might be that construction has only one set of overloads
On 6/17/21 1:46 PM, Steven Schveighoffer wrote:
> Implicit construction is supported:
>
> struct Foo
> {
> int x;
> this(int y) { x = y; }
> }
>
> Foo f = 5; // ok implicit construction
That's so unlike the rest of the language that I consider it to be a
bug. :) Really, why? What if
On 6/17/21 4:15 PM, H. S. Teoh wrote:
On Thu, Jun 17, 2021 at 07:44:31PM +, JN via Digitalmars-d-learn wrote:
[...]
Foo[int] foos = [
0: Foo("abc"),
1: Foo(5)
];
}
```
Why does D need the explicit declarations whereas C++ can infer it?
Because D does not
On Thu, Jun 17, 2021 at 07:44:31PM +, JN via Digitalmars-d-learn wrote:
[...]
> Foo[int] foos = [
> 0: Foo("abc"),
> 1: Foo(5)
> ];
> }
> ```
>
> Why does D need the explicit declarations whereas C++ can infer it?
Because D does not support implicit construction. The
This C++ code compiles:
```cpp
#include
#include
#include
int main()
{
using Foo = std::variant;
std::map foos = {{0, "abc"}, {1, 5}};
}
This code doesn't:
```d
import std.variant;
void main()
{
alias Foo = Algebraic!(int, string);
Foo[int] foos = [
0: "abc",