Little-known C++: operator auto

A user-defined conversion function enables an implicit or explicit conversion between types. Such, a function has the following form (no return type and no parameters):

struct foo
   operator int() const {return 42;}

foo f;
int i = f;  // implicit conversion

template <auto>

If you wanted to create templates with non-type template parameters, you had to specify both the type and the value. In C++17, this is no longer the case, as template <auto> helps simplify these scenarios.

C++17 New Rules For auto Deduction From braced-init-list

Initialization of variables in C++ can have several forms: default initialization: std::string s; value initialization: std::string s{}; direct initialization: std::string s(“demo”); copy initialization: std::string s = “demo”; list initialization: std::string s{‘d’, ‘e’, ‘m’, ‘o’}; aggregate initialization: char s[5] = {‘d’, ‘e’, ‘m’, ‘o’}; reference initialization: char& c = s[0]; C++11 introduced a generalized syntax for…

Visual Studio 2010 changes for VC++ (part 3)

Some of the important changs in Visual Studio 2010 in regard to VC++ are represented by the support in the C++ compiler of some of the features already approved for the new C++ standard, so far called C++0x. In this post I will give a short overview on then. static_assert I already wrote a post…

Type inference in C++

The new C++0x standard provides support for type inference. The auto keyword that was doing nothing in C++ was given a new meaning: a placeholder for a type inferred by the compiler. For those familiar with C#’s var keyword, this is basically the same. Here is a comparison between auto in C++ and var in…