[ create a new paste ] login | about

Link: http://codepad.org/ciKTrh2r    [ raw code | output | fork ]

mloskot - C++, pasted on Mar 22:
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <iostream>
#include <map>
#include <string>

typedef boost::function<void(void)> fun_t;
typedef std::map<std::string, fun_t> funs_t;

void foo() { std::cout <<"\n"; }
void bar(int p) { std::cout<<"("<<p<<")\n"; }
void goo(std::string p) { std::cout<<"("<<p<<")\n";}

int main()
{
 funs_t f;
 f["foo"] = boost::bind(foo);
 f["bar"] = boost::bind(bar, int(17));
 f["goo"] = boost::bind(goo, "I am goo");

 for (funs_t::iterator it = f.begin(); it != f.end(); ++it)
 {
  std::cout << (*it).first << "->";
  (*it).second();
 }

 f["bar"]();

 return 0;
}


Output:
1
2
3
4
bar->(17)
foo->
goo->(I am goo)
(17)


Create a new paste based on this one


Comments: