GCC 7 没有选择正确的类型特征专业化

GCC 7 not choosing the correct type trait specialization

本文关键字:类型 特征 专业化 有选择 GCC      更新时间:2023-10-16

我在使用 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> >’是我弄错了什么,还是你在实验编译器上得到的?

编辑:强制性的神螺栓:

https://godbolt.org/g/Y1EFYC

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;
};