Variadic template arguments unpacking

TommiT tommitissari at hotmail.com
Sat Jul 6 10:00:46 PDT 2013


On Saturday, 6 July 2013 at 12:21:29 UTC, Max Strakhov wrote:
> Artur, if i use your solution like
>
> printf("...", ForEach!(val => conv(val).c_str())(values).tuple);
>
> Than i would get a crash, because all the tuple elements would 
> be char*'s, pointing to already freed memory, as std::string's 
> destructor gets called each time right after alias function 
> exits. Ths is what c++ unpacking operator for: i actually 
> return a packed list of std::string's, apply .c_str() to each 
> and than unpack the list to current context.

I thought about this a bit more and realised you're right. The 
following should work though:

printf( "...", ForEach!(tmp => tmp.c_str())(ForEach!(val => 
conv(val))(values).tuple).tuple );

It's a defect in ForEach though, and gives me more reason to ask 
for the C++ style ellipsis expansion operator for D.


More information about the Digitalmars-d-learn mailing list