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
11
namespace
ProcessLib::Graph
12
{
13
namespace
detail
14
{
15
template
<
typename
T>
16
concept
HasCreate
=
requires
{ T::create; };
17
18
template
<
typename
Model,
typename
TupleOfArgs>
19
Model
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
}
37
template
<
template
<
typename
...>
typename
Tuple,
38
typename
... Models,
39
typename
TupleOfArgs>
40
Tuple<Models...>
constructModels
(
41
std::type_identity<Tuple<Models...>>
/*unused*/
, TupleOfArgs&& args)
42
{
43
return
Tuple{
constructModel<Models>
(args)...};
44
}
45
}
// namespace detail
46
58
template
<
typename
TupleOfModels,
typename
... Args>
59
TupleOfModels
constructModels
(Args&&... args)
60
{
61
return
detail::constructModels
(
62
std::type_identity<TupleOfModels>{},
63
std::forward_as_tuple(std::forward<Args>(args)...));
64
}
65
}
// namespace ProcessLib::Graph
Apply.h
ProcessLib::Graph::detail::HasCreate
Definition
ConstructModels.h:16
ProcessLib::Graph::detail
Definition
Apply.h:11
ProcessLib::Graph::detail::constructModels
Tuple< Models... > constructModels(std::type_identity< Tuple< Models... > >, TupleOfArgs &&args)
Definition
ConstructModels.h:40
ProcessLib::Graph::detail::applyImpl
auto applyImpl(Function &&f, Args &&... args) -> typename detail::GetFunctionReturnType< std::decay_t< Function > >::type
Definition
Apply.h:216
ProcessLib::Graph::detail::constructModel
Model constructModel(TupleOfArgs &args)
Definition
ConstructModels.h:19
ProcessLib::Graph
Definition
Apply.h:9
ProcessLib::Graph::constructModels
TupleOfModels constructModels(Args &&... args)
Definition
ConstructModels.h:59
ProcessLib
Graph
ConstructModels.h
Generated by
1.14.0