OGS
ConstructModels.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <tuple>
14#include <utility>
15
16#include "Apply.h"
17
18namespace ProcessLib::Graph
19{
20namespace detail
21{
22template <typename T>
23concept HasCreate = requires
24{
25 T::create;
26};
27
28template <typename Model, typename TupleOfArgs>
29Model constructModel(TupleOfArgs& args)
30{
31 if constexpr (HasCreate<Model>)
32 {
33 return applyImpl(&Model::create, args);
34 }
35 else if constexpr (std::is_default_constructible_v<Model>)
36 {
37 return Model{};
38 }
39 else
40 {
41 static_assert(std::is_default_constructible_v<
42 Model> /* This is definitely false, here. */,
43 "The model to be constructed has neither a static "
44 "create() function nor is it default constructible.");
45 }
46}
47template <template <typename...> typename Tuple,
48 typename... Models,
49 typename TupleOfArgs>
50Tuple<Models...> constructModels(std::type_identity<Tuple<Models...>>,
51 TupleOfArgs&& args)
52{
53 return Tuple{constructModel<Models>(args)...};
54}
55} // namespace detail
56
68template <typename TupleOfModels, typename... Args>
69TupleOfModels constructModels(Args&&... args)
70{
72 std::type_identity<TupleOfModels>{},
73 std::forward_as_tuple(std::forward<Args>(args)...));
74}
75} // namespace ProcessLib::Graph
Tuple< Models... > constructModels(std::type_identity< Tuple< Models... > >, TupleOfArgs &&args)
auto applyImpl(Function &&f, Args &&... args) -> typename detail::GetFunctionReturnType< std::decay_t< Function > >::type
Definition Apply.h:220
Model constructModel(TupleOfArgs &args)
TupleOfModels constructModels(Args &&... args)