Meeting 27 June 2019

Concept-based interfaces, by Gianluca Delfino

template <typename T>
concept Shape = requires(const T& t)
{
    { t.area() } -> float;
};

template <typename T>
struct Rectangle
{
    Rectangle() { static_assert(Shape<T>); }
    float area() const;
    T base;
    T height;
};

Alternative solution:

template <typename T>
concept Shape = requires(const T& t)
{
    { t.area() } -> float;
};

template<class T>
struct ModelsShape
{
    ModelsShape() requires(Shape<T>) = default;
};

struct Circle: ModelsShape<Circle>
{
    float area() const;
    float radius;
};

Intel Data Parallel C++

Part of Intel One API Project. Based on C++14 and SYCL. Open Source. Developer Beta in 2019 Q4.

Follow-up: std::function const correctness

struct Callable {
    void operator()(){count++;}
    void operator()() const = delete;
    int count = 0;
};

void f()
{
    Callable counter;
    std::function<void(void)> f = counter;
    f();
    const std::function<void(void) const> cf = counter;
    //                                    ^^
    // error: implicit instantiation of undefined template
    // 'std::__1::function<void () const>'
    //
    cf(); // Should not compile
}

Follow-up: std::function movable callables

void f()
{
    std::unique_ptr<int> up;
    auto l=[up=std::move(up)](){};
    std::function<void(void)> f1=l; // Error
    std::function<void(void)> f2=std::move(l); // OK
}

bad_alloc is not out-of-memory!

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1404r1.html

TL;DR: Throwing std::bad_alloc is not the same as "there is no heap space available" - in particular when dealing with custom allocators.

In support of P1485 “Better keywords for coroutines”

https://quuxplusone.github.io/blog/2019/06/26/pro-p1485/

https://stackoverflow.com/a/44244451/1424877

A function becomes a coroutine by having [a keyword such as co_await, co_yield, or co_return] in its body. So [without close inspection of every line of the body] they are indistinguishable from functions.

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1485r1.html

https://www.reddit.com/r/cpp/comments/c5uu56/in_support_of_p1485_better_keywords_for_coroutines/

To boldly suggest an overall plan for C++23

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0592r1.html

Must have:

  • Library support for coroutines
  • Executors
  • Networking

Good to have:

Twitter

/img/ecstatic_cast.png