지금은 SFINAE를 배우려고합니다.하지만 강요에 문제가있는 것 같습니다. hasRead<Y>
및 hasRead<Z>
은 메서드 인수가 std::uint16_t
에 해당하지 않으므로 어떻게해야합니까? ?C++ SFINAE 및 숫자 변환 (강요)
내가 원하는대로 작동하도록하려면 어떻게해야할까요? 사전 :
#include <cstdint>
#include <iostream>
#include <utility>
template<typename Class>
struct hasRead {
private:
template<typename T>
static constexpr auto check(T *) -> typename std::is_same<
decltype(std::declval<T>().read(std::declval<uint16_t>())), uint8_t>::type;
template<typename>
static constexpr std::false_type check(...);
typedef decltype(check<Class>(0)) type;
public:
static constexpr bool value = type::value;
};
struct X {
uint8_t read(uint16_t x) { return 3; }
};
struct Y {
uint8_t read(uint8_t x) { return 3; }
};
struct Z {
uint8_t read(int64_t x) { return 3; }
};
static_assert(hasRead<X>, "");
static_assert(hasRead<Y>, "");
static_assert(hasRead<Z>, "");
나는 이런 연구를 통해 좀 더 간결해질 수있는 연구 결과를 얻었다. https://godbolt.org/g/BTzufc – uknys
그레이트! 매우 간단하고 우아한. – max66