【发布时间】:2014-12-20 16:47:16
【问题描述】:
我正在尝试使用 Xcode 6 上的 Clang 编译一些适用于 MSVC 的 SIMD 代码。不幸的是,我收到一个错误,其中数组访问运算符在我无法修复的自定义向量类中被重载。向量模板对使用 SIMD 内在函数的长度为 4 和 8 的数组进行了专门化,但是数组访问运算符返回对向量元素的引用(用于更新该元素)给我一个关于 clang 的错误“非常量引用不能绑定到向量元素”。
重载运算符:
#ifdef _MSC_VER
float operator[](int idx) const { return v.m256_f32[idx]; } // m256_f32 MSVC only
float& operator[](int idx) { return v.m256_f32[idx]; }
#else
float operator[](int idx) const { return v[idx]; }
float& operator[](int idx) { return v[idx]; }
#endif
来自 Clang 的错误:
non-const reference cannot bind to vector element
float& operator[](int idx) { return v[idx]; }
^~~~~~
【问题讨论】:
标签: c++ operator-overloading clang simd avx