Languages other than C++ are also prone to having "fun" footguns. Take C#'s reference semantics for example. All I wanted was a dictionary with a file hash as a key. Since built-in cryptographic tools […]
[Original post on techhub.social]
Languages other than C++ are also prone to having "fun" footguns. Take C#'s reference semantics for example. All I wanted was a dictionary with a file hash as a key. Since built-in cryptographic tools […]
[Original post on techhub.social]
Rule of 5 says that if you need to implement one of the copy/move constructors/assignment operators or a destructor, you shall implement all of them to avoid resource management issues. However, this often […]
[Original post on techhub.social]
Rule of 5 says that if you need to implement one of the copy/move constructors/assignment operators or a destructor, you shall implement all of them to avoid resource management issues. However, this often […]
[Original post on techhub.social]
Disposable pattern is an attempt to retrofit scope-based resource management into a garbage-collected language. It executes a dedicated cleanup function when the object goes out of scope, rather than […]
[Original post on techhub.social]
Disposable pattern is an attempt to retrofit scope-based resource management into a garbage-collected language. It executes a dedicated cleanup function when the object goes out of scope, rather than […]
[Original post on techhub.social]
Tired of convoluted templates in your C++? Want to make them more legible?
C++20 introduced concepts - a powerful feature that can restrict your templated APIs to only such arguments that fulfil a particular […]
[Original post on techhub.social]
Tired of convoluted templates in your C++? Want to make them more legible?
C++20 introduced concepts - a powerful feature that can restrict your templated APIs to only such arguments that fulfil a particular […]
[Original post on techhub.social]
When interoping C# with, for example, C++, one can send a pointer to the managed memory directly to the native code and work with it without the need to copy it into the local address space. For as […]
[Original post on techhub.social]
When interoping C# with, for example, C++, one can send a pointer to the managed memory directly to the native code and work with it without the need to copy it into the local address space. For as […]
[Original post on techhub.social]
If you're a C++ programmer, you can easily troll yourself while working with C#'s `string` objects. In C++, they are optimized vectors of bytes and can be dynamically resized at will through […]
[Original post on techhub.social]
If you're a C++ programmer, you can easily troll yourself while working with C#'s `string` objects. In C++, they are optimized vectors of bytes and can be dynamically resized at will through […]
[Original post on techhub.social]
In both C++ and C#, enums are mere named numerical constants. Even if they appear to be distinct types, and switch statements can check whether you covered all names within an enum, that's simply not […]
[Original post on techhub.social]
In both C++ and C#, enums are mere named numerical constants. Even if they appear to be distinct types, and switch statements can check whether you covered all names within an enum, that's simply not […]
[Original post on techhub.social]
When creating a library, semantic versioning is a really useful versioning scheme to use.
It's a promise to your users that changes bumping the minor/patch version numbers are backward-compatible. As such, much of the software relies on these […]
When creating a library, semantic versioning is a really useful versioning scheme to use.
It's a promise to your users that changes bumping the minor/patch version numbers are backward-compatible. As such, much of the software relies on these […]
JSON is a fairly trivial format and as such, its only way of supporting polymorphic data is an enum-discriminated approach.
In other words, you might have an array of objects where […]
[Original post on techhub.social]
JSON is a fairly trivial format and as such, its only way of supporting polymorphic data is an enum-discriminated approach.
In other words, you might have an array of objects where […]
[Original post on techhub.social]
If you follow my #tuesdaycodingtips, this showcases a […]
If you follow my #tuesdaycodingtips, this showcases a […]
`emplace_*` is an alternative to methods like `insert` or `push_*` in standard C++ containers. It allows you to construct the inserted object directly inside the container, passing all required […]
[Original post on techhub.social]
`emplace_*` is an alternative to methods like `insert` or `push_*` in standard C++ containers. It allows you to construct the inserted object directly inside the container, passing all required […]
[Original post on techhub.social]
I like my logs structured. If nothing else, I can log into a CSV file, load that CSV into Excel, turn on filters, and boom, I have a quite nice log analyzer tool. To get the maximum out of it, I need to […]
[Original post on techhub.social]
I like my logs structured. If nothing else, I can log into a CSV file, load that CSV into Excel, turn on filters, and boom, I have a quite nice log analyzer tool. To get the maximum out of it, I need to […]
[Original post on techhub.social]
While writing type-safe APIs, a "tag" type is often useful. It is nothing more than a forward declaration of a type that will never be fully defined, just for the sake of creating a template […]
[Original post on techhub.social]
While writing type-safe APIs, a "tag" type is often useful. It is nothing more than a forward declaration of a type that will never be fully defined, just for the sake of creating a template […]
[Original post on techhub.social]
I recently asked myself: How do you make a reliable type trait for callable types so you can read their return values and call parameters?
The complexity lies in the fact that C++ has four […]
[Original post on techhub.social]
I recently asked myself: How do you make a reliable type trait for callable types so you can read their return values and call parameters?
The complexity lies in the fact that C++ has four […]
[Original post on techhub.social]
I recently debugged a case where code generated by NLOHMANN_JSON_SERIALIZE_ENUM failed at invariant assertions deep in the nlohmann_json library. When examined under a debugger, the […]
[Original post on techhub.social]
I recently debugged a case where code generated by NLOHMANN_JSON_SERIALIZE_ENUM failed at invariant assertions deep in the nlohmann_json library. When examined under a debugger, the […]
[Original post on techhub.social]
Ever found yourself in the situation where you have an exact same handling code for two (or more) selected exception types? C# has a nice way of deduplicating said code.
A `catch` block, processing a base […]
[Original post on techhub.social]
Ever found yourself in the situation where you have an exact same handling code for two (or more) selected exception types? C# has a nice way of deduplicating said code.
A `catch` block, processing a base […]
[Original post on techhub.social]
For a particular C++ application I wrote, I wanted to send an enum over a string-based protocol and pattern match on it on the receiving end to make sure that all possible values were handled.
You […]
[Original post on techhub.social]
For a particular C++ application I wrote, I wanted to send an enum over a string-based protocol and pattern match on it on the receiving end to make sure that all possible values were handled.
You […]
[Original post on techhub.social]
Mutability rules in C# are funky. While trivial types are passed into functions by value, they are captured by reference for their usage in lambdas.
That can lead to stupid bugs - what if you […]
[Original post on techhub.social]
Mutability rules in C# are funky. While trivial types are passed into functions by value, they are captured by reference for their usage in lambdas.
That can lead to stupid bugs - what if you […]
[Original post on techhub.social]
How can you collect values from a std::map into some collection in C++? I know three basic ways to do so.
➤ A naïve imperative approach is manually iterating over the map and […]
[Original post on techhub.social]
How can you collect values from a std::map into some collection in C++? I know three basic ways to do so.
➤ A naïve imperative approach is manually iterating over the map and […]
[Original post on techhub.social]
In C#, you can easily read a whole file using `File.ReadAllText` method. Obviously, things can't be as easy in C++.
You can choose the 'old way' where you pre-allocate a buffer to which you can […]
[Original post on techhub.social]
In C#, you can easily read a whole file using `File.ReadAllText` method. Obviously, things can't be as easy in C++.
You can choose the 'old way' where you pre-allocate a buffer to which you can […]
[Original post on techhub.social]
A quality-of-life C++23 feature has finally been integrated into Visual Studio (v17.12) after it was available in Clang (trunk) for quite some time. That feature is the support of the […]
[Original post on techhub.social]
A quality-of-life C++23 feature has finally been integrated into Visual Studio (v17.12) after it was available in Clang (trunk) for quite some time. That feature is the support of the […]
[Original post on techhub.social]