Meeting 12 July 2018

Combined proposal for short concepts syntax

Twitter: concepts and constraint checking

|

|

Twitter: Bryce Lelbach

This is horrific:

1int a; std::cout << &a << std::endl;
2int volatile a; std::cout << &a << std::endl;

What’s the difference?

  • Line 1: Implicitly converts to void*, calls operator<<(ostream&, void*).
  • Line 2: Implicitly converts to bool, calls operator<<(ostream&, bool).

Revisiting Builder Pattern with Fluent API

Post

 1class FooBuilder;
 2
 3class Foo {
 4public:
 5    friend class FooBuilder;
 6    static FooBuilder builder();
 7private:
 8    Foo() = default;
 9    std::string name_;
10};
 1class FooBuilder {
 2    FooBuilder& name(const char* name) {
 3        foo_.name_ = name;
 4        return *this;
 5    }
 6    operator Foo&&() {return std::move(foo_);}
 7    Foo build() {return foo_;}
 8private:
 9    Foo foo_;
10}
11
12FooBuilder Foo::build() {return FooBuilder();}
1int main() {
2    Foo foo1 = Foo::builder().name("foo1");
3    Foo foo2 = Foo::builder().name("foo2").build();
4}

The generated optimised code is the same.

C++Now 2018: Jean-Louis Leroy - yomm2: Fast, Orthogonal, Open Methods in a Library

Twitter