lapthorn.net *this.that(&theOther);

std::unique_ptr usage

If you’re new to C++11, this post on Stackoverflow answers the question “How do I pass a unique_ptr argument to a constructor or a function?” going through each case:

  • by value
  • by non-const l-value reference
  • by const l-value reference
  • by r-value reference

Code Smell

There is a type of code smell I’ve noticed in C++ code recently, but I would imagine it extends to other languages as well. Consider this class:

class Widget
{
public:
    const std::string Name() const;
    const SomeComplexObject SomeMethod() const;
};

Now consider this class

class Gadget
{
public:
    void ShowName(const Widget & widget) const { std::cout << widget.Name(); }
};

async and await in C++

I’ve just watched Herb Sutter‘s talk on C++ in Visual Studio 2013 and onwards.

The last quarter of the talk was concerned with Microsoft introducing the __async and __await keywords in a similar implementation to that already used in C#, note the __ prefix.

As he explained, this is going to be an implementation of a proposed feature for inclusion in a future version of C++, much like the modules feature currently being implemented in CLang.

The Visual Studio roadmap was intertesting, but it looks like we’re going to have to wait a while for generic lambdas.

© 2017   lapthorn.net