www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - reason variadic templates

reply cppljevans cox-internet.com writes:
Variadic templates would help implement:

http://all-technology.com/eigenpolls/dwishlist/index.php?it=28

because each tuple type could be expressed as a template:

tuple!(T1,T2,...,Tn) some_function(A1,A2,...,Am)

where T1,..,Tn are the result types, and A1,...,Am are the
argument types to some function, some_function.

Thus, the dwishlist example above:

int,int getPoint();

could be expressed:

tuple!(int,int) getPoint();

boost tuple already has this:

http://www.boost.org/libs/tuple/doc/tuple_users_guide.html#tuple_types
Oct 15 2005
parent reply Sean Kelly <sean f4.ca> writes:
In article <dir2ns$28pb$1 digitaldaemon.com>, cppljevans cox-internet.com
says...
Variadic templates would help implement:

http://all-technology.com/eigenpolls/dwishlist/index.php?it=28

because each tuple type could be expressed as a template:

tuple!(T1,T2,...,Tn) some_function(A1,A2,...,Am)

where T1,..,Tn are the result types, and A1,...,Am are the
argument types to some function, some_function.

Thus, the dwishlist example above:

int,int getPoint();

could be expressed:

tuple!(int,int) getPoint();

I'm fairly certain that tuples can be implemented in D right now. I agree that variadric templates would be a very nice feature however. This has come up in the past and Walter seemed to like the idea, so it will probably happen eventually. Sean
Oct 15 2005
parent reply Larry Evans <cppljevans cos-internet.com> writes:
On 10/15/2005 11:34 AM, Sean Kelly wrote:
 In article <dir2ns$28pb$1 digitaldaemon.com>, cppljevans cox-internet.com
 says...

because each tuple type could be expressed as a template:

tuple!(T1,T2,...,Tn) some_function(A1,A2,...,Am)

where T1,..,Tn are the result types, and A1,...,Am are the
argument types to some function, some_function.


Well, actually, what I was looking for was something like boost's mpl::vector or mpl::list. Any tuple (or variant) could then be created with a combination of mpl::vector and mpl::fold. [snip]
 I'm fairly certain that tuples can be implemented in D right now.  I agree that

Does anybody have some sample code I could view?
 variadric templates would be a very nice feature however.  This has come up in
 the past and Walter seemed to like the idea, so it will probably happen
 eventually.

Can't wait. The way boost did it was with help of the Boost preprocessor library and, IIRC, some special class value to signal the end of valid template arguments. They also did some preprocessing to generate header files. Anyway, it was pretty confusing to me, and I thought if D had a better way, I'd be very happy!
Nov 04 2005
parent reply Larry Evans <cppljevans cos-internet.com> writes:
On 11/04/2005 08:03 AM, Larry Evans wrote:
[snip]
 variadric templates would be a very nice feature however.  This has 
 come up in
 the past and Walter seemed to like the idea, so it will probably happen
 eventually.


http://archives.free.net.ph/message/20060926.213635.0a8fa8a2.en.html Maybe Doug's implementation would give Walter some howto ideas.
Oct 01 2006
parent reply "Lionello Lunesu" <lionello lunesu.remove.com> writes:
"Larry Evans" <cppljevans cos-internet.com> wrote in message 
news:efokmo$1det$1 digitaldaemon.com...
 On 11/04/2005 08:03 AM, Larry Evans wrote:
 [snip]
 variadric templates would be a very nice feature however.  This has come 
 up in
 the past and Walter seemed to like the idea, so it will probably happen
 eventually.


http://archives.free.net.ph/message/20060926.213635.0a8fa8a2.en.html Maybe Doug's implementation would give Walter some howto ideas.

I'm not into metaprogramming, but I think this would be a great feature of D to pick up. Already I'm noticing some D templates doing the same copy-paste trick to get a template to accept any number of parameters (like in the S&S examples in the respective thread). IIRC the was another D template library that actually used a D program/script to generate its .d files for any number of parameters! Surely we can do better than that... L.
Oct 01 2006
parent Bill Baxter <dnewsgroup billbaxter.com> writes:
Lionello Lunesu wrote:
 "Larry Evans" <cppljevans cos-internet.com> wrote in message 
 news:efokmo$1det$1 digitaldaemon.com...
 On 11/04/2005 08:03 AM, Larry Evans wrote:
 [snip]
 variadric templates would be a very nice feature however.  This has come 
 up in
 the past and Walter seemed to like the idea, so it will probably happen
 eventually.


http://archives.free.net.ph/message/20060926.213635.0a8fa8a2.en.html Maybe Doug's implementation would give Walter some howto ideas.

I'm not into metaprogramming, but I think this would be a great feature of D to pick up. Already I'm noticing some D templates doing the same copy-paste trick to get a template to accept any number of parameters (like in the S&S examples in the respective thread). IIRC the was another D template library that actually used a D program/script to generate its .d files for any number of parameters! Surely we can do better than that... L.

That is pretty great. Though I would prefer some sort of "static foreach" kind of construct rather than having to go purely functional to use the feature. --bb
Oct 02 2006