digitalmars.D.learn - Deduce type of struct in function arguments
- Andrey (4/11) Aug 20 2018 How to pass struct into function without naming its type?
- Paul Backus (8/19) Aug 20 2018 Create an overload of foo that takes two arguments and combines
- Andrey (4/11) Aug 20 2018 Hmm, not very good solution. In C++ you can not to write type and
- Paul Backus (9/21) Aug 20 2018 Yes, D's syntax for structure literals requires you to write the
- Seb (6/18) Aug 20 2018 ... yet. Though you can vote for this DIP and show your support
- Andrey (2/7) Aug 20 2018 How and where to vote?
- Seb (5/15) Aug 21 2018 At the pull request via +1 and the upcoming "official" discussion
- Mike Parker (6/10) Aug 21 2018 Except that there's no voting process for DIPs. The Community
- Seb (6/18) Aug 21 2018 I'm aware, but we don't have any other process for people to show
- Mike Parker (4/9) Aug 21 2018 Sure, I know you know. I didn't want anyone reading what you
- Jonathan M Davis (8/19) Aug 21 2018 It would probably be better to tell people to show their appreciation or
Hello, I have a function and a struct:void foo(ref Data data) { ... }struct Data { int a; string text; }How to pass struct into function without naming its type? This doesn't work:foo({1234, "Hello!"});
Aug 20 2018
On Monday, 20 August 2018 at 09:23:27 UTC, Andrey wrote:Hello, I have a function and a struct:Create an overload of foo that takes two arguments and combines them into a `Data` struct internally: void foo(int a, string text) { Data data = {a, text}; foo(data); }void foo(ref Data data) { ... }struct Data { int a; string text; }How to pass struct into function without naming its type? This doesn't work:foo({1234, "Hello!"});
Aug 20 2018
On Monday, 20 August 2018 at 11:38:39 UTC, Paul Backus wrote:Create an overload of foo that takes two arguments and combines them into a `Data` struct internally: void foo(int a, string text) { Data data = {a, text}; foo(data); }Hmm, not very good solution. In C++ you can not to write type and compiler will deduce it automatically. In D, as I understand, this feature isn't supported.
Aug 20 2018
On Monday, 20 August 2018 at 12:33:34 UTC, Andrey wrote:On Monday, 20 August 2018 at 11:38:39 UTC, Paul Backus wrote:Yes, D's syntax for structure literals requires you to write the name of the type: https://dlang.org/spec/struct.html#struct-literal If the name of the type is too cumbersome to write out, you can use an alias: alias ShortName = MyLongAndComplicatedType!(PossiblyWith, TemplateArguments); foo(ShortName(a, text));Create an overload of foo that takes two arguments and combines them into a `Data` struct internally: void foo(int a, string text) { Data data = {a, text}; foo(data); }Hmm, not very good solution. In C++ you can not to write type and compiler will deduce it automatically. In D, as I understand, this feature isn't supported.
Aug 20 2018
On Monday, 20 August 2018 at 12:33:34 UTC, Andrey wrote:On Monday, 20 August 2018 at 11:38:39 UTC, Paul Backus wrote:... yet. Though you can vote for this DIP and show your support there: https://github.com/dlang/DIPs/pull/71 It even comes with an implementation in DMD already: https://github.com/dlang/dmd/pull/8460Create an overload of foo that takes two arguments and combines them into a `Data` struct internally: void foo(int a, string text) { Data data = {a, text}; foo(data); }Hmm, not very good solution. In C++ you can not to write type and compiler will deduce it automatically. In D, as I understand, this feature isn't supported.
Aug 20 2018
On Monday, 20 August 2018 at 17:45:25 UTC, Seb wrote:... yet. Though you can vote for this DIP and show your support there: https://github.com/dlang/DIPs/pull/71 It even comes with an implementation in DMD already: https://github.com/dlang/dmd/pull/8460How and where to vote?
Aug 20 2018
On Tuesday, 21 August 2018 at 06:29:12 UTC, Andrey wrote:On Monday, 20 August 2018 at 17:45:25 UTC, Seb wrote:At the pull request via +1 and the upcoming "official" discussion of the PR. The last discussion was here (https://forum.dlang.org/post/lpixarbirhorkltaqlew forum.dlang.org) and it seems there's no clear consensus on the best syntax for this yet :/... yet. Though you can vote for this DIP and show your support there: https://github.com/dlang/DIPs/pull/71 It even comes with an implementation in DMD already: https://github.com/dlang/dmd/pull/8460How and where to vote?
Aug 21 2018
On Tuesday, 21 August 2018 at 08:32:17 UTC, Seb wrote:Except that there's no voting process for DIPs. The Community Review is not intended as a way to vote, simply to provide feedback on it with the aim of making it a better proposal. I know people tend to throw their +1's in there, but I wouldn't expect Walter and Andrei to put any weight on that.How and where to vote?At the pull request via +1 and the upcoming "official" discussion of the PR.
Aug 21 2018
On Tuesday, 21 August 2018 at 08:47:53 UTC, Mike Parker wrote:On Tuesday, 21 August 2018 at 08:32:17 UTC, Seb wrote:I'm aware, but we don't have any other process for people to show their support for a DIP, do we? And for DMD/Druntime/Phobos etc. having a bunch of +1 helps a PR to move faster as we as reviewers can thus realize that this is sth. that's very important to the community.Except that there's no voting process for DIPs. The Community Review is not intended as a way to vote, simply to provide feedback on it with the aim of making it a better proposal. I know people tend to throw their +1's in there, but I wouldn't expect Walter and Andrei to put any weight on that.How and where to vote?At the pull request via +1 and the upcoming "official" discussion of the PR.
Aug 21 2018
On Tuesday, 21 August 2018 at 14:56:21 UTC, Seb wrote:I'm aware, but we don't have any other process for people to show their support for a DIP, do we? And for DMD/Druntime/Phobos etc. having a bunch of +1 helps a PR to move faster as we as reviewers can thus realize that this is sth. that's very important to the community.Sure, I know you know. I didn't want anyone reading what you wrote to get the impression that DIP reviews are an actual vote where the +1s are tallied up.
Aug 21 2018
On Tuesday, August 21, 2018 6:56:06 PM MDT Mike Parker via Digitalmars-d- learn wrote:On Tuesday, 21 August 2018 at 14:56:21 UTC, Seb wrote:It would probably be better to tell people to show their appreciation or support for the DIP by adding +1 to it than it would be to say anything about voting, since no voting is involved, and this is not a democratic process in any way shape or form. LOL. It's much more like a petition to the king. :) - Jonathan M DavisI'm aware, but we don't have any other process for people to show their support for a DIP, do we? And for DMD/Druntime/Phobos etc. having a bunch of +1 helps a PR to move faster as we as reviewers can thus realize that this is sth. that's very important to the community.Sure, I know you know. I didn't want anyone reading what you wrote to get the impression that DIP reviews are an actual vote where the +1s are tallied up.
Aug 21 2018