Skip to content
Why is a raven like a writing desk?

Thoughts both confusing and enlightening.

Why is a raven like a writing desk?

Thoughts both confusing and enlightening.

Category: Programming

“The Lambda Trick”

elbeno, 18 May, 201530 June, 2015

I just got back from C++Now, an excellent conference where C++ template metaprogramming experts abound. A phrase I overheard often was “the lambda trick”. It’s a trick for speeding up compiles when templates get deep. Every C++ programmer knows that deep templates can slow down compilation. Most assume that this…

“In-place” might be less in-place than you think

elbeno, 5 May, 2015

The intuitive view of algorithms that work in-place is that (it sounds obvious) they don’t use any extra space. Canonically in C/C++ we think of something like reversing an array, or that interview staple, removing spaces from an ASCII string, which we might write as: int remove_spaces(char *s) { char…

Recursive lambdas

elbeno, 16 April, 201530 June, 2015

One can assign a lambda to auto or to std::function. Normally one would assign a lambda to auto to avoid possible unwanted allocation from std::function. But if you want recursion, you need to be able to refer to the lambda variable inside the lambda, and you can’t do that if…

Rules for using <random>

elbeno, 8 April, 20153 June, 2025

These days, it’s easy to do the right thing. Don’t do this: Don’t use std::rand(). Ever. Don’t use std::random_shuffle() to permute containers. (Too easy to misuse; can use std::rand() under the hood.) Don’t use any kind of clock for a seed. Don’t use mod (%) to get a random value…

C++ Tuples: the missing functionality

elbeno, 6 April, 201530 June, 2015

C++ provides a strange mix of compile-time and runtime functionality for dealing with tuples. There are some interesting parts, like std::tie to destructure a tuple, and std::tuple_cat to join together several tuples into one. So there is evidence that the standard has been influenced by some functional programming ideas, but…

Another myth, about C++ lambdas

elbeno, 16 March, 201530 June, 2015

Myth: Lambda expressions can cause heap allocations. I see this myth coming up a lot. People think that lambdas can cause a heap allocation – on Reddit, on StackOverflow, on Channel9 comments, in personal conversations. I don’t blame people for thinking this – C++ is complex. But it always seems…

A persistent myth about STL’s remove (and friends)

elbeno, 8 March, 201530 June, 2015

There seems to be a persistent myth about STL’s remove, remove_if, etc. Ask even a relatively experienced C++ programmer to explain this code. vector v = { 1,2,3,4,5 }; v.erase(remove_if(v.begin(), v.end(), [] (int i) { return (i & 1) == 0; }), v.end()); They’ll recognize the erase-remove idiom and correctly…

Adopting C++11: no-brainer features

elbeno, 20 February, 201530 June, 2015

C++11/14 is a significant change from C++98/03, and features like move semantics take a while to get used to. Also, people tend to be quite conservative about adopting new features (especially if they look unfamiliar). It took us in the games industry a while to move to C++ from C….

VS2010 woes: tuples as map keys

elbeno, 20 February, 201530 June, 2015

Another day, another compiler/library bug. If you’re unfortunate enough to still be using Visual Studio 2010, don’t use tuples as map keys. #include #include #include using namespace std; typedef tuple FooT; typedef map MapT; int main(int, char*[]) { MapT m; // put a value in the map { FooT f(nullptr,…

A problem with C++ lambdas?

elbeno, 18 February, 201530 June, 2015

C++ lambdas are wonderful for all sorts of reasons (especially with their C++14-and-beyond power). But I’ve run into a problem that I can’t think of a good way around yet. If you’re up to date with C++, of course you know that rvalue references and move semantics are a major…

  • Previous
  • 1
  • 2
  • 3
  • …
  • 7
  • Next
©2026 Why is a raven like a writing desk? | WordPress Theme by SuperbThemes