Which Parameter Type Should I Use?

In this article, we’ll discuss a small but practical question: when should you use each kind of function parameter type? Classifying Parameters Suppose we have a type T (to keep things simple, T here is not a generic type parameter). How many ways are there to pass a parameter of this type to a function? Let’s break it down: Qualifier: const-qualified or not Reference category: by value, by lvalue reference, by rvalue reference Based on this classification, we get exactly 5 parameter types:...

August 1, 2025 · 6 min · 1087 words · Wokron

Writing a Compile-Time Sort

Let’s have some fun with templates this time. C++ has std::integer_sequence, which lets you define compile-time integer sequences. For example: #include <utility> using my_seq = std::integer_sequence<int, 1, 2, 3, 4, 5>; Now let’s write a seq_sort_t trait that performs compile-time sorting, something like: using my_seq = std::integer_sequence<int, 2, 5, 3, 1, 4>; using sorted_my_seq = seq_sort_t<my_seq>; // std::integer_sequence<int, 1, 2, 3, 4, 5> Let’s start with some groundwork. Runtime Output Use type extraction to convert std::integer_sequence into a runtime std::initializer_list for easy output....

March 7, 2025 · 7 min · 1431 words · Wokron

A Practical CMake Tutorial

1. Introduction I’ve been working on a C++ project recently and had to learn CMake. Honestly, CMake’s quirky syntax can be quite intimidating at first. But once you get hands-on, you’ll find that only a small subset is needed day-to-day, and it generally follows predictable patterns. Master this subset and you can likely organize a fairly large project. That’s exactly what this tutorial aims to cover. Of course, you’ll need to understand compilation and linking before reading this....

September 3, 2023 · 7 min · 1408 words · Wokron