diff --git a/doc/cppnow-2017/index.html b/doc/cppnow-2017/index.html index 09cfc7ce88..f15163012b 100644 --- a/doc/cppnow-2017/index.html +++ b/doc/cppnow-2017/index.html @@ -69,30 +69,34 @@ ## Type constraints -#### +/- Concepts-Lite syntax in C++14/17 (predicates) +#### C++14/17 Type constraints (~Concepts-Lite predicates) ```cpp -template | struct Foo { -constexpr auto Fooable = | int foo(); - $requires(T)(auto&& t) ( | }; - int( t.foo() ) | - ); | template)> - | void foo(T&&); +template | struct Foo { +constexpr auto Fooable = | int foo(); + $requires(T)(auto&& t) ( | }; + int( t.foo() ) | + ); | template)> + | void foo(T&&); ``` + -#### Concepts-Lite (type with predicates) +#### Non-dependable constraints ```cpp -struct Readable { | struct Reader { - template && | Reader& operator=(Reader&&) = default; - MoveAssignable && | int read(); - Callable($(read)) | }; - ) Readable(T); | -}; | static_assert( - | std::is_convertible{} - | ); +struct Readable { | // Readable Implementation + template | + auto operator()() const { | struct Reader { // no inheritance + MoveConstructible && <|> Reader(Reader&&) = default; // ✔ + MoveAssignable && <|> Reader& operator=(Reader&&) = default; // ✔ + Callable($(read))<|> int read(); // ✔ + }; ^ | }; +}; \__ | + \ | static_assert( + callable using ---/ | is_satisfied_by{} + function name | ); ``` + ---- @@ -104,16 +108,18 @@ void onError(std::string_view msg) { throw T{msg}; } }; ``` + #### policy design ```cpp template class App : TPolicy { void run() { - if (false) { TPolicy::onError("error!"); } + if (...) { TPolicy::onError("error!"); } } }; ``` + #### Static dispatch and wiring ```cpp @@ -125,6 +131,7 @@ injector.create().run(); // App is a template! } ``` + ---- @@ -153,7 +160,7 @@ di::bind.to(), // concepts checking at wiring! di::bind.to() ); - injector.create().run(); // App is a template! + di::make(injector).run(); // App is a template! } ``` @@ -165,8 +172,8 @@ template // type = concept class App { TReader reader; - any printer; // type erasure based on the same concept! - + any printer; // type erasure based on the same concept + // as concepts example public: App(TReader reader, any printer) // 100% value semantics : reader(reader), printer(printer) @@ -178,27 +185,25 @@ #### Dynamic bindings using virtual concepts ```cpp -int main(int argc, char**) { - const auto injector = di::make_injector( +auto config = [](std::string_view printer) { + return di::make_injector( di::bind.to(), - di::bind([&](auto&& _) -> Printable { - return argc == 1 - ? _.to() - : _.to(); + di::bind([&](auto&& _) { + return printer == "QT" ? + _.to() : _.to(); }) ); - injector.create().run(); -} +}; ``` ---- -## Automatic concepts based mocks injection +## Automatic, concepts based, mocks injection ```cpp "should print read text"_test = [] { constexpr auto value = 42; - auto [sut, mocks] = testing::make(); // creates System Under Test + auto [app, mocks] = testing::make(); // creates System Under Test // and mocks! InSequence sequence; @@ -207,9 +212,10 @@ EXPECT_CALL(mocks(), print(value)); } - sut.run(); + app.run(); }; ``` +#### It works with concepts/type_erasure and interfaces! ==============================================================================