Meeting 15 February 2018
C++ in 2018, by Jens Weller, Meeting C++
Overload #143
- Class template argument deduction, by Roger Orr
- C++ with metaclasses, by Francis Glassborow
- Functional Error-Handling with Optional and Expected, by Simon Brand
- A Multiple-Writers-Single-Reader (MWSR) queue with minimalist locking
Book: Better Code: Goals for Software Developers, by Sean Parent
Released 19 May 2018.
StackOverflow: int
in C++
- Why aren’t the C-supplied integer types good enough for basically any project?
- Is there still a reason to use
int
in C++ code?
StackOverflow: Scope of a variable initialized in the parameter list of a function
emBO++: Embedded C++ Conference in Bochum, Germany
Insomniac Games C++ Coding Standard (2011)
- 2-space indents, no tabs
- No exceptions
- Constructors shouldn’t do any real work, the real initialization is done in
Create()
orTryCreate()
- Destructors are empty, all deinitialization is done in
Destroy()
- Integer scalars are signed
- No
enum
data members (size is implementation-specific) - Output parameters are pointers, not references (“References can be confusing”)
- Function parameter order: output, update, input
- Use C-style casts. Do not use C++-style casts (“The brevity of the C-style cast outweighs the semantic benefits of explicitness of C++-style casts”)
- Under no circumstances should the keyword
mutable
be used
JUCE C++ Coding Standard
- 4 spaces, no tabs, Allman-style braces
- Space before opening parens
func (foo, bar)
- Avoid underscores in names (except macros)
- Don’t use macros
- Avoid C-style casts
- Pass small types by value
The 15 C++11 features you must really use in your C++ projects
CppCon 2016: David Sankel - Variants: Past, Present, and Future
- Variant: ‘OR’ type, sum type, discriminated union, ADT, “one-of” type
- P0088R3
- Implementations: Anthony Williams, Eric Fiselier
std::overload
by Vicente Botet Escriba: P0051R2
1void output(const std::variant<std::string, int>& v) {
2 return std::visit(std::overload(
3 [](const std::string& s) {std::cout << "String: " << s << "\n";},
4 [](const int i) {std::cout << "Integer: " << i << "\n";}), v);
5}
Mach7: A pattern-matching library for C++, by Yuriy Solodkyy, Gabriel Dos Reis, Bjarne Stroustrup
- GitHub (BSD)
- Article: Another Polymorphism
- Generated code is faster than visitors
1void print(const boost::variant<double,float,int>& v)
2{
3 var<double> d; var<float> f; var<int> n;
4 Match(v)
5 {
6 Case(C<double>(d)) cout << "double " << d << endl; break;
7 Case(C<float> (f)) cout << "float " << f << endl; break;
8 Case(C<int> (n)) cout << "int " << n << endl; break;
9 }
10 EndMatch
11}
C++Now 2017: Vittorio Romeo - Implementing variant
visitation using lambdas
This is trivial. Is this clear to everyone? Silence
1enum MyVariant {
2 IntTag(i32),
3 FloatTag(f32),
4 DoubleTag(f64)
5}
6
7let v0 = FloatTag(2.0);
8match v0 {
9 IntTag(x) => println!("{}i", x),
10 FloatTag(x) => println!("{}f", x),
11 DoubleTag(x) => println!("{}d", x)
12}
1using shape = std::variant<circle, box>;
2shape s0{circle{/*...*/}};
3shape s1{box{/*...*/}};
4
5// In place `match` visitation.
6scelta::match([](circle, circle){ /* ... */ },
7 [](circle, box) { /* ... */ },
8 [](box, circle){ /* ... */ },
9 [](box, box) { /* ... */ })(s0, s1);
CppCon 2015: John R. Bandela - Simple, Extensible Pattern Matching in C++14
- simple_match (C++14), no macros, focus on clarity and simplicity (not speed)
- GitHub
Jens Weller - Programming in a different domain - Meeting C++ 2017
Computers Biology
Byte: 8 bits Byte: 3 ‘bits’ Bit: 0 or 1 ‘Bit’: (G or C) or (T or A) C++ Assembler + punch tape
Programming life? New cures? Growing things? A new Clang target?
Verdigris: Qt without MOC, v1.0
Selene: A C++14 image representation, processing and I/O library
- GitHub (MIT)
- Offers flexible classes for image and multi-channel pixel representations, and functions for image data access.
- Provides easy-to-use APIs to read and write images in JPEG and PNG formats (leveraging libjpeg and libpng).
- Offers basic image processing algorithms such as color conversions, pixel-wise operations, rotation, flipping, etc.
- Lightweight and easy to build using CMake on Linux, MacOS, Windows.
Vc: SIMD Vector Classes for C++ by Matthias Kretz
- GitHub (C++14) (BSD-3-Clause)
- P0214R7: Data-Parallel Vector Types & Operations
libbson: A BSON utility library by MongoDB
- GitHub (Apache-2.0)