Boost logo

Boost Users :

From: Mihalicza, Jozsef (JMihalicza_at_[hidden])
Date: 2004-12-17 07:05:11


Hello,

Attached you can find a modified version of your code snipplet that works.
In fact you needn't specify <bool>, but you have to pass as many arguments as the function actually takes, three in this case.
Even if you specify a default value for threshold, the compiler treats equ as a function taking three parameters.

HTH
Best regards,
Jocó

P.S. to Agoston Bejo: Kicsi a világ :)

-----Original Message-----
From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of Agoston Bejo
Sent: Friday, December 17, 2004 1:01 AM
To: boost-users_at_[hidden]
Subject: [Boost-users] bind and default function parameters

Hi!
A small example:

--------------------------------
template<typename T1, typename T2>
bool equ(T1 t1, T2 t2, double threshold) {
 return t1 == t2;
}

int _tmain(int argc, _TCHAR* argv[])
{
 int ia1[] = {1,2,3,4,5};
 cout << *find_if(ia1, ia1+5, bind<bool>(equ<int, int>, _1, 5)) << endl;
// ERROR
 return 0;
}
-----------------------------------
Compiler: VC++7.1

(Intermezzo: another question: why do I have to specify the result type for
bind in this case (bool)? Why can't it deduce it from the template function
declaration: the return type is non-dependent.)

Error message:

c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\boost\bind.hpp(246) : error C2198: 'bool (__cdecl
*)(int,int,double)' : too few arguments for call through pointer-to-function

... and the rest (I suppose they are mainly irrelevant)

        c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\boost\bind\bind_template.hpp(33) : see reference to
function template instantiation 'R boost::_bi::list2<A1,A2>::operator
()<boost::_bi::bind_t<R,F,L>::result_type,bool(__cdecl
*)(T1,T2,double),boost::_bi::list1<int &>>(boost::_bi::type<T>,F,A &)' being
compiled
        with
        [
            R=boost::_bi::bind_t<bool,bool (__cdecl
*)(int,int,double),boost::_bi::list2<boost::_bi::list_av_2<boost::arg<1>,int
>::B1,boost::_bi::list_av_2<boost::arg<1>,int>::B2>>::result_type,
            A1=boost::_bi::list_av_2<boost::arg<1>,int>::B1,
            A2=boost::_bi::list_av_2<boost::arg<1>,int>::B2,
            F=bool (__cdecl *)(int,int,double),

L=boost::_bi::list2<boost::_bi::list_av_2<boost::arg<1>,int>::B1,boost::_bi:
:list_av_2<boost::arg<1>,int>::B2>,
            T1=int,
            T2=int,
            T=boost::_bi::bind_t<bool,bool (__cdecl
*)(int,int,double),boost::_bi::list2<boost::_bi::list_av_2<boost::arg<1>,int
>::B1,boost::_bi::list_av_2<boost::arg<1>,int>::B2>>::result_type,
            A=boost::_bi::list1<int &>
        ]
        c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\algorithm(64) : see reference to function template
instantiation 'boost::_bi::bind_t<R,F,L>::result_type
boost::_bi::bind_t<R,F,L>::operator ()<int>(A1 &)' being compiled
        with
        [
            R=bool,
            F=bool (__cdecl *)(int,int,double),

L=boost::_bi::list2<boost::_bi::list_av_2<boost::arg<1>,int>::B1,boost::_bi:
:list_av_2<boost::arg<1>,int>::B2>,
            A1=int
        ]
        d:\prog\vcpp\Boost\xBindAndDefFuncArg\xBindAndDefFuncArg.cpp(22) :
see reference to function template instantiation '_InIt
std::find_if<int*,boost::_bi::bind_t<R,F,L>>(_InIt,_InIt,_Pr)' being
compiled
        with

_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users




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