什么稳定的c++11特性可以安全地使用

时间:2021-09-19 07:14:57

What are the C++11 features that have got enough mature that I can start using safely in my projects. I am talking about GCC mainly I rarely need Visual Studio. and I obviously don't want to include a feature in my code that requires a rewrite after few months. and should I even start using these features in this very beginning ? cause whatever we mostly do is not c++11 dependent we can do all things and every things in old school methods too. so should we even start using C++11 features at this early stage ?

c++ 11有哪些特性已经足够成熟,我可以在我的项目中安全地使用它们。我主要讲的是GCC,我很少需要Visual Studio。显然,我不想在代码中包含几个月后需要重写的特性。我是否应该在一开始就开始使用这些特性呢?因为我们主要做的不是依赖于c++11我们也可以用旧的方法做所有的事情。那么,我们是否应该在这个早期阶段就开始使用c++ 11特性呢?

2 个解决方案

#1


8  

The C++11 standard is finally done and published, so there won't be any more changes. Implementations still lag behind a little and may implement slightly older versions of C++0x, but you probably won't notice much difference when they are updated.

最终完成并发布了c++ 11标准,因此不会再有任何更改。实现仍然落后一点,可能实现稍微旧一点的c++ 0x版本,但是当它们被更新时,您可能不会注意到有什么不同。

C++11 isn't perfectly backwards compatible, so the first thing you should do is start developing with C++11 compatibility in mind. GCC has a warning flag, "-Wc++0x-compat", to help with this. The incompatibilities are pretty small but this should turn up anything that will be a problem.

c++ 11并不是完全向后兼容的,所以您应该做的第一件事就是开始开发c++ 11兼容性。GCC有一个警告标志“-Wc+ 0x-compat”来帮助解决这个问题。不相容度很小,但这应该会出现任何问题。

One large incompatibility is that libstdc++'s ABI changes with the move to C++11, so you'll also have to make sure you can deal with that.

一个很大的不兼容性是libstdc++的ABI随着迁移到c++ 11而改变,所以您还必须确保能够处理这些问题。

Once you know it's safe to move over, just start building in C++11 mode. You can gradually adopt whatever C++11 features seem useful to you as you write new code or change old code. You might want to also consider checking for uses of deprecated functionality, such as the old exception specifications, and replace those with the new stuff.

一旦你知道移动是安全的,就开始在c++ 11模式下构建。在编写新代码或修改旧代码时,您可以逐渐采用任何对您有用的c++ 11特性。您可能还需要考虑检查弃用功能的使用情况,比如旧的异常规范,并将其替换为新功能。

There's a lot of new stuff so have a look through the standard if you can get it or some documentation online. I find that most of the really interesting stuff I want to use directly is in the library. Unfortunately that seems to be where current implementations still lag the most.

这里有很多新东西,所以如果你能在网上找到它或者一些文档,可以看看这个标准。我发现我想直接使用的大部分有趣的东西都在图书馆里。不幸的是,目前的实现仍然是最滞后的。

#2


0  

You may want to visit:

你可能想参观:

http://gcc.gnu.org/projects/cxx0x.html

http://gcc.gnu.org/projects/cxx0x.html

This link gives the C++0x Support in different GCC versions.

这个链接在不同的GCC版本中提供c++ 0x支持。

I suggest you use C++11 now (just adding -std=c++0x into the GCC command line). If you were lucky, then nothing would be changed in your code. Even if you do not use any C++11 features, you may still benefit from performance improvements coming from the rvalue references and move semantics.

我建议您现在就使用c++ 11(只需在GCC命令行中添加-std=c++0x)。如果幸运的话,代码中没有任何更改。即使您不使用任何c++ 11特性,您仍然可以从rvalue引用和移动语义的性能改进中获益。

#1


8  

The C++11 standard is finally done and published, so there won't be any more changes. Implementations still lag behind a little and may implement slightly older versions of C++0x, but you probably won't notice much difference when they are updated.

最终完成并发布了c++ 11标准,因此不会再有任何更改。实现仍然落后一点,可能实现稍微旧一点的c++ 0x版本,但是当它们被更新时,您可能不会注意到有什么不同。

C++11 isn't perfectly backwards compatible, so the first thing you should do is start developing with C++11 compatibility in mind. GCC has a warning flag, "-Wc++0x-compat", to help with this. The incompatibilities are pretty small but this should turn up anything that will be a problem.

c++ 11并不是完全向后兼容的,所以您应该做的第一件事就是开始开发c++ 11兼容性。GCC有一个警告标志“-Wc+ 0x-compat”来帮助解决这个问题。不相容度很小,但这应该会出现任何问题。

One large incompatibility is that libstdc++'s ABI changes with the move to C++11, so you'll also have to make sure you can deal with that.

一个很大的不兼容性是libstdc++的ABI随着迁移到c++ 11而改变,所以您还必须确保能够处理这些问题。

Once you know it's safe to move over, just start building in C++11 mode. You can gradually adopt whatever C++11 features seem useful to you as you write new code or change old code. You might want to also consider checking for uses of deprecated functionality, such as the old exception specifications, and replace those with the new stuff.

一旦你知道移动是安全的,就开始在c++ 11模式下构建。在编写新代码或修改旧代码时,您可以逐渐采用任何对您有用的c++ 11特性。您可能还需要考虑检查弃用功能的使用情况,比如旧的异常规范,并将其替换为新功能。

There's a lot of new stuff so have a look through the standard if you can get it or some documentation online. I find that most of the really interesting stuff I want to use directly is in the library. Unfortunately that seems to be where current implementations still lag the most.

这里有很多新东西,所以如果你能在网上找到它或者一些文档,可以看看这个标准。我发现我想直接使用的大部分有趣的东西都在图书馆里。不幸的是,目前的实现仍然是最滞后的。

#2


0  

You may want to visit:

你可能想参观:

http://gcc.gnu.org/projects/cxx0x.html

http://gcc.gnu.org/projects/cxx0x.html

This link gives the C++0x Support in different GCC versions.

这个链接在不同的GCC版本中提供c++ 0x支持。

I suggest you use C++11 now (just adding -std=c++0x into the GCC command line). If you were lucky, then nothing would be changed in your code. Even if you do not use any C++11 features, you may still benefit from performance improvements coming from the rvalue references and move semantics.

我建议您现在就使用c++ 11(只需在GCC命令行中添加-std=c++0x)。如果幸运的话,代码中没有任何更改。即使您不使用任何c++ 11特性,您仍然可以从rvalue引用和移动语义的性能改进中获益。