CppCon 2014 Presentation

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:

  • Invited talks and panels: the CppCon keynote by Bjarne Stroustrup will start off a week full of insight from some of the world’s leading experts in C++. Still have questions? Ask them at one of CppCon’s panels featuring those at the cutting edge of the language.
  • Presentations by the C++ community: What do embedded systems, game development, high frequency trading, and particle accelerators have in common? C++, of course! Expect talks from a broad range of domains focused on practical C++ techniques, libraries, and tools.
  • Lightning talks: Get informed at a fast pace during special sessions of short, less formal talks. Never presented at a conference before? This is your chance to share your thoughts on a C++-related topic in an informal setting.
  • Evening events and “unconference” time: Relax, socialize, or start an impromptu coding session.

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.

Share

C++14 STL Features, Fixes, And Breaking Changes In Visual Studio 14 CTP1

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.

Share

Visual Studio “14” CTP

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:

  • Generalized lambda capture
  • User-defined literals in the language and standard library
  • Completed noexcept
  • Inline namespaces
  • Thread-safe “magic” statics
  • Unrestricted unions
  • All November 2013 compiler CTP features
  • Null forward iterators
  • quoted()
  • Heterogeneous associative lookup
  • integer_sequence
  • exchange()
  • get()
  • Dual-range equal(), is_permutation(), mismatch()
  • tuple_element_t
  • Filesystem “V3″ Technical Specification (TS)
  • Object file size reductions
  • Debug checking fixes
  • Create declaration or definition
  • Native memory diagnostics
  • Refactored C Runtime (CRT): This CTP contains the first preview of the substantially refactored CRT. msvcr140.dll no longer exists. It is replaced by a trio of DLLs: vcruntime140.dll, appcrt140.dll, and desktopcrt140.dll.

Read Eric’s blog for a bit more details on those improvements.

Download the CTP.

Share

2048 Pro

2048 Pro IconNuonSoft 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!

Instructions

  • Swipe to move all numbers left, right, up, or down.
  • If two identical numbers collide, they merge into one. For example: 2+2=4, 16+16=32, …
  • The goal is to reach the magic 2048 tile (or higher of course!)

Coming soon

  • Regular updates with fixes and new features
  • More game modes
  • Global leader board
  • Strategy guide: learn how to play

Get 2048 Pro now from the Windows Store and give it a rating or visit the 2048 Pro website.

Share

Microsoft MVP VC++ 2014 Award

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.

See my MVP profile.

Share

Next BeCPP UG Meeting Planned For May 8th, 2014

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

Materialise_logo
We will have an international speaker for this event: Artur Laksberg.

  • Artur Laksberg leads the Visual C++ Libraries development team at Microsoft, responsible for the STL, CRT, C++ AMP, PPL, Casablanca and other libraries. His interests include concurrency, programming language and library design, and modern C++. Artur is one of the co-authors of the ISO C++ proposal on Parallelism (aka Parallel STL) as well as the Concurrency Technical Specification.

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:

  • 18:00: Sandwiches.
  • 18:30: Session 1: Parallelism in the Standard C++: What to Expect in C++ 17 (Artur Laksberg)
    It is 2014 and parallel programming has entered the mainstream. No longer is it the domain of the few highly trained experts. The tools available in the C++ today make parallelism accessible – if not yet easy – to average developers. However, writing efficient cross-platform parallel code in C++ is still hard. The standard constructs available in C++ 11/14 are too basic and too low-level. More advanced tools exist, but most are either vendor-specific or don’t work on all platforms. In this presentation, we’ll talk about the joint effort spearheaded by several members of the ISO C++ Committee to bring parallelism into the C++ Standard Template Library. The project known as the “Parallel STL” aims to bring muliticore and SIMD parallelism into the next revision of the ISO C++ Standard.
  • 19:30: Break
  • 19:45: Session 2: Asynchronous programming with futures and await (Artur Laksberg)
    We have to write asynchronous code for a number of reasons, such as making our GUI apps more responsive, or our server code more scalable. Dealing with asynchrony is hard, perhaps harder than parallelism, and doing it in C++ in a portable way is even harder. If you are familiar with the “callback soup”, “control flow inversion” and other such phenomena, you’ve experienced the pain of asynchrony. In this presentation, we’ll look at the state of the art of asynchrony in C++, discuss futures and continuations, await and resumable functions, and how these concepts are making their way to Standard C++.
  • 20:45: Guided tour of the Materialise facilities for interested people followed by a drink.

The event is free for everyone, but you need to register for it.

There are 100 seats available for this event.

Read the official announcement.

Register for this free event.

Share

My BeCPP Presentation “What’s new in Visual C++ 2013″

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.

Share

C++ AMP Presentation for KLA Tencor / ICOS

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:

Share

Introduction to WIC: How to use WIC to load an image, and draw it with tranparency using only GDI?

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 »

Share

Next BeCPP UG Meeting Planned For March 17th, 2014

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.

KLA-Tencor/ ICOS Belgium

The agenda is as follows:

  • 18:00: Sandwiches.
  • 18:30: Session 1: What’s new in C++14 (Peter Van Weert)
    An overview of the new features in the latest C++14 standard.
  • 19:30: Break
  • 19:45: Session 2: What’s new in Visual C++ 2013 (Marc Gregoire)
    An overview of the new features in Visual C++ 2013 and the Visual C++ 2013 November CTP.
  • 20:45: Short technically oriented presentation by the host KLA-Tencor / ICOS Belgium.
  • 21:00: Drink.

