473,722 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Boost's bind functions

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::operato r=(const tracer&
other)\n"; return *this;
}

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

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

int main()
{
tracer t;
boost::bind(&tr acer::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
6 2604
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

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::operato r=(const tracer&
other)\n"; return *this;
}

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

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

int main()
{
tracer t;
boost::bind(&tr acer::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
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::cm f1<void, tracer, const std::string&>,
boost::_bi::lis t2<boost::_bi:: value<tracer>, boost::arg<1 >)
(std::string) /usr/include/boost/bind/bind_template.h pp:17: note:
candidates are: typename boost::_bi::res ult_traits<R, F>::type
boost::_bi::bin d_t<R, F, L>::operator()( ) [with R = void, F =
boost::_mfi::cm f1<void, tracer, const std::string&>, L =
boost::_bi::lis t2<boost::_bi:: value<tracer>, boost::arg<1>
>] /usr/include/boost/bind/bind_template.h pp:23: note:
typename boost::_bi::res ult_traits<R, F>::type boost::_bi::bin d_t<R,
F, L>::operator()( ) const [with R = void, F = boost::_mfi::cm f1<void,
tracer, const std::string&>, L =
boost::_bi::li st2<boost::_bi: :value<tracer>, boost::arg<1>
>>] /usr/include/boost/bind/bind_template.h pp:29: note:
typename boost::_bi::res ult_traits<R, F>::type boost::_bi::bin d_t<R,
F, L>::operator()( A1&) [with A1 = std::string, R = void, F =
boost::_mfi:: cmf1<void, tracer, const std::string&>, L =
boost::_bi::l ist2<boost::_bi ::value<tracer> , boost::arg<1>
>>>] /usr/include/boost/bind/bind_template.h pp:35:
note: typename boost::_bi::res ult_traits<R, F>::type
boost::_bi:: bind_t<R, F, L>::operator()( A1&) const [with A1 =
std::strin g, R = void, F = boost::_mfi::cm f1<void, tracer, const
std::string& >, L = boost::_bi::lis t2<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
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
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(con st 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::pri nt, t, std::tr1::place holders::_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::place holders;

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

Cheers! --M

Nov 17 '06 #6
I think your boost-libs isn't full-compiled.

Dec 6 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2937
by: P G | last post by:
I hope this is on topic here. I have a problem compiling a simple example of the use of boost::bind. Please take a look at the program below. /**************************************************************************/ #include <boost/function.hpp> #include <boost/bind.hpp> #include <boost/shared_ptr.hpp>
4
2729
by: Arturo Cuebas | last post by:
The program below contains a compile error. Following the program you will find the typical fix then my idea for a library that facilitates a more elegant fix. #include <boost\bind.hpp> using namespace boost; struct C {
13
3585
by: Russell Hind | last post by:
I'm trying to use boost::bind and boost::function inside managed code, but there appears to be some code generation problems. The following code compiles fine, but the function object throws an exception when you call it with f() saying the function is empty. If you un-comment the #pragma unamanged, it runs fine. It appears to be a code generation problem when compiling function and bind as managed. Thanks Russell
0
1941
by: Arnaud Debaene | last post by:
Hello all. I've got a bunch of existing, non managed, C++ DLLs that export types with, among other things, public events implemented using the boost::signals library. Now, I need to have these DLL interoperate with managed code. Among others things, the managed code need to be able to register for notification with the boost signals. I've tried different approaches (trying to register a pinned delegate with the boost::signal, etc...),
2
4024
by: Martin Herbert Dietze | last post by:
Hi, in a project I am using callbacks which are called like ordinary functions but in fact are Loki::Functor's encapsulating calls to non-static member functions on instances of different classes. The approach using Loki::Functor looks like this: | class X {
7
2692
by: Henrique A. Menarin | last post by:
I want to create a function _and so that I could write vector<boolasserts; //... bool b = _and(asserts); and it "anded" all the elements in the vector. I implemented it like this:
1
3846
by: Olaf Petzold | last post by:
Hi, at this time I try to combine Qt and boost. Unfortunately I've run into trouble: void QWidget::insertAction ( QAction * before, QAction * action ); class QAction : public QWidget { ... }; class ActionCategory { ...
1
2794
by: Tigera | last post by:
Greetings, I am trying to learn to use the Boost library, and I've run into a frustrating problem with the line marked here: #include <boost/function.hpp> #include <boost/functional.hpp> #include <boost/bind.hpp> #include <iostream>
3
6815
by: =?iso-8859-1?B?Tm9yZGz2dw==?= | last post by:
Hey there, C++ Coders! I am learning multi-threading with boost and have come up with the following code example shown below. This example implements a test of the producer-consumer design pattern. gcc-4.1.2 however complains with errors about my use of boost::bind(). Doesn't bind support this way of specifying a function and its arguments or should I solve it in another way?
0
8867
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9239
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9158
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5996
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4764
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3208
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2606
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2148
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.