ternary operator for clang's extended vectors

后端 未结 3 1128
孤街浪徒
孤街浪徒 2021-01-24 02:38

I\'ve tried playing with clang\'s extended vectors. The ternary operator is supposed to work, but it is not working for me. Example:

int main()
{
  using int4 =          


        
3条回答
  •  执念已碎
    2021-01-24 03:07

    In the end I went with this:

    #if defined(__clang__)
    template 
    constexpr inline std::enable_if_t<
      !std::is_arithmetic{},
      V
    >
    select(V const a, V const b, U const c) noexcept
    {
      return V((c & U(a)) | (~c & U(b)));
    }
    #else
    template 
    constexpr inline std::enable_if_t<
      !std::is_arithmetic{},
      V
    >
    select(V const a, V const b, U const c) noexcept
    {
      return c ? a : b;
    }
    #endif
    

    The same could have been accomplished in other ways, using the indices trick, for example, but it might not optimize very well (I didn't want any conditionals in there).

提交回复
热议问题