(Start at the beginning of the series if you want more context.) So, I was going to implement monoidal_zip, and to do that, I would clone zip_with.hpp. So I did that. Eric’s a great library author, and the ranges code is pretty easy to read. For the most part I found it concise, well-expressed and… Continue reading Exercising Ranges (part 3)
Author: elbeno
Exercising Ranges (part 2)
(Start at the beginning of the series if you want more context.) First steps with power series A power series (or polynomial, to give it a more familiar term in the case where it’s finite) is represented simply as a sequence of coefficients of increasing powers of x. This is simple – to represent: [latex]1… Continue reading Exercising Ranges (part 2)
Exercising Ranges (part 1)
The idea For some time since attending C++Now, I have been meaning to get around to playing with Eric Niebler’s range library. Eric presented ranges in a worked example as one of the keynotes at C++Now – a prior version of the talk that he gave at the Northwest C++ Users Group is currently available… Continue reading Exercising Ranges (part 1)
.emacs bankruptcy
So, this past week I decided to redo my .emacs file. Previously, I was using the (somewhat common?) literate programming approach with org-mode, but I decided to ditch that, go back to a flat file and embrace John Wiegley’s excellent use-package. My .emacs is at https://github.com/elbeno/dotemacs if you want to follow along or just peruse… Continue reading .emacs bankruptcy
“The Lambda Trick”
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 is because of excessive code… Continue reading “The Lambda Trick”
“In-place” might be less in-place than you think
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 *readptr = s; char *writeptr… Continue reading “In-place” might be less in-place than you think
Recursive lambdas
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 it’s assigned to auto. So… Continue reading Recursive lambdas
Rules for using <random>
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 into a range. It introduces… Continue reading Rules for using <random>
C++ Tuples: the missing functionality
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 I don’t think the full… Continue reading C++ Tuples: the missing functionality
Another myth, about C++ lambdas
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 to be some vague notion… Continue reading Another myth, about C++ lambdas