小编Tha*_*lys的帖子

std::move 在不同编译器上的行为不同?

我正在尝试使用一个简单的代码来计算余弦相似度:

#include <iostream>
#include <numeric>
#include <array>
#include <cmath>

float safe_divide(const float& a, const float& b) { return b < 1e-8f && b > -1e-8f ? 0.f : a / b; }

template< size_t N >
float cosine_similarity( std::array<float, N> a, std::array<float, N> b )
{
    const float&& a2 = std::move( std::inner_product( a.begin(), a.end(), a.begin(), 0.f ) );
    const float&& b2 = std::move( std::inner_product( b.begin(), b.end(), b.begin(), 0.f ) );
    const float&& dot_product = std::move( std::inner_product( a.begin(), a.end(), b.begin(), 0.f …
Run Code Online (Sandbox Code Playgroud)

c++ gcc g++ clang

8
推荐指数
1
解决办法
350
查看次数

标签 统计

c++ ×1

clang ×1

g++ ×1

gcc ×1