RSSAmplifier

Blog

tristanbrindle.com

(c) Tristan Brindle. Code samples are MIT licensed unless otherwise stated. Attribution is appreciated.

tristanbrindle.comRSS feed ↗10 posts

Latest posts

The Road to Flux 1.0

I’ve just posted a long update about my plans for Flux on the Github discussions page , but I figured it might be worth posting here as well for a wider audience. If you’ve used Flux before – or you’re just curious about alternatives to std::ranges – then hopefully you’ll find it interesting. Just to reiterate what it says below – I’m very keen to get feedback about the plans outlined here. If you…

Compile-time Bounds Checking in Flux

When using bounds checked interfaces, there are often situations during optimisation where the compiler is able to statically prove that a bounds check will always pass, allowing it to omit the checking code entirely. The simplest example would be something like so: int get_first_elem ( const std :: array < int , 5 >& arr ) { return arr . at ( 0 ); } Compiler Explorer When optimising this…

Parameter Passing in Flux versus Ranges

Regular readers of this irregular blog will know that I’m a huge fan of C++20 Ranges and the ‘collection-orientated’ style of code that they allow. For the last few months, I’ve been working on a new C++20 library called Flux , which aims to provide many of the same facilities as Ranges as well as offering improved safety, ease-of-use, and in some cases better runtime efficiency. In the first of…

Experimenting with Modules in Flux

TL;DR : Flux , my C++20 sequence-orientated programming library, now has experimental support for being used as a module. Provided you’re using a recent compiler and don’t mind a few rough edges, you can say import flux and get going. The future is (almost) here! Trying it out If you fancy giving it a try, you’ll need a recent version of one of the three major compilers: I’ve got it working with…

Ranges and Forwarding References

Arthur O’Dwyer recently blogged about “universal references” vs “forwarding references” , where he puts the case that T&& (where T is a deduced template parameter) should be properly called a “forwarding reference” rather than the original term (coined by Scott Meyers), “universal reference”. I happen to agree that “forwarding reference” is a better name. But Arthur goes on to say If you see code…

Numeric Range Algorithms for C++20

TL;DR: I’ve written C++20 range-based versions of the algorithms in the <numeric> header, and you can get them here C++20 brings with it updated versions of the many, many algorithms in the <algorithm> header. Sadly, as Peter Dimov recently noted , it does not do so for the “other” algorithms in the <numeric> header. The reason for this is simply one of time. It turns out that correctly defining…

Rvalue Ranges and Views in C++20

Back in the mists of time, when the world was a more normal place (well, September last year) I gave a talk at CppCon entitled “An Overview of Standard Ranges” . Unfortunately I ran a little long and didn’t have time to take questions on video at the end, but since my talk was right before lunch I ended up having a informal Q&A session in the room afterwards for about 45 minutes. One of the…

Opt-in UFCS with "using class"

Sadly, I’ve never had a chance to read Bjarne Stoustrup’s “Design and Evolution of C++” . I suspect I’d find it fascinating, and that it would probably answer many questions I have in my mind about why things in C++ are the way they are today. Unfortunately the book seems to be in short supply (I assume it’s out of print), and the prices for new copies on Amazon are rather on the steep side.…

Beware of copies with std::initializer_list!

Pop quiz: what does the following C++ program do? #include <memory> #include <string> #include <vector> using namespace std ; int main () { vector < unique_ptr < string >> vec { make_unique < string > ( "foo" ), make_unique < string > ( "bar" ), make_unique < string > ( "baz" ) }; } This is a trick question of course: the answer is that the above program will fail to compile . If this surprises…

A more useful compile-time quicksort in C++17

A few days ago a post from Björn Fahller did the rounds about a compile-time quicksort in C++ , using template metaprogramming. It is, as the author concludes, “of limited usefulness, but kind of cool”. Today, I happened to see a follow-up in D , effectively pointing out that D’s standard library sort() function can be used at compile-time. This got me thinking: can we implement a normal sort()…