Meeting 9 August 2018
IEEE Most popular programming languages of 2018
Follow-up: Toby Allsopp - An Introduction to the Proposed Coroutine Support for C++
How to use coroutines today
- Visual Studio 2017 (
/await
) - Clang 5.0 with libc++ 5.0 (
-fcoroutines-ts -stdlib=libc++
)
Abstraction libraries
Clang Concepts is feature-complete
- Announcement
- Compiler Explorer
- Code
- Andrew Sutton’s reply: “If I had not gone on vacation, I might have beaten you to the punch in GCC ;) I’m in the process of working through older TS tests.”
The optimal way to return from a function, by Jason Turner
Single return (20%):
1string val(const bool b) {
2 string ret;
3 if (b) ret = "Hello"; else ret = "World";
4 return ret;
5}
versus multiple return (61%):
1string val(const bool b) {
2 if (b) return "Hello"; else return "World";
3}
versus:
1string val(const bool b) {
2 return b ? "Hello" : "World";
3}
Practical C++17, by Jason Turner
C++17: std::apply
and std::invoke
C++17 in libsigc++ : invoke
, apply
, and constexpr if
libsigc++ implements a typesafe callback system for standard C++. It allows you to define signals and to connect those signals to any callback function, either global or a member function, regardless of whether it is static or virtual.
Modules TS example
pet.cpp:
1module pets.pet;
2import std.core;
3
4export class Pet
5{
6public:
7 virtual char const* pet() = 0;
8};
dog.cpp:
1module pets.dog;
2import std.core;
3import pets.pet;
4
5export class Dog : public Pet
6{
7public:
8 char const* pet() override;
9};
10
11char const* Dog::pet()
12{
13 return "Woof!";
14}
interface.cpp (or maybe pets.cpp?):
1module pets;
2
3export module pets.pet;
4export module pets.dog;
main.cpp:
1import pets;
2import std.core;
3import std.memory;
4
5int main()
6{
7 std::unique_ptr<Pet> pet = std::make_unique<Dog>();
8 std::cout << "Pet says: "<< pet->pet() << std::endl;
9}
More on Modules
- C++ modules and why we need them desperately
- Using modules in Visual C++
- Migrating existing C++ code to use modules
- Compiling boost on QNX: a tale of why modules are needed in C++
A C++ Puzzle by Leor Zolman
Question
Write a portable C++ (or C) program that displays:
Hello World
on the standard output when executed, WITHOUT USING ANY SEMICOLONS (;)
- Don’t worry what’s in standard header files (and in the C version you don’t need any headers)
- No preprocessor directives are required (aside from
#include
for C++) - No assembly language required
Solutions
C++:
1#include <iostream>
2int main() {
3 if (std::cout << "Hello World") {}
4}
C:
1int main() {
2 if (printf("Hello World")) {}
3}
CppChat: Volatile Is the Embedded Keyword
- For many embedded or kernel developers using C++ for anything is anathema: “Here is a thing I made in C++ which solves this problem in the kernel/embedded system” – “Why are you even using C++? You should use C!”
- C and C++ compiler defaults differ, so compiling C code with a C++ compiler will make it slower. When you disable certain C++ defaults (RTTI, exceptions) it becomes faster than C.
- Freestanding proposals by Ben Craig:
- Static exceptions by Herb Sutter
Volatile
volatile
is needed:- John Regehr’s tweet: “I think it’s 100% clear the C++ committee should remove
volatile
”- JF Bastien’s reply: “No! I used
volatile
recently, and advocated for its use too!!! It’s great for signals, and TOCTOU, at a minimum. I’m wondering if we should deprecate volatile-qualified functions though. I don’t think they’re useful anymore.” - JF Bastien’s tweet: “<…> it defines the member function to call if the
this
pointer isvolatile
. That’s been standard C++ forever. Same for const member function overloads. Don’t forget about ref and rvalue member functions! <…>”
- JF Bastien’s reply: “No! I used
- John Regehr’s tweet: “I think it’s 100% clear the C++ committee should remove
1class Foo {
2 void bar() volatile;
3};
Spdlog V1.0
A very fast header-only C++ logging library