teqp
0.19.1
Loading...
Searching...
No Matches
include
teqp
containers.hpp
Go to the documentation of this file.
1
#pragma once
2
3
//template <typename T>
4
//concept has_meta = requires(T const& m) {
5
// { m.get_meta() };
6
//};
7
namespace
teqp
{
8
template
<
typename
... Args>
9
class
ModelContainer
{
10
public
:
11
using
mid
= std::size_t;
12
using
varModels
= std::variant<Args...>;
13
private
:
14
mid
last_id = 0;
15
std::map<mid, varModels> modcoll;
16
public
:
17
template
<
typename
T>
const
auto
&
get_ref
(
mid
id
) {
return
std::get<T>(
get_model
(
id
)); }
18
19
auto
size
()
const
{
return
modcoll.size(); }
20
auto
new_id
() {
21
last_id++;
22
return
last_id;
23
}
24
template
<
typename
Instance>
25
auto
add_model
(Instance&& instance) {
26
auto
uid =
new_id
();
27
modcoll.emplace(uid, std::move(instance));
28
return
uid;
29
}
30
31
const
varModels
&
get_model
(
mid
id
)
const
{
32
return
modcoll.at(
id
);
33
}
34
35
template
<
typename
Function>
36
auto
caller
(
const
mid
&
mid
,
const
Function &f)
const
{
37
return
std::visit([&](
auto
& model) {
return
f(model); },
get_model
(
mid
));
38
}
39
40
//nlohmann::json get_meta(const mid& mid) const {
41
// const auto& modvar = get_model(mid);
42
// nlohmann::json result;
43
// std::visit([&](auto&& model) {
44
// if constexpr (has_meta<decltype(model)>) { result = model.get_meta(); }
45
// }, modvar);
46
// return result;
47
//}
48
};
49
};
// namespace teqp
teqp::ModelContainer
Definition
containers.hpp:9
teqp::ModelContainer::mid
std::size_t mid
Definition
containers.hpp:11
teqp::ModelContainer::caller
auto caller(const mid &mid, const Function &f) const
Definition
containers.hpp:36
teqp::ModelContainer::new_id
auto new_id()
Definition
containers.hpp:20
teqp::ModelContainer::add_model
auto add_model(Instance &&instance)
Definition
containers.hpp:25
teqp::ModelContainer::get_ref
const auto & get_ref(mid id)
Definition
containers.hpp:17
teqp::ModelContainer::size
auto size() const
Definition
containers.hpp:19
teqp::ModelContainer::varModels
std::variant< Args... > varModels
Definition
containers.hpp:12
teqp::ModelContainer::get_model
const varModels & get_model(mid id) const
Definition
containers.hpp:31
teqp
Definition
ancillary_builder.hpp:8
Generated by
1.10.0