digitalmars.D.learn - Using std.format required std.string?
- =?iso-8859-1?Q?Robert_M._M=FCnch?= (15/16) Mar 15 2015 Hi, wondering why this happens:
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (8/20) Mar 15 2015 For whatever reasons, format() used to be defined in std.string.
- =?iso-8859-1?Q?Robert_M._M=FCnch?= (9/17) Mar 15 2015 Ok, good to here. Didn't cath/remember this one.
- =?iso-8859-1?Q?Robert_M._M=FCnch?= (10/14) Mar 15 2015 Answerting myself:
- anonymous (13/23) Mar 15 2015 That doesn't do what you want.
- =?iso-8859-1?Q?Robert_M._M=FCnch?= (11/29) Mar 16 2015 Ah, ok. Got it. so __traits(compiles,...) checks if the code can be
- ketmar (8/10) Mar 16 2015 then you can check properties, not versions. ;-)
- Mike Parker (5/9) Mar 15 2015 static if( __VERSION__ >= 2.067 ) {
- Mike Parker (2/13) Mar 15 2015 Ugh. 2067, not 2.067.
Hi, wondering why this happens: import std.format; void ods(T...)(auto ref T args){ format(args).ptr; return; } ods("%s %s", mystring, mystring.ptr);If I add: "import std.string;" everything compiles and works. Since the docs of std.format contains all the format specifier description etc. I would expect that only including "std.format" should be enough. -- Robert M. Münch http://www.saphirion.com smarter | better | fasterError: undefined identifier format
Mar 15 2015
On Sunday, 15 March 2015 at 15:48:34 UTC, Robert M. Münch wrote:Hi, wondering why this happens: import std.format; void ods(T...)(auto ref T args){ format(args).ptr; return; } ods("%s %s", mystring, mystring.ptr);For whatever reasons, format() used to be defined in std.string. Indeed it's unintuitive to have it there, and it also pulls in lots of other unrelated things like Unicode tables when you import std.string. That's why it was moved into std.format in this PR: https://github.com/D-Programming-Language/phobos/pull/2732 It will be available in 2.067, soon to be released.If I add: "import std.string;" everything compiles and works. Since the docs of std.format contains all the format specifier description etc. I would expect that only including "std.format" should be enough.Error: undefined identifier format
Mar 15 2015
On 2015-03-15 17:36:24 +0000, Robert M. Münch said:Is there a way to use "version(...)" to have code sections depending on compiler version? Something like: version(dmd >= 2.067) or version(dmd < 2.067)?Answerting myself: static if (__traits(compiles, version_minor < 67)) import std.string; // format() for versions < 2.0.67 else import std.format; // format() for versions >= 2.0.67 -- Robert M. Münch http://www.saphirion.com smarter | better | fasterMar 15 2015On Sunday, 15 March 2015 at 18:03:55 UTC, Robert M. Münch wrote:On 2015-03-15 17:36:24 +0000, Robert M. Münch said:That doesn't do what you want. You need to `import std.compiler;` for version_minor. Without that import, `__traits(compiles, version_minor < 67)` is always false, because version_minor is undefined. And if you add the import, `__traits(compiles, version_minor < 67)` is always true, no matter the value of version_minor. Use `static if(version_minor < 67)` instead. Also, if you check version_minor, it's probably a good idea to check (or static assert) version_major, too. Finally, there's need for this (yet). `std.string.format` is fine with 2.067, too. So unless you're going for (far) future compatiblity, you can just do `import std.string;`.Is there a way to use "version(...)" to have code sections depending on compiler version? Something like: version(dmd >= 2.067) or version(dmd < 2.067)?Answerting myself: static if (__traits(compiles, version_minor < 67)) import std.string; // format() for versions < 2.0.67 else import std.format; // format() for versions >= 2.0.67Mar 15 2015On 2015-03-15 19:16:52 +0000, anonymous said:I have std.compiler imported.Answerting myself: static if (__traits(compiles, version_minor < 67)) import std.string; // format() for versions < 2.0.67 else import std.format; // format() for versions >= 2.0.67That doesn't do what you want. You need to `import std.compiler;` for version_minor. Without that import, `__traits(compiles, version_minor < 67)` is always false, because version_minor is undefined.And if you add the import, `__traits(compiles, version_minor < 67)` is always true, no matter the value of version_minor. Use `static if(version_minor < 67)` instead.Ah, ok. Got it. so __traits(compiles,...) checks if the code can be compiled, that's it.Finally, there's need for this (yet). `std.string.format` is fine with 2.067, too. So unless you're going for (far) future compatiblity, you can just do `import std.string;`.I prefer to move things to the "far future compatibility" path ASAP. Reduce a lot of maintenance headaches. Thanks for the feedback. -- Robert M. Münch http://www.saphirion.com smarter | better | fasterMar 16 2015On Mon, 16 Mar 2015 12:32:01 +0100, Robert M. M=C3=BCnch wrote:I prefer to move things to the "far future compatibility" path ASAP. Reduce a lot of maintenance headaches.then you can check properties, not versions. ;-) static if (__traits(compiles, {import std.string : format;})) { import std.string : format; } else { import std.format : format; } =Mar 16 2015On Sunday, 15 March 2015 at 17:36:24 UTC, Robert M. Münch wrote:Ok, good to here. Didn't cath/remember this one. Is there a way to use "version(...)" to have code sections depending on compiler version? Something like: version(dmd >= 2.067) or version(dmd < 2.067)?static if( __VERSION__ >= 2.067 ) { ... } This works with any D compiler using the DMD frontend.Mar 15 2015On Monday, 16 March 2015 at 04:31:19 UTC, Mike Parker wrote:On Sunday, 15 March 2015 at 17:36:24 UTC, Robert M. Münch wrote:Ugh. 2067, not 2.067.Ok, good to here. Didn't cath/remember this one. Is there a way to use "version(...)" to have code sections depending on compiler version? Something like: version(dmd >= 2.067) or version(dmd < 2.067)?static if( __VERSION__ >= 2.067 ) { ... }Mar 15 2015