この解決策では、符号なしの型がパラメータリストにあります。過負荷の解決は呼び出し元によって異なるため、これはオーバーロードされた関数では機能しません(また、できません)。ここでは、関数そのものを調べています。
#include <iostream>
#include <type_traits>
template <typename>
struct has_unsigned_param : std::false_type {};
template < typename R, typename T >
struct has_unsigned_param < R(T) >
{
static constexpr bool value = std::is_unsigned <T>::value;
};
template < typename R, typename T, typename ... S >
struct has_unsigned_param < R(T,S...) >
{
static constexpr bool value =
std::is_unsigned <T>::value || has_unsigned_param < R(S...) >::value;
};
template < typename C, typename R, typename ... T >
struct has_unsigned_param < R(C::*)(T...) >
{
static constexpr bool value = has_unsigned_param < R(T...) >::value;
};
struct foo {
void test1(int) {}
void test2(unsigned int) {}
void test3(int, unsigned int) {}
void test4(int, unsigned int, double) {}
void test5(int, unsigned int, float, unsigned char) {}
void test6(int, int, float, char) {}
};
void test1(int) {}
void test2(unsigned int) {}
void test3(int, unsigned int) {}
void test4(int, unsigned int, double) {}
void test5(int, unsigned int, float, unsigned char) {}
void test6(int, int, float, char) {}
int main()
{
std::cout << std::boolalpha;
std::cout << has_unsigned_param < decltype(test1) >::value << '\n';
std::cout << has_unsigned_param < decltype(test2) >::value << '\n';
std::cout << has_unsigned_param < decltype(test3) >::value << '\n';
std::cout << has_unsigned_param < decltype(test4) >::value << '\n';
std::cout << has_unsigned_param < decltype(test5) >::value << '\n';
std::cout << has_unsigned_param < decltype(test6) >::value << '\n';
std::cout << has_unsigned_param < decltype(&foo::test1) >::value << '\n';
std::cout << has_unsigned_param < decltype(&foo::test2) >::value << '\n';
std::cout << has_unsigned_param < decltype(&foo::test3) >::value << '\n';
std::cout << has_unsigned_param < decltype(&foo::test4) >::value << '\n';
std::cout << has_unsigned_param < decltype(&foo::test5) >::value << '\n';
std::cout << has_unsigned_param < decltype(&foo::test6) >::value << '\n';
}
Live example
あなたはもし 'のstd :: numeric_limitsの ::分()'、ゼロに等しい、すなわち 'もし(!のstd :: numeric_limitsの ::分())をテストすることができ{/ *は符号なし* /} 'です。 –
Bernard
@Bernard:ちょうど 'T 'を得るためにどのように提案しますか? – MSalters
@MSalters申し訳ありませんが、私は質問を誤解しました。 – Bernard