GCC 7 没有选择正确的类型特征专业化
GCC 7 not choosing the correct type trait specialization
我在使用 gcc 7.2 时遇到一些问题。我有这种性格特征
template<typename T>
struct audio_frame_channels {}
template<int N>
struct audio_frame_channels<std::array<float, N>> {
static constexpr auto value = N;
};
然后我这样使用它:
template<typename T>
auto redirect(T& buf) ->
ProcessData<audio_frame_channels<std::remove_reference_t<
decltype(buf[0])>>::value>;
clang 6 对此没有问题,但 gcc 7.2 抱怨 ‘value’ is not a member of ‘top1::audio::audio_frame_channels<std::array<float, 1> >’
我是不是弄错了什么,或者这是你在实验性编译器上得到的?
编辑:强制性 godbolting:
std::array
的第二个模板参数是 std::size_t
,而不是 int
。您需要像这样更改它:
template<std::size_t N> //instead of int N
struct audio_frame_channels<std::array<float, N>> {
static constexpr auto value = N;
};
我在使用 gcc 7.2 时遇到一些问题。我有这种性格特征
template<typename T>
struct audio_frame_channels {}
template<int N>
struct audio_frame_channels<std::array<float, N>> {
static constexpr auto value = N;
};
然后我这样使用它:
template<typename T>
auto redirect(T& buf) ->
ProcessData<audio_frame_channels<std::remove_reference_t<
decltype(buf[0])>>::value>;
clang 6 对此没有问题,但 gcc 7.2 抱怨 ‘value’ is not a member of ‘top1::audio::audio_frame_channels<std::array<float, 1> >’
我是不是弄错了什么,或者这是你在实验性编译器上得到的?
编辑:强制性 godbolting:
std::array
的第二个模板参数是 std::size_t
,而不是 int
。您需要像这样更改它:
template<std::size_t N> //instead of int N
struct audio_frame_channels<std::array<float, N>> {
static constexpr auto value = N;
};