C++ For C# Developers: Part 31 – Destructuring and Attributes

Both languages have both destructuring (var (x, y) = vec;) and attributes ([MyAttribute]). C++ differs from C# in several ways, so today we’ll take a look at those differences and learn how to make use of these language features.

Read the rest of this article »

C++ For C# Developers: Part 30 – Type Aliases

C# has support for type aliases in the form of using ScoreMap = System.Collections.Generic.Dictionary<string, int>; directives. This allows us to use ScoreMap instead of the verbose System.Collections.Generic.Dictionary<string, int> or even Dictionary<string, int>. C++ also has type aliases, but they go way beyond what C# supports. Today we’ll dig into everything C++ offers us to make our code more concise and readable.

Read the rest of this article »

C++ For C# Developers: Part 29 – Template Constraints

C# where constraints enable our generics to do a lot more. C++ also has constraints and they enable us to write more expressive and efficient code. Today we’ll see how to add some constraints to our templates to achieve these goals.

Read the rest of this article »

C++ For C# Developers: Part 28 – Variadic Templates

All of the templates we’ve written so far had a fixed number of parameters, but C++ lets us take a variable number of parameters too. This is like params in C# functions, but for parameters to C++ templates. Today we’ll dig into this feature, which has no C# equivalent, and learn how to write and use templates with any number of parameters.

Read the rest of this article »

C++ For C# Developers: Part 27 – Template Deduction and Specialization

Template deduction in C++ is like generic type parameter deduction in C#: it allows us to omit template arguments. Template specialization has no C# equivalent, but enables special-casing of templates based on certain arguments. Today we’ll look at how these features can make our code a lot less noisy and also a lot more efficient.

Read the rest of this article »

C++ For C# Developers: Part 26 – Template Parameters

Last time, we started looking at a core feature of C++: templates. We compared and contrasted them to C# generics and saw how they’re applied to classes, functions, lambdas, and even variables. Today we’ll leverage the power of so-called “non-type template parameters” and “template template parameters” to write some really interesting code.

Read the rest of this article »

C++ For C# Developers: Part 25 – Intro to Templates

C# generics (List<T>) look a lot like C++ templates (list<T>), but they’re different in many key ways. It’s a big subject, so today we’ll start by looking at some of the most common uses of templates: applying them to classes, functions, members, lambdas, and variables.

Read the rest of this article »

C++ For C# Developers: Part 24 – Preprocessor

C# and C++ have similar lists of preprocessor directives like #if, but their features and usage are very different. This is especially the case in C++ with support for “macros” that can replace code. Today we’ll look into everything we can use the preprocessor for in C++ and compare with C#’s preprocessor.

Read the rest of this article »

C++ For C# Developers: Part 23 – Compile-Time Programming

The vast majority of the code we write executes at runtime. Today’s article is about the other kind of code, which runs during compilation. C# has very limited support for this. In C++, especially its newer versions, most of the language features are usable at compile-time. Read on to learn how to take advantage of this!

Read the rest of this article »

C++ For C# Developers: Part 22 – Lambdas

Both C++ and C# have lambdas, but they have quite a few differences. Today we’ll go into how C++ lambdas work, including all their features and how they compare and contrast with C# lambdas. Read on to learn all the details!

Read the rest of this article »