C ++ 11与C ++ 03相比有什么好处? [英] What benefits does C++11 bring in comparison to C++03?
问题描述
我将在一个月内开始学习C ++ 11,并且想知道,与C ++ 03相比,C ++ 11有什么好处?
如果我不得不指出两件事情,我会说rvalue引用和可变参数模板是C ++ 11超过C ++ 03的最深刻的改进。两者都可以让你做真正的应该一直可能的事情,并增加巨大的表达力的语言。最后,你可以有一个适当的 unique_ptr
和移动语义的容器由于右值引用,和直接构造而不是复制构造感谢两个建设和谐玩:
模板< typename ... Args>
void construct(void * p,Args& ... args)
{
:: new(p)T(std :: forward& 。);
}
另一个巨大的改进是将内存模型合并到语言中,对并发执行(多线程)的标准化描述。
有许多小的添加,使得语言更具表现力,并允许你做简单的事情以前无法执行:
-
括号初始化允许初始化类成员数组和值构建自动对象。 p>
-
初始值列表允许初始化容器。
/ p> -
为类和联合体指定了更好的内存布局,以及细致的微不足道概念,以尽可能优化。
-
lambda表达式和闭包使算法和函数式编程更容易,更可行。
I will start studying C++11 in a month and was wondering, what benefits does C++11 provide when compared to C++03?
解决方案If I had to nail it down to two things, I'd say that "rvalue references and variadic templates" are the most profound improvement of C++11 over C++03. Both allow you to do things that really should have been possible all along, and add enormous expressive power to the language. Finally you can have a proper
unique_ptr
and containers with move semantics thanks to rvalue references, and direct construction rather than copy construction thanks to both constructions playing in harmony:template <typename ...Args> void construct(void * p, Args &&... args) { ::new (p) T(std::forward<Args>(args)...); }
Another huge improvement is the incorporation of a memory model into the language that allows for a standardized description of concurrent execution (multi-threading).
There are tons of smaller additions that make the language more expressive, though, and allow you to do things you simply couldn't do previously:
brace-initialization allows you to initialize class member arrays and value-construct automatic objects.
initializer lists allow you to initialize containers.
a better concept of constant expressions.
a better-specified memory layout for classes and unions, as well as fine-grained notions of "triviality" to allow optimizations as much as possible.
lambda expressions and closures make algorithmic and functorial programming much easier and more viable.
这篇关于C ++ 11与C ++ 03相比有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!