By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,603 Members | 1,422 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,603 IT Pros & Developers. It's quick & easy.

Boost's bind functions

P: n/a
I think one of the program snippets in the Boost's Bind library is
wrong. I've just been trying to find the error in this program as
below, perhaps there's an typo in there somewhere but I can't find it.
Perhaps one of you lot might know what the typo is:

#include <iostream>
#include <string>
#include <boost/bind.hpp>

class tracer
{
public:
tracer()
{
std::cout << "tracer::tracer()\n";
}

tracer(const tracer& other)
{
std::cout << "tracer::tracer(const tracer& other)\n";
}

tracer& operator=(const tracer& other)
{
std::cout << "tracer& tracer::operator=(const tracer&
other)\n"; return *this;
}

~tracer()
{
std::cout << "tracer::~tracer()\n";
}

void print(const std::string& s) const
{
std::cout << s << '\n';
}
};

int main()
{
tracer t;
boost::bind(&tracer::print, t, _1)(std::string("I'm called on a
copy of t\n")); return 0;
}

--
http://www.munted.org.uk

You've been eating the cat food again, haven't you?
Nov 16 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Alex Buell wrote:
I think one of the program snippets in the Boost's Bind library is
wrong. I've just been trying to find the error in this program as
below, perhaps there's an typo in there somewhere but I can't find it.
Perhaps one of you lot might know what the typo is:
What is the actual problem you're having? Nobody here is a mind-reader
(that I know of)

FWIW, your code compiles fine for me, and outputs:

[dhcp-55:~] ccox% g++ test.cpp -I /usr/local/include/boost && ./a.out
tracer::tracer()
tracer::tracer(const tracer& other)
tracer::tracer(const tracer& other)
tracer::tracer(const tracer& other)
tracer::tracer(const tracer& other)
tracer::tracer(const tracer& other)
tracer::~tracer()
tracer::~tracer()
tracer::tracer(const tracer& other)
tracer::~tracer()
tracer::~tracer()
I'm called on a copy of t

tracer::~tracer()
tracer::~tracer()
tracer::~tracer()

--
Clark S. Cox III
cl*******@gmail.com
Nov 16 '06 #2

P: n/a

Alex Buell wrote:
I think one of the program snippets in the Boost's Bind library is
wrong. I've just been trying to find the error in this program as
below, perhaps there's an typo in there somewhere but I can't find it.
Perhaps one of you lot might know what the typo is:

#include <iostream>
#include <string>
#include <boost/bind.hpp>

class tracer
{
public:
tracer()
{
std::cout << "tracer::tracer()\n";
}

tracer(const tracer& other)
{
std::cout << "tracer::tracer(const tracer& other)\n";
}

tracer& operator=(const tracer& other)
{
std::cout << "tracer& tracer::operator=(const tracer&
other)\n"; return *this;
}

~tracer()
{
std::cout << "tracer::~tracer()\n";
}

void print(const std::string& s) const
{
std::cout << s << '\n';
}
};

int main()
{
tracer t;
boost::bind(&tracer::print, t, _1)(std::string("I'm called on a
copy of t\n")); return 0;
}
Looks fine to me. Where do you think there's a typo?

Cheers! --M

Nov 16 '06 #3

P: n/a
On Thu, 16 Nov 2006 16:52:46 -0500, I waved a wand and this message
magically appears in front of Clark S. Cox III:
I think one of the program snippets in the Boost's Bind library is
wrong. I've just been trying to find the error in this program as
below, perhaps there's an typo in there somewhere but I can't find
it. Perhaps one of you lot might know what the typo is:

What is the actual problem you're having? Nobody here is a mind-reader
(that I know of)
Sorry, knew I'd forgotten something. Here's the error (it just won't
compile!):
tracer.cpp: In function β€˜int main()’:
tracer.cpp:38: error: no match for call to β€˜(boost::_bi::bind_t<void,
boost::_mfi::cmf1<void, tracer, const std::string&>,
boost::_bi::list2<boost::_bi::value<tracer>, boost::arg<1 >)
(std::string)’ /usr/include/boost/bind/bind_template.hpp:17: note:
candidates are: typename boost::_bi::result_traits<R, F>::type
boost::_bi::bind_t<R, F, L>::operator()() [with R = void, F =
boost::_mfi::cmf1<void, tracer, const std::string&>, L =
boost::_bi::list2<boost::_bi::value<tracer>, boost::arg<1>
>] /usr/include/boost/bind/bind_template.hpp:23: note:
typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R,
F, L>::operator()() const [with R = void, F = boost::_mfi::cmf1<void,
tracer, const std::string&>, L =
boost::_bi::list2<boost::_bi::value<tracer>, boost::arg<1>
>>] /usr/include/boost/bind/bind_template.hpp:29: note:
typename boost::_bi::result_traits<R, F>::type boost::_bi::bind_t<R,
F, L>::operator()(A1&) [with A1 = std::string, R = void, F =
boost::_mfi::cmf1<void, tracer, const std::string&>, L =
boost::_bi::list2<boost::_bi::value<tracer>, boost::arg<1>
>>>] /usr/include/boost/bind/bind_template.hpp:35:
note: typename boost::_bi::result_traits<R, F>::type
boost::_bi::bind_t<R, F, L>::operator()(A1&) const [with A1 =
std::string, R = void, F = boost::_mfi::cmf1<void, tracer, const
std::string&>, L = boost::_bi::list2<boost::_bi::value<tracer>,
boost::arg<1]
FWIW, your code compiles fine for me, and outputs:
How strange! I'm using Boost 1.33.1 with G++ 4.1.1 here.
--
http://www.munted.org.uk

You've been eating the cat food again, haven't you?
Nov 16 '06 #4

P: n/a
On 16 Nov 2006 13:56:24 -0800, I waved a wand and this message
magically appears in front of mlimber:
>
Looks fine to me. Where do you think there's a typo?
See my another post with the ouitput from the compiler for details. I'm
totally stumped coz it should compile yet it doesn't! I'm using GCC
4.1.1 with Boost 1.33.1.

--
http://www.munted.org.uk

You've been eating the cat food again, haven't you?
Nov 17 '06 #5

P: n/a
Alex Buell wrote:
On 16 Nov 2006 13:56:24 -0800, I waved a wand and this message
magically appears in front of mlimber:

Looks fine to me. Where do you think there's a typo?

See my another post with the ouitput from the compiler for details. I'm
totally stumped coz it should compile yet it doesn't! I'm using GCC
4.1.1 with Boost 1.33.1.
FYI, this compiles fine with Dinkumware's TR1:

#include <iostream>
#include <string>
#include <functional>

class tracer
{
public:
tracer()
{
std::cout << "tracer()\n";
}

tracer(const tracer& other)
{
std::cout << "tracer(const tracer&)\n";
}

tracer& operator=(const tracer& other)
{
std::cout << "operator=\n";
return *this;
}

~tracer()
{
std::cout << "~tracer()\n";
}

void print(const std::string& s) const
{
std::cout << s << '\n';
}

};

int main()
{
tracer t;
std::tr1::bind(&tracer::print, t, std::tr1::placeholders::_1)
( std::string("I'm called on a copy of t\n") );
return 0;
}

You can get rid of the namespace qualifications by adding this to the
top:

using namespace std;
using namespace std::tr1;
using namespace std::tr1::placeholders;

In Boost's version, the placeholders are in an anonymous namespace
rather than std::tr1::placeholders (see
http://boost.org/libs/bind/bind.html#Interface).

Cheers! --M

Nov 17 '06 #6

P: n/a
I think your boost-libs isn't full-compiled.

Dec 6 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.