OGS
ConstructModels.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <tuple>
7#include <utility>
8
9#include "Apply.h"
10
11namespace ProcessLib::Graph
12{
13namespace detail
14{
15template <typename T>
16concept HasCreate = requires
17{
18 T::create;
19};
20
21template <typename Model, typename TupleOfArgs>
22Model constructModel(TupleOfArgs& args)
23{
24 if constexpr (HasCreate<Model>)
25 {
26 return applyImpl(&Model::create, args);
27 }
28 else if constexpr (std::is_default_constructible_v<Model>)
29 {
30 return Model{};
31 }
32 else
33 {
34 static_assert(std::is_default_constructible_v<
35 Model> /* This is definitely false, here. */,
36 "The model to be constructed has neither a static "
37 "create() function nor is it default constructible.");
38 }
39}
40template <template <typename...> typename Tuple,
41 typename... Models,
42 typename TupleOfArgs>
43Tuple<Models...> constructModels(std::type_identity<Tuple<Models...>>,
44 TupleOfArgs&& args)
45{
46 return Tuple{constructModel<Models>(args)...};
47}
48} // namespace detail
49
61template <typename TupleOfModels, typename... Args>
62TupleOfModels constructModels(Args&&... args)
63{
65 std::type_identity<TupleOfModels>{},
66 std::forward_as_tuple(std::forward<Args>(args)...));
67}
68} // 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:214
Model constructModel(TupleOfArgs &args)
TupleOfModels constructModels(Args &&... args)