Boost logo

Boost Users :

Subject: [Boost-users] Binding to a function with optional parameters
From: Yang Zhang (yanghatespam_at_[hidden])
Date: 2008-12-02 02:39:26


Is there a way to bind to a function with optional arguments? See my
simple demo program below to see what I've tried:

#include <boost/bind.hpp>
#include <iostream>
using namespace boost;
using namespace std;

int f(int x, int y = 0) { return x + y; }

// Commented lines below don't compile.
int main() {
   cout << bind(f, 1, 2)() << endl;
   // cout << bind(f, 1)() << endl;
   int (*p)(int, int) = f;
   cout << bind(p, 1, 2)() << endl;
   // int (*q)(int) = f;
   // cout << bind(q, 1)() << endl;
   return 0;
}

-- 
Yang Zhang
http://www.mit.edu/~y_z/

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