Trouble implementing the equivalent of boost::mpl::or_
Jun 6, 2017 at 8:02pm UTC
Hi,
As an exercise, I am trying to implement boost::mpl::or_ calling it logical_or. I have suceeded by using mpl::eval_if but have not been able to do it using mpl::if_. Following code shows my correct implementation and my attempt to use mpl::if_:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
namespace mpl = boost::mpl;
template <typename N1, typename N2>
struct logical_or : mpl::bool_<
mpl::eval_if<
N1,
mpl::true_,
mpl::eval_if<
N2,
mpl::true_,
mpl::false_>
>::type::value
>
{};
namespace Using_if_
{
template <typename N1, typename N2>
struct logical_or : mpl::bool_<
mpl::if_<
N1,
mpl::true_,
mpl::if_<
N2,
mpl::true_,
mpl::false_>
>::value
>
{};
}
I am trying to retain short-circuit behavior as that given by mpl::or_.
Any help greatly appreciated!!
Juan Dent
I found the solution!! Place an extra type at the end of the first mpl::if_ as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
namespace Using_if_
{
template <typename N1, typename N2>
struct logical_or : mpl::bool_<
mpl::if_<
N1,
mpl::true_,
mpl::if_<
N2,
mpl::true_,
mpl::false_>
>::type::type::value
>
{};
}
Just putting it in writing cleared my mind!!
Eureka!
Regards,
Juan Dent
Last edited on Jun 6, 2017 at 8:07pm UTC
Topic archived. No new replies allowed.