Use std::enable_if to enable SFINAE rather than static_assert

This commit is contained in:
Nick Thompson
2018-10-29 11:58:18 -06:00
parent 6c58aa9a48
commit df7adb52ca
2 changed files with 6 additions and 10 deletions

View File

@ -22,16 +22,12 @@ struct euclidean_result_t {
Z y;
};
template<class Z>
euclidean_result_t<Z> extended_euclidean(Z m, Z n)
{
using std::numeric_limits;
static_assert(numeric_limits<Z>::is_integer,
"The extended Euclidean algorithm works on integral types.\n");
static_assert(numeric_limits<Z>::is_signed,
"The extended Euclidean algorithm only works on signed integer types.\n");
template<class Z>
euclidean_result_t<typename std::enable_if<numeric_limits< Z >::is_signed, Z>::type>
extended_euclidean(Z m, Z n)
{
if (m < 1 || n < 1)
{
BOOST_THROW_EXCEPTION(std::domain_error("Arguments must be strictly positive.\n"));

View File

@ -17,8 +17,8 @@ test-suite integer
[ run integer_mask_test.cpp ]
[ run static_log2_test.cpp ]
[ run static_min_max_test.cpp ]
[ run extended_euclidean_test.cpp : : : [ requires cxx11_unified_initialization_syntax ] ]
[ run mod_inverse_test.cpp : : : [ requires cxx11_unified_initialization_syntax ] ]
[ run extended_euclidean_test.cpp : : : [ requires cxx11_unified_initialization_syntax sfinae_expr ] ]
[ run mod_inverse_test.cpp : : : [ requires cxx11_unified_initialization_syntax sfinae_expr ] ]
[ compile integer_traits_include_test.cpp ]
[ compile integer_include_test.cpp ]
[ compile integer_mask_include_test.cpp ]