Boost.Hana  1.5.0
Your standard library for metaprogramming
boost::hana::when< condition > Struct Template Reference

Description

template<bool condition>
struct boost::hana::when< condition >

Enable a partial specialization only if a boolean condition is true.

You might also want to take a look at when_valid, which provides similar functionality but enables a specialziation only when some expression is well-formed.

Rationale for using when instead of std::enable_if

when is used to control the priority of partial specializations in a finer grained manner than what can be achieved with the usual typename Enable = void and std::enable_if pattern. For example, a partially specialized tag-dispatched method will have a higher priority than an equivalent specialization that uses when. For more details, see the tutorial section on tag-dispatching.

Example

// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <type_traits>
namespace hana = boost::hana;
template <typename T, typename = hana::when<true>>
struct base_template;
template <typename T>
struct base_template<T, hana::when<std::is_integral<T>::value>> {
// something useful...
};
int main() { }