digitalmars.D - [OT] ISO C++ 17 changes
- Andrea Fontana (1/1) Apr 03 2017 https://isocpp.org/files/papers/p0636r0.html
- Meta (5/6) Apr 03 2017 The fold expressions and inference of constructor template args
- Timon Gehr (2/8) Apr 03 2017 String mixins.
- Meta (22/34) Apr 03 2017 I try to avoid string mixins if possible as they're incredibly
- Dukc (11/13) Apr 03 2017 auto fold(string op, Args...)(Args args)
- Dukc (1/1) Apr 03 2017 ^ sorry misquote
- Meta (9/22) Apr 04 2017 This does work I guess. I'm not sure if the foreach will be
- ag0aep6g (5/10) Apr 04 2017 [...]
- Meta (10/21) Apr 04 2017 I mean what goes on inside fold. If you look at the C++ example
- Dukc (5/7) Apr 04 2017 Luckily that hardly matters, you just need to define one generic
- ag0aep6g (8/12) Apr 04 2017 But the shown `fold` implements the functionality of that C++ language
- Martin Nowak (16/20) Apr 08 2017 It's special syntax for a very limited (only infix operators) and
- Timon Gehr (10/41) Apr 06 2017 I usually just use:
- mogu (5/11) Apr 03 2017 Structured bindings and class template arguments deduction are
- evilrat (3/15) Apr 03 2017 String interpolation would be nice too, it would really help with
- Dukc (11/13) Apr 03 2017 If you mean runtime interpolation, that means one has to bundle
- evilrat (14/20) Apr 03 2017 No, just static symbols will be enough. Not really interpreter
- Patrick Schluter (3/24) Apr 03 2017 writeln("Your item: ", someName, " = ", someInt");
- evilrat (5/12) Apr 03 2017 This works due to variadic args nature of writeln, but the point
- Andrea Fontana (2/17) Apr 04 2017 text("Your item: ", someName, " = ", someInt");
- evilrat (7/25) Apr 04 2017 Well, thanks, I guess... But it seems no one else interested in
- Guillaume Piolat (4/10) Apr 04 2017 There is a library solution in scriptlike:
- evilrat (7/18) Apr 04 2017 Сool, i was thinking about the same, just make interp with alias
- Xinok (17/19) Apr 04 2017 This really isn't in the spirit of D and is better left to
- Russel Winder via Digitalmars-d (14/35) Apr 04 2017 Interestingly, or not, Python 3.6 introduces string interpolation even
- Jack Stouffer (4/7) Apr 06 2017 I can say the redditor Python userbase wasn't. The same sentiment
- Russel Winder via Digitalmars-d (16/24) Apr 07 2017 Different communities then. I don't do Reddit =E2=80=93 waste of time.
- Jack Stouffer (4/6) Apr 07 2017 1. the format function
- Russel Winder via Digitalmars-d (13/20) Apr 07 2017 Well 3 doesn't count, it is deprecated. ;-)
- Walter Bright (2/3) Apr 04 2017 http://dlang.org/phobos/std_algorithm_iteration.html#.fold
- Meta (5/8) Apr 04 2017 Not quite the same as this is a fold over a TypeTuple/AliasSeq.
- Nick Treleaven (9/15) Apr 05 2017 To avoid the runtime loop above, we could add an overload
- H. S. Teoh via Digitalmars-d (13/17) Apr 04 2017 That is not what "fold expressions" mean. Fold expressions are
https://isocpp.org/files/papers/p0636r0.html
Apr 03 2017
On Monday, 3 April 2017 at 08:53:57 UTC, Andrea Fontana wrote:https://isocpp.org/files/papers/p0636r0.htmlThe fold expressions and inference of constructor template args look very nice. C++ is quickly catching up to D in a lot of areas, although usually still with worse syntax. I don't know how fold expressions could be emulated in D.
Apr 03 2017
On 03.04.2017 20:24, Meta wrote:On Monday, 3 April 2017 at 08:53:57 UTC, Andrea Fontana wrote:String mixins.https://isocpp.org/files/papers/p0636r0.htmlThe fold expressions and inference of constructor template args look very nice. C++ is quickly catching up to D in a lot of areas, although usually still with worse syntax. I don't know how fold expressions could be emulated in D.
Apr 03 2017
On Monday, 3 April 2017 at 21:33:20 UTC, Timon Gehr wrote:On 03.04.2017 20:24, Meta wrote:I try to avoid string mixins if possible as they're incredibly ugly. I did try hacking something together with templates and string mixins, though, but could not get it to work. I stopped here: template fold(string op, Args...) { static if (Args.length == 1) enum fold = Args[0]; else enum fold = mixin("Args[0] " ~ op ~ " fold!(op, Args[1..$])"); //variable _param_2 cannot be read at compile time } auto f(Args...)(Args args) { return fold!("+", args); } void main() { assert(f(1, 2, 3) == 6); } Any suggestions as to how to get something similar working?On Monday, 3 April 2017 at 08:53:57 UTC, Andrea Fontana wrote:String mixins.https://isocpp.org/files/papers/p0636r0.htmlThe fold expressions and inference of constructor template args look very nice. C++ is quickly catching up to D in a lot of areas, although usually still with worse syntax. I don't know how fold expressions could be emulated in D.
Apr 03 2017
On Monday, 3 April 2017 at 21:43:41 UTC, Meta wrote:On Monday, 3 April 2017 at 21:33:20 UTC, Timon Gehr wrote: Any suggestions as to how to get something similar working?auto fold(string op, Args...)(Args args) { foreach(e; args[1 .. $]) args[0] += e; return args[0]; } void main() { import std.stdio; fold!"+"(1, 2, 3).writeln; //6 }
Apr 03 2017
On Tuesday, 4 April 2017 at 05:04:04 UTC, Dukc wrote:On Monday, 3 April 2017 at 21:43:41 UTC, Meta wrote:This does work I guess. I'm not sure if the foreach will be unrolled or not but if it is I guess this is fairly close to the C++ example. However, it's still more verbose. My goal was to emulate almost exactly what C++ was doing by using a template so you could just write "fold!('+', args)" and have it automatically rewritten as "Args[0] + Args[1] + Args[2] ...". However it gets difficult because the compiler is trying to interpret args at compile time.On Monday, 3 April 2017 at 21:33:20 UTC, Timon Gehr wrote: Any suggestions as to how to get something similar working?auto fold(string op, Args...)(Args args) { foreach(e; args[1 .. $]) args[0] += e; return args[0]; } void main() { import std.stdio; fold!"+"(1, 2, 3).writeln; //6 }
Apr 04 2017
On 04/04/2017 03:29 PM, Meta wrote:On Tuesday, 4 April 2017 at 05:04:04 UTC, Dukc wrote:[...][...]fold!"+"(1, 2, 3).writeln; //6However, it's still more verbose. My goal was to emulate almost exactly what C++ was doing by using a template so you could just write "fold!('+', args)"I'm probably missing something, but `fold!"+"(args)` isn't more verbose than `fold!('+', args)`.
Apr 04 2017
On Tuesday, 4 April 2017 at 13:38:57 UTC, ag0aep6g wrote:On 04/04/2017 03:29 PM, Meta wrote:I mean what goes on inside fold. If you look at the C++ example it's very concise and IMO beautiful: <typename ...Args> auto f(Args ...args) { return (0 + ... + args); } So I wanted a solution that was about the same in terms of brevity. My first attempt was: enum fold(string op, Args...) = mixin("Args[0] " ~ op ~ " fold!(op, Args[1..$])"; But of course this doesn't work.On Tuesday, 4 April 2017 at 05:04:04 UTC, Dukc wrote:[...][...]fold!"+"(1, 2, 3).writeln; //6However, it's still more verbose. My goal was to emulate almost exactly what C++ was doing by using a template so you could just write "fold!('+', args)"I'm probably missing something, but `fold!"+"(args)` isn't more verbose than `fold!('+', args)`.
Apr 04 2017
On Tuesday, 4 April 2017 at 13:45:47 UTC, Meta wrote:I mean what goes on inside fold. If you look at the C++ example it's very concise and IMO beautiful:Luckily that hardly matters, you just need to define one generic template for the whole program, which can even be in a library. Btw my fold template implementation was erroneous, I forgot to mixin the operator string passed to it.
Apr 04 2017
On 04/04/2017 03:45 PM, Meta wrote:I mean what goes on inside fold.Ok. That's what I missed.If you look at the C++ example it's very concise and IMO beautiful: <typename ...Args> auto f(Args ...args) { return (0 + ... + args); }But the shown `fold` implements the functionality of that C++ language feature. That is, you have to compare `fold!"+"(args)` with `(0 + ... + args)`. The C++ version may be more beautiful, but verbosity seems about the same. I think I accidentally sent this directly to your email, too. Sorry about that; Thunderbird's "answer" buttons can be confusing for me.
Apr 04 2017
On Tuesday, 4 April 2017 at 13:45:47 UTC, Meta wrote:I mean what goes on inside fold. If you look at the C++ example it's very concise and IMO beautiful: <typename ...Args> auto f(Args ...args) { return (0 + ... + args); }It's special syntax for a very limited (only infix operators) and rather obscure use-case. There are many different ways to do this already, recursive calls, static foreach, string mixin, and they work with any reduce function/op. It seems the reason C++ needs this, is because parameter pack expansion is so restricted (and complex at the same time http://en.cppreference.com/w/cpp/language/parameter_pack). Compare this with a fully generic fold in a few lines. fold(alias op, Args...)(Args args) if (Args.length > 1) { static if (Args.length > 2) return op(args[0], fold!op(args[1 .. $])); else return op(args[0], args[1]); }
Apr 08 2017
On 03.04.2017 23:43, Meta wrote:On Monday, 3 April 2017 at 21:33:20 UTC, Timon Gehr wrote:I usually just use: mixin(iota(args.length).map!(i=>text("args[",i,"]")).join("+")) Obvious and fully customizable; IMHO, the aesthetics are actually better than for the C++ example: "0 + ... + args" ? "0 + args" does not make sense, so why should "0 + ... + args" ? Furthermore, the feature explicitly special-cases operators (why not allow fold over arbitrary binary functions?) and adds a few more rules to C++'s language definition.On 03.04.2017 20:24, Meta wrote:I try to avoid string mixins if possible as they're incredibly ugly. I did try hacking something together with templates and string mixins, though, but could not get it to work. I stopped here: template fold(string op, Args...) { static if (Args.length == 1) enum fold = Args[0]; else enum fold = mixin("Args[0] " ~ op ~ " fold!(op, Args[1..$])"); //variable _param_2 cannot be read at compile time } auto f(Args...)(Args args) { return fold!("+", args); } void main() { assert(f(1, 2, 3) == 6); } Any suggestions as to how to get something similar working?On Monday, 3 April 2017 at 08:53:57 UTC, Andrea Fontana wrote:String mixins.https://isocpp.org/files/papers/p0636r0.htmlThe fold expressions and inference of constructor template args look very nice. C++ is quickly catching up to D in a lot of areas, although usually still with worse syntax. I don't know how fold expressions could be emulated in D.
Apr 06 2017
On Monday, 3 April 2017 at 18:24:31 UTC, Meta wrote:On Monday, 3 April 2017 at 08:53:57 UTC, Andrea Fontana wrote:Structured bindings and class template arguments deduction are parts D realy loose. Wish D can implement quickly. Cpp20 may bring more attributes like concept, asio, coroutines and so on. Come on! D! Beats them all.https://isocpp.org/files/papers/p0636r0.htmlThe fold expressions and inference of constructor template args look very nice. C++ is quickly catching up to D in a lot of areas, although usually still with worse syntax. I don't know how fold expressions could be emulated in D.
Apr 03 2017
On Tuesday, 4 April 2017 at 00:46:25 UTC, mogu wrote:On Monday, 3 April 2017 at 18:24:31 UTC, Meta wrote:String interpolation would be nice too, it would really help with readability!On Monday, 3 April 2017 at 08:53:57 UTC, Andrea Fontana wrote:Structured bindings and class template arguments deduction are parts D realy loose. Wish D can implement quickly. Cpp20 may bring more attributes like concept, asio, coroutines and so on. Come on! D! Beats them all.https://isocpp.org/files/papers/p0636r0.htmlThe fold expressions and inference of constructor template args look very nice. C++ is quickly catching up to D in a lot of areas, although usually still with worse syntax. I don't know how fold expressions could be emulated in D.
Apr 03 2017
On Tuesday, 4 April 2017 at 02:43:26 UTC, evilrat wrote:String interpolation would be nice too, it would really help with readability!If you mean runtime interpolation, that means one has to bundle the interpreter with the executable, and sacrifice alot of code speed. I recall that there is a DUB package which lets you use DMD as interpreter but it is Linux-only. Also Arsd-official library does contain an interpreter of some sort of script language that looks much like D, but is not quite. Stupid D compiler, if it some day compiles the standard library, I believe it will become a good interpreter. But if all you want is to construct some code in interpreter-like way at compile time, string mixin does precisely that.
Apr 03 2017
On Tuesday, 4 April 2017 at 05:18:26 UTC, Dukc wrote:On Tuesday, 4 April 2017 at 02:43:26 UTC, evilrat wrote:No, just static symbols will be enough. Not really interpreter but common day-to-day things like print some formatted stuff while keep it readable. I know it is easy to do with string.format() but it'll add more commas, templates, mixins or all at once, which is without decent tools like Visual Assist for C++ doesn't really makes it better. void printStuff() { int someInt = calcSmth(); string someName = getSmthDisplayName(); // ... do other things ... writeln("Your item: {#someName} = {#someInt}"); }String interpolation would be nice too, it would really help with readability!But if all you want is to construct some code in interpreter-like way at compile time, string mixin does precisely that.
Apr 03 2017
On Tuesday, 4 April 2017 at 05:36:55 UTC, evilrat wrote:On Tuesday, 4 April 2017 at 05:18:26 UTC, Dukc wrote:writeln("Your item: ", someName, " = ", someInt"); ????On Tuesday, 4 April 2017 at 02:43:26 UTC, evilrat wrote:No, just static symbols will be enough. Not really interpreter but common day-to-day things like print some formatted stuff while keep it readable. I know it is easy to do with string.format() but it'll add more commas, templates, mixins or all at once, which is without decent tools like Visual Assist for C++ doesn't really makes it better. void printStuff() { int someInt = calcSmth(); string someName = getSmthDisplayName(); // ... do other things ... writeln("Your item: {#someName} = {#someInt}"); }[...]But if all you want is to construct some code in interpreter-like way at compile time, string mixin does precisely that.
Apr 03 2017
On Tuesday, 4 April 2017 at 05:53:00 UTC, Patrick Schluter wrote:On Tuesday, 4 April 2017 at 05:36:55 UTC, evilrat wrote:This works due to variadic args nature of writeln, but the point is that it might be used with simple string assignment and other functions that takes one string, besides, the point is to avoid clutter and improve readability of code.On Tuesday, 4 April 2017 at 05:18:26 UTC, Dukc wrote:writeln("Your item: ", someName, " = ", someInt"); ????On Tuesday, 4 April 2017 at 02:43:26 UTC, evilrat wrote:[...]
Apr 03 2017
On Tuesday, 4 April 2017 at 06:13:24 UTC, evilrat wrote:On Tuesday, 4 April 2017 at 05:53:00 UTC, Patrick Schluter wrote:text("Your item: ", someName, " = ", someInt");On Tuesday, 4 April 2017 at 05:36:55 UTC, evilrat wrote:This works due to variadic args nature of writeln, but the point is that it might be used with simple string assignment and other functions that takes one string, besides, the point is to avoid clutter and improve readability of code.On Tuesday, 4 April 2017 at 05:18:26 UTC, Dukc wrote:writeln("Your item: ", someName, " = ", someInt"); ????On Tuesday, 4 April 2017 at 02:43:26 UTC, evilrat wrote:[...]
Apr 04 2017
On Tuesday, 4 April 2017 at 07:21:09 UTC, Andrea Fontana wrote:On Tuesday, 4 April 2017 at 06:13:24 UTC, evilrat wrote:Well, thanks, I guess... But it seems no one else interested in such feature. I get it. Sure this shouldn't be top priority thing and it can(it surely will) be hard to implement in compiler, and this maybe not an option for such a little benefit, but at least I can dream one day it will made it in D, yay.On Tuesday, 4 April 2017 at 05:53:00 UTC, Patrick Schluter wrote:text("Your item: ", someName, " = ", someInt");On Tuesday, 4 April 2017 at 05:36:55 UTC, evilrat wrote:This works due to variadic args nature of writeln, but the point is that it might be used with simple string assignment and other functions that takes one string, besides, the point is to avoid clutter and improve readability of code.On Tuesday, 4 April 2017 at 05:18:26 UTC, Dukc wrote:writeln("Your item: ", someName, " = ", someInt"); ????On Tuesday, 4 April 2017 at 02:43:26 UTC, evilrat wrote:[...]
Apr 04 2017
On Tuesday, 4 April 2017 at 08:16:48 UTC, evilrat wrote:Well, thanks, I guess... But it seems no one else interested in such feature. I get it. Sure this shouldn't be top priority thing and it can(it surely will) be hard to implement in compiler, and this maybe not an option for such a little benefit, but at least I can dream one day it will made it in D, yay.There is a library solution in scriptlike: https://p0nce.github.io/d-idioms/#String-interpolation-as-a-library I think you only ever miss it when doing web stuff.
Apr 04 2017
On Tuesday, 4 April 2017 at 10:40:19 UTC, Guillaume Piolat wrote:On Tuesday, 4 April 2017 at 08:16:48 UTC, evilrat wrote:Сool, i was thinking about the same, just make interp with alias and mixin... But this lib has some other interesting functions too! Though not in Phobos, but at least dub makes it super quick to use. Thanks! No, not web stuff, just quick dirty concepting stuff. Unfortunatelly this days I usually deal with C++ only :/Well, thanks, I guess... But it seems no one else interested in such feature. I get it. Sure this shouldn't be top priority thing and it can(it surely will) be hard to implement in compiler, and this maybe not an option for such a little benefit, but at least I can dream one day it will made it in D, yay.There is a library solution in scriptlike: https://p0nce.github.io/d-idioms/#String-interpolation-as-a-library I think you only ever miss it when doing web stuff.
Apr 04 2017
On Tuesday, 4 April 2017 at 02:43:26 UTC, evilrat wrote:String interpolation would be nice too, it would really help with readability!This really isn't in the spirit of D and is better left to library functions which give the user far more power and flexibility. Incorporating such a feature into the language raises many questions and concerns: * It becomes a language feature thereby further bloating the language and runtime * What if you want it to be nogc? * What if you want to combine it with allocators? * What if you want to store the result in a particular buffer? * What if you want the result to be lazily evaluated? * What if you want an input range of chars? ... that is lazily evaluated? * What if you want to format the arguments in a specific way? Given the ease in which such a feature can be implemented and used as a library function, I don't see interpolated strings as being a necessary feature in D.
Apr 04 2017
On Tue, 2017-04-04 at 12:46 +0000, Xinok via Digitalmars-d wrote:On Tuesday, 4 April 2017 at 02:43:26 UTC, evilrat wrote:Interestingly, or not, Python 3.6 introduces string interpolation even though Python already has the format function. And pythonistas are happy about this.String interpolation would be nice too, it would really help=C2=A0 with readability!=20 This really isn't in the spirit of D and is better left to=C2=A0 library functions which give the user far more power and=C2=A0 flexibility. Incorporating such a feature into the language=C2=A0 raises many questions and concerns:* It becomes a language feature thereby further bloating the=C2=A0 language and runtime * What if you want it to be nogc? * What if you want to combine it with allocators? * What if you want to store the result in a particular buffer? * What if you want the result to be lazily evaluated? * What if you want an input range of chars? ... that is lazily=C2=A0 evaluated? * What if you want to format the arguments in a specific way? =20 Given the ease in which such a feature can be implemented and=C2=A0 used as a library function, I don't see interpolated strings as=C2=A0 being a necessary feature in D.--=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Apr 04 2017
On Tuesday, 4 April 2017 at 15:41:08 UTC, Russel Winder wrote:Interestingly, or not, Python 3.6 introduces string interpolation even though Python already has the format function. And pythonistas are happy about this.I can say the redditor Python userbase wasn't. The same sentiment was repeated by every comment: "So now there's three ways to format a string that all do the same thing? Why?".
Apr 06 2017
On Thu, 2017-04-06 at 21:02 +0000, Jack Stouffer via Digitalmars-d wrote:On Tuesday, 4 April 2017 at 15:41:08 UTC, Russel Winder wrote:Different communities then. I don't do Reddit =E2=80=93 waste of time. Why three? There is the format function and now f-strings, that makes two. =20 --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winderInterestingly, or not, Python 3.6 introduces string=C2=A0 interpolation even though Python already has the format=C2=A0 function. And pythonistas are happy about this.=20 I can say the redditor Python userbase wasn't. The same sentiment=C2=A0 was repeated by every comment: "So now there's three ways to=C2=A0 format a string that all do the same thing? Why?".
Apr 07 2017
On Friday, 7 April 2017 at 09:01:37 UTC, Russel Winder wrote:Why three? There is the format function and now f-strings, that makes two.1. the format function 2. the new format strings 3. the old "" % syntax
Apr 07 2017
On Fri, 2017-04-07 at 14:05 +0000, Jack Stouffer via Digitalmars-d wrote:On Friday, 7 April 2017 at 09:01:37 UTC, Russel Winder wrote:Well 3 doesn't count, it is deprecated. ;-) --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winderWhy three? There is the format function and now f-strings, that=C2=A0 makes two.=20 1. the format function 2. the new format strings 3. the old "" % syntax
Apr 07 2017
On 4/3/2017 11:24 AM, Meta wrote:I don't know how fold expressions could be emulated in D.
Apr 04 2017
On Tuesday, 4 April 2017 at 08:38:32 UTC, Walter Bright wrote:On 4/3/2017 11:24 AM, Meta wrote:Not quite the same as this is a fold over a TypeTuple/AliasSeq. You could of course do: only(args).fold!"a + b"() But the semantics are different.I don't know how fold expressions could be emulated in D.
Apr 04 2017
On Tuesday, 4 April 2017 at 13:30:47 UTC, Meta wrote:On Tuesday, 4 April 2017 at 08:38:32 UTC, Walter Bright wrote:To avoid the runtime loop above, we could add an overload fold(alias fun, A...)(A args). (There are already min, max that take variadic arguments in std.algorithm). I think this would be more powerful than the C++ feature as it would support any function. To make it a little nicer, we could have binaryFun accept operators as strings, e.g. fold!"+"(args). Doing that would allow e.g. sort!">"(r).Not quite the same as this is a fold over a TypeTuple/AliasSeq. You could of course do: only(args).fold!"a + b"() But the semantics are different.
Apr 05 2017
On Tue, Apr 04, 2017 at 01:38:32AM -0700, Walter Bright via Digitalmars-d wrote:On 4/3/2017 11:24 AM, Meta wrote:That is not what "fold expressions" mean. Fold expressions are newly-introduced C++ syntax where you can write: bool b = ... && args; (with a literal "...") and the compiler automatically expands it to `args[0] && args[1] && args[2]` (assuming args has 3 elements). Of course, whether or not D ought to have such a thing is up for debate. My present opinion is that D doesn't need it, because D's compile-time capabilities are already convenient enough to use without needing special syntax support from the language. T -- Customer support: the art of getting your clients to pay for your own incompetence.I don't know how fold expressions could be emulated in D.
Apr 04 2017