Meeting 18 October 2018

Bjarne Stroustrup Interview at CppCon 2018

CppCon 2018 Trip Reports

CppCon 2018: Hana Dusíková - Compile-Time Regular Expressions

Pre-San Diego Mailing

Pre-San Diego: Modules

Pre-San Diego: Concept-constrained auto

1template <typename T>
2void foo(std::vector<T>& v)
3{
4    auto<RandomAccessIterator> it{std::begin(v)};
5    // ...
6}

(Not in pre-San Diego) Type functions and beyond: An exploration of type functions and concept functions, by J. Monnon

P0844

This document proposes to extend functions to let them operate directly on types and concepts. The goal is to allow writing metaprogramming in the most intuitive and consistent way with the rest of the language.

1ForwardIterator IteratorType(typename T) {
2    // In a type function, an `if` behaves as a `if constexpr`.
3    if (Container(T))  // `Container` is a concept
4        return T::iterator;
5    else if (Array(T)) // `Array` is a concept
6        return Decay(T);
7}
8// On call site:
9typename I = IteratorType(C);

P0844

Concept functions are introduced to manipulate and transform concepts. One of the simplest examples of concept function is to create a new concept by adding constraints to an existing one:

1// Adds the constraints of the `Serialize` concept to any concept.
2concept Serializable(concept C) {
3    return C && Serialize;
4};
5
6// On call site:
7template<Serializable(Container) C>

Pre-San Diego: A sane variant converting constructor

  • P0608R3
    • Zhihao Yuan zy@miator.net
    • This paper proposes to constrain the variant converting constructor and the converting assignment operator to prevent narrowing conversions and conversions to bool.
1using T = variant<float, long>;
2T v;
3v = 0;    // what is stored in v: 1) float 2) long 3) ill-formed

Pre-San Diego: Monadic operations for std::optional

1std::optional<image> get_cute_cat (const image& img) {
2    return crop_to_cat(img)
3           .and_then(add_bow_tie)
4           .and_then(make_eyes_sparkle)
5           .map(make_smaller)
6           .map(add_rainbow);
7}

Pre-San Diego: C++ Monadic interface

Pre-San Diego: Adding a workflow operator to C++

1int total = accumulate { 0 } <| view::iota(1)
2                             |> view::transform([](int x){return x*x;})
3                             |> view::take(10);

Pre-San Diego: Language Variants

1lvariant command {
2  std::size_t set_score; // Set the score to the specified value
3  std::monostate fire_missile; // Fire a missile
4  unsigned fire_laser; // Fire a laser with the specified intensity
5  double rotate; // Rotate the ship by the specified degrees.
6};
 1std::ostream& operator<<( std::ostream& stream, const command cmd ) {
 2  return inspect( cmd ) {
 3    set_score value =>
 4      stream << "Set the score to " << value << ".\n"
 5    fire_missile m =>
 6      stream << "Fire a missile.\n"
 7    fire_laser intensity:
 8      stream << "Fire a laser with " << intensity << " intensity.\n"
 9    rotate degrees =>
10      stream << "Rotate by " << degrees << " degrees.\n"
11  };
12}

Pre-San Diego: Pattern matching

1enum color { red, yellow, green, blue };
2const Vec3 opengl_color =
3  inspect(c) {
4    red    => Vec3(1.0, 0.0, 0.0)
5    yellow => Vec3(1.0, 1.0, 0.0)
6    green  => Vec3(0.0, 1.0, 0.0)
7    blue   => Vec3(0.0, 0.0, 1.0)
8  };

Pre-San Diego: Reflection

Pre-San Diego: A polymorphic value‒type for C++

Add a class template, polymorphic_value<T>, to the standard library to support polymorphicobjects with value‒like semantics.

The class template, polymorphic_value, confers value‒like semantics on a free‒store allocated object. A polymorphic_value<T> may hold an object of a class publicly derived from T, and copying the polymorphic_value<T>will copy the object of the derived type.

Pre-San Diego: A Unified Executors Proposal for C++

Pre-San Diego: Text Formatting

This paper proposes a new text formatting library that can be used as a safe and extensible alternative to the printf family of functions. It is intended to complement the existing C++ I/O streams library and reuse some of its infrastructure such as overloaded insertion operators for user-defined types.

1string message = format("The answer is {}.", 42);

A full implementation of this proposal is available at https://github.com/fmtlib/fmt/tree/std.

Pre-San Diego: Freestanding Proposal

Pre-San Diego: Down with typename!

  • P0634R2
    • Nina Ranns, Daveed Vandevoorde

Pre-San Diego: Parametric Functions

 1double Gauss(double x, double mean = 0., double width = 1., double height = 1.);
 2Gauss(0.1, mean := 0., width := 2.);
 3
 4// same as:
 5
 6Gauss(0.1, 0., 2.);
 7
 8// potential error:
 9
10Gauss(0.1, width := 2., age := 65.);
1// declaration
2void memcpy(to: char *, from: const char *, n: size_t);
3// call site
4memcpy(to: buf, from: in, n: bytes);

Pre-San Diego: Signed size() functions

1template <class C>
2constexpr ptrdiff_t ssize(const C& c);
3
4template <class T, ptrdiff_t N>
5constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept;

Twitter