|
Boost Users : |
Subject: Re: [Boost-users] How to write a predicate for mpl::find_if that is able to work with placeholders?
From: Michael Schulze (mschulze_at_[hidden])
Date: 2010-09-21 14:51:14
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I solved it. I crawled through the mpl sources (not an easy task) and
found how it has to work.
The predicate needs to be defined as:
template<typename A, typename B>
struct contained
{
static const int value=is_same<typename A::slot_id, B>::value;
template<typename T1, typename T2>
struct apply;
};
> template<int i>
> struct Slot {
> typedef Slot type;
> typedef int_<i> slot_id;
> };
> typedef vector<Slot<0>, Slot<10>, Slot<15> > slots;
> typedef find_if<slots, contained< _1, int_<10> > >::type t10;
> BOOST_MPL_ASSERT(( is_same< deref<t10>::type, Slot<10> > ));
This works as intended. However, finding out how to write such a
predicate, was very hard. Providing examples, describing the different
kinds of predicates and how they need to be written in order to work
with placeholders, would be very helpful. Maybe such things could be
added to the mpl documentation, because I am sure, I am not the first
that came up with such an issue.
Regards,
Michael
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/
iQEcBAEBAgAGBQJMmP6eAAoJEKn9/33w5fU9FQAH/0gzuptHEBfAqfkVrmjD3/+X
ibhtkSMCyXarkTSbTLYeJ7mOZ7cZ9hMpa2pLvQG0W6jLFvyjVnL+zJDrIbNFDFs9
++nIzlijFqnaVSqi8WRAw5mXn9Ai2j0NFRyBDz70N+fPFkm+KsRDyL6pME6oLI+u
WDRG4jexnLeomrIePrWbTdpNQaTKerp91cnR/6wJdMNBgDxePnP9Yzye5ltPsJzi
H7SpqqHpX9yXxslvMi7vN7V8qrPwHx1Y17ILzIP77/EA/hBpFkcxPC8H8YdoUF9n
UxIJ5RGwq54bEgF8qvVKkZsZy8s5u42H3E+rbNxmUcoQmaQ+Ow7gvEzQqVJTbHI=
=siFh
-----END PGP SIGNATURE-----
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net