@odinthenerd
@odin
- dinthe
thener nerd
– not the god
Auto-Intern GmbH 1
@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
@odinthenerd
– not the god
Auto-Intern GmbH 1
@odinthenerd
Auto-Intern GmbH 2
Hana Dusíková compile time regex
@odinthenerd
Auto-Intern GmbH 3
Mixins
@odinthenerd
Auto-Intern GmbH 4
@odinthenerd
Bare metal drivers
Auto-Intern GmbH 5
@odinthenerd
Bare metal drivers
Auto-Intern GmbH 6
@odinthenerd
Bare metal drivers
Auto-Intern GmbH 7
@odinthenerd
Bare metal drivers
Auto-Intern GmbH 8
@odinthenerd
Bare metal drivers
Auto-Intern GmbH 9
@odinthenerd
Bare metal drivers
Auto-Intern GmbH 10
@odinthenerd
Bare metal drivers
Auto-Intern GmbH 11
@odinthenerd
Bare metal drivers
Auto-Intern GmbH 12
@odinthenerd
Bare metal drivers
Auto-Intern GmbH 13
@odinthenerd
Bare metal drivers
Auto-Intern GmbH 14
@odinthenerd
Bare metal drivers
Auto-Intern GmbH 15
@odinthenerd
Bare metal drivers
Auto-Intern GmbH 16
@odinthenerd
Inspiration in
book form
Auto-Intern GmbH 17
@odinthenerd
Bare metal drivers
Auto-Intern GmbH 18
@odinthenerd
Auto-Intern GmbH 19
@odinthenerd
Auto-Intern GmbH 20
Implementation details
@odinthenerd
Auto-Intern GmbH 21
Mixin composition
ring() blow() guts more_guts
@odinthenerd
Code example
Auto-Intern GmbH 22
auto thing = mixin::compose( mixin::interface<bells, whistles>, guts, more_guts);
@odinthenerd
Code example
Auto-Intern GmbH 23
auto thing = mixin::compose( mixin::interface<bells, whistles>, guts, more_guts);
@odinthenerd
Code example
Auto-Intern GmbH 24
auto thing = mixin::compose( mixin::interface<bells, whistles>, guts, more_guts);
@odinthenerd
Code example
Auto-Intern GmbH 25
auto thing = mixin::compose( mixin::interface<bells, whistles>, guts{haggis}, more_guts);
@odinthenerd
Code example
Auto-Intern GmbH 26
auto thing = mixin::compose( mixin::interface<bells, whistles>, guts{haggis}, more_guts); thing.ring();
@odinthenerd
Code example
Auto-Intern GmbH 27
auto thing = mixin::compose( mixin::interface<bells, whistles>, guts{haggis}, more_guts, my_allocator{arena});
@odinthenerd
Definition of terms
Auto-Intern GmbH 28
@odinthenerd
Auto-Intern GmbH 29
Mixin composition
ring() blow() guts more_guts my_allocator
@odinthenerd
Composition
Auto-Intern GmbH 30
auto thing = mixin::compose( mixin::interface<bells, whistles>, guts{haggis}, more_guts, my_allocator{arena});
@odinthenerd
Definition of terms
Auto-Intern GmbH 31
@odinthenerd
Auto-Intern GmbH 32
Mixin composition
ring() blow() guts more_guts my_allocator
@odinthenerd
Interface
Auto-Intern GmbH 33
template<typename T> struct bells : T { void ring(); };
@odinthenerd
Interface – concept
Auto-Intern GmbH 34
template<typename T> struct bells : T { void ring(); };
@odinthenerd
Interface – adds to the composition objects interface
Auto-Intern GmbH 35
template<typename T> struct bells : T { void ring(); };
@odinthenerd
Auto-Intern GmbH 36
Mixin composition
ring() blow() guts more_guts my_allocator
@odinthenerd
Implementation
Auto-Intern GmbH 37
struct guts { };
@odinthenerd
Definition of terms
Auto-Intern GmbH 38
@odinthenerd
Auto-Intern GmbH 39
Mixin composition
ring() blow() guts more_guts my_allocator
@odinthenerd
Abilities
Auto-Intern GmbH 40
struct ringable{};
@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(); }); } };
@odinthenerd
Associating abilities with a mixin
Auto-Intern GmbH 42
using guts = make_mixin< guts_impl, ringable, magic_frog_power, allocator_use_capable>;
@odinthenerd
Definition of terms
Auto-Intern GmbH 43
@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(); }); } };
@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(); }); } };
@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(); }); } };
@odinthenerd
Auto-Intern GmbH 47
Mixin composition
ring() blow() guts more_guts my_allocator
@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; //… };
@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
@odinthenerd
Protect
Auto-Intern GmbH 50
template<typename T> struct protect : protected T {}; protect<access<composition<Ts…>>> Protect Access
@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
@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
@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
@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
@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
@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; } };
@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
@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(); }); } };
@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 }
@odinthenerd
Auto-Intern GmbH 60
Mixin composition
ring() blow() guts more_guts my_allocator
@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); } ); } };
@odinthenerd
Auto-Intern GmbH 62
Mixin composition
ring() blow() guts more_guts my_allocator
@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)); } };
@odinthenerd
Auto-Intern GmbH 64
Can we build a fixed_vector?
begin() end() size() Index operator push_back() Fixed size buffer Contiguous control block
@odinthenerd
Can we build fixed_vector?
Auto-Intern GmbH 65
@odinthenerd
Auto-Intern GmbH 66
fixed_vector
begin() end() size() Index operator push_back() Fixed size buffer Contiguous control block
@odinthenerd
Dynamic mixins
Auto-Intern GmbH 67
using guts = make_dynamic_mixin< fixed_buffer_factory, allocator>;
@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; //… };
@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; //… };
@odinthenerd
Can we build fixed_vector
Auto-Intern GmbH 70
@odinthenerd
Can we build fixed_vector
Auto-Intern GmbH 71
@odinthenerd
Can we build fixed_vector
Auto-Intern GmbH 72
@odinthenerd
Can we build fixed_vector
Auto-Intern GmbH 73
@odinthenerd
Can we build industrial strength GUIs?
Auto-Intern GmbH 74
@odinthenerd
Qt
Auto-Intern GmbH 75
@odinthenerd
Qt
Auto-Intern GmbH 76
@odinthenerd
Qt
Auto-Intern GmbH 77
@odinthenerd
Qt
Auto-Intern GmbH 78
@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) ) ) );
@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) ) ) );
@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) ) ) );
@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... ); }
@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... ); }
@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... ); }
@odinthenerd
Qt
Auto-Intern GmbH 85
@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);}); } };
@odinthenerd
Qt
Auto-Intern GmbH 87
@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)); } };
@odinthenerd
Signals slots
Auto-Intern GmbH 89
@odinthenerd
Signals slots
Auto-Intern GmbH 90
@odinthenerd
Signals slots
Auto-Intern GmbH 91
@odinthenerd
Signals slots
Auto-Intern GmbH 92
@odinthenerd
Signals slots
Auto-Intern GmbH 93
@odinthenerd
Step 7
17 step hello world tutorial
Auto-Intern GmbH 94
@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");
@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>>
@odinthenerd
Liberasure style composable type erasure
Auto-Intern GmbH 97
auto thing = erase(interface<foo,bar>); thing = compose(interface<foo,bar,baz>, some_guts{},
thing = compose(interface<foo,bar,ding,dong>, james_bond{}, martini{}, blond{}, redhead{});
@odinthenerd
@odinthenerd
04.11.2016 Auto-Intern GmbH 98