哪些 Boost 特性与 C++11 重叠?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8851670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 19:13:58  来源:igfitidea点击:

Which Boost features overlap with C++11?

c++boostc++11

提问by user377178

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++ 技能放在了架子上,现在看来,当我再次需要它们时,情况发生了变化。

We have got C++11 now, and my understanding is that it overlaps many Boost features.

我们现在已经有了 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?

是否有一些重叠之处的总结,哪些 Boost 库将成为遗产,建议使用哪些 C++11 特性而不是 boost 特性,哪些最好不要?

回答by kennytm

Replaceable by C++11 language features or libraries

可替换为 C++11 语言特性或库

TR1 (they are marked in the documentationif those are TR1 libraries)

TR1(如果它们是 TR1 库,则在文档中标记)

Features back-ported from C++11:

从 C++11 向后移植的功能:

Replaceable by C++17 language features:

可替换为 C++17 语言特性:

  • 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
  • Variant→ std::variant (P0088R2)
  • String_ref→ std::string_view
  • 文件系统<文件系统>(文件系统 TS)
  • 可选→ std::optional (库基础 TS v1)
  • Any→ std::any(库基础 TS v1)
  • 数学/特殊函数<cmath>( Special Math IS),见下表
    • 贝塔函数
    • (正常/相关/球面)勒让德多项式
    • (正常/关联)勒让德多项式
    • 厄米多项式
    • Bessel (J/Y/I/K) 函数(Y 在 C++ 中称为 Neumann 函数)
    • 球面贝塞尔 (j / y) 函数
    • (不完全/完全)椭圆积分(第一类/第二类/第三类)
    • 黎曼zeta函数
    • 指数积分 Ei
  • 变体→ std::variant ( P0088R2)

The standard team is still working on it:

标准团队仍在努力:

A large part of MPLcan be trimmed down or removed using variadic templates. Some common use cases of Lexical castcan be replaced by std::to_string and std::stoX.

可以使用可变参数模板修剪或删除大部分MPL词法转换的一些常见用例可以被 std::to_string 和 std::sto X替换。

Some Boost libraries are related to C++11 but also have some more extensions, e.g. Boost.Functional/Hashcontains hash_combineand related functions not found in C++11, Boost.Chronohas 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.

一些 Boost 库与 C++11 相关,但也有更多扩展,例如Boost.Functional/Hash包含hash_combine和 C++11 中没有的相关函数,Boost.Chrono具有 I/O 和舍入以及许多其他时钟,等等,所以你可能仍然想在真正解雇他们之前看看他们。

回答by sehe

Actually, I don't think the boost libraries are going to become legacy.

实际上,我认为 boost 库不会成为遗产。

Yes, you should be able to use std::type_traits, regex, shared_ptr, unique_ptr, tuple<>, std::tie, std::begininstead of Boost Typetraits/Utility, Boost Smartpointer, Boost Tuple, Boost Range libraries, but there should in practice be no real need to 'switch' unless you are moving more of your code to c++11.

是的,您应该能够使用std::type_traits, regex, shared_ptr, unique_ptr, tuple<>, std::tie,std::begin而不是 Boost Typetraits/Utility、Boost Smartpointer、Boost Tuple、Boost Range 库,但实际上应该没有真正需要“切换”,除非您正在移动更多你的代码到c++11。

Also, in my experience, the stdversions of most of these are somewhat less featureful. E.g. AFAICT the standard does nothave

此外,根据我的经验,其中std大多数版本的功能稍差。例如AFAICT标准并不能

  • Perl5 regular expressions
  • call_traits
  • Certain regex interface members (such as bool boost::basic_regex<>::empty()) and othe interface differences
    • this bites more since the Boost interface is exactly matched with Boost Xpressive
    • and it plays much more nicely with Boost String Algorithms Obviously, the latter don't have standardcounterparts (yet?)
  • Many things relating to TMP (Boost Fusion)
  • Lazy, expression template-based lambdas; they have inevitable benefits in that they canbe polymorphic today, as opposed to C++11. Therefore they can often be more succinct:

     std::vector<int> v = {1,2,-9,3};
    
     for (auto i : v | filtered(_arg1 >=0))
         std::cout << i << "\n";
    
     // or:
     boost::for_each(v, std::cout << _arg1);
    

    Most definitely, this still has some appeal over C++11 lambdas (with trailing return types, explicit capturing and declared parameters).

  • Perl5 正则表达式
  • call_traits
  • 某些正则表达式接口成员(如bool boost::basic_regex<>::empty())和其他接口差异
    • 由于 Boost 接口与 Boost Xpressive 完全匹配,因此咬得更多
    • 并且它与 Boost String Algorithms 一起玩得更好显然,后者没有标准对应物(还没有?)
  • 许多与 TMP(Boost Fusion)相关的事情
  • 懒惰的、基于表达式模板的 lambdas;它们具有不可避免的好处,因为它们 今天可以是多态的,而不是 C++11。因此,它们通常可以更简洁:

     std::vector<int> v = {1,2,-9,3};
    
     for (auto i : v | filtered(_arg1 >=0))
         std::cout << i << "\n";
    
     // or:
     boost::for_each(v, std::cout << _arg1);
    

    最肯定的是,这仍然比 C++11 lambdas(带有尾随返回类型、显式捕获和声明参数)具有一些吸引力。

Also, there is a BIG role for Boost, precisely in facilitating path-wise migration from C++03 to C++11 and integrating C++11 and C++03 codebases. I'm particularly thinking of

此外,Boost 还扮演着重要角色,正是在促进从 C++03 到 C++11 的路径迁移以及集成 C++11 和 C++03 代码库方面。我特别想

  • Boost Auto (BOOST_AUTO)
  • Boost Utility (boost::result_of<>and related)
  • Boost Foreach (BOOST_FOREACH)
  • Don't forget: Boost Move - which makes it possible to write classes with move semantics with a syntax that will compile equally well on C++03 compilers with Boost 1_48+ and C++11 compilers.
  • 提升自动 (BOOST_AUTO)
  • Boost Utility(boost::result_of<>及相关)
  • 提升 Foreach (BOOST_FOREACH)
  • 不要忘记:Boost Move - 这使得编写具有移动语义的类成为可能,其语法在具有 Boost 1_48+ 和 C++11 编译器的 C++03 编译器上编译得同样好。

Just my $0.02

只是我的 0.02 美元