小编Mat*_*cer的帖子

为什么没有为函数参数省略副本

我有以下代码

#include <cstdlib>
#include <vector>
#include <chrono>
#include <iostream>

static const uint64_t BENCHMARK_RUNS(1000000);

std::vector<float> vec_mul_no_ref(const std::vector<float> x,
                                  const std::vector<float> y) {
  if(x.size() != y.size()) {
    throw std::runtime_error("vectors are not the same size!");
  }
  std::vector<float> ans(x.size());
  for (size_t ii=0; ii<x.size(); ii++) {
    ans[ii] = x[ii] * y[ii];
  }
  return ans;
}

std::vector<float> vec_mul_ref_args(const std::vector<float>& x,
                                   const std::vector<float>& y) {
  if(x.size() != y.size()) {
    throw std::runtime_error("vectors are not the same size!");
  }
  std::vector<float> ans(x.size());
  for (size_t ii=0; ii<x.size(); ii++) {
    ans[ii] = …
Run Code Online (Sandbox Code Playgroud)

c++ g++ c++17

3
推荐指数
1
解决办法
73
查看次数

标签 统计

c++ ×1

c++17 ×1

g++ ×1