CppCon 2014
Two pictures of me at CppCon 2014.
Two pictures of me at CppCon 2014.
On Monday September 8th, 2014 I gave a presentation titled “Introduction to Microsoft C++ AMP” at CppCon 2014.
The slides of my presentation can be downloaded below:
CppCon is the annual, week-long face-to-face gathering for the entire C++ community. The conference is organized by the C++ community for the community. Taking place this year in the beautiful Seattle neighborhood and including multiple diverse tracks, the conference will appeal to anyone from C++ novices to experts.
What you can expect at CppCon:
I’ll be giving a presentation myself at CppCon 2014: Introduction to C++ AMP (GPGPU Computing).
If you use C++, you should seriously consider coming to the conference.
Stephan T. Lavavej, aka STL, has written a very detailed blog post describing new C++14 STL features, implemented fixes, and breaking changes in Visual Studio 14 CTP1. Read it here.
One notable breaking change is that containers cannot have const elements:
The Standard has always forbidden containers of const elements (e.g. vector
, set ). (C++98/03’s prohibition was crystal clear: elements must be Assignable, which const T isn’t. C++11/14’s prohibition is obscurely hidden, but it’s there.) Previously, VC accepted such containers due to non-Standard machinery in std::allocator. We’ve removed that machinery, so such containers now fail to compile.
Microsoft has released Visual Studio “14” CTP. You can read the announcement on Soma’s blog. Visual Studio “14” will most likely be available sometime in 2015.
Note: This is a CTP release, thus it should be installed in a test environment, such as a VM or a clean machine. Do not install on a machine with another version of Visual Studio installed.
Specifically for C++, there are quite a few improvements, such as:
Read Eric’s blog for a bit more details on those improvements.
NuonSoft has released 2048 Pro for Windows 8 and Windows 8.1.
2048 Pro is the most addictive game since Flappy Bird made easy! It is a fun and challenging puzzle to slide tiles and match them together.
Vote for us here
2048 Pro was created by Marc Gregoire and Peter Van Weert. We are participating in a contest organized by Microsoft. We would really appreciate it if you could vote for us.
Playing 2048 Pro earns you credits, credits buy you “lifelines”. Made a mistake? Undo! Stuck? Ask for hints, and watch the computer clean up your mess!
Get 2048 Pro now from the Windows Store and give it a rating or visit the 2048 Pro website.
Today I got a mail from Microsoft saying that my MVP (Most Valuable Professional) award for Visual C++ is extended for 2014 đ
Congratulations! We are pleased to present you with the 2014 MicrosoftÂź MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in Visual C++ technical communities during the past year.
The next meeting of the Belgian C++ Users Group is planned for Thursday May 8th, 2014 at 18:00 at Materialise HQ.
Materialise ( http://materialise.be/ ) is sponsoring this event by providing the location, drinks and catering
If you ever wanted to ask a question to a member of the Visual C++ product team, now is your chance.
The agenda is as follows:
The event is free for everyone, but you need to register for it.
There are 100 seats available for this event.
On Monday March 17th, 2014 I gave a “What’s new in Visual C++ 2013” presentation for the Belgian C++ Users Group (BeC++).
This time there were around 55 attendees for the BeC++ meeting, quite a success đ
The slides of my presentation can be downloaded below:
Peter Van Weert gave a presentation “What’s new in C++14”.
His slides can be downloaded from the official BeC++ blog.
There are also a couple of pictures from the event on the BeC++ blog.
And I already started planning the next Belgian C++ Users Group meeting. It will be on May 8th, 2014. Details will follow soon.
Today I gave an introduction presentation on C++ AMP for software engineers and team leads of KLA Tencor / ICOS. The presentation was almost the same as I gave on Meeting C++ in November 2013.
The slides can be downloaded below:
A while ago I wrote an article: “Introduction to WIC: How to use WIC to load an image, and draw it with GDI?”
The code in that article didn’t handle transparency.
It’s actually trivial to implement transparency in that sample code. Read the rest of this entry »
The next meeting of the Belgian C++ Users Group is planned for Monday March 17th, 2014 at 18:00 at KLA-Tencor / ICOS Belgium.
KLA-Tencor / ICOS Belgium ( http://kla-tencor.com/ ) is sponsoring this event by providing the location, drinks and catering.
The agenda is as follows:
In C++, a one-argument constructor can implicitly be used to convert some source value or object into an instance of your class.
To prevent this you can mark your one-argument constructors as explicit. In that case, if you want the conversion you have to explicitly perform the casting.
C++11 adds this functionality to conversion operators as well, however, its behavior surprised me.
For example:
#include <iostream> using namespace std; class Foo { public: explicit operator bool() const { return true; } }; int main() { Foo f; if (f) { cout << "f is true" << endl; } return 0; }
The output of this piece of code is “f is true”.
In other words, the compiler is implicitly converting f into a Boolean, even though the conversion operator is marked as explicit.
This surprised me. I immediately blamed it on a compiler bug. However, after some more investigation, it turns out the C++ standard has this notion of “contextually converted to bool”.
The C++ standard has a paragraph explaining this behavior, section 4 Standard conversions [conv]
3 An expression e can be implicitly converted to a type T if and only if the declaration T t=e; is well-formed, for some invented temporary variable t (8.5).
4 Certain language constructs require that an expression be converted to a Boolean value. An expression e appearing in such a context is said to be contextually converted to bool and is well-formed if and only if the declaration bool t(e); is well-formed, for some invented temporary variable t (8.5).
Searching through the standard, an expression can be contextually converted to bool in several cases, not only in the above if-statement.
I also found this blog post explaining this behavior.
A couple of weeks ago I had a very nice 10 course dinner in the Beluga in Maastricht.
All 10 dishes were amazing, paired with a very nice selection of wines đ Here are some pictures:
Visual Studio 2013 Update 1 has been released.
The following are Visual C++ related bug fixes:
Update 1Â is a rather small update. A list of all the fixes can be found here.
Download the update from here.
S. Somasegar said that they are well underway on Visual Studio 2013 Update 2, their first major feature update for VS2013, which they are looking forward to delivering this spring.
C++ allows you to write clean, safe and fast code, and writing it is even easier than ever thanks to new features in C++11 and C++14. This article highlights a couple of tips.
Code gets read a lot more often than it gets written, so make sure that your code can be read and understood in the future, by yourself and by other developers. This means that you have to add comments, and that you should avoid trying to make code as terse and âcleverâ as possible; because that hurts readability.
In modern C++ you should avoid any explicit calls to delete operators or functions to deallocate memory such as free(). Code that relies on such explicit calls is susceptible to memory leaks. For example:
void foo(size_t size) { char* buffer = new char[size]; // ... delete [] buffer; }
The code is straightforward; it allocates memory, does something with the memory, and then deletes the memory. It uses a ânakedâ pointer, which you have to manage yourself. This piece of code causes a memory leak if an exception is thrown before the delete operator is called. You should avoid using naked pointers, instead use encapsulation objects that automatically handle the memory. For example, the above code should be written using a container such as a vector:
void foo(size_t size) { std::vector buffer(size); // ... }
Using a container, there is no need to free the memory, the destructor of the container will handle all that for you. Similarly, if you need dynamically allocated objects, do not store them in naked pointers, instead use smart pointers such as std::unique_ptr, which is not reference counted, or if you need shared ownership, std::shared_ptr, which is reference counted. unique_ptr will automatically delete the object when the unique_ptr goes out of scope. An object wrapped in a shared_ptr is automatically deleted when the reference count goes to zero.
When you use unique_ptr, use std::make_unique<>(). Similarly, use std::make_shared<>() when you use shared_ptr.
One key point to remember: never use std::auto_ptr, it has officially been deprecated because of its problems. One of its problems is that it is forbidden to store them in STL containers because auto_ptr does not meet C++98/03’s requirements for container elements.  unique_ptr  and shared_ptr donât have any of these problems and are perfectly safe to use in STL containers.
Use auto to let the compiler deduce the type of variables automatically. This helps a lot with complicated types that are hard or even impossible to write. For example:
std::map<std::string, std::vector> myMap; for (std::map<std::string, std::vector>::iterator iter = begin(myMap); iter != end(myMap); ++iter) { //... }
This is complicated, difficult to write and error prone.
Note that since C++11 it’s recommended to use the non-member functions std::begin(), end(), cbegin(), cend(), rbegin(), rend(), crbegin(), and crend() instead of the member functions.
Using the auto keyword the above can be rewritten in a very clean way:
for (auto iter = begin(myMap); iter != end(myMap); ++iter) { ... }
Using the range-based for loop, the code can be written even more elegantly:
for (auto&& item : myMap) { ... }
Or:
for (auto& item : myMap) { ... }
Or:
for (const auto& item : myMap) { ... }
Never write the following, unless your container only contains primitive types:
for (auto item : myMap) { ... }
If you use this for containers with non-primitive elements performance will suffer because item will be a copy of each of the elements in the container.
Do not use NULL for pointers, use the nullptr keyword. NULL is a macro for 0 which can sometimes result in problems that are hard to track down. nullptr is really a null pointer type and is not just a macro for 0.
Move semantics since C++11 helps with performance, allowing objects to be moved instead of copied. It is based on rvalue references, represented as &&. C++ automatically uses move semantics in cases where the source object will cease to exist. You can explicitly move an object by using std::move(). The STL also supports move semantics. To add move semantics to your classes you only need to implement a move constructor and move assignment operator which have the following prototype:
MyObject(MyObject&& src);Â Â Â Â Â Â Â Â Â Â Â Â Â Â // Move constructor MyObject& operator=(MyObject&& rhs);Â Â Â // Move assignment operator
Lambda expressions are a powerful addition to the C++ language. One huge benefit is that they make it much easier to use STL algorithms. For example, you can use the count_if() algorithm in combination with a simple lambda expression to count all elements in a vector that are less than 0.
std::vector vec; auto count = std::count_if(cbegin(vec), cend(vec), [](int i){ return i < 0; });
Investing time in learning about lambda expressions will pay itself off quickly.
You should read up on the threading functionalities introduced in C++11. One useful and often overlooked function is std::call_once(), used to make sure that a specific callable entity is executed exactly one time, no matter how many threads call it simultaneously. This can for example be used to make a compact and thread safe implementation of the singleton pattern.
Text matching, parsing, and searching can be tricky and complicated, especially when it should work with Unicode strings. You should avoid writing your own functions to perform such operations, instead use classes from <regex> such as std::wregex.
C++11 supports raw string literals. They are extremely useful in the context of regular expressions. For example, the following regular expression searches for spaces, newlines, and backslashes:
string s = "( |\\n|\\\\)";
The last 4 backslashes are correct. If you want to match a backslash, it needs to be escaped in the regular expression, thus \\. If you want to write \\ in a normal string literal, you need to escape both backslashes, resulting in 4 of them. Using raw string literals you simply write:
string s = R"(( |\n|\\))";
R”( and )” denote the boundary of the raw string literal.
If your application needs to generate random numbers, donât use the old C style srand()/rand() functions. Their randomness is not good. Instead, use <random>, which contains classes to generate random numbers, such as a Mersenne Twister, and supports different mathematical distributions, for example a uniform distribution, a Poisson distribution, and so on.
Take a look at “Professional C++ 2nd Edition” if you are determined to master C++, including all C++11 features.
Visual Studio 2013 has only been released very recently, and the Visual C++ team already has a new CTP out with new features đ
The following table gives an overview and even includes features that are planned for future releases.
Remember, this is a CTP so it does not come with a Go Live license.
More details can be found on the VCBlog.
The 2013 edition of Meeting C++ was once again a great conference.
This year I gave an introduction to Microsoft C++ AMP on the conference.
The session was a great success. I estimate there were around 100 people in the room, and lots of interesting questions đ
After the session I read on Twitter
Awesome presentation on C++ AMP in track B. #meetingcpp
C++ AMP makes it possible to write C++ for GPUs in a STLesque fashion. #meetingcpp
Below you can download the slides of my presentation.