0
// bind.hpp
template< class A1 > class list1: private storage1< A1 >
{

    template<class R, class F, class A> R operator()(type<R>, F & f, A & a, long)
    {
        return unwrapper<F>::unwrap(f, 0)(a[base_type::a1_]);
    }

    template<class F, class A> void operator()(type<void>, F & f, A & a, int)
    {
        unwrapper<F>::unwrap(f, 0)(a[base_type::a1_]);
    }
}

Why add arguments int/long in operator()?

If I delete these int/long, still pass compile.

CinCout
  • 9,486
  • 12
  • 49
  • 67
zpeng
  • 101
  • 5
  • 1
    The only difference between those two overloads seems to be the return type, and the last type parameter is being used as a tag type to explicitly differentiate between functions that return void and functions that return any other type. – bku_drytt May 03 '16 at 10:52
  • R operator()(type, F f, A & a) and void operator()(type, F f, A & a) still work well, if I call operator()(type, f, a). Why need add a argument to do overload resolution? – zpeng May 03 '16 at 11:20
  • You don't have to if you test them both out and it works. Normally, you don't even need the `int` overload version, as returning `void` will work properly when `T = void`; returning void is a valid expression, see: http://stackoverflow.com/a/3305917/4683600. – bku_drytt May 03 '16 at 11:23
  • here is my demo code. http://ideone.com/MZtwbc. Overload resolution choose the operator()(type, F f, A & a) for non void, another for void – zpeng May 03 '16 at 11:30
  • Because you have an overload that uses `type` which is an exact match. That is also a tag. If you just want to defer a function call to another, you can just do this: http://coliru.stacked-crooked.com/a/7f6c2c86768f8979 – bku_drytt May 03 '16 at 11:59
  • I got your idea(return void is valid). But why boost::bind do above? add a void overload version. – zpeng May 03 '16 at 12:38

0 Answers0