agent based class design - c++ europe conference€¦ · @odinthenerd what is the problem...
TRANSCRIPT
![Page 1: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/1.jpg)
@odinthenerd
Agent based class design
Auto-Intern GmbH 1
![Page 2: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/2.jpg)
@odinthenerd
@odinthenerd
–origin story
Auto-Intern GmbH 2
![Page 3: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/3.jpg)
@odinthenerd
Odinthehippiekid
Auto-Intern GmbH 3
![Page 4: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/4.jpg)
@odinthenerd
Abstract hippie
Auto-Intern GmbH 4
![Page 5: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/5.jpg)
@odinthenerd
Talknerdytome
Auto-Intern GmbH 5
![Page 6: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/6.jpg)
@odinthenerd
Inspirationinoldbookform
Auto-Intern GmbH 6
![Page 7: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/7.jpg)
@odinthenerd
Auto-Intern GmbH 7
think of something
implement it (feel like an idiot)
solicit feedback
look like an idiot
fix it
![Page 8: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/8.jpg)
@odinthenerd
What is the problem
Auto-Intern GmbH 8
• Non thread safe std::shared_pointer• Nothrow std::function• Inplace everything• Qt• Embedded drivers
![Page 9: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/9.jpg)
@odinthenerd
std::shared_ptr in pieces
Auto-Intern GmbH 9
template<typename T>
using shared_ptr = composed<
interface_t<shared_pointer_interface,
shared_from_nullptr_t,
shared_from_ptr,
array_indexing>,
shared_pointer_value<T>,
erased_allocator,
erased_deleter,
atomic_counter,
atomic_weak_counter,
ub_on_empty_use>;
shared_ptr<something> p(new something(input));
![Page 10: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/10.jpg)
@odinthenerd
My shared_ptr, only what I want
Auto-Intern GmbH 10
template<typename T>
using my_shared_ptr = composed<
interface_t<shared_pointer_interface,
hana_style_make>,
shared_pointer_value<T>,
thread_local_counter,
terminate_on_empty_use>;
my_shared_ptr<something> p(make<something>,input);
![Page 11: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/11.jpg)
@odinthenerd
What is the problem
Auto-Intern GmbH 11
• Non thread safe std::shared_pointer• Nothrow std::function• Inplace everything• Qt• Embedded drivers
![Page 12: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/12.jpg)
@odinthenerd
Qt
Auto-Intern GmbH 12
![Page 13: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/13.jpg)
@odinthenerd
Qt
Auto-Intern GmbH 13
![Page 14: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/14.jpg)
@odinthenerd
Qt
Auto-Intern GmbH 14
![Page 15: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/15.jpg)
@odinthenerd
Qt
Auto-Intern GmbH 15
![Page 16: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/16.jpg)
@odinthenerd
Statically linking Widgets
Auto-Intern GmbH 16
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)
)
)
);
![Page 17: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/17.jpg)
@odinthenerd
template<typename C = identity>
struct build_indexed {
template <typename... Ts>
using f = typename C::template f<detail::id<typename detail::id_builder<(
sizeof...(Ts) > 16 ? 3 : 1)>::template f<Ts...>>>;
};
template<>
struct build_indexed<identity> {
template <typename... Ts>
using f = detail::id<typename detail::id_builder<(
sizeof...(Ts) > 16 ? 3 : 1)>::template f<Ts...>>;
};
The notorious T M P
Image: genius.com 17
![Page 18: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/18.jpg)
@odinthenerd
TabeaMariePaul
Auto-Intern GmbH 18
![Page 19: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/19.jpg)
@odinthenerd
What is the problem
Auto-Intern GmbH 19
• Non thread safe std::shared_pointer• Nothrow std::function• Inplace everything• Qt• Embedded drivers
![Page 20: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/20.jpg)
@odinthenerd
Step 7 of 17stephelloworldtutorial
Auto-Intern GmbH 20
![Page 21: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/21.jpg)
@odinthenerd
drivers
Auto-Intern GmbH 21
auto myUart = compose(
interface<blocking_tx>,
uart1,
9600_baud,
rx = 0.9_pin,
tx = 0.10_pin
);
myuart.blocking_send("hello world");
![Page 22: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/22.jpg)
@odinthenerd
Policy based class design all the things!
Auto-Intern GmbH 22
![Page 23: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/23.jpg)
@odinthenerd
Auto-Intern GmbH 23
think of something
implement it (feel like an idiot)
solicit feedback
look like an idiot
fix it
You are here
![Page 24: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/24.jpg)
@odinthenerd
Auto-Intern GmbH 24
![Page 25: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/25.jpg)
@odinthenerd
Auto-Intern GmbH 25
think of something
implement it (feel like an idiot)
solicit feedback
look like an idiot
fix it
You are here
![Page 26: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/26.jpg)
@odinthenerd
#windmill
Auto-Intern GmbH 26
![Page 27: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/27.jpg)
@odinthenerd
#Fail
Auto-Intern GmbH 27
![Page 28: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/28.jpg)
@odinthenerd
Auto-Intern GmbH 28
![Page 29: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/29.jpg)
@odinthenerd
Why did I fail?
Auto-Intern GmbH 29
![Page 30: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/30.jpg)
@odinthenerd
Stealing terms
Auto-Intern GmbH 30
![Page 31: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/31.jpg)
@odinthenerd
Auto-Intern GmbH 31
think of something
implement it (feel like an idiot)
solicit feedback
look like an idiot
fix it
scienceengineering
![Page 32: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/32.jpg)
@odinthenerd
Agent Based Class Design
Auto-Intern GmbH 32
Agt. Smith
![Page 33: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/33.jpg)
@odinthenerd
Valid set of agents
Auto-Intern GmbH 33
Agt. Smith Agt. Jones
Squiddy
![Page 34: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/34.jpg)
@odinthenerd
Enough UML crap
Auto-Intern GmbH 34
auto mob = compose(
agt_smith{},
agt_jones{},
squiddy{});
mob.kick_neos_ass();
![Page 35: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/35.jpg)
@odinthenerd
Valid set of agents
Auto-Intern GmbH 35
Agt. Smith Agt. Jones
Squiddy
![Page 36: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/36.jpg)
@odinthenerd
Agent
Auto-Intern GmbH 37
struct agt_smith{
void kick_ass(){
}
};
![Page 37: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/37.jpg)
@odinthenerd
Mapping abilities to agents
Auto-Intern GmbH 38
struct agt_smith_impl{
void kick_ass(){
}
};
using agt_smith = agent<
ability_t<ass_kicking>,
agt_smith_impl>;
![Page 38: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/38.jpg)
@odinthenerd
Public interface
Auto-Intern GmbH 39
template<typename B>
struct public_ass_kicking : B{
void kick_neos_ass(){
B::for_each(ability<ass_kicking>,[](auto& a){
a.kick_ass();
});
}
};
![Page 39: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/39.jpg)
@odinthenerd
Public interface
Auto-Intern GmbH 40
template<typename B>
struct public_talking : B{
void talk(){
B::for_each(ability<agent_speak>,
[&agts = B::agents()](auto& a){
a.talk_oddly(agts);
});
}
};
![Page 40: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/40.jpg)
@odinthenerd
Agents talk to each other
Auto-Intern GmbH 41
struct agt_smith{
template<typename T>
void talk_oddly(T& agents){
agents.for_each(
ability<agent_listen>,
[](auto& a){
a.listen(”Never send a human to do a machine's job.
- Agent Smith on statically checked interfaces”);
});
}
};
![Page 41: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/41.jpg)
@odinthenerd
0 – 1 optional
Auto-Intern GmbH 42
struct agt_jones{
template<typename T>
void talk_oddly(T& agents){
agents.optional(
ability<agent_listen>,
[](auto& a){
a.listen(”I hate this place. This zoo. This prison.”);
});
}
};
![Page 42: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/42.jpg)
@odinthenerd
0 – 1 optional with fallback
Auto-Intern GmbH 43
struct agt_smith{
template<typename T>
void talk_oddly(T& agents){
agents.optional(
abcd::ability<agent_listen>,
[](auto& a){
a.listen(”I hate this place. This zoo. This prison.”);
},
[](){
feel_lonley();
cry();
}
);
}
};
![Page 43: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/43.jpg)
@odinthenerd
Exactly 1
Auto-Intern GmbH 44
struct agt_squiddy{
template<typename T>
void talk_oddly(T& agents){
agents.execute(
ability<highlander>,
[](auto& a){
a.listen(”There can be only one.”);
});
}
};
![Page 44: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/44.jpg)
@odinthenerd
compose()
Auto-Intern GmbH 45
template<typename...Ts>
composed<Ts...> compose(Ts...args){
return composed<Ts...>(
std::tuple<Ts...>{args...}
);
}
![Page 45: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/45.jpg)
@odinthenerd
Return type of compose()
Auto-Intern GmbH 46
template<typename... Ts>
class composed : public mpl::call<detail::make_base<composed<Ts...>>, Ts...>
{
std::tuple<Ts...> data;
//…
};
![Page 46: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/46.jpg)
@odinthenerd
Return type of compose()
Auto-Intern GmbH 47
template<typename... Ts>
class composed : public mpl::call<detail::make_base<composed<Ts...>>, Ts...>
{
std::tuple<Ts...> data;
//…
};
Access
![Page 47: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/47.jpg)
@odinthenerd
Return type of compose()
Auto-Intern GmbH 48
template<typename... Ts>
class composed : public mpl::call<detail::make_base<composed<Ts...>>, Ts...>
{
std::tuple<Ts...> data;
//…
};
Interface 1 Access
![Page 48: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/48.jpg)
@odinthenerd
Return type of compose()
Auto-Intern GmbH 49
template<typename... Ts>
class composed : public mpl::call<detail::make_base<composed<Ts...>>, Ts...>
{
std::tuple<Ts...> data;
//…
};
Interface 2 Interface 1 Access
![Page 49: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/49.jpg)
@odinthenerd
Return type of compose()
Auto-Intern GmbH 50
template<typename... Ts>
class composed : public mpl::call<detail::make_base<composed<Ts...>>, Ts...>
{
std::tuple<Ts...> data;
//…
};
Interface 3 Interface 2 Interface 1 Access
![Page 50: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/50.jpg)
@odinthenerd
Return type of compose()
Auto-Intern GmbH 51
template<typename... Ts>
class composed : public mpl::call<detail::make_base<composed<Ts...>>, Ts...>
{
std::tuple<Ts...> data;
//…
};
Composed Interface 3 Interface 2 Interface 1 Access
![Page 51: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/51.jpg)
@odinthenerd
Return type of compose()
Auto-Intern GmbH 52
template<typename... Ts>
class composed : public mpl::call<detail::make_base<composed<Ts...>>, Ts...>
{
std::tuple<Ts...> data;
//…
};
Composed Interface 3 Interface 2 Interface 1 Access
![Page 52: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/52.jpg)
@odinthenerd
Return type of compose()
Auto-Intern GmbH 53
template<typename... Ts>
class composed : public mpl::call<detail::make_base<composed<Ts...>>, Ts...>
{
std::tuple<Ts...> data;
friend access<composed<Ts...>>;
//…
};
![Page 53: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/53.jpg)
@odinthenerd
Return type of compose()
Auto-Intern GmbH 54
template<typename... Ts>
class composed : public mpl::call<detail::make_base<composed<Ts...>>, Ts...>
{
std::tuple<Ts...> data;
friend access<composed<Ts...>>;
private:
using access<composed<Ts...>>::for_each;
//…
};
![Page 54: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/54.jpg)
@odinthenerd
Return type of compose()
Auto-Intern GmbH 55
template<typename... Ts>
class composed : public mpl::call<detail::make_base<composed<Ts...>>, Ts...>
{
//…
public:
composed(std::tuple<Ts...> &&d) : data{std::move(d)} {
for_each(data,ability<requires_init_and_destruct>,
detail::call_init{});
}
~composed() {
for_each(data,ability<requires_init_and_destruct>,
detail::call_destruct{});
}
};
![Page 55: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/55.jpg)
@odinthenerd
to_upper
Auto-Intern GmbH 56
![Page 56: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/56.jpg)
@odinthenerd
to_upper
Auto-Intern GmbH 57
struct ASCII_to_upper{
char operator()(const char c){
if(c>='a' && c<='z'){
return (c - 'a')+ 'A';
}
return c;
}
};
![Page 57: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/57.jpg)
@odinthenerd
to_upper
Auto-Intern GmbH 58
struct ASCII_to_upper{
template<typename T, typename U>
char operator()(T& in_begin, T& in_end, U& out_begin, U& out_end){
auto c = *in_begin;
if(c>='a' && c<='z' && out_begin != out_end){
++in_begin;
*out_begin++ = (c - 'a')+ 'A';
return true;
}
return false;
}
};
![Page 58: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/58.jpg)
@odinthenerd
String formatting
Auto-Intern GmbH 59
cout << compose(
"my IQ is {} but today its {} because I slept {} hours"_format,
fmt::int_{90},
fmt::zerofill_int{65},
fmt::hex{2} ).string();
![Page 59: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/59.jpg)
@odinthenerd
drivers
Auto-Intern GmbH 60
auto myUart = compose(
interface<blocking_tx>,
uart1,
9600_baud,
rx = 0.9_pin,
tx = 0.10_pin
);
myuart.blocking_send("hello world");
![Page 60: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/60.jpg)
@odinthenerd
Auto baud public
Auto-Intern GmbH 61
template<typename B>
struct uart_auto_baud_public : B{
void reset_auto_baud(){
execute(abcd::by_type<uart_auto_baud>,[](auto& a){
a.reset();
});
}
bool auto_baud_is_set(){
bool ret = false;
execute(abcd::by_type<uart_auto_baud>,[&ret](auto& a){
ret = a.is_set();
});
return ret;
}
};
![Page 61: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/61.jpg)
@odinthenerd
Statically linking Widgets
Auto-Intern GmbH 62
auto 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)
)
)
);
![Page 62: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/62.jpg)
@odinthenerd
Statically linking Widgets
Auto-Intern GmbH 63
template<typename...Ts>
auto v_box_layout(Ts...args){
return compose(abilities<widget_event_subscribe>,
interface<widget_interface>,
widget_event_forward_to_children{},
drawable_v_box{},
args...
);
}
![Page 63: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/63.jpg)
@odinthenerd
Liberasure style composable type erasure
Auto-Intern GmbH 64
auto interface = erase(interface<foo,bar>);
interface = compose(interface<foo,bar,baz>,
some_agent{},
other_agent{});
interface = compose(interface<foo,bar,ding,dong>,
james_bond{},
martini{},
blond{},
redhead{});
![Page 64: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/64.jpg)
@odinthenerd
initializing agentsfromconstructorargs
Auto-Intern GmbH 65
template<typename T>
using shared_ptr = composed<
interface_t<shared_pointer_interface,
weak_pointer_interface>,
shared_pointer_value<T>,
atomic_counter,
atomic_weak_counter,
throw_on_empty_use>;
shared_ptr<something> p(new something());
![Page 65: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/65.jpg)
@odinthenerd
overkill
Auto-Intern GmbH 66
template<typename T>
using shared_ptr = composed<
interface_t<shared_pointer_interface,
weak_pointer_interface>,
shared_pointer_value<T>,
atomic_counter,
atomic_weak_counter,
throw_on_empty_use>;
shared_ptr<something> p = compose(
interface<shared_pointer_interface,
weak_pointer_interface>,
shared_pointer_value<something>{new something()},
atomic_counter{},
atomic_weak_counter{},
throw_on_empty_use{}
);
![Page 66: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/66.jpg)
@odinthenerd
Cleverhack
Auto-Intern GmbH 67
template<typename T>
using shared_ptr = composed<
interface_t<shared_pointer_interface,
weak_pointer_interface>,
shared_pointer_value<T>,
atomic_counter,
atomic_weak_counter,
throw_on_empty_use>;
shared_ptr<something> p(
named<shared_pointer_value<T>> = new something());
![Page 67: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/67.jpg)
@odinthenerd
Betterhack
Auto-Intern GmbH 68
template<typename T>
using shared_ptr = composed<
interface_t<shared_pointer_interface,
weak_pointer_interface>,
shared_pointer_value<T>,
atomic_counter,
atomic_weak_counter,
throw_on_empty_use>;
shared_ptr<something> p(
named<shared_pointer_value<T>>{new something()});
![Page 68: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/68.jpg)
@odinthenerd
Production Guidelines
04.11.2016 Auto-Intern GmbH 69
Thank you:C++ user group LondonGašper Ažman
![Page 69: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/69.jpg)
@odinthenerd
Future work
04.11.2016 Auto-Intern GmbH 70
• How do we test?•
•
•
![Page 70: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/70.jpg)
@odinthenerd
Future work
04.11.2016 Auto-Intern GmbH 71
• How do we test?• Pre instantiation reflection•
•
![Page 71: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/71.jpg)
@odinthenerd
Future work
04.11.2016 Auto-Intern GmbH 72
• How do we test?• Pre instantiation reflection• Complex type dependency•
![Page 72: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/72.jpg)
@odinthenerd
Future work
04.11.2016 Auto-Intern GmbH 73
• How do we test?• Pre instantiation reflection• Complex type dependency• Decomposition can be hard
![Page 73: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/73.jpg)
@odinthenerd
Victory
• Paper drop
• …
• Oh no wait, lots of hard work
04.11.2016 Auto-Intern GmbH 74
![Page 74: Agent based class design - C++ Europe Conference€¦ · @odinthenerd What is the problem Auto-Intern GmbH 8 •Non thread safe std::shared_pointer •Nothrow std::function •Inplace](https://reader036.vdocuments.site/reader036/viewer/2022071005/5fc2809a567b4d27db7bb40e/html5/thumbnails/74.jpg)
@odinthenerd
@odinthenerd
04.11.2016 Auto-Intern GmbH 75
• Github.com• Twitter.com• Gmail.com• Blogspot.com• LinkedIn.com• Embo.io