C++17: std::byte--Marc Gregoire
Do you know it?
C++17: std::byte
by Marc Gregoire
From the article:
C++17 introduced a new type: std::byte...
September 13-19, Aurora, CO, USA
October 25, Pavia, Italy
November 6-8, Berlin, Germany
November 3-8, Kona, HI, USA
By Adrien Hamelin | Jun 4, 2018 01:38 PM | Tags: c++17 basics
Do you know it?
C++17: std::byte
by Marc Gregoire
From the article:
C++17 introduced a new type: std::byte...
By Adrien Hamelin | Jun 4, 2018 01:19 PM | Tags: experimental
Nothing is easy.
App-level Developer on std::error Exceptions Proposal for C++. Part II. The Discussion.
by "No Bugs" Hare
From the article:
For quite a long while, in certain parts of C++ community, there is a substantial resistance to existing C++ exceptions; this leads to an alternative subculture of using error codes instead of exceptions, so there are effectively two barely-compatible C++ worlds: world-using-exceptions, and world-using-error-codes...
By Adrien Hamelin | Jun 4, 2018 12:57 PM | Tags: experimental
Talking about the future.
App-level Developer on std::error Exceptions Proposal for C++. Part I. The Good
by "No Bugs" Hare
From the article:
Very recently (that’s less than 3 weeks ago) a very audacious proposal was published by no less than Herb Sutter, under the name of [P0709R0]...
By shreck | Jun 3, 2018 01:07 AM | Tags: None
An updated discussion on C++ type design, especially the overlap between Regular and reference types.
Revisiting Regular Types
By Titus Winters
From the article:
With 20 years of experience, we know that Regular type design is a good pattern - we should model user-defined types based on the syntax and semantics of built-in types where possible. However, common formulations of Regular type semantics only apply to values, and for performance reasons we commonly pass by reference in C++. In order to use such a reference as if it were its underlying Regular type we need some structural knowledge of the program to guarantee that the type isn’t being concurrently accessed. Using similar structural knowledge, we can treat some non-Regular types as if they were Regular, including reference types which don’t own their data. Under such an analysis, string_view indeed behaves as if it were Regular when applied to common usage (as a parameter). However, span does not, and further it is (currently) impossible to have shallow copy, deep compare, and Regular const semantics in the same type in C++.
This analysis provides us some basis to evaluate non-owning reference parameters types (like string_view and span) in a practical fashion, without discarding Regular design.
By Thomas Young | Jun 3, 2018 01:05 AM | Tags: None
For C++ code-bases with multiple targets and shared code elements, static libraries are kind of the default approach, but is there a better way to set this up?
Automatic Object Linkage, with Include Graphs
by Thomas Young
From the article:
In this post I describe an alternative approach to sharing source code elements between multiple build targets.
...
We'll need to enforce some constraints on the way the source code is set up, notably with regards to header file organisation, but can then automatically determine what to include in the link operation for each build target, based on a graph of include relationships extracted from the source files.
The resulting dynamic, fine grained, object-file centric approach to code sharing avoids the need for problematic static library decomposition, and the associated 'false dependencies'.
By Christopher Di Bella | Jun 3, 2018 01:04 AM | Tags: c++17
Today, we dive into what std::find
does, and how we can leverage various concepts to cleanly express its requirements, as achieved in std::ranges::find
.
Transforming
std::find
intostd::ranges::find
By Christopher Di Bella
From the article:
... The code is nearly the same, but not quite. Where it differs is in how we determine the end of the sequence, how we take the successor of our current element, and how we retrieve the value. While this is conceptually the same, it’s implementationally different.
...
Iterators are a topic rich with mathematics. Because they are part of what makes generic programming so powerful, this topic spans multiple chapters in books on generic programming.
...
we’ll now refine find to consider the
EqualityComparableWith
concept that we laboured over in the last article....
By Adrien Hamelin | May 28, 2018 01:14 PM | Tags: intermediate community
Do you use it?
Hello CMake!
by Arne Mertz
From the article:
Since I have mentioned CMake in a handful of past blog posts, it is time to give a short introduction for those that don’t know it yet.
CMake is one of the most popular build systems for C++ out there. One of the main reasons probably is that it is cross-platform: It does not build the project itself but operates a platform-specific system. That means it can generate Makefiles, ninja-build files, or project files for Visual Studio or Xcode, to name just a few...
By Adrien Hamelin | May 28, 2018 01:08 PM | Tags: advanced
Quick A: const
in a header implicitely means static
.
Recently on SO:
use of constexpr in header file
constexpr
implies const and const on global/namespace scope implies static (internal linkage), which means that every translation unit including this header gets its own copy of PI. The memory for that static is only going to be allocated if an address or reference to it is taken, and the address is going to be different in each translation unit.That implied static for const variables was introduced specifically to use const instead of #define in header files in C++ to define constants. Without static there would be multiple symbol definitions linker error if that header file is included in more than one translation unit which were linked together.
In C++17 you can also make it
inline
, so that there is only ever a single copy of PI if an address or reference to it is taken (i.e. notstatic
).inline
variables were introduced in C++17 to allow for header-only libraries with non-const variable definitions in the header files.In other words, you should use
constexpr
for your constants in header files, if possible, otherwiseconst
. And if you require the address of that constant to be the same everywhere mark it asinline
.
By Adrien Hamelin | May 24, 2018 01:07 PM | Tags: intermediate
If you can.
How to Turn a Hierarchy of Virtual Methods into a CRTP
by Jonathan Boccara
From the article:
So let’s see how to implement static polymorphism in the above code. This question can be split into two parts:
- How to replace virtual methods by a CRTP,
- How to make a CRTP inherit from another CRTP...
By Adrien Hamelin | May 24, 2018 12:56 PM | Tags: intermediate c++17
Do you have a prefered way?
Error Handling and std::optional
by Bartlomiej Filipek
From the article:
In my last two posts in the C++17 STL series, I covered how to use std::optional. This wrapper type (also called “vocabulary type”) is handy when you’d like to express that something is ‘nullable’ and might be ‘empty’. For example, you can return std::nullopt to indicate that the code generated an error… but it this the best choice?