0
我試圖用「SFINAE」來實現cbor格式的尺寸代碼,因爲缺少更好的單詞。但它不起作用,例如,size_code<3>
評估爲0x1b
。怎麼了?可變模板「SFINAE」不工作
template <::std::size_t N,
typename = ::std::enable_if_t<N <= 0x17>
>
constexpr ::std::uint8_t const size_code = N;
template <::std::size_t N,
typename = ::std::enable_if_t<(N > 0x17) &&
(N <= ::std::numeric_limits<::std::uint8_t>::max())
>
>
constexpr ::std::uint8_t const size_code = 0x18;
template <::std::size_t N,
typename = ::std::enable_if_t<
(N > ::std::numeric_limits<::std::uint8_t>::max()) &&
(N <= ::std::numeric_limits<::std::uint16_t>::max())
>
>
constexpr ::std::uint8_t const size_code = 0x19;
template <::std::size_t N,
typename = ::std::enable_if_t<
(N > ::std::numeric_limits<::std::uint16_t>::max()) &&
(N <= ::std::numeric_limits<::std::uint32_t>::max())
>
>
constexpr ::std::uint8_t const size_code = 0x1a;
template <::std::size_t N,
typename = ::std::enable_if_t<
(N > ::std::numeric_limits<::std::uint32_t>::max()) &&
(N <= ::std::numeric_limits<::std::uint64_t>::max())
>
>
constexpr ::std::uint8_t const size_code = 0x1b;
它不應該評估任何東西。這個代碼不適合多重定義'size_code'。 –
你可能最好爲此寫一個'constexpr'函數。 – TartanLlama
@ T.C。海灣合作委員會的怪異,但鏗認識到這一點。 – user1095108