September 2014

Rapid prototyping and teaching ZeroMQ in C++ with biicode -- Diego Rodriguez-Losada

From the biicode beta product blog:

Rapid prototyping and teaching ZeroMQ in C++ with biicode

by Diego Rodriguez-Losada

From the article:

Today, if you try to build the basic C++ client-server example that ZeroMQ provides in their site, you might encounter some problems. You have to guess that the C++ binding is not in the library, instead, it’s inside another repo (zmqcpp). I had to google it myself to find it. You have to get, configure and build the library, then setup your own project to use it.

The question is: Given some example source code snippets that use zmq, can anyone, even unexperienced developers build them quickly and easily, even without writing a single line of configuration, in any of the major OS? We think that it can be done, in a few simple steps...

Quick Q: Can computing the length of a C string really be compile-time constexpr? -- StackOverflow

Quick A: Yes, when the string being traversed is itself a constant expression, such as a string literal.

Recently on StackOverflow:

Computing length of a C string at compile time. Is this really a constexpr?

I'm trying to compute the length of a string literal at compile time. To do so I'm using following code:

#include <cstdio>

int constexpr length(const char* str)
{
    return *str ? 1 + length(str + 1) : 0;
}

int main()
{
    printf("%d %d", length("abcd"), length("abcdefgh"));
}

Everything works as expected, the program prints 4 and 8. The assembly code generated by clang shows that the results are computed at compile time:

0x100000f5e:  leaq   0x35(%rip), %rdi          ; "%d %d"
0x100000f65:  movl   $0x4, %esi
0x100000f6a:  movl   $0x8, %edx
0x100000f6f:  xorl   %eax, %eax
0x100000f71:  callq  0x100000f7a               ; symbol stub for: printf

My question: is it guaranteed by the standard that length function will be evaluated compile time?

If this is true the door for compile time string literals computations just opened for me... for example I can compute hashes at compile time and many more...

A Conversation with Bjarne Stroustrup, Carl Hewitt, and Dave Ungar -- Charles Torre

stroustrup-hewitt-ungar.PNGAn appetizer while the CppCon videos are being processed, we are pleased to link to this interview on Channel 9:

A Conversation with Bjarne Stroustrup, Carl Hewitt, and Dave Ungar

by Charles Torre

What happens when you put three titans of programming language design and computing in a room and turn a camera on to capture what takes place?

That's the thought experiment that led to this conversation with C++ language creator Bjarne Stroustrup, Self language creator Dave Ungar, and actor model creator Carl Hewitt. Thank goodness all three of them were present at Lang.NEXT 2014. Many topics are covered, as you can imagine. It's best that you find some quality time to watch, listen, and learn from some true masters. This is a long conversation and there is great programming history herein!

This is a rare (and very candid) gathering of some of the best minds in the programming world today.

Huge thanks to Bjarne, Carl, and Dave for spending over an hour to make conversation in real time. The topics naturally evolved out of the random and it was an honor to be in the room with such wonderful people who've had such a huge impact on programming.

Tune in. Enjoy.

Quick Q: Why can I return a unique_ptr by value? -- StackOverflow

Quick A: Because return local_obj; automatically treats it as an rvalue. After all, you won't be using it any more.

When this FAQ came up again recently on SO, the answer was to refer to this previous Q&A:

Returning unique_ptr from functions

unique_ptr<T> does not allow copy construction, instead it supports move semantics. Yet, I can return a unique_ptr<T> from a function and assign the returned value to a variable...

unique_ptr<int> foo()
{
  unique_ptr<int> p( new int(10) );

  return p;                   // 1
  //return move( p );         // 2
}

The code above compiles and works as intended. So how is it that line 1 doesn't invoke the copy constructor and result in compiler errors? If I had to use line 2 instead it'd make sense (using line 2 works as well, but we're not required to do so)....

Destructors: Two Use Cases -- Andrzej KrzemieĊ„ski

Freshly pressed from Andrzej:

Destructors: Two Use Cases

by Andrzej Krzemieński

From the article:

In this post I want to describe an interesting observation: programmers generally use destructors for two purposes. One is fairly obvious: releasing resources; the other — not necessarily so...

Alexander Stepanov Introduces Bjarne Stroustrup at CppCon 2014 -- A9 Videos

cppcon-stepanov.PNGThe CppCon videos will start appearing soon. In the meantime, A9 Videos posted this introduction that preceded CppCon 2014's opening keynote by Bjarne Stroustrup. In six minutes, Alex Stepanov gives a great capsule summary of what makes C++ important, and why it will continue to be important for a long time yet.

Alexander Stepanov Introduces Bjarne Stroustrup at CppCon 2014

A9 Videos

Exceptions, error codes, and assertions in C++ -- Joseph Mansfield

mansfield.pngOne reasoned take on the various error reporting mechanisms in C++ and a policy for deciding when each is appropriate:

Exceptions, error codes, and assertions in C++

by Joseph Mansfield

From the article:

It can often be difficult to decide between the various methods of error reporting in C++. For example, some common advice is that exceptions should only be thrown in exceptional circumstances. Needless to say, this isn't particularly helpful. What exactly is an exceptional circumstance? An exception to what? If we throw assertions into the mix, this can become even more complicated.

In general, functions express a contract to the calling code...

First community planning session was a full success

Yesterday I held the first planning session for local C++ communities at the #meetingcpp chat at freenode.My plan is to make this a monthly online meeting, where new user groups can be planned and existing user groups can exchange and connect.

First community planning session was a full success

by Jens Weller

From the article:

Yesterday I held the first planning session for local C++ communities at the #meetingcpp chat at freenode.My plan is to make this a monthly online meeting, where new user groups can be planned and existing user groups can exchange and connect. As this was the first time, and I just returned from CppCon, so I only could announce it a day before. Yet it was a good start, especially the contact to the brazilian C++ User Group is great to have.