Using strings in C++ template metaprograms

Of all the reasons to love metaprogramming,[^1] probably the most compelling is that it lets us embed “little languages” in our programs. For example, we might want to express a parser for complex numbers this way, rather than explicitly writing a recursive descent parser ourselves:

auto parse_complex =
    '(' >> double_ >> -(',' >> double_) >> ')'
  | double_;
 

Or, instead of hand-coding the state machine for a CD player, we might want to express its transition table like this:

Continue Reading

Unifying Generic Functions and Function Objects

A couple of noteworthy things have happened since we floated the idea of a pythy syntax for functions. First, Paul Fultz came up with a library implementation of Pythy syntax. Wow! I’m not sure where this will lead but I’m eager to see what it feels like in practice (also check out some of his other git repos; there’s some really cool stuff in there). Continue Reading

Portable Stackless Coroutines in One* Header

I remember hearing about this back at last years’ BoostCon, but never had a chance to absorb it until now. Chris Kohlhoff’s ASIO library contains an extraordinary little header, not in the public interface, but in the examples directory, that implements what he calls “Stackless Coroutines” (very similar to Python’s Simple Generators if you’re familiar with those). He does it completely portably, with just a few macros, and considering that there are zero lines of platform-specific code, they work amazingly well. This article explains how to use them. The ability to flatten callback-based code in this way is sorely missing from C++ (especially for asynchronous applications), so I thought this header deserved more notice. Frankly I’d like to see it as a top-level component in the Boost Utility library. Check it out! Continue Reading

Boost.Contract and Library-Based Language Extensions

This week I have the privilege of managing the review of the proposed Boost.Contract library.

This library is possibly the most ambitious example yet of a category of libraries that, essentially, implement core language features using library constructs. Other examples include: Continue Reading

Evil, or Just Misunderstood?

Opening Scene

INT. DOWNTOWN CLUB – MIDNIGHT

CODER and USER DEFINED TYPE, both dressed to kill, a little tipsy, and obviously about to close the deal, occupy adjacent bar stools. They lean close to be heard over the atmospheric music enveloping the room. Continue Reading

BoostCon / C++Now! 2012

As you may have heard, the 2012 edition of BoostCon has been re-branded as C++Now! Well, the keynote speakers have been announced and the program has been set. This year is looking like a blockbuster! See you there…

9 comments so far, add yours

A Breakthrough for Concepts

This entry is part of a series, Having It All»

In the last article in this series, I mentioned that we’ve solved the problem with polymorphic lambdas and concepts, and I promised to discuss it here. So here we go!

Quick concepts review

Just like type declarations, concepts would add two kinds of type-checking to the C++ template system. To understand how, let’s first look at an ordinary C++ function: Continue Reading

Having it all: Pythy syntax for C++

This entry is part of a series, Having It All»

As I’ve been dreaming about the future of C++, I’ve started to ask myself, “what if we could have it all?” What if we could write C++ code with the agility of Python programmers, and still have all the static checking we really want, when we want it?

I’ll be honest with you; I haven’t been all that excited about the future of C++ recently, in large part because of the ever-growing weight of syntax that we use to describe our interfaces. Today it’s rvalue references and noexcept. Tomorrow it’ll be concept constraints and who-knows-what-else? It’s a drag. Continue Reading

Entries in this series:
  1. Having it all: Pythy syntax for C++
  2. A Breakthrough for Concepts
Powered by Hackadelic Sliding Notes 1.6.5

BoostCon 2011: Early Registration Deadline Approaching

The premier annual US C++ event, BoostCon, runs May 15-20, 2011 in beautiful Aspen, Colorado!

Hans Boehm, the father of C++ garbage collection and the C++0x threading model, headlines the fifth annual Boost Conference, with his keynote, “Threads and Shared Variables in C++0x.” Other sessions about which which I’m personally excited: Continue Reading

Appearing and Disappearing consts in C++

C++Next is happy to republish the following article by Scott Meyers, with Scott’s permission, of course. Thanks, Scott!

If you write “int i;” in C++, i’s type seems obvious: int. If you write “const int i;”, i’s type seems equally obviously to be const int. Often, these types are exactly what they seem to be, but sometimes they’re not. Under certain circumstances, C++ treats non-const types as const, and under others it treats const types as non-const. Understanding when consts appear and disappear lends insight into the behavior of C++, and that makes it possible to use the language more effectively.This article examines various aspects of type declaration and deduction in both current standard C++ as well as the forthcoming revised standard (C++0x), with an eye towards helping you understand how and why the effective type of a variable can be different from what’s “obvious.” You’ll find the article most useful if you are familiar with the basic rules for template argument deduction, are aware of the difference between lvalues and rvalues, and have had some exposure to the new C++0x features lvalue and rvalue references, auto variables, and lambda expressions. Continue Reading