Passing dynamic arguments with boost?

Hi, After programming with Python and switching back to C++, I am missing the flexibility of a scripted language. Specifically, I am annoyed at having to specify the arguments of a function at compile time. Is there anyway I can avoid specifying the exact arg structure? I thought boost might do this somehow? Say for example, I have a message handler function. I want to be able to send all sorts of arguments to the same function, which can then deduce what to do according to the data held in those args. I don't want to have to overload everything as I am passing these message handlers around using boost::function/boost::bind. Thanks

Hi,
After programming with Python and switching back to C++, I am missing the flexibility of a scripted language.
Specifically, I am annoyed at having to specify the arguments of a function at compile time. Is there anyway I can avoid specifying the exact arg structure? I thought boost might do this somehow?
Say for example, I have a message handler function. I want to be able to send all sorts of arguments to the same function, which can then deduce what to do according to the data held in those args. I don't want to have to overload everything as I am passing these message handlers around using boost::function/boost::bind.
Are you thinking of named arguments, or do you want 'isinstance'? --John

John Femiani wrote:
Hi,
After programming with Python and switching back to C++, I am missing the flexibility of a scripted language.
Specifically, I am annoyed at having to specify the arguments of a function at compile time. Is there anyway I can avoid specifying the exact arg structure? I thought boost might do this somehow?
Say for example, I have a message handler function. I want to be able to send all sorts of arguments to the same function, which can then deduce what to do according to the data held in those args. I don't want to have to overload everything as I am passing these message handlers around using boost::function/boost::bind.
Are you thinking of named arguments, or do you want 'isinstance'?
I was hoping to be able to call one function with different args, wrapping those args somehow. In python, I could call a function with a list, dict or tuple. Since this one object was the argument, it didn't matter what it contained. I know I could pass a vector in C++, but this needs a single data type. In python I could call: MyFunc((1, "2", anObject)) # - all in a tuple MyFunc(("aardvark", 42)) # another tuple Anyway to replicate this very convenient functionality? Si

on Fri Jul 11 2008, Simon Pickles <sipickles-AT-googlemail.com> wrote:
I was hoping to be able to call one function with different args, wrapping those args somehow.
In python, I could call a function with a list, dict or tuple. Since this one object was the argument, it didn't matter what it contained.
I know I could pass a vector in C++, but this needs a single data type. In python I could call:
MyFunc((1, "2", anObject)) # - all in a tuple MyFunc(("aardvark", 42)) # another tuple
Anyway to replicate this very convenient functionality?
Make MyFunc a function template and use Boost.Range? -- Dave Abrahams BoostPro Computing http://www.boostpro.com

for variable number of arguments: void myFunction(std::vector<boost::any> &); or for arguments by name: void myFunction(std::map<std::string, boost::any> &); -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Simon Pickles Sent: Friday, July 11, 2008 11:38 To: boost-users@lists.boost.org Subject: [Boost-users] Passing dynamic arguments with boost? Hi, After programming with Python and switching back to C++, I am missing the flexibility of a scripted language. Specifically, I am annoyed at having to specify the arguments of a function at compile time. Is there anyway I can avoid specifying the exact arg structure? I thought boost might do this somehow? Say for example, I have a message handler function. I want to be able to send all sorts of arguments to the same function, which can then deduce what to do according to the data held in those args. I don't want to have to overload everything as I am passing these message handlers around using boost::function/boost::bind. Thanks _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

if the number of types to be passed is known at compile time, using boost::variant<type1, type2, ...> instead of boost::any results in faster code. -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Simon Pickles Sent: Friday, July 11, 2008 13:45 To: boost-users@lists.boost.org Subject: Re: [Boost-users] Passing dynamic arguments with boost? peter_foelsche@agilent.com wrote:
for variable number of arguments:
void myFunction(std::vector<boost::any> &);
or for arguments by name:
void myFunction(std::map<std::string, boost::any> &);
Thanks, this is really interesting.... _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (4)
-
David Abrahams
-
John Femiani
-
peter_foelsche@agilent.com
-
Simon Pickles