Search code examples
c++enable-if

How to use BOOST_STATIC_ASSERT with an OR condition


For example I have

BOOST_STATIC_ASSERT(
     boost::has_range_iterator<T>::value,
);

but I have other types that are range like that I can detect with

is_foo_type::value

How do I combine the two as a disjunction. ie in psuedocode

BOOST_STATIC_ASSERT(
     std::or<
       boost::has_range_iterator<T>::value,
       is_foo_type<T>::value
     >::value
);

Solution

  • Since C++17 you could use a type trait std::disjunction:

    BOOST_STATIC_ASSERT(
         std::disjunction_v<
           boost::has_range_iterator<T>::value,
           is_foo_type<T>::value
         >
    );
    

    Before C++17 you have to use ||, as @StoryTeller has mentioned:

    BOOST_STATIC_ASSERT(boost::has_range_iterator<T>::value || is_foo_type<T>::value);