www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.metastrings and Variadic CTFE funcs

reply Bill Baxter <wbaxter gmail.com> writes:
To Don, Walter, or anyone else who knows:
How hard is it going to be to get variadic CTFE functions working?
Or how hard would it be to get

std.metastrings.Format should be a major workhorse of CTFE string
functions, but it can't be because it's all done using template args.
And I'm assuming it's a template because variadic CTFE funcs don't work.


In general, it would be nice to have more std.string functions
available (as CTFE-capable functions) in std.metastrings.  Like
Replace and IndexOf.  I whipped up a quick version of those two based
somewhat on std.strings' versions just now.

--bb
Nov 06 2009
next sibling parent reply Daniel Keep <daniel.keep.lists gmail.com> writes:
Bill Baxter wrote:
 To Don, Walter, or anyone else who knows:
 How hard is it going to be to get variadic CTFE functions working?
 Or how hard would it be to get
 
 std.metastrings.Format should be a major workhorse of CTFE string
 functions, but it can't be because it's all done using template args.
 And I'm assuming it's a template because variadic CTFE funcs don't work.

I just wrote my own. http://github.com/DanielKeep/gb/blob/master/src/gb/ctfe/Format.d Takes metastrings.Format out back and beats it black and blue before putting a silly hat on its head and dropping a cream pie down the front of its trousers.
 In general, it would be nice to have more std.string functions
 available (as CTFE-capable functions) in std.metastrings.  Like
 Replace and IndexOf.  I whipped up a quick version of those two based
 somewhat on std.strings' versions just now.

Again, I just add stuff as I need it. http://github.com/DanielKeep/gb/blob/master/src/gb/ctfe/String.d I remember Walter talking about how CTFE meant you wouldn't need distinct runtime and compile-time libraries. Oh, how I chuckle. -- Daniel
Nov 06 2009
next sibling parent Daniel Keep <daniel.keep.lists gmail.com> writes:
Bill Baxter wrote:
 It just occurred to me when I woke up this morning that it should be
 possible to use a templated variadic function for Format instead of a
 template.  And looks that like what you're doing.  That's a much
 better approach.  I guess the only down side is that the CTFE memory
 leaks still exists.  But anyway, would you be willing to make your
 code available under the Boost license so it can be used in Phobos?

The license should be compatible with Boost; I changed it yesterday so Eldar could use it for something.
Nov 06 2009
prev sibling parent grauzone <none example.net> writes:
Daniel Keep wrote:
 I remember Walter talking about how CTFE meant you wouldn't need
 distinct runtime and compile-time libraries.
 
 Oh, how I chuckle.

You just have to wait until all D features are fully implemented in CTFE.
Nov 06 2009
prev sibling parent Bill Baxter <wbaxter gmail.com> writes:
On Fri, Nov 6, 2009 at 5:58 AM, Daniel Keep <daniel.keep.lists gmail.com> w=
rote:
 Bill Baxter wrote:
 To Don, Walter, or anyone else who knows:
 How hard is it going to be to get variadic CTFE functions working?
 Or how hard would it be to get

 std.metastrings.Format should be a major workhorse of CTFE string
 functions, but it can't be because it's all done using template args.
 And I'm assuming it's a template because variadic CTFE funcs don't work.

I just wrote my own. http://github.com/DanielKeep/gb/blob/master/src/gb/ctfe/Format.d Takes metastrings.Format out back and beats it black and blue before putting a silly hat on its head and dropping a cream pie down the front of its trousers.

It just occurred to me when I woke up this morning that it should be possible to use a templated variadic function for Format instead of a template. And looks that like what you're doing. That's a much better approach. I guess the only down side is that the CTFE memory leaks still exists. But anyway, would you be willing to make your code available under the Boost license so it can be used in Phobos?
 In general, it would be nice to have more std.string functions
 available (as CTFE-capable functions) in std.metastrings. =A0Like
 Replace and IndexOf. =A0I whipped up a quick version of those two based
 somewhat on std.strings' versions just now.

Again, I just add stuff as I need it. http://github.com/DanielKeep/gb/blob/master/src/gb/ctfe/String.d

Yeh, ok, but the point of this message was that it would be nice to have something better in Phobos so everyone doesn't have to roll their own.
 I remember Walter talking about how CTFE meant you wouldn't need
 distinct runtime and compile-time libraries.

 Oh, how I chuckle.

Yeh. It seems unlikely that things like throwing exceptions will be supported in CTFE any time soon. So it would be nice to have a collection of string processing functions that do work CTFE in std.metastrings. --bb
Nov 06 2009