Clang/GCC weirdness

Consider the following code: #include #include using namespace std; // base template template struct what_type { void operator()() { cout

How to print anything in C++ (postscript)

Part 1 Part 2 Part 3 Part 4 Part 5 Postscript Refactoring! My initial plan for customizing opener/closer/separator for containers turned out to be unwieldy: I realized that it wouldn’t be possible for me to provide default specializations and also allow clients to specialize. Also, you may have noticed that the code for printing pairs,… Continue reading How to print anything in C++ (postscript)

How to print anything in C++ (part 4)

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 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

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