The following is possibly what you want.
The possible error message mentions that the function is deleted, and
I'd hoped it would also mention the condition where it is deleted, but
alas, both g++ and MSVC fail to include that in the diagnostic.
It's /possible/ that instead of this functionality you really intended
what you get with the out-commented definition of `has_all_values_of_? .
---------------------------------------------------------------------------
#include <limits.h> // CHAR_BIT
#include <stdint.h> // uint32_t, uint64_t
#include <utility>
using std::enable_if_t, std::is_integral_v, std::is_signed_v;
// template< class A, class B >
// constexpr bool has_all_values_of_ = true
// and (is_integral_v<A> and is_integral_v<B>)
// and (is_signed_v<A> == is_signed_v<B>? sizeof( A ) <= sizeof( B
) : sizeof( A ) < sizeof( B ));
template< class A, class B >
constexpr bool has_all_values_of_ = true
and is_integral_v<A> and is_integral_v<B> and sizeof( A ) <=
sizeof( B );
#if 0
using Word = uint64_t;
#else
using Word = uint32_t;
#endif
void func( const Word ) {}
template< class T, class = enable_if_t<not has_all_values_of_<T, Word>> >
void func( const T ) = delete;
auto main() -> int
{
func( Word( 1 ) ); // OK
func( 'A' ); // OK
func( 1 ); // OK with the uncommented definition of
`has_all_values_of_`.
func( 0LL ); //! Oh noes.
}
---------------------------------------------------------------------------
- Alf