www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Variadic opIndexAssign

reply AJG <AJG_member pathlink.com> writes:
Hi,

I'm using a variadic version of opIndexAssign, and it seems to work. I dunno if
this is a hack or not, but what the heck. In addition, I'm using std.boxer
internally. The problem is that I can't streamline the parameter-to-box
conversion. Here's an example:

# import std.boxer;
# alias char[] string;
#
# class Test {
#     private Box[string] m_Boxes;
#     void opIndexAssign(...) in {
#         assert(_arguments.length == 2);
#         assert(_arguments[1] == typeid(string));
#     } body {
#         // The parameter I want to box is _arguments[0].
#         Box b = box(std.stdarg.va_arg!(__UNKNOWN__)(_argptr));
#         string id = std.stdarg.va_arg!(string)(_argptr);
#         m_Boxes[id] = b;
#     }
# }

My question is, what do I put in __UNKNOWN__?

Plan B is to do a manual type-by-type test, like:

# if (_arguments[0] == typeid(int))
#     b = box(va_arg!(int)(_argptr));
# else if (_arguments[0] == typeid(char))
#     b = box(va_arg!(char)(_argptr));

But this would really suck, as it ruins the whole thing. Surely there's a way to
automate that bit of nastiness so that I can do something like:

# b = box(va_arg!(typeof(typeid(_arguments[0])))(_argptr));

Right?

Thanks a ton for the help.
--AJG.
Aug 14 2005
parent reply "Ben Hinkle" <ben.hinkle gmail.com> writes:
 #         // The parameter I want to box is _arguments[0].
 #         Box b = box(std.stdarg.va_arg!(__UNKNOWN__)(_argptr));

something like Box b = box(_arguments[0],_argptr); _argptr += (_arguments[0].tsize() + int.sizeof - 1) & ~(int.sizeof - 1); Someone really should put that argptr increment in a standard place. It's come up twice recently...
Aug 14 2005
parent reply AJG <AJG_member pathlink.com> writes:
Hi,

something like

 Box b = box(_arguments[0],_argptr);

Nice! :)
 _argptr += (_arguments[0].tsize() + int.sizeof - 1) & ~(int.sizeof - 1);

I don't get this part. How come the example in the docs doesn't do that?
Someone really should put that argptr increment in a standard place. It's 
come up twice recently... 

Thanks! --AJG.
Aug 14 2005
parent AJG <AJG_member pathlink.com> writes:
 _argptr += (_arguments[0].tsize() + int.sizeof - 1) & ~(int.sizeof - 1);


Oh, nevermind. I'm a doofus. It's because you didn't use the template macro to get the arg. Right?
Someone really should put that argptr increment in a standard place. It's 
come up twice recently... 


Yes, this seems like a good idea. Cheers, --AJG.
Aug 14 2005