experimental::filesystem linker error

The Filesystem TS is nothing to do with C++1z support, it is a completely separate specification not part of the C++1z working draft. GCC’s implementation (in GCC 5.3 and later) is even available in C++11 mode. You just need to link with -lstdc++fs to use it. (The relevant library, libstdc++fs.a, is a static library, so … Read more

Is stateful metaprogramming ill-formed (yet)?

This is CWG active issue 2118: Defining a friend function in a template, then referencing that function later provides a means of capturing and retrieving metaprogramming state. This technique is arcane and should be made ill-formed. Notes from the May, 2015 meeting: CWG agreed that such techniques should be ill-formed, although the mechanism for prohibiting … Read more

How to assert that a constexpr if else clause never happen?

You have to make the discarded statement dependent of the template parameters template <class…> constexpr std::false_type always_false{}; if constexpr(condition1){ … } else if constexpr (condition2) { …. } else if constexpr (condition3) { …. } else { static_assert(always_false<T>); } This is so because [temp.res]/8 – The program is ill-formed, no diagnostic required, if no valid … Read more

What are template deduction guides and when should we use them?

Template deduction guides are patterns associated with a template class that tell the compiler how to translate a set of constructor arguments (and their types) into template parameters for the class. The simplest example is that of std::vector and its constructor that takes an iterator pair. template<typename Iterator> void func(Iterator first, Iterator last) { vector … Read more

reinterpret_cast creating a trivially default-constructible object

There is no X object, living or otherwise, so pretending that there is one results in undefined behavior. [intro.object]/1 spells out exhaustively when objects are created: An object is created by a definition ([basic.def]), by a new-expression ([expr.new]), when implicitly changing the active member of a union ([class.union]), or when a temporary object is created … Read more

What are the new features in C++17?

Language features: Templates and Generic Code Template argument deduction for class templates Like how functions deduce template arguments, now constructors can deduce the template arguments of the class http://wg21.link/p0433r2 http://wg21.link/p0620r0 http://wg21.link/p0512r0 template <auto> Represents a value of any (non-type template argument) type. Non-type template arguments fixes template<template<class…>typename bob> struct foo {} ( Folding + … … Read more

How to enable C++17 compiling in Visual Studio?

There’s now a drop down (at least since VS 2017.3.5) where you can specifically select C++17. The available options are (under project > Properties > C/C++ > Language > C++ Language Standard) ISO C++14 Standard. msvc command line option: /std:c++14 ISO C++17 Standard. msvc command line option: /std:c++17 Visual Studio 2022 (MSVC C++20 and the … Read more