30분전 쯤 샤워하다가 시작한 생각인데
conditional_t 을 이용해서 원하는 조건이 아니면 컴파일타임 에러나게
false시 재귀로 계속해서 자기자신을 호출하게 하면 되겠다.
까지 생각해놓고 보니까
uniform_int_distribution같은경우 double 집어넣어놓으면 컴파일 에러띠우던데
STL님은 어떻게 만들어 놨는지 궁금해짐
따라가 봤더니
1 2 3 4 5 | static_assert( ((is_integral<_Ty>::value || is_enum<_Ty>::value) && !is_same<_Ty, bool>::value), "make_signed<T>/make_unsigned<T> require that T shall be a (possibly " "cv-qualified) integral type or enumeration but not a bool type."); | cs |
요런식으로 에러뜨게 해놓음
is_enum은
1 2 3 4 5 | template<class _Ty> struct is_enum : _Cat_base<__is_enum(_Ty)> { // determine whether _Ty is an enumerated type }; | cs |
;
_Cat_base는
1 2 3 4 5 | template<bool _Val> struct _Cat_base : integral_constant<bool, _Val> { // base class for type predicates }; | cs |
integral_constant는
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | template<class _Ty, _Ty _Val> struct integral_constant { // convenient template for integral constant types static constexpr _Ty value = _Val; typedef _Ty value_type; typedef integral_constant<_Ty, _Val> type; constexpr operator value_type() const _NOEXCEPT { // return stored value return (value); } constexpr value_type operator()() const _NOEXCEPT { // return stored value return (value); } }; | cs |
뭐 그냥 static 변수인 __is_enum(_Ty)의 결과를 value에다가 집어넣어놓겠다 이런소리고
정작 중요한건 __is_enum 이거였음
그런데 모든 헤더를 뒤져봐도 함수 선언,정의를 찾아볼 수 없길래
여기저기 검색해본 결과 내가 찾을 수 없던게 당연한거 마냥 sizeof같은 컴파일러 마법이라고 알려줌;;
굳이 만들어서 쓰고 싶다면 my__is_enum을 만들어서 일일이 타입비교 해주는 사람도 있더이다.
아무튼 하루 빨리 갓파일러님을 빨리 파헤쳐야 되요.
저거 template<class _Ty, _Ty _Val> 은 C++17 부터 template<auto _Val> 가 된다 - return 0;
ㅇㅎ 근데 저 VS17로 열어본건데
내부에서 _Ty로 변수를 선언해야 되서 저렇게 넘겨준거지 싶네요
ㄴㄴ 그것도 auto 처리하면 됨 - return 0;
auto 이전의 옛날 스타일이 저런식 - return 0;
ㅇㅎ 그냥 MS님들이 냅둔거군
auto가 아니라 decltype으로 해야될거 같은 느낌인데
ㄴ 새로 생긴 문법임 - return 0;
static constexpr _Ty value = _Val; 이거는 auto로 대체하고
typedef _Ty value_type; 이거는 decltype 으로 하면 될꺼 같은데
후자는 딱히 방법 없지 않아요?
ㅇㅇ 그럴듯 - return 0;
decltype 이 _Ty 보다도 더 명시적일 것 같아 더 좋은 해법인듯 - return 0;
ㅇㅎ 재밌네용 멘션 감사합니다.