CppCon2017 Trip Report -- Gordon Brown

Trip report from CppCon 2017. Highlights, trends and some tips for getting the most out of the conference.

CppCon2017 Trip Report

by Gordon Brown

From the article:

CppCon this year was bigger than ever with approaching 1200 attendees and 7 tracks; making it even harder to pick which talks to go to. Thankfully all the talks are made available online, so if you couldn’t make it to the conference or even if you did but couldn’t get to see all the talks you wanted to, you can go online and watch them. I only got to a handful of the talks as I often had conflicting appointments, but I’ve highlighted a few from what I saw that I would recommend checking out and some which I didn’t make it to but heard good things about.

Quick Q: What is the usefulness of `enable_shared_from_this`?

Quick A: It allows you to get a valid shared pointer from your instance directly.

Recently on SO:

What is the usefulness of `enable_shared_from_this`?

It enables you to get a valid shared_ptr instance to this, when all you have is this. Without it, you would have no way of getting a shared_ptr to this, unless you already had one as a member. This example from the boost documentation for enable_shared_from_this:

class Y: public enable_shared_from_this<Y>
{
public:

    shared_ptr<Y> f()
    {
        return shared_from_this();
    }
}

int main()
{
    shared_ptr<Y> p(new Y);
    shared_ptr<Y> q = p->f();
    assert(p == q);
    assert(!(p < q || q < p)); // p and q must share ownership
}

The method f() returns a valid shared_ptr, even though it had no member instance. Note that you cannot simply do this:

class Y: public enable_shared_from_this<Y>
{
public:

    shared_ptr<Y> f()
    {
        return shared_ptr<Y>(this);
    }
}

The shared pointer that this returned will have a different reference count from the "proper" one, and one of them will end up losing and holding a dangling reference when the object is deleted.

enable_shared_from_this is going to be a part of the new C++0x standard as well, so you can also get it from there as well as from boost.

PVS-Studio Reports Now in Html

FullHtml is a full-fledged report format for viewing analysis results.

PVS-Studio Reports Now in Html

by Svyatoslav Razmyslov

From the article:

It allows you to search for and sort messages by type, file, level, code, and warning text. What makes it special is that it allows you to navigate faulty fragments in the source files pointed out by the analyzer. The reported source files themselves are copied to Html and become part of the report. To see how FullHtml really looks like, I converted in this format one of the latest reports, which I've used when writing the article about the MuseScore project: MuseScoreHtml.7z.

Abstraction design and implementation: `repeat` -- Vittorio Romeo

This series of two articles covers the train of thought behind the design and implementation of a simple `repeat` abstraction that, given a number `n` and a function object `f`, invokes `f` `n` times. The abstraction can be used to repeat actions both at run-time and compile-time. The articles also cover importance of propagating `noexcept`-correctness (and the pain caused by it!).

abstraction design and implementation: `repeat`

compile-time `repeat` & `noexcept`-correctness

by Vittorio Romeo

From the articles:

In my previous "passing functions to functions" and "zero-overhead C++17 currying & partial application" articles I've praised C++11 (and newer standards) for allowing us to write "more functional" code. [...] If I want to repeat an action n times, I exactly want to write that in my code:

    repeat(10, []
    {
        foo();
    });

Cannot get simpler than that - let's implement it!

2017 Albuquerque ISO C++ Committee Reddit Trip Report

Another report:

2017 Albuquerque ISO C++ Committee Reddit Trip Report

From the article:

The ISO C++ Committee met in Albuquerque, New Mexico, USA last week to continue work on C++ Technical Specifications and the next International Standard, C++20. C++17 is done; the final version was sent to ISO for publication in September. We started to firm up the schedule and feature set for C++20 at this meeting; we're hoping to land most of the major features by the first meeting of 2019...

Trip report: Fall ISO C++ standards meeting (Albuquerque)--Herb Sutter

C++ continues to evolve.

Trip report: Fall ISO C++ standards meeting (Albuquerque)

by Herb Sutter

From the article:

A few minutes ago, the ISO C++ committee completed its fall meeting in Albuquerque, New Mexico, USA, hosted with our thanks by Sandia National Laboratories. We had some 140 people at the meeting, representing 10 national bodies. As usual, we met for six days Monday through Saturday, including several evenings.

POCO Release 1.8.0 Available

POCO 1.8.0 is now available:

POCO Release 1.8.0 is out

by POCO Team

POCO C++ Libraries release 1.8.0 is available. This release brings Unix Domain Socket support in the Net library, Zip64 support in the Zip library, an XML stream parser API, the new Redis client library, support for connection string URIs in the MongoDB client library and a couple of other improvements and bugfixes.

In addition to optional C++11/14 features support, this release still supports C++03 compilers, including Visual C++ 2008. Support for OpenVMS has been removed. Full C++11/14 support coming soon in release 2.0.

 

Quick Q: What does the explicit keyword mean?

Quick A: It tell the compiler not to do any implicit conversions of types.

Recnetly on SO:

What does the explicit keyword mean?

The compiler is allowed to make one implicit conversion to resolve the parameters to a function. What this means is that the compiler can use constructors callable with a single parameter to convert from one type to another in order to get the right type for a parameter.

Here's an example class with a constructor that can be used for implicit conversions:

class Foo
{
public:
  // single parameter constructor, can be used as an implicit conversion
  Foo (int foo) : m_foo (foo)
  {
  }

  int GetFoo () { return m_foo; }

private:
  int m_foo;
};

Here's a simple function that takes a Foo object:

void DoBar (Foo foo)
{
  int i = foo.GetFoo ();
}

and here's where the DoBar function is called.

int main ()
{
  DoBar (42);
}

The argument is not a Foo object, but an int. However, there exists a constructor for Foo that takes an int so this constructor can be used to convert the parameter to the correct type.

The compiler is allowed to do this once for each parameter.

Prefixing the explicit keyword to the constructor prevents the compiler from using that constructor for implicit conversions. Adding it to the above class will create a compiler error at the function call DoBar (42). It is now necessary to call for conversion explicitly with  DoBar (Foo (42))

The reason you might want to do this is to avoid accidental construction that can hide bugs. Contrived example:

  • You have a MyString(int size) class with a constructor that constructs a string of the given size. You have a function print(const MyString&), and you call print(3) (when you actually intended to call print("3")). You expect it to print "3", but it prints an empty string of length 3 instead.