471,571 Members | 1,618 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,571 software developers and data experts.

Using gernerics Predicate<T> in C++/CLI

Hello all,

Has everyone tried to use the functions taking a Predicate in Generics
container in C++/CLI?

Say I have a List<MyClass^>^ my_array, and I want to call RemoveAll on
it. How would you do this?

The most natural approach would be :

MyClass^ elem_to_be_removed = //......;
Predicate<MyClass^>^ equality_predicate=gcnew
Predicate<MyClass^>(handler, &MyClass::Equals); //1

This is already klunky and heavy-syntax, but it also doesn't compile!
At line //1, the compiler complains that the Equals method doesn't have
the right signature (which is true, because this is really the
Object::Equals method here - but I would have hoped that some kind of
"parameter type covariance" would have worked here).

I also have tried using the IEquatable interface, but it doesn't work
either. How are you supposed to use all those functions with predicates
in C++/CLI? Do you need to hand-write a specific function just for
handle-equality checking for *each* type ?

It really is a pity, but it looks like one more time the designers
thought only about C# (where you've got anonymous delegates) when they
designed the whole thing. I hope the STL.NETwill do better!

Also, concerning all this stuff, it there any plan to support generics
delegates in C++/CLI?


Oct 31 '06 #1
0 2183

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by clécio | last post: by
1 post views Thread by Marc Boucher | last post: by
6 posts views Thread by A | last post: by
6 posts views Thread by Juha Nieminen | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

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.