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

Home Posts Topics Members FAQ

Problems mixing boost::lambda:: bind and boost::shared_p tr..

Hi,

Consider the following:

class A
{
public:
virtual bool foo() = 0;
};

class B : public A
{
public:
virtual bool foo() { return false; }
};

void fn()
{
std::list< A * > aList(10);
std::list< boost::shared_p tr<A> > aSharedList(10) ;

// This works fine..
std::count_if(
aList.begin(),
aList.end(),
boost::lambda:: bind(A::foo, boost::lambda:: _1)
);

// This doesn't compile..
std::count_if(
aSharedList.beg in(),
aSharedList.end (),
boost::lambda:: bind(A::foo, boost::lambda:: _1)
);
}

--

Why doesn't the second case compile ? The only difference is that I'm
making the call through a shared_ptr instead of a naked one. If
shared_ptr semantics are (essentially) identical to the naked pointer
ones then this should surely work ? Is there some extra syntax required
in the shared_ptr case or does this simply not work ?

Thanks in advance,

--
t o b e
Rawflow,
London, UK.
Jun 1 '06 #1
6 4026

Toby Bradshaw wrote:
Hi,

Consider the following:

class A
{
public:
virtual bool foo() = 0;
};

class B : public A
{
public:
virtual bool foo() { return false; }
};

void fn()
{
std::list< A * > aList(10);
std::list< boost::shared_p tr<A> > aSharedList(10) ;

// This works fine..
std::count_if(
aList.begin(),
aList.end(),
boost::lambda:: bind(A::foo, boost::lambda:: _1)
);

// This doesn't compile..
std::count_if(
aSharedList.beg in(),
aSharedList.end (),
boost::lambda:: bind(A::foo, boost::lambda:: _1)
);
}

--

Why doesn't the second case compile ? The only difference is that I'm
making the call through a shared_ptr instead of a naked one. If
shared_ptr semantics are (essentially) identical to the naked pointer
ones then this should surely work ? Is there some extra syntax required
in the shared_ptr case or does this simply not work ?

Thanks in advance,

--
t o b e
Rawflow,
London, UK.

With g++ the error is this (sorry that is very very long lines)
no matching function for call to `boost::lambda: :function_adapt or<bool
(A::*)() const>::apply(b ool (A::*const&)() const,
boost::shared_p tr<A>&)'
canidate are:
static Result boost::lambda:: function_adapto r<Result (Object::*)()
const>::apply(R esult (Object::*)() const, const Object&) [with RET =
bool, Object = A, Result = bool]

As you can see it trys to match pointer to member function with
reference to member function - with boost::lambda don't have - why
shared_ptr is passing this? I'm not sure (its gatting late :) )
Hope you can continue from here..
good luck

Jun 1 '06 #2
You know, these boost questions would be better answered in the boost
mailing list. Many here are not familiar with boost and don't
appreciate the off-topic nature of discussion about it. You'll get
better responses where boost is on topic and where there are people
more familiar with how to use it.

Jun 1 '06 #3
See inline response

Toby Bradshaw wrote:
Hi,

Consider the following:

class A
{
public:
virtual bool foo() = 0;
};

class B : public A
{
public:
virtual bool foo() { return false; }
};

void fn()
{
std::list< A * > aList(10);
std::list< boost::shared_p tr<A> > aSharedList(10) ;

// This works fine..
std::count_if(
aList.begin(),
aList.end(),
boost::lambda:: bind(A::foo, boost::lambda:: _1)
boost::lambda:: bind(&A::foo, boost::lambda:: _1)
);

// This doesn't compile..
std::count_if(
aSharedList.beg in(),
aSharedList.end (),
boost::lambda:: bind(A::foo, boost::lambda:: _1)
boost::lambda:: bind(&A::foo, boost::lambda:: _1)
);
}

--

Why doesn't the second case compile ? The only difference is that I'm
making the call through a shared_ptr instead of a naked one. If
shared_ptr semantics are (essentially) identical to the naked pointer
ones then this should surely work ? Is there some extra syntax
required in the shared_ptr case or does this simply not work ?


I haven't used lambda bind a lot, but boost bind requires the & as shown
above, although some compilers will let you get by without it. Other than
that, the code will result in undefined behaviour since your containers are
not pointing to valid instances.

Jeff Flinn
Jun 1 '06 #4
Noah Roberts wrote:
You know, these boost questions would be better answered in the boost
mailing list. Many here are not familiar with boost and don't
appreciate the off-topic nature of discussion about it. You'll get
better responses where boost is on topic and where there are people
more familiar with how to use it.


Many on here are not familiar with virtual base classes but I would be
happy to answer questions on them. Furthermore.. many of the concepts
contained within Boost are being considered for inclusion in C++0x.

Regards,

--
t o b e
Jun 2 '06 #5

Toby Bradshaw wrote:
Noah Roberts wrote:
You know, these boost questions would be better answered in the boost
mailing list. Many here are not familiar with boost and don't
appreciate the off-topic nature of discussion about it. You'll get
better responses where boost is on topic and where there are people
more familiar with how to use it.

Many on here are not familiar with virtual base classes but I would be
happy to answer questions on them.


You don't understand the difference??

Furthermore.. many of the concepts contained within Boost are being considered for inclusion in C++0x.


Actually very few are so far.

Jun 2 '06 #6
Noah Roberts wrote:

Toby Bradshaw wrote:
Noah Roberts wrote:
> You know, these boost questions would be better answered in the boost
> mailing list. Many here are not familiar with boost and don't
> appreciate the off-topic nature of discussion about it. You'll get
> better responses where boost is on topic and where there are people
> more familiar with how to use it.
>


Many on here are not familiar with virtual base classes but I would be
happy to answer questions on them.


You don't understand the difference??


Please, don't confuse the critique of a reasoning with the critique of the
conclusion. You wrote "Many here are not familiar with boost and don't
appreciate the off-topic nature of discussion about it." as though the
former was a reason as to why boost is off-topic. The parody of your
statement just goes to show that the reasoning is not sound. Of course, it
still maybe the case that boost is off-topic; but that would need to be
argued differently.

[snip]
Best

Kai-Uwe Bux
Jun 2 '06 #7

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

Similar topics

16
2610
by: Jeff Flinn | last post by:
At the risk of raising the OT ire of some here, I'd like to know what might be done to raise the awareness of the boost libraries. I've found boost and it's libraries invaluable in my work for ~5 years now. The first two postings in this group this morning are addressed almost trivially by using libraries from www.boost.org. IMO, the functionality in boost increases the usability of C++ at least as much as the standard library does. ...
43
5000
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide much of the same functionality through their own libraries. I'm not sure if that's a good thing or not. AFAIK, most of Qt is compatable with the Standard Library. That is, QLT can interoperate with STL, and you can convert back and forth between std::string and Qt::QString, etc. Are there any...
5
4321
by: google | last post by:
Hi All, I'm just getting started learning to use <algorithm> instead of loads of little for loops, and I'm looking for a bit of advice/mentoring re: implementing the following... I have a vector of boost::shared_ptr's, some of which may be NULL. I'd like to find out if there are any non-NULL elements in the vector. Here's what I have at the moment.
5
2030
by: asianmuscle | last post by:
I am trying to learn RAII and some template techniques by writer a smarter pointer class to manage the resource management. Since I find that a lot of the resource management is kinda the same, I try to mimic some other examples outther then tailor to my needs. My case is for windows handle like hkey, dll library, file handle, etc. But the code largely uses standard C++. Only the Clean up action, I put windows api call in there. In...
3
3382
by: Misiu | last post by:
Hello everybody, How to avoid using struct IsDataType for comparison for find_if algorithm but use something like that what is now commented out in the code below? Regards, Misiu template<typename T>
0
1044
by: jaybny | last post by:
just starting using boost.... I have the following member function: double Position::GetValue() { return _val; } and the following vector:
6
1557
by: Protoman | last post by:
Read this code I found on the Internet: Object o,*oo; // Some objects int (Object::*ptr_to_o_func)(double); // ptr_to_obj_func is a pointer to a // member function of Object oo = getObjectPtr(); ptr_to_o_func = (//some boolean condition) ?
5
2911
by: Jun | last post by:
Hello, I've code like : =========================================== class A{ public : // create print content friend std::ostream& operator<< (std::ostream& os, const A& a);
2
3032
by: anton.bredikhin | last post by:
Hello everybody. I want to write an unnamed predicate for std::find_if in-place. If the vector is filled by raw struct, then I can find the target element like that: struct C { int i;
0
8740
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9386
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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
9090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6685
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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...
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.