从boost到std :: experimental以及c ++ 17 [英] From boost to std::experimental and furthermore c++17

查看:84
本文介绍了从boost到std :: experimental以及c ++ 17的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常使用boost实现一些功能,特别是boost :: filesystem(1.58.0).

I commonly use boost to implement some features, specially ths boost::filesystem (1.58.0).

我还对string_view使用std :: experimental(我的编译器尚未将其作为标准包含-g ++ 5.4.0 20160609).

Also I use std::experimental to string_view (my compiler didn't include it as standard yet - g++ 5.4.0 20160609).

因为我使用的增强功能已得到批准,所以我想准备好使用c ++ 17.

Because the boost features I use are aprooved I want to be ready to c++17.

很幸运,我在代码中使用了以下命令:

Fortunaly I use the following commands in my code:

using namespace boost::filesystem; //the only exeption is to boost::filesystem::remove

using namespace std::experimental;

如果将boost行替换为'using namespace std::experimental::filesystem;',我将得到与boost实现完全相同的行为,而代码中仅更改了一个内容?

If I replace the boost line to 'using namespace std::experimental::filesystem;' I will get exactly the same behavior as boost implementation with change nothing more in my code?

在我获得了正式的gcc编译器之后,这些功能已经作为标准配置包括在内,我需要做的是: a)将'std::experimental::filesystem;'更改为'std::filesystem' b)删除行"using namespace std::experimental;"

And after I get the official gcc compiler with these features already include as standard all I need to do is: a) change the 'std::experimental::filesystem;' to 'std::filesystem' b) delete the line 'using namespace std::experimental;'

在代码中仅更改就得到相同的行为吗?

and get the same behavior with change nothing more in my code?

c ++ 17包含哪些其他增强功能,并且还可以如上所述轻松替换?

Which other boost features are included on c++17 and also can be easily replaced as describe above?

推荐答案

提升不是ISO标准的(附属于).

Boost is not (affiliated with the) ISO standard.

不,您不应盲目期望语义相同.即使在80%-90%的情况下,界面都是兼容的,您也会有所不同.

No, you shouldn't blindly expect the semantics to be identical. Even though in 80%-90% of the cases the interface will be compatible, you will get differences.

例如允许boost::optional<T&>,但在标准版本中不允许.还有其他区别.

E.g. boost::optional<T&> is allowed, but not in the standard version. There are other differences.

通常,使用 -指令 ,尤其是当您使用它来记录这些差异时.如果要保持依赖关系的移动性,最好创建自己的名称空间,包装函数.

In general, it's bad practice to use using-directives, especially if you use it to paper of these differences. If you want to keep your dependencies mobile, it's probably best to create your own namespaces, wrapper functions.

在我的代码库中,例如我用过

In my code-base, e.g. I have used

namespace XXX {

     using nullopt_t = ::boost::none_t;
     static CONSTEXPR nullopt_t nullopt = {};

     template <typename T> using optional = ::boost::optional<T>;
}

我们在任何非增强型代码中都独家使用此接口.

We use this interface exclusively in any non-boost specific code.

除了已经概述的语义差异之外,这应该有助于过渡到标准库版本.

This should aid in transitioning to the standard library version, except for semantic differences already outlined.

这篇关于从boost到std :: experimental以及c ++ 17的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