使用或不使用C ++ 0x功能 [英] To use or not to use C++0x features

查看:94
本文介绍了使用或不使用C ++ 0x功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

您今天如何使用C ++ 0x?






<我和一个团队在一个相当新的系统上工作。我们正在谈论迁移到MSVC 2010,我们已经迁移到GCC 4.5。这些是我们使用的唯一编译器,我们没有计划尽快将代码移植到不同的编译器。



我建议在我们完成后,利用一些C ++ 0x功能已经提供像auto。我的同事建议反对这一点,建议等待,直到C ++ 0x实际上成为标准。我必须不同意,但我可以看到他的措辞的呼吁。然而,我不禁想到,这种反对意见更多地来自于学习C ++ 0x的恐惧和恐惧,而不是真正关注标准化。



新的状态的系统,我想让我们利用新技术可用。例如,只是auto,将使我们的日常生活更容易(只是编写基于迭代器的循环,直到基于范围的循环,例如)。



认为这个?它不是像我提议我们彻底改变我们的发芽代码库,但只是开始使用C ++ 0x功能,在方便。我们知道我们使用什么编译器,没有立即计划端口(如果我们移植代码基础,那么肯定编译器将可用于C ++ 0x功能以及目标平台)。否则,似乎在我看来,避免在1997年使用iostreams只是因为ISO C ++标准还没有发布,尽管事实上所有的编译器已经提供了他们的便携式方式。



如果你们都同意,你能提供我可以用来加强我的立场的论据吗?如果没有,我可以得到一个更多的细节这个直到C ++ 0x是标准的想法?

解决方案

我会根据每个特征做出决定。 p>

请记住,标准是真的接近完成。



所以一个简单的功能,如 auto 不会去走开,或者改变它的语义。所以为什么不使用它。



Lambdas是复杂的,他们可能会改变他们的措辞,在几个角落的语义固定了一点,但总的来说,他们将采取他们今天的方式(虽然VS2010有一些关于捕获的变量的范围的错误,MS已经声明它们是错误,因此可以在主要产品版本之外修复)。



如果你想安全地玩,请远离兰布达。否则,在方便的地方使用它们,但避免超级棘手的情况,或者只是在标准定稿时准备检查lambda使用情况。



大多数功能按照这样分类,他们是那么简单和稳定,他们在GCC / MSVC的实现正是他们将如何工作在最终标准,或者他们是棘手的,他们可能会得到一些错误修复应用,所以他们可以今天使用,但你有冒险在某些边框情况下遇到一些粗糙的边缘。



这听起来很蠢以避免C ++ 0x功能,因为它们尚未正式化。避免您不信任的功能是完整,无错误和稳定的,但使用其余功能。


Possible Duplicate:
How are you using C++0x today?

I'm working with a team on a fairly new system. We're talking about migrating to MSVC 2010 and we've already migrated to GCC 4.5. These are the only compilers we're using and we have no plans to port our code to different compilers any time soon.

I suggested that after we do it, we start taking advantage of some of the C++0x features already provided like auto. My co-worker suggested against this, proposing to wait "until C++0x actually becomes standard." I have to disagree, but I can see the appeal in the way he worded it. Nevertheless, I can't help but think that this counter-argument comes more out of fear and trepidation of learning C++0x than a genuine concern for standardization.

Given the new state of the system, I want for us to take advantage of the new technology available. Just auto, for instance, would make our daily lives easier (just writing iterator-based for loops until range-based loops come along, e.g.).

Am I wrong to think this? It is not as though I'm proposing we radically change our budding codebase, but just start making use of C++0x features where convenient. We know what compilers we're using and have no immediate plans to port (if we ever port the code base, by then surely compilers will be available with C++0x features as well for the target platform). Otherwise it seems to me like avoiding the use of iostreams in 1997 just because the ISO C++ standard was not published yet in spite of the fact that all compilers already provided them in a portable fashion.

If you all agree, could you provide me arguments I could use to strengthen my position? If not, could I get a bit more details on this "until the C++0x is standard" idea? BTW, anyone know when that's going to be?

解决方案

I'd make the decision on a per-feature basis.

Remember that the standard is really close to completion. All that is left is voting, bugfixing and more voting.

So a simple feature like auto is not going to go away, or have its semantics changed. So why not use it.

Lambdas are complex enough that they might have their wording changed and the semantics in a few corner cases fixed up a bit, but on the whole, they're going to behave the way they do today (although VS2010 has a few bugs about the scope of captured variables, MS has stated that they are bugs, and as such may be fixed outside of a major product release).

If you want to play it safe, stay away from lambdas. Otherwise, use them where they're convenient, but avoid the super tricky cases, or just be ready to inspect your lambda usage when the standard is finalized.

Most features can be categorized like this, they're either so simple and stable that their implementation in GCC/MSVC are exactly how they're going to work in the final standard, or they're tricky enough that they might get a few bugfixes applied, and so they can be used today, but you run the risk of running into a few rough edges in certain border cases.

It does sound silly to avoid C++0x feature solely because they're not formalized yet. Avoid the features that you don't trust to be complete, bug-free and stable, but use the rest.

这篇关于使用或不使用C ++ 0x功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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