@odin odinthe thener nerd not the god Auto-Intern GmbH 1 - - PowerPoint PPT Presentation

odin odinthe thener nerd
SMART_READER_LITE
LIVE PREVIEW

@odin odinthe thener nerd not the god Auto-Intern GmbH 1 - - PowerPoint PPT Presentation

@odinthenerd @odin odinthe thener nerd not the god Auto-Intern GmbH 1 @odinthenerd Hana Duskov compile time regex Auto-Intern GmbH 2 @odinthenerd Mixins Auto-Intern GmbH 3 @odinthenerd Auto-Intern GmbH 4 @odinthenerd


slide-1
SLIDE 1

@odinthenerd

@odin

  • dinthe

thener nerd

– not the god

Auto-Intern GmbH 1

slide-2
SLIDE 2

@odinthenerd

Auto-Intern GmbH 2

Hana Dusíková compile time regex

slide-3
SLIDE 3

@odinthenerd

Auto-Intern GmbH 3

Mixins

slide-4
SLIDE 4

@odinthenerd

Auto-Intern GmbH 4

slide-5
SLIDE 5

@odinthenerd

Bare metal drivers

Auto-Intern GmbH 5

slide-6
SLIDE 6

@odinthenerd

Bare metal drivers

Auto-Intern GmbH 6

  • In assembler
slide-7
SLIDE 7

@odinthenerd

Bare metal drivers

Auto-Intern GmbH 7

  • In assembler
slide-8
SLIDE 8

@odinthenerd

Bare metal drivers

Auto-Intern GmbH 8

  • In assembler
  • In C with Macros
slide-9
SLIDE 9

@odinthenerd

Bare metal drivers

Auto-Intern GmbH 9

  • In assembler
  • In C with Macros
slide-10
SLIDE 10

@odinthenerd

Bare metal drivers

Auto-Intern GmbH 10

  • In assembler
  • In C with Macros
  • By hand in C++
slide-11
SLIDE 11

@odinthenerd

Bare metal drivers

Auto-Intern GmbH 11

  • In assembler
  • In C with Macros
  • By hand in C++
slide-12
SLIDE 12

@odinthenerd

Bare metal drivers

Auto-Intern GmbH 12

  • In assembler
  • In C with Macros
  • By hand in C++
  • Aggregation
slide-13
SLIDE 13

@odinthenerd

Bare metal drivers

Auto-Intern GmbH 13

  • In assembler
  • In C with Macros
  • By hand in C++
  • Aggregation
slide-14
SLIDE 14

@odinthenerd

Bare metal drivers

Auto-Intern GmbH 14

  • In assembler
  • In C with Macros
  • By hand in C++
  • Aggregation
  • Inheritance + virtual functions
slide-15
SLIDE 15

@odinthenerd

Bare metal drivers

Auto-Intern GmbH 15

  • In assembler
  • In C with Macros
  • By hand in C++
  • Aggregation
  • Inheritance + virtual functions
slide-16
SLIDE 16

@odinthenerd

Bare metal drivers

Auto-Intern GmbH 16

  • In assembler
  • In C with Macros
  • By hand in C++
  • Aggregation
  • Inheritance + virtual functions
  • Inheritance + CRTP
slide-17
SLIDE 17

@odinthenerd

Inspiration in

  • ld

book form

Auto-Intern GmbH 17

slide-18
SLIDE 18

@odinthenerd

Bare metal drivers

Auto-Intern GmbH 18

  • In assembler
  • In C with Macros
  • By hand in C++
  • Aggregation
  • Inheritance + virtual functions
  • Inheritance + CRTP
slide-19
SLIDE 19

@odinthenerd

Auto-Intern GmbH 19

Even your cat will like you!

slide-20
SLIDE 20

@odinthenerd

Auto-Intern GmbH 20

Implementation details

slide-21
SLIDE 21

@odinthenerd

Auto-Intern GmbH 21

Mixin composition

ring() blow() guts more_guts

slide-22
SLIDE 22

@odinthenerd

Code example

Auto-Intern GmbH 22

auto thing = mixin::compose( mixin::interface<bells, whistles>, guts, more_guts);

slide-23
SLIDE 23

@odinthenerd

Code example

Auto-Intern GmbH 23

auto thing = mixin::compose( mixin::interface<bells, whistles>, guts, more_guts);

slide-24
SLIDE 24

@odinthenerd

Code example

Auto-Intern GmbH 24

auto thing = mixin::compose( mixin::interface<bells, whistles>, guts, more_guts);

slide-25
SLIDE 25

@odinthenerd

Code example

Auto-Intern GmbH 25

auto thing = mixin::compose( mixin::interface<bells, whistles>, guts{haggis}, more_guts);

slide-26
SLIDE 26

@odinthenerd

Code example

Auto-Intern GmbH 26

auto thing = mixin::compose( mixin::interface<bells, whistles>, guts{haggis}, more_guts); thing.ring();

slide-27
SLIDE 27

@odinthenerd

Code example

Auto-Intern GmbH 27

auto thing = mixin::compose( mixin::interface<bells, whistles>, guts{haggis}, more_guts, my_allocator{arena});

slide-28
SLIDE 28

@odinthenerd

Definition of terms

Auto-Intern GmbH 28

  • Composition
slide-29
SLIDE 29

@odinthenerd

Auto-Intern GmbH 29

Mixin composition

ring() blow() guts more_guts my_allocator

slide-30
SLIDE 30

@odinthenerd

Composition

Auto-Intern GmbH 30

auto thing = mixin::compose( mixin::interface<bells, whistles>, guts{haggis}, more_guts, my_allocator{arena});

slide-31
SLIDE 31

@odinthenerd

Definition of terms

Auto-Intern GmbH 31

  • Composition
  • Interface / Implementation
slide-32
SLIDE 32

@odinthenerd

Auto-Intern GmbH 32

Mixin composition

ring() blow() guts more_guts my_allocator

slide-33
SLIDE 33

@odinthenerd

Interface

Auto-Intern GmbH 33

template<typename T> struct bells : T { void ring(); };

slide-34
SLIDE 34

@odinthenerd

Interface – concept

Auto-Intern GmbH 34

template<typename T> struct bells : T { void ring(); };

slide-35
SLIDE 35

@odinthenerd

Interface – adds to the composition objects interface

Auto-Intern GmbH 35

template<typename T> struct bells : T { void ring(); };

slide-36
SLIDE 36

@odinthenerd

Auto-Intern GmbH 36

Mixin composition

ring() blow() guts more_guts my_allocator

slide-37
SLIDE 37

@odinthenerd

Implementation

Auto-Intern GmbH 37

struct guts { };

slide-38
SLIDE 38

@odinthenerd

Definition of terms

Auto-Intern GmbH 38

  • Composition
  • Interface / Implementation
  • Abilities
slide-39
SLIDE 39

@odinthenerd

Auto-Intern GmbH 39

Mixin composition

ring() blow() guts more_guts my_allocator

slide-40
SLIDE 40

@odinthenerd

Abilities

Auto-Intern GmbH 40

struct ringable{};

slide-41
SLIDE 41

@odinthenerd

Find mixins by ability

Auto-Intern GmbH 41

template<typename T> struct bells : T{ void ring(){ for_each(this, ability<ringable>, [](auto& a){ a.ring(); }); } };

slide-42
SLIDE 42

@odinthenerd

Associating abilities with a mixin

Auto-Intern GmbH 42

using guts = make_mixin< guts_impl, ringable, magic_frog_power, allocator_use_capable>;

slide-43
SLIDE 43

@odinthenerd

Definition of terms

Auto-Intern GmbH 43

  • Composition
  • Interface / Implementation
  • Abilities
  • Requirements
slide-44
SLIDE 44

@odinthenerd

Find mixins by ability 0-n

Auto-Intern GmbH 44

template<typename T> struct bells : T{ void ring(){ for_each(this, ability<ringable>, [](auto& a){ a.ring(); }); } };

slide-45
SLIDE 45

@odinthenerd

Find mixins by ability exactly 1

Auto-Intern GmbH 45

template<typename T> struct bells : T{ void ring(){ execute(this, ability<ringable>, [](auto& a){ a.ring(); }); } };

slide-46
SLIDE 46

@odinthenerd

Find mixins that match an arbitrary predicate

Auto-Intern GmbH 46

template<typename T> struct bells : T{ void ring(){ call_on(this, predicate<my_selector>, [](auto& a){ a.ring(); }); } };

slide-47
SLIDE 47

@odinthenerd

Auto-Intern GmbH 47

Mixin composition

ring() blow() guts more_guts my_allocator

slide-48
SLIDE 48

@odinthenerd

Return type of compose()

Auto-Intern GmbH 48

template<typename... Ts> class composition:public call_<detail::make_base<composition<Ts...>>, Ts...> { std::tuple<Ts...> data; //… };

slide-49
SLIDE 49

@odinthenerd

Return type of compose()

Auto-Intern GmbH 49

template<typename... Ts> class composition:public call_<detail::make_base<composition<Ts...>>, Ts...> { std::tuple<Ts...> data; //… }; protect<access<composition<Ts…>>> Protect Access

slide-50
SLIDE 50

@odinthenerd

Protect

Auto-Intern GmbH 50

template<typename T> struct protect : protected T {}; protect<access<composition<Ts…>>> Protect Access

slide-51
SLIDE 51

@odinthenerd

Return type of compose()

Auto-Intern GmbH 51

template<typename... Ts> class composition:public call_<detail::make_base<composition<Ts...>>, Ts...> { std::tuple<Ts...> data; //… }; interface1<protect<access<composition<Ts…>>>> Interface 1 Protect Access

slide-52
SLIDE 52

@odinthenerd

Return type of compose()

Auto-Intern GmbH 52

template<typename... Ts> class composition:public call_<detail::make_base<composition<Ts...>>, Ts...> { std::tuple<Ts...> data; //… }; interface2<interface1<protect<access<composition<Ts…>>>>> Interface 2 Interface 1 Protect Access

slide-53
SLIDE 53

@odinthenerd

Return type of compose()

Auto-Intern GmbH 53

template<typename... Ts> class composition:public call_<detail::make_base<composition<Ts...>>, Ts...> { std::tuple<Ts...> data; //… }; interface3<interface2<interface1<protect<access<composition<Ts…>>>>>> Interface 3 Interface 2 Interface 1 Protect Access

slide-54
SLIDE 54

@odinthenerd

Return type of compose()

Auto-Intern GmbH 54

template<typename... Ts> class composition:public call_<detail::make_base<composition<Ts...>>, Ts...> { std::tuple<Ts...> data; //… }; interface3<interface2<interface1<protect<access<composition<Ts…>>>>>> Interface 3 Interface 2 Interface 1 Protect Access Composition

slide-55
SLIDE 55

@odinthenerd

Completing the circle

Auto-Intern GmbH 55

template<typename... Ts> class composition:public call_<detail::make_base<composition<Ts...>>, Ts...> { std::tuple<Ts...> data; //… }; interface3<interface2<interface1<protect<access<composition<Ts…>>>>>> Composition Interface 3 Interface 2 Interface 1 Protect Access

slide-56
SLIDE 56

@odinthenerd

Access

Auto-Intern GmbH 56

Composition Interface 3 Interface 2 Interface 1 Protect Access

template<typename T> struct access { auto& get_data(){ return static_cast<T*>(this)->data; } };

slide-57
SLIDE 57

@odinthenerd

Encapsulation

Auto-Intern GmbH 57

template<typename... Ts> class composition:public call_<detail::make_base<composition<Ts...>>, Ts...> { std::tuple<Ts...> data; friend access<composition<Ts...>>; //… }; Composition Interface 3 Interface 2 Interface 1 Protect Access

slide-58
SLIDE 58

@odinthenerd

Public interface call

Auto-Intern GmbH 58

Composition Interface 3 Interface 2 Interface 1 Protect Access

template<typename T> struct bells : T{ void ring(){ for_each(this, ability<ringable>, [](auto& m){ m.ring(); }); } };

slide-59
SLIDE 59

@odinthenerd

for_each

Auto-Intern GmbH 59

Composition Interface 3 Interface 2 Interface 1 Protect Access

template<typename T, typename A, typename L> void for_each(access<T>* p, A, L l){ auto& data = p->get_data(); //magic here }

slide-60
SLIDE 60

@odinthenerd

Auto-Intern GmbH 60

Mixin composition

ring() blow() guts more_guts my_allocator

slide-61
SLIDE 61

@odinthenerd

Inter implementation mixin access

Auto-Intern GmbH 61

template<typename T> struct bells : T{ void ring(){ for_each(this, ability<ringable>, [a = access_to(this)](auto& m){ m.ring(a); } ); } };

slide-62
SLIDE 62

@odinthenerd

Auto-Intern GmbH 62

Mixin composition

ring() blow() guts more_guts my_allocator

slide-63
SLIDE 63

@odinthenerd

Init and Destruct

Auto-Intern GmbH 63

template<typename... Ts> class composition:public call_<detail::make_base<composition<Ts...>>, Ts...> { //… public: composition(std::tuple<Ts...> &&d) : data{std::move(d)} { for_each(this,ability<requires_init_and_destruct>, detail::call_init(this)); } ~composition() { for_each(this,ability<requires_init_and_destruct>, detail::call_destruct(this)); } };

slide-64
SLIDE 64

@odinthenerd

Auto-Intern GmbH 64

Can we build a fixed_vector?

begin() end() size() Index operator push_back() Fixed size buffer Contiguous control block

slide-65
SLIDE 65

@odinthenerd

Can we build fixed_vector?

Auto-Intern GmbH 65

  • Data footprint dependent on other mixins
slide-66
SLIDE 66

@odinthenerd

Auto-Intern GmbH 66

fixed_vector

begin() end() size() Index operator push_back() Fixed size buffer Contiguous control block

slide-67
SLIDE 67

@odinthenerd

Dynamic mixins

Auto-Intern GmbH 67

using guts = make_dynamic_mixin< fixed_buffer_factory, allocator>;

slide-68
SLIDE 68

@odinthenerd

Return type of compose()

Auto-Intern GmbH 68

template<typename... Ts> class composition:public call_<detail::make_base<composition<Ts...>>, Ts...> { std::tuple<Ts...> data; //… };

slide-69
SLIDE 69

@odinthenerd

Return type of compose()

Auto-Intern GmbH 69

template<typename... Ts> class composition:public call_<detail::make_base<composition<Ts...>>, Ts...> { std::tuple<call_<Ts, Ts...>...> data; //… };

slide-70
SLIDE 70

@odinthenerd

Can we build fixed_vector

Auto-Intern GmbH 70

  • Data footprint dependent on other mixins
  • Debug builds are bloated
slide-71
SLIDE 71

@odinthenerd

Can we build fixed_vector

Auto-Intern GmbH 71

  • Data footprint dependent on other mixins
  • Debug builds are bloated
  • Iterator validity contracts are hard
slide-72
SLIDE 72

@odinthenerd

Can we build fixed_vector

Auto-Intern GmbH 72

  • Data footprint dependent on other mixins
  • Debug builds are bloated
  • Iterator validity contracts are hard
  • Testing is hard
slide-73
SLIDE 73

@odinthenerd

Can we build fixed_vector

Auto-Intern GmbH 73

  • Data footprint dependent on other mixins
  • Debug builds are bloated
  • Iterator validity contracts are hard
  • Testing is hard
  • Constructors are hard
slide-74
SLIDE 74

@odinthenerd

Can we build industrial strength GUIs?

Auto-Intern GmbH 74

slide-75
SLIDE 75

@odinthenerd

Qt

Auto-Intern GmbH 75

slide-76
SLIDE 76

@odinthenerd

Qt

Auto-Intern GmbH 76

slide-77
SLIDE 77

@odinthenerd

Qt

Auto-Intern GmbH 77

slide-78
SLIDE 78

@odinthenerd

Qt

Auto-Intern GmbH 78

slide-79
SLIDE 79

@odinthenerd

Statically linking Widgets

Auto-Intern GmbH 79

auto font_dialog = dialog( v_box_layout( grid_layout( dimentions(2_c, 2_c), //bunch of widgets ), h_box_layout( h_stretch, push_button("Ok",ok_action), push_button("Cancel",cancel_action) ) ) );

slide-80
SLIDE 80

@odinthenerd

Statically linking Widgets

Auto-Intern GmbH 80

auto font_dialog = dialog( v_box_layout( grid_layout( dimentions(2_c, 2_c), //bunch of widgets ), h_box_layout( h_stretch, push_button("Ok",ok_action), push_button("Cancel",cancel_action) ) ) );

slide-81
SLIDE 81

@odinthenerd

Statically linking Widgets

Auto-Intern GmbH 81

auto font_dialog = dialog( v_box_layout( grid_layout( dimentions(2_c, 2_c), //bunch of widgets ), h_box_layout( h_stretch, push_button("Ok",ok_action), push_button("Cancel",cancel_action) ) ) );

slide-82
SLIDE 82

@odinthenerd

Statically linking Widgets

Auto-Intern GmbH 82

template<typename...Ts> auto v_box_layout(Ts...args){ return compose(ability<widget_event_subscribe>, interface<widget_interface>, widget_event_forward_to_children{}, drawable_v_box{}, args... ); }

slide-83
SLIDE 83

@odinthenerd

Statically linking Widgets

Auto-Intern GmbH 83

template<typename...Ts> auto v_box_layout(Ts...args){ return compose(ability<widget_event_subscribe>, interface<widget_interface>, widget_event_forward_to_children{}, drawable_v_box{}, args... ); }

slide-84
SLIDE 84

@odinthenerd

Statically linking Widgets

Auto-Intern GmbH 84

template<typename...Ts> auto v_box_layout(Ts...args){ return compose(ability<widget_event_subscribe>, interface<widget_interface>, widget_event_forward_to_children{}, drawable_v_box{}, args... ); }

slide-85
SLIDE 85

@odinthenerd

Qt

Auto-Intern GmbH 85

slide-86
SLIDE 86

@odinthenerd

Event dispatch

Auto-Intern GmbH 86

template<typename B> struct widget_interface : B{ template<typename E> auto dispatch_event(E& e){ return for_each(this,ability<widget_event_subscribe>, gather<E>, [a = access_to(this),&](auto& m){m.dispatch_event(e,a);}); } template<typename E, typename A> auto dispatch_event(E& e, A a){ return for_each(this,ability<widget_event_subscribe>, gather<E>, [&](auto& m){m.dispatch_event(e,a);}); } };

slide-87
SLIDE 87

@odinthenerd

Qt

Auto-Intern GmbH 87

slide-88
SLIDE 88

@odinthenerd

Signals slots

Auto-Intern GmbH 88

template<typename T> struct on_keypress{ template<typename A, typename R> auto consume_event(keypress_event e, A a, R root){ //... root.dispatch_event( signal_event(signal_name<T>,a)); } };

slide-89
SLIDE 89

@odinthenerd

Signals slots

Auto-Intern GmbH 89

slide-90
SLIDE 90

@odinthenerd

Signals slots

Auto-Intern GmbH 90

slide-91
SLIDE 91

@odinthenerd

Signals slots

Auto-Intern GmbH 91

slide-92
SLIDE 92

@odinthenerd

Signals slots

Auto-Intern GmbH 92

slide-93
SLIDE 93

@odinthenerd

Signals slots

Auto-Intern GmbH 93

slide-94
SLIDE 94

@odinthenerd

Step 7

  • f

17 step hello world tutorial

Auto-Intern GmbH 94

slide-95
SLIDE 95

@odinthenerd

drivers

Auto-Intern GmbH 95

auto myUart = make_uart( interface<blocking_tx>, uart1, 9600_baud, rx = 0.9_pin, tx = 0.10_pin ); myuart.blocking_send("hello world");

slide-96
SLIDE 96

@odinthenerd

Auto-Intern GmbH 96

Serial_port

blocking_tx uart1 baud_t<uint<9600>> rx_pin_t<pin<0,9>> tx_pin_t<pin<0,10>>

slide-97
SLIDE 97

@odinthenerd

Liberasure style composable type erasure

Auto-Intern GmbH 97

auto thing = erase(interface<foo,bar>); thing = compose(interface<foo,bar,baz>, some_guts{},

  • ther_guts{});

thing = compose(interface<foo,bar,ding,dong>, james_bond{}, martini{}, blond{}, redhead{});

slide-98
SLIDE 98

@odinthenerd

@odinthenerd

04.11.2016 Auto-Intern GmbH 98

  • Github.com
  • Twitter.com
  • Gmail.com
  • Blogspot.com
  • LinkedIn.com
  • Embo.io