Bjarne Stroustrup, inventor of the C++ programming language, is acomputer scientist and the College of Engineering Chair Professor ofComputer Science at Texas A&M University. He has always been highlyinvolved in the standardization of C++. Since 2004, Bjarne and thestandards committee have been busy hammering out the details of a newstandard, temporarily titled C++0x. Bjarne was gracious enough to taketime out of his busy schedule to speak with DevX C++ Pro, Danny Kalev,about new C++0x features and the state of the C++ language.
We hope to voteout a draft standard for public review in October 2008 so that we'll beable to hand in a final draft for international vote in 2009. Becauseof this heavy ISO process, it's touch and go whether C++0x will beC++09, but there is still hope and the major features are now known(barring disasters). We can classify the extensions like this
Concurrency: //这次C++还真是下了血本来支持并发了
memory model supporting modern machine architectures
various library components to held library builders
Language:
rvalue references (move semantics) 大名鼎鼎的右值引用问题
static_assert: static assertions
variadic templates
strongly typed enumerations with scoped enumerators
constexpr: generalized constant expressions
control of alignment
delegating and inheriting constructors
auto: deducing a type from an initializer
decltype: a way of using the type of an expression in a declaration
control of defaults
nullptr: a name for the null pointer
a range-based for loop
lambda functions
raw string literals
UTF8 literals
concepts (a type system for template arguments) concepts是对模板的革命性支持
initializer lists and uniform initializations syntax and semantics
in-class member initializers
Lists are, by themselves, not very interesting, but you can readup on a description of my general philosophy for language evolution andsome of the individual decisions in my HOPL-iii paper "Evolving a language in and for the real world: C++ 1991-2006." You can also find more information than you could possibly want on the committee's web site.Basically, the "concurrency" features will standardize the basic layersneeded to do systems programming in a multi-core world. Obviously,facilities for doing that already exist in C++ implementations, butthey are not standardized. I'd have liked to see library support forsome high-level concurrency models, but the committee didn't have thetime or consensus for that. "I'd have liked to see library support for somehigh-levelconcurrency models, but the committee didn't have the timeor consensusfor that."
The library facilities provide a set of new library components and someimprovements to the existing ones. I would have liked to see many more,but the committee is a volunteer effort and we just didn't have theresources for a massive extension of what was offered. Fortunately,there are many libraries available "out there," possibly already onyour machine. For example, many of the C++0x libraries (e.g., regex and unordered_map) are now shipped by major vendors and boost.orgoffers many components (for instance, file system and networking) thatwe'll probably soon see in the standard. There is also much talk of atechnical report on the libraries we most wanted but had to postpone.
The language extensions are a varied lot. Fortunately most aresmall and fit together with each other and with existing facilities tomake a better integrated language. Consider a few examples:
// using C++0x features:
vector<string> v = {"Gorm", "Harald", "Sven", "Harald", "Knud" };
for (auto p = v.begin(); p!=v.end(); ++p) cout << *p <<'\n';
for (auto x : v) cout << x <<'\n';
复制代码
I suspect most is pretty obvious. You can provide an initializer list directly for a vector,you can deduce the type of an iterator from its initializer, anditerate through a sequence without explicitly mentioning the iterator.More examples:
enum class Season { winter, spring, summer, fall };
int summer; // doesn’t clash with Season::summer
Season s = Season::spring; // note qualification
summer = s; // error: no Season to int conversion
Season += Season::fall; // error: can’t add Seasons
You can have enumeration types (class enums) that behaves more like types than glorified integers and the “lambda” notation ([],etc.) is a simplified notation for defining a function object. Each ofthese simple examples can without heroic effort be written today.However, in C++98 that code would be twice the size and in every caseopen opportunities for making errors and/or for introducing overhead.Note that all "primitive" features are meant to be used incombination and in combination with existing features to solveproblems. For example, there is no "magic" for initializing vectors inparticular or even any new "magic" for constructors. Instead, theinitialization of vector was achieved simply by a rule that state thatan initializer_list<T> can be initialized by a list of any numbers of Ts {t1, t2, t3} for any type T. Given that rule, we simply give vector<T> a constructor that accepts an initializer_list<T>. Incidentally, this mechanism can also be used to eliminate about 80 percent of the uses of the type-unsafe stdargs macros.作者: ubuntuhk 时间: 23-8-2008 22:29
完蛋,越搞越复杂了,像多线程,并发性这些不是应该留给OS来完成吗?作者: coredump 时间: 23-8-2008 22:42 标题: 回复 #3 ubuntuhk 的帖子 有一篇文章分析为什么并发必须在语言级别上才能被真正地、彻底地、优雅地解决: