Angus Leeming wrote:
Even if this turns out to be impossible, I'd like to go on and try to
define some_boolean_condition if I may. I see that Aleksey plans a
contains_c metafunction for 1.33,
Apologies for replying to self, but I have managed to define a contains_c
metafunction. (Below).
I still don't know how to use it with enable_if, however. This fails to
compile:
boost::enable_if<
mpl::contains_c<
mpl::vector_c< int, foo::state2, foo::state3 >
, foo::state2
>
, foo::state
::type s = foo::state2;
My naïve understanding is that enable_if<...>::type should be foo::state
here. Any pointers?
Regards,
Angus
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace boost {
namespace mpl {
template
struct contains_c {
private:
typedef typename
find_if<
IntegralSequence
, equal_to<
_1
, integral_c
>
>::type iter;
public:
typedef typename
not_<
is_same<
iter
, typename end<IntegralSequence>::type
>
>::type type;
typedef typename type::value_type value;
};
} // namespace mpl
} // namespace boost
class foo {
public:
enum state {
state1,
state2,
state3
};
};
int main()
{
namespace mpl = boost::mpl;
typedef mpl::vector_c< int, foo::state2, foo::state3 >
allowable_values;
// Fails to compile, as expected.
// BOOST_MPL_ASSERT(( mpl::contains_c< allowable_values, foo::state1 > ));
// Compiles, as expected.
BOOST_MPL_ASSERT(( mpl::contains_c< allowable_values, foo::state2 > ));
// Why doesn't this compile?
boost::enable_if<
mpl::contains_c< allowable_values, foo::state2 >
, foo::state
>::type s = foo::state2;
return 0;
}