|
Boost Users : |
Subject: Re: [Boost-users] correct usage of bind
From: Roman Perepelitsa (roman.perepelitsa_at_[hidden])
Date: 2009-03-18 04:07:52
2009/3/17 Sandeep Gupta <gupta.sandeep_at_[hidden]>
> Hi,
> Both the statements below bind function buildPair. While the first
> works the other fails. What could be a possible fix. Thanks in
> advance.
>
> //---- Function to be used by bind -------------------------
> template<typename X, typename Y>
> std::pair<X, Y> buildPair(X x, Y y)
> {
> std::pair<X,Y> apair(x,y);
> return apair;
> }
>
>
> (std::cout<<buildPair(_1,_2).first<<' ')(1,2); ///--compiles
> fine---------
This one does not bind buildPair, it evaluates buildPair immediately. This
line of code is equivalent to
(std::cout<<_1<<' ')(1,2);
> (bind(buildPair,_1,_2))(3,5); ///-fails------------
>
You should specify template arguments for buildPair.
(bind(buildPair<int, int>,_1,_2))(3,5);
Roman Perepelitsa.
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