RSSAmplifier

Blog

Pydong

A blog about interesting things you can do in Python, C++ and other languages.

pydong.orgRSS feed ↗4 posts

Latest posts

Variadic Switch

Several years back I found an interesting question on Reddit. Essentially the author asks why there is no way to expand a pack into a sequence of case labels followed by a statement. It was illustrated with the following imaginary syntax: template <class Visitor, class Variant, std::size_t ... Is> auto visit_impl(Visitor visitor, Variant && variant, std::index_sequence<Is...&gt...

C++26 Expansion Tricks

P1306 gives us compile time repetition of a statement for each element of a range - what if we instead want the elements as a pack without introducing a new function scope? In this blog post we’ll look at the expand helper, expansion statements and how arbitrary ranges can be made decomposable via structured bindings to reduce the need for IILEs. Element-wise expansion The expand pattern The ...

Fun with C++26 reflection - Keyword Arguments

In this blog post, we’ll explore implementing order-independent keyword arguments for C++ through use of C++26’s proposed reflection features. I stumbled upon this technique while experimenting with reflection a few days ago and thought it might be worthwhile to share, as it nicely showcases just how powerful the proposed reflection features are. An example implementation of the technique pres...

Python's Preprocessor

Every now and then you hear outrageous claims such as “Python has no preprocessor”. This is simply not true. In fact, Python has the best preprocessor of all languages - it quite literally allows us to do whatever we want, and a lot more. It’s just a little tricky to (ab)use. Python source code encodings Thanks to PEP-0263 it is possible to define a source code encoding by placing a magic com...