Thread overview | |||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 03, 2017 [OT] ISO C++ 17 changes | ||||
---|---|---|---|---|
| ||||
https://isocpp.org/files/papers/p0636r0.html |
April 03, 2017 Re: [OT] ISO C++ 17 changes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrea Fontana | On Monday, 3 April 2017 at 08:53:57 UTC, Andrea Fontana wrote:
> https://isocpp.org/files/papers/p0636r0.html
The 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.
|
April 03, 2017 Re: [OT] ISO C++ 17 changes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On 03.04.2017 20:24, Meta wrote:
> On Monday, 3 April 2017 at 08:53:57 UTC, Andrea Fontana wrote:
>> https://isocpp.org/files/papers/p0636r0.html
>
> The 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.
String mixins.
|
April 03, 2017 Re: [OT] ISO C++ 17 changes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | On Monday, 3 April 2017 at 21:33:20 UTC, Timon Gehr wrote:
> On 03.04.2017 20:24, Meta wrote:
>> On Monday, 3 April 2017 at 08:53:57 UTC, Andrea Fontana wrote:
>>> https://isocpp.org/files/papers/p0636r0.html
>>
>> The 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.
>
> String mixins.
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?
|
April 04, 2017 Re: [OT] ISO C++ 17 changes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | 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:
>> https://isocpp.org/files/papers/p0636r0.html
>
> The 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.
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.
|
April 04, 2017 Re: [OT] ISO C++ 17 changes | ||||
---|---|---|---|---|
| ||||
Posted in reply to mogu | On Tuesday, 4 April 2017 at 00:46:25 UTC, mogu wrote:
> 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:
>>> https://isocpp.org/files/papers/p0636r0.html
>>
>> The 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.
>
> 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.
String interpolation would be nice too, it would really help with readability!
|
April 04, 2017 Re: [OT] ISO C++ 17 changes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | 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
}
|
April 04, 2017 Re: [OT] ISO C++ 17 changes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dukc | ^ sorry misquote |
April 04, 2017 Re: [OT] ISO C++ 17 changes | ||||
---|---|---|---|---|
| ||||
Posted in reply to evilrat | 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.
|
April 04, 2017 Re: [OT] ISO C++ 17 changes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dukc | On Tuesday, 4 April 2017 at 05:18:26 UTC, Dukc wrote:
> On Tuesday, 4 April 2017 at 02:43:26 UTC, evilrat wrote:
>> 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.
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}");
}
|
Copyright © 1999-2021 by the D Language Foundation