Boost logo

Boost Users :

From: Jeff Faust (jeff_at_[hidden])
Date: 2002-09-03 11:07:16


Julia,

The only way I can think of accomplishing this is to have all the methods
have the same return type. function<void> and function<int> are two
distinct types. Assigning them both to a function<void> just doesn't seem
right.

Jeff

-----Original Message-----
From: news [mailto:news_at_[hidden]]On Behalf Of Julia Donawald
Sent: Tuesday, September 03, 2002 8:22 AM
To: boost-users_at_[hidden]
Subject: [Boost-Users] boost::function map with different return types

Hi,
I have the following code:
---------------
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <map>
#include <string>

class Foo {
public:
   void Function3() const
   {
    int i =2;
   };
   const std::string Function4() const
   {
    return "";
   };
   unsigned int Function5() const
   {
    return 2;
   };
};

   std::map<std::string, boost::function<void> > functions;

   Foo foo;
   functions["Function3"] = boost::bind(&Foo::Function3, &foo);
   functions["Function4"] = boost::bind(&Foo::Function4, &foo);
   functions["Function5"] = boost::bind(&Foo::Function5, &foo);

   // call the functions
   functions["Function4"]();
--------------

Calling the correct function with the entries in the map is no problem, but
how can I get the return value. I tried something like that:
"unsigned int i = functions["Function5"]();" but sadly it doesnt work, maybe
cause in the map I declared for the return value "void"?
How can I have such a map where to have functions with different return
types in it and to get the return value after a call of the function through
the map?

Thanks in advance
Julia

Info: <http://www.boost.org>
Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl>
Unsubscribe: <mailto:boost-users-unsubscribe_at_[hidden]>

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net