哪些 Boost 特性与 C++11 重叠?
几年前我把我的 C++ 技能放在了架子上,现在看来,当我再次需要它们时,情况发生了变化.
I put my C++ skills on the shelf several years ago and it seems now, when I need them again, the landscape has changed.
我们现在已经有了 C++11,我的理解是它与许多 Boost 特性重叠.
We have got C++11 now, and my understanding is that it overlaps many Boost features.
是否有一些重叠之处的总结,哪些 Boost 库将成为遗产,建议使用哪些 C++11 特性而不是 boost 特性,哪些最好不要?
Is there some summary where those overlaps lie, which Boost libraries going to become legacy, recommendation of which C++11 features to use instead of boost ones and which better not?
推荐答案
可由 C++11 语言特性或库替换
Replaceable by C++11 language features or libraries
- Foreach → 基于范围
- Functional/Forward → 完美转发(使用 右值引用、可变参数模板 和 std::转发)
- 现场工厂,输入工厂→ 完美转发(至少对于记录在案的用例而言)
- Lambda → Lambda 表达式(在非多态情况下)
- 本地函数 → Lambda 表达式
- 最小-最大 → std::minmax, std::minmax_element
- 比率 → std::ratio
- 静态断言 → static_assert
- 线程 → <线程> 等(但请检查这个问题).
- Typeof → auto, decltype
- 值初始化 → 列表初始化(§8.5.4/3)
- 数学/特殊函数→
,见下表- 伽马函数 (tgamma)、对数伽马函数 (lgamma)
- 误差函数(erf、erfc)
log1p
,expm1
cbrt
、hypot
acosh
、asinh
、atanh
- Foreach → range-based for
- Functional/Forward → Perfect forwarding (with rvalue references, variadic templates and std::forward)
- In Place Factory, Typed In Place Factory → Perfect forwarding (at least for the documented use cases)
- Lambda → Lambda expression (in non-polymorphic cases)
- Local function → Lambda expression
- Min-Max → std::minmax, std::minmax_element
- Ratio → std::ratio
- Static Assert → static_assert
- Thread → <thread>, etc (but check this question).
- Typeof → auto, decltype
- Value initialized → List-initialization (§8.5.4/3)
- Math/Special Functions →
<cmath>
, see the list below- gamma function (tgamma), log gamma function (lgamma)
- error functions (erf, erfc)
log1p
,expm1
cbrt
,hypot
acosh
,asinh
,atanh
TR1(它们在文档中被标记,如果那些是 TR1 库)
TR1 (they are marked in the documentation if those are TR1 libraries)
- 数组 → std::array莉>
- 绑定 → std::绑定
- 启用如果→ std::enable_if
- 函数 → std::function莉>
- 成员函数 → std::mem_fn
- 随机 → <随机>莉>
- Ref → std::ref, std::cref
- 正则表达式 →
- 结果 → std::result_of
- Smart Ptr → std::unique_ptr, std::shared_ptr, std::weak_ptr (但是 boost::intrusive_ptr 仍然不能被替换)
- 交换(交换数组)→ std::swap
- 元组 → std::tuple
- 类型特征 →
- 无序 →
, <;unordered_map>
- Array → std::array
- Bind → std::bind
- Enable If → std::enable_if
- Function → std::function
- Member Function → std::mem_fn
- Random → <random>
- Ref → std::ref, std::cref
- Regex → <regex>
- Result Of → std::result_of
- Smart Ptr → std::unique_ptr, std::shared_ptr, std::weak_ptr (but boost::intrusive_ptr still cannot be replaced)
- Swap (swapping arrays) → std::swap
- Tuple → std::tuple
- Type Traits → <type_traits>
- Unordered → <unordered_set>, <unordered_map>
从 C++11 向后移植的功能:
Features back-ported from C++11:
- 原子 ← std::atomic 莉>
- 计时 ← <计时>(见下文)
- Move ← 右值引用
- Atomic ← std::atomic
- Chrono ← <chrono> (see below)
- Move ← Rvalue references
可替换为 C++17 语言特性:
Replaceable by C++17 language features:
- String_ref → 标准::string_view
- 文件系统 →
(文件系统 TS) - 可选 → std::optional (图书馆基础 TS v1)
- 任何 → std::any(库基础 TS v1)
- 数学/特殊函数→
(特殊数学是),见下表- 测试功能
- (正常/相关/球面)勒让德多项式
- (正态/关联)勒让德多项式
- 厄米多项式
- Bessel (J/Y/I/K) 函数(Y 在 C++ 中称为 Neumann 函数)
- 球形贝塞尔 (j/y) 函数
- (第一类/第二类/第三类)的(不完全/完全)椭圆积分
- 黎曼 zeta 函数
- 指数积分 Ei
- String_ref → std::string_view
- Filesystem → <filesystem> (Filesystem TS)
- Optional → std::optional (Library Fundamentals TS v1)
- Any → std::any (Library Fundamentals TS v1)
- Math/Special Functions →
<cmath>
(Special Math IS), see the list below- beta function
- (normal / associated / spherical) Legendre polynomials
- (normal / associated) Legendre polynomials
- Hermite polynomials
- Bessel (J / Y / I / K) functions (Y is called Neumann function in C++)
- spherical Bessel (j / y) functions
- (incomplete / complete) elliptic integrals of (first / second / third kind)
- Riemann zeta function
- exponential integral Ei
标准团队仍在努力:
- 数学公因数 →std::experimetal::gcd、lcm(库基础 TS v2)
- 概念检查 → 概念 TS
- 范围 → 范围 TS
- Asio → 网络 TS(套接字和定时器仅)
- 多精度 → 数字 TS
- 协程/Coroutine2 → 协程 TS
- Math Common Factor → std::experimetal::gcd, lcm (Library Fundamentals TS v2)
- Concept check → Concepts TS
- Range → Range TS
- Asio → Networking TS (sockets and timers only)
- Multiprecision → Numerics TS
- Coroutine/Coroutine2 → Coroutines TS
MPL 的很大一部分可以使用可变参数模板修剪或删除.词法转换的一些常见用例可以替换为std::to_string 和 std::stoX.
A large part of MPL can be trimmed down or removed using variadic templates. Some common use cases of Lexical cast can be replaced by std::to_string and std::stoX.
一些 Boost 库与 C++11 相关,但也有更多的扩展,例如Boost.Functional/Hash 包含 hash_combine 以及 C++11 中未找到的相关函数,Boost.Chrono 具有 I/O 和舍入以及许多其他时钟等,因此您可能仍想在真正关闭它们之前查看一下 boost .
Some Boost libraries are related to C++11 but also have some more extensions, e.g. Boost.Functional/Hash contains hash_combine and related functions not found in C++11, Boost.Chrono has I/O and rounding and many other clocks, etc. so you may still want to take a look at the boost ones before really dismissing them.
相关文章