Part 1 Part 2 Part 3 Part 4 Part 5 Postscript Callable things. There are several types: functions member functions std::functions bind expressions lambdas objects that support operator() (function objects) So, going back to my tag code, so far (with everything I’ve added) and including callable things, it will look like: template using stringifier_tag =… Continue reading How to print anything in C++ (part 4)
How to print anything in C++ (part 3)
Part 1 Part 2 Part 3 Part 4 Part 5 Postscript So far, we’ve dealt with things that are already outputtable with operator<<, and things that are iterable with begin() and end(). To round out the “containers”, we need to deal with pair and tuple. It’s simple to print a pair: template struct stringifier_select {… Continue reading How to print anything in C++ (part 3)
How to print anything in C++ (part 2)
Part 1 Part 2 Part 3 Part 4 Part 5 Postscript We have a basic plan, and the ability to detect concrete types. But how can we detect whether an object supports output with operator<<? For this, there is a recently-discovered amazing trick. Here’s the code: template using void_t = void; template using operator_output_t =… Continue reading How to print anything in C++ (part 2)
How to print anything in C++ (part 1)
Part 1 Part 2 Part 3 Part 4 Part 5 Postscript I thought I’d have a go at writing some code that could print things. A pretty-printer, if you like. What I want to be able to do is this: // Print x correctly, where x is ANY type. cout
Holy Wars
All right, I have some opinions. Here are the definitive answers to the three most important dilemmas facing programmers today 🙂 * Static typing vs Dynamic typing Static typing. I suppose dynamic types are OK if you’re hacking together a small tool. But static (strong, preferably HM-inferred) typing allows you to reason about your program… Continue reading Holy Wars
Do-notation can be misleading
Consider the following function: oddness :: Maybe Int oddness = do let a = Just 1 :: Maybe Int b >= \b -> return b And recall the definition of (>>=) for Maybe: instance Monad Maybe where (Just x) >>= k = k x Nothing >>= _ = Nothing So what’s happening here is that… Continue reading Do-notation can be misleading
C++ Guru Question – followup
(following on from C++ Guru Question) There are a few reasons why the code before didn’t work: mainly a) C++ template argument deduction works one-way with a list of candidates, it’s not H-M type inference. b) A C++ lambda is a thing with some internal type, not a std::function (although it can be assigned to… Continue reading C++ Guru Question – followup
C++ Guru Question
Wondering about this… template argument deduction succeeds for the explicitly-typed variable, fails in the auto case. (Also, it succeeds either way for an equivalently-typed unary operator template). template struct Foo { T m_t; }; template Foo operator/=(Foo foo, function fn) { return fn(foo.m_t); } void mystery() { auto foo = Foo{1}; // this works… function… Continue reading C++ Guru Question
2013 Books
Books I read in 2013: Mr Penumbra’s 24 Hour Bookstore (Robin Sloane)I loved this book. A modern-day mystery story, set in San Francisco with all the tech hipsterism that implies, but also featuring old books, movable type and a secret society. Taking Sudoku Seriously (Jason Rosenhouse and Laura Taalman)This was another awesome book. A thorough… Continue reading 2013 Books
Indiecade day 1
An excellent day of networking at Indiecade. Link dump time so I don’t forget these people… First was the guys from Rust presenting their experience making The Museum of the Microstar. Then I hung out in the rotunda meeting interesting folks, having thought-provoking discussions and playing some cool games. Chatted with Henry Fernandez. Arthur Danskin… Continue reading Indiecade day 1