gpt4 book ai didi

c++ - 在哪里使用 "std::valarray"是个好主意?

转载 作者:可可西里 更新时间:2023-11-01 15:25:07 25 4
gpt4 key购买 nike

我在 Nicolai M. Josuttis 编写的 C++ 书中读到了有关 std::valarray 的内容。他在他的书 The C++ Standard Library 第 17.4 章中写道:

The valarray classes were not designed very well. In fact, nobody tried to determine whether the final specification worked. This happened because nobody felt “responsible” for these classes. The people who introduced valarrays to the C++ standard library left the committee long before the standard was finished. As a consequence, valarrays are rarely used.

那么,在哪里使用 std::valarray 是个好主意?

最佳答案

创建 Valarrays 是为了让编译器更快地执行。然而,这些优化可以通过其他方式实现,并且很少使用 valarrays。

std::valarray and helper classes are defined to be free of certain forms of aliasing, thus allowing operations on these classes to be optimized similar to the effect of the keyword restrict in the C programming language. In addition, functions and operators that take valarray arguments are allowed to return proxy objects to make it possible for the compiler to optimize an expression such as v1 = av2 + v3; as a single loop that executes v1[i] = av2[i] + v3[i]; avoiding any temporaries or multiple passes. .....

换句话说,valarrays 应该用在有很多值的地方,这些值主要传递给简单的表达式。

Only rarely are valarrays optimized any further, as in e.g. Intel Parallel Studio.

您可以在 cppreference 找到更多信息。

关于c++ - 在哪里使用 "std::valarray"是个好主意?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46465011/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com