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 { T::create; };
17
18template <typename Model, typename TupleOfArgs>
19Model constructModel(TupleOfArgs& args)
20{
21 if constexpr (HasCreate<Model>)
22 {
23 return applyImpl(&Model::create, args);
24 }
25 else if constexpr (std::is_default_constructible_v<Model>)
26 {
27 return Model{};
28 }
29 else
30 {
31 static_assert(std::is_default_constructible_v<
32 Model> /* This is definitely false, here. */,
33 "The model to be constructed has neither a static "
34 "create() function nor is it default constructible.");
35 }
36}
37template <template <typename...> typename Tuple,
38 typename... Models,
39 typename TupleOfArgs>
40Tuple<Models...> constructModels(
41 std::type_identity<Tuple<Models...>> /*unused*/, TupleOfArgs&& args)
42{
43 return Tuple{constructModel<Models>(args)...};
44}
45} // namespace detail
46
58template <typename TupleOfModels, typename... Args>
59TupleOfModels constructModels(Args&&... args)
60{
62 std::type_identity<TupleOfModels>{},
63 std::forward_as_tuple(std::forward<Args>(args)...));
64}
65} // 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:216
Model constructModel(TupleOfArgs &args)
TupleOfModels constructModels(Args &&... args)