Read the official announcement.

Register for this free event.

Share

C++11 – Contextually Converted to bool

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.

Share

Beluga – Pictures

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:

Read the rest of this entry »

Share

Visual Studio 2013 Update 1

Visual Studio 2013 Update 1 has been released.

The following are Visual C++ related bug fixes:

  • Assume that you edit a dialog that contains at least one picture control in Resource Editor. After you save the file, the project can no longer be compiled.
  • When you edit multiple resources in Resource Editor, Visual Studio crashes randomly.
  • Addresses some Visual C++ automatic formatting issues.
  • Visual C++ IDE does not work as expected if there is an unexpected registry subkey under the following registry key:
    HKCU\Software\Microsoft\VisualSTudio\12.0\FileExtensionMapping
  • When you try to link with PGO on amd64_x86 complier, Visual Studio crashes.

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.

Share

Modern C++ Tips and Tools

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.

Comments & ‘Cleverness’

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.

Memory Management

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.

The auto Keyword

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.

nullptr

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

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

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.

Threading

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.

Strings

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.

Random Numbers

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.

Further Reading

Take a look at “Professional C++ 2nd Edition” if you are determined to master C++, including all C++11 features.

Share

Happy New Year 2014

2014
Happy New Year
Sretna Nova Godina
Gelukkig Nieuwjaar
Bonne Année
:)

Share

MVP Global Summit 2013 November Report

I gave a report of the November MVP Global Summit 2013 to software engineers in my company. Obviously, I’m only talking about things that did not fall under NDA.
The slides can be downloaded below:

Share

Announcing the Visual C++ Compiler November 2013 CTP

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.

  • Implicit move special member function generation (thus also completing =default)
  • Reference qualifiers on member functions (a.k.a. “& and && for *this”)
  • Thread-safe function local static initialization (a.k.a. “magic statics”)
  • Inheriting constructors
  • alignof/alignas
  • __func__
  • Extended sizeof
  • constexpr (except for constructors)
  • noexcept (unconditional)
  • C++14 decltype(auto)
  • C++14 auto function return type deduction
  • C++14 generic lambdas (with explicit lambda capture list)
  • (Proposed for C++17) Resumable functions and await

Remember, this is a CTP so it does not come with a Go Live license.
More details can be found on the VCBlog.

Share

Meeting C++ 2013 – “Introduction to Microsoft C++ AMP”

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.

Share

MVP Global Summit November 2013

Looking forward to the Microsoft MVP Global Summit November 2013 :)
MVP Global Summit November 2013

Share

Visual Studio 2013 Available for Download

The final versions of Visual Studio 2013, Team Foundation Server 2013 and .NET 4.51 are now available from MSDN. You can also download trials.

VS 2013 can be installed side by side with previous versions of Visual Studio or, if you have a VS 2013 pre-release, it can be installed straight on top of the pre-release. TFS 2013 cannot be installed side by side but can also be installed on top of either a previous version (TFS 2012 or TFS 2010) or a pre-release.

Learn more about what’s new in Visual Studio 2013.

What’s new in Visual C++ 2013 (excerpt from MSDN):

  • Compiler
    • Added support for the following ISO C++11 language features:
      • Default template arguments for function templates.
      • Delegating constructors.
      • Explicit conversion operators.
      • Initializer lists and uniform initialization.
      • Raw string literals.
      • Variadic templates.
      • Alias templates.
      • Deleted functions.
      • Non-static data member initializers (NSDMIs).
      • Defaulted functions.  (using =default to request memberwise move constructors and move assignment operators is not supported)
    • Added support for the following ISO C99 language features:
      • _Bool
      • Compound literals.
      • Designated initializers.
      • Mixing declarations with code.
    • String literal conversion to modifiable values can be disallowed by using the new compiler option /Zc:strictStrings. In C++98, conversion from string literals to char * (and wide string literals to wchar_t *) was deprecated. In C++11, the conversion was removed entirely. Although the compiler could strictly conform to the standard, instead it provides the /Zc:strictStrings option so that you can control conversion. By default, the option is off. Note that when you are using this option in debug mode, the STL will not compile.
    • rvalue/lvalue Reference Casts. With rvalue references, C++11 can clearly distinguish between lvalues and rvalues. Previously, the Visual C++ compiler did not provide this in specific casting scenarios. A new compiler option, /Zc:rvalueCast, has been added to make the compiler conformant with the C++ Language Working Paper(see section 5.4, [expr.cast]/1). The default behavior when this option is not specified is the same as in Visual Studio 2012.
  • STL
    • Support for the C++11 explicit conversion operators, initializer lists, scoped enums, and variadic templates.
    • All containers now support the C++11 fine-grained element requirements.
    • Support for these C++14 features:
      • “Transparent operator functors” less<>, greater<>, plus<>, multiplies<>, and so on.
      • make_unique<T>(args…) and make_unique<T[]>(n)
      • cbegin()/cend(), rbegin()/rend(), and crbegin()/crend() non-member functions.
    • <atomic> received numerous performance enhancements.
    • <type_traits> received major stabilization and code fixes.

This list is just a small part of everything that’s new. There are also

  • Visual C++ library enhancements
  • C++ application performance enhancements
  • Diagnostics enhancements
  • 3D graphics enhancements
  • Quite a few very nice IDE and Productivity enhancements.

Read all the details here.

Visual C++ 2013 now also supports “just my code” debugging which makes working with C++ even better. The ability to filter the call stack down to just the code you wrote when debugging has long existed for managed languages and is now available for C++ :)

Share