|
Boost Users : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-09-07 07:51:39
Gast 128 wrote:
> Dear all,
>
> In my work I use the boost libraries quite frequently, especially
> boost::bind to create function objects. However its use is not as
> transparent as I hoped for. Especially using functions in boost bind
> with signatures returning const& can give unpredictable results.
>
> For example:
>
> struct KX
> {
> KX (int i);
> //etc.
> };
>
> typedef std::pair<int, KX> pair_t;
>
> pair_t do_kx_pair(int i)
> {
> return std::make_pair(i, KX(i));
> }
>
> //following will go wrong:
> KX x = boost::bind(&pair_t::second, boost::bind(&do_kx_pair, i))();
>
> The last line compiles on Visual .NET 2003 without any warning (even
> on level 4). However after spending two days in boost bind source
> code, I could see that it actually returns const& to a temporary
> created by boost bind.
Very nice example, thank you. The question whether pointers to data members
should return a const reference by default (as opposed to a value) seems
settled.
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