469,319 Members | 2,398 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,319 developers. It's quick & easy.

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
my_array->RemoveAll(equality_predicate);

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?

Arnaud
MVP - VC

Oct 31 '06 #1
0 2105

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 zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.