December 11, 2006
Aarti_pl kirjoitti:
> I just would wish myself that Walter will add support for templatized constructors to achieve following:
>     # printVariadic(new Any(4), new Any("Yet another text"[]), new Any(3.14)); // it doesn't work now...
> 

Would this work?

static Any opCall(T)(T t)
{
  return (new Any()).assign(t);
}
December 11, 2006
Endea napisaƂ(a):
> Aarti_pl kirjoitti:
>> I just would wish myself that Walter will add support for templatized constructors to achieve following:
>>     # printVariadic(new Any(4), new Any("Yet another text"[]), new Any(3.14)); // it doesn't work now...
>>
> 
> Would this work?
> 
> static Any opCall(T)(T t)
> {
>   return (new Any()).assign(t);
> }

Yes, it should work...

BR
Marcin Kuszczak
December 11, 2006
novice2 wrote:
> many thanks, Jarrett Billingsley.
> i don't like templates, so you solution good.
> i hope, Walter will add support for this in language,
> and such ugly construction will gone from sources in future.

There's also Chris Miller's Variadic class (and my modification of it)

http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=42894

Oh, dang, the fine news group software doesn't handle uuencoded attachments :-/

Check out this link instead:
http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=42648


--bb
December 11, 2006
Bill Baxter wrote:
> novice2 wrote:
> 
>> many thanks, Jarrett Billingsley.
>> i don't like templates, so you solution good.
>> i hope, Walter will add support for this in language,
>> and such ugly construction will gone from sources in future.
> 
> 
> There's also Chris Miller's Variadic class (and my modification of it)
> 
> http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=42894 
> 
> 
> Oh, dang, the fine news group software doesn't handle uuencoded attachments :-/
> 
> Check out this link instead:
> http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=42648 
> 
> 
> 
> --bb

Here's the link I meant to post:

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=42894

--bb
December 12, 2006
thanx Bill Baxter.
but i don't need foreach...
no need any *processing*
just repassing to variadic function, not my, for example format
(...) or writef(...)

please, don't show me how to reimplement format with doFormat(),
i already to do it. but it is ugly :)
December 12, 2006
novice2 wrote:
> thanx Bill Baxter.
> but i don't need foreach...
> no need any *processing*
> just repassing to variadic function, not my, for example format
> (...) or writef(...)
> 
> please, don't show me how to reimplement format with doFormat(),
> i already to do it. but it is ugly :)

Ok, then for you I'll make the special "lean and mean" version:

struct VArgs
{
    static VArgs opCall(TypeInfo[] arguments, va_list argptr)
    {
        VArgs result;
        result.arguments = arguments;
        result.argptr = argptr;
        return result;
    }
    TypeInfo[] arguments;
    va_list argptr;
}


void vFoo(VArgs args)
{
    // do the actual body of the function here
    vBar(args);
}

void foo(...)
{
    vFoo(VArgs(_arguments, _argptr));
}

void vBar(VArgs args)
{

}

void bar(...)
{
    vBar(VArgs(_arguments, _argptr));
}
----


The point is more that _arguments and _argptr belong together, so it makes sense to package them up into a single struct to pass them around together rather than always passing them as two separate arguments. Whether or not you want the struct to help with processing the arguments  is up to you.

Personally I wish that D would a) pass a struct like the above to variadic functions, and b) let users specify a name rather than giving access to them through magic parameter names.  Magic parameter names with underscores just look terribly hackish.   Instead we could have something like:

void bar(...args) {
   //use args.types[i], *args.argptr here
}

--bb
December 12, 2006
Thanx again.
Sorry for my dumbness.
But i specially emphasized that target function not my.
Alien/legacy/phobos code.
How i can create vWritef() for example?
As i see in std.stdio we have xwritef()
But it not accessible outside module :(

So i don't see other way to repassing variadic args to other function else some "syntatic shugar" like

void foo(...)
{
  bar(...);
}

or something other syntax.

may be this problem is forced and not actual, but i meet this :)


== Quote from Bill Baxter (dnewsgroup@billbaxter.com)'s article
> novice2 wrote:
> > thanx Bill Baxter.
> > but i don't need foreach...
> > no need any *processing*
> > just repassing to variadic function, not my, for example format
> > (...) or writef(...)
> >
> > please, don't show me how to reimplement format with doFormat(),
> > i already to do it. but it is ugly :)
> Ok, then for you I'll make the special "lean and mean" version:
> struct VArgs
> {
>      static VArgs opCall(TypeInfo[] arguments, va_list argptr)
>      {
>          VArgs result;
>          result.arguments = arguments;
>          result.argptr = argptr;
>          return result;
>      }
>      TypeInfo[] arguments;
>      va_list argptr;
> }
> void vFoo(VArgs args)
> {
>      // do the actual body of the function here
>      vBar(args);
> }
> void foo(...)
> {
>      vFoo(VArgs(_arguments, _argptr));
> }
> void vBar(VArgs args)
> {
> }
> void bar(...)
> {
>      vBar(VArgs(_arguments, _argptr));
> }
> ----
> The point is more that _arguments and _argptr belong together, so
it
> makes sense to package them up into a single struct to pass them
around
> together rather than always passing them as two separate
arguments.
> Whether or not you want the struct to help with processing the
arguments
>   is up to you.
> Personally I wish that D would a) pass a struct like the above to
> variadic functions, and b) let users specify a name rather than
giving
> access to them through magic parameter names.  Magic parameter
names
> with underscores just look terribly hackish.   Instead we could
have
> something like:
> void bar(...args) {
>     //use args.types[i], *args.argptr here
> }
> --bb

1 2
Next ›   Last »