C++0x features in VC2010 – nullptr

Summary Page   (n3090.pdf is the current working draft of C++0x standard, it is available at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3090.pdf) What we have before C++0x Everyone knows that null pointer value is NULL. In C++, NULL is defined as follows:   #define NULL    0   One interesting thing about ‘0’, it can be converted to any pointer types….

0

C++0x features in VC2010 – some decltype bugs

1.       decltype(*&function) https://connect.microsoft.com/VisualStudio/feedback/details/510640   int foo(); decltype(*&foo) df; // it should be “int (&)()”, but it is “int (*)()”   The internal representation (it is special for “*&function”) doesn’t contain the enough information for decltype to get the correct type. The work around is to help the compiler:   decltype(&foo) temp; decltype(*temp) df;   2.      …

0

C++0x features in VC2010 – decltype

Summary Page    (n3090.pdf is the current working draft of C++0x standard, it is available at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3090.pdf) What we have before C++0x When do generic programming in C++, you often have to generate type from template parameters. Type traits are mainly used for this purpose, but sometimes it is still difficult or even impossible. For…

0

C++0x features in VC2010 – auto

Summary Page    (n3090.pdf is the current working draft of C++0x standard, it is available at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3090.pdf) What we have before C++0x C++ is a strongly typed programming language. You have to specify the type when declaring variables. Sometimes it is tedious or even difficult. To simplify variable declaration, GCC has an extension keyword “__typeof__”…

1

C++0x features in VC2010 – static_assert

Summary Page    (n3090.pdf is the current working draft of C++0x standard, it is available at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3090.pdf) What we have before C++0x It is a common task to output meaningful error message from source code based on compile-time conditions. For example, you may want to ensure that the size of your core structure has not…

0

C++0x features in VC2010 – Summary

VC2010 has been released for a while. It adds many C++0x features (The complete list can be found here: C++0x Core Language Features In VC10: The Table)   In the following posts, I’d like to share some of my experience of these new features. They will cover:   What we have before C++0x What we…

0

VC’s "evil" extension: Pre-definition of basic types

In VC, you may find that you can use “size_t” directly without including any headers.size_t i = 0;int main(){    atexit(0);} However, “size_t” is not a built-in type. It is a typedef in <stddef.h>. So what’s the magic? In VC compiler, it will include some internal headers for various reasons before compile your code. For example, “size_t” and “atexit” are introduced in…

0

VC’s "evil" extension: Implicit definition of static constant member

C++ supports in-class initialization of static integral constant members. It is nearly the same as enum, with the following difference (quoted from C++03 9.4.2.4 ([class.static.data])): The member shall still be defined in a namespace scope if it is used in the program and the namespace scope definition shall not contain an initializer. For example:struct S {    static const int i = 0;};const int S::i; // the definition is required if S::i is usedint main(){    return &S::i ? 1 : 0;} However, if…

0

VC’s "evil" extension: $

In C++, only a few characters can be used as part of the identifier. identifier:    identifier-nondigit    identifier identifier-nondigit    identifier digitidentifier-nondigit:    nondigit    universal-character-name    other implementation-defined charactersnondigit: one of    a b c d e f g h i j k l m    n o p q r s t u v w x y z    A B…

2