|
Boost Users : |
From: Angus Leeming (angus.leeming_at_[hidden])
Date: 2005-04-05 08:30:45
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 <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/mpl/end.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/find_if.hpp>
#include <boost/mpl/lambda.hpp>
#include <boost/mpl/integral_c.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/vector_c.hpp>
namespace boost {
namespace mpl {
template <typename IntegralSequence, int Value>
struct contains_c {
private:
typedef typename
find_if<
IntegralSequence
, equal_to<
_1
, integral_c<typename IntegralSequence::value_type, Value>
>
>::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;
}
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