Articles & Books

Quick Q: How do I make an array of shared_ptrs to unrelated types? -- StackOverflow

Quick A: Try vector<shared_ptr<boost::any>>.

Recently on SO:

Array of shared pointers to different classes

I am new to c++11 programming and now I'm trying to figure out if it is possible to create an array of shared pointers to different types. For example, something like that:

vector<shared_ptr<**???**>> v;
v.push_back(shared_ptr<int>(new int));
v.push_back(shared_ptr<MyClass>(new MyClass()));

or any other way to pass shared_ptr without knowing its type.

Functional Programming in C++ -- John Carmack

In case you missed it:

Functional Programming in C++

by John Carmack

From the article:

... My pragmatic summary: A large fraction of the flaws in software development are due to programmers not fully understanding all the possible states their code may execute in. In a multithreaded environment, the lack of understanding and the resulting problems are greatly amplified, almost to the point of panic if you are paying attention. Programming in a functional style makes the state presented to your code explicit, which makes it much easier to reason about, and, in a completely pure system, makes thread race conditions impossible.

I do believe that there is real value in pursuing functional programming, but it would be irresponsible to exhort everyone to abandon their C++ compilers and start coding in Lisp, Haskell, or, to be blunt, any other fringe language...

Quick Q: What type do lambdas get compiled into? -- StackOverflow

Quick A: A compiler-generated type that stores the captured variables in its data members, and exposes the function signature and body as its operator().

Recently on SO:

What type do lambdas get compiled into?

As I know all data types must be known at compile time, and lambda is not a type. Does lambda got translated into anonymous struct with operator() or std::function wrapped?

For example,

std::for_each(v.begin(), v.end(), [](int n&){n++;});

Tiny Metaprogramming Library -- Eric Niebler

eric-niebler-toronto.PNGWe like to link to articles at all levels. This one's near the top of the scale, for those looking for a real challenge:

Tiny Metaprogramming Library

by Eric Niebler

As the intro says [emphasis ours]:

(Difficult-to-grok metaprogramming below. Not for the faint of heart.)

From the rest of the introduction:

At the recent Urbana-Champaign meeting of the C++ Standardization Committee, Bill Seymour presented his paper N4115: Searching for Types in Parameter Packs which, as its name suggests, describes a library facility for, uh, searching for a type in a parameter pack, among other things. It suggests a template called packer to hold a parameter pack:

// A class template that just holds a parameter pack:
template <class... T> struct packer { };

Many of you are probably already familiar with such a facility, but under a different name:

// A class template that is just a list of types:
template <class... T> struct typelist { };

It became clear in the discussion about N4115 that C++ needs a standard typelist template and some utilities for manipulating them. But what utilities, exactly? ...

What makes Clang so special? -- CoderGears

Today on CoderGears:

What makes Clang so special?

by CoderGears Team

From the article:

It’s proven that Clang is a mature compiler for C and C++ as [are the] GCC and Microsoft compilers, but what makes it special is the fact that it’s not just a compiler. It’s also an infrastructure to build tools. Thanks to its library based architecture which makes the reuse and integration of functionality provided more flexible and easier to integrate into other projects...

Effective Modern C++ available today -- Scott Meyers

Available today on O'Reilly and Amazon, in print in early December:

EMC++ Exits Publishing Purgatory!

by Scott Meyers

From the announcement:

I just received the following from O'Reilly: "Congratulations! Your book went to print on Friday, and we've now completed production. The Retail Availability Date for ebooks on oreilly.com and Amazon is tomorrow, 11/11. For print books, it's estimated at 12/2."

Trip report: using std::cpp 2014 -- J. Daniel Garcia

usingcpp2014.PNGThis just in from our Spanish correspondent:

Event report: using std::cpp 2014 at Spain

J. Daniel Garcia

From the article:

The success of this event is fully in line with several other international events as the recent CppCon in USA or Meeting C++ in Germany and can be seen as another proof of the high interest with which the industry has received the new versions of the C++ standard. It is also worth mentioning that as many other countries there is also a farly active C++ meetup group in Spain...

Where will Evolution lead C++17?

The third part of my series about the proposals for Urbana is about the subgroup evolution:

Where will Evolution lead C++17?

by Jens Weller

From the article:

This is the third part in my series about the proposals for the current C++ committee meeting in Urbana. This time its all about the subgroup Evolution, which has the most papers, so this is only the first part. The previous parts were about concurrency, and Part 2 about core, networking, models and undefined behavior.