LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
mesh_function_traits.h
1
11#ifndef __7e4ffaa81e244723acbfbbaea68e03b1
12#define __7e4ffaa81e244723acbfbbaea68e03b1
13
14#include <lf/mesh/mesh.h>
15
16#include <type_traits>
17
18namespace lf::mesh::utils {
19namespace internal {
20
21// TODO(craffael): Replace this with std::invoke_result_t once issue in msvc is
22// fixed: https://github.com/microsoft/STL/issues/1288
23template <class T>
24using MeshFunctionReturnType_t = decltype(std::declval<T>()(
25 std::declval<const Entity>(), std::declval<const Eigen::MatrixXd>()));
26
27template <typename>
28struct VectorElementType {
29 using type = void;
30};
31
32template <typename T, typename A>
33struct VectorElementType<std::vector<T, A>> {
34 using type = T;
35};
36
37template <class T>
38using VectorElement_t = typename VectorElementType<T>::type;
39
40template <class T, class RETURN_TYPE,
41 class = typename std::enable_if<!std::is_same_v<
42 VectorElement_t<MeshFunctionReturnType_t<T>>, void>>::type>
43constexpr bool IsMeshFunctionCallable(int /*unused*/) {
44 if constexpr (std::is_same_v<RETURN_TYPE, void>) {
45 // user didn't want us to check whether the return type is something
46 // particular
47 return true;
48 }
49 // user specified a RETURN_TYPE -> Check that std::vector<RETURN_TYPE> is
50 // returned.
51 return std::is_same_v<VectorElement_t<MeshFunctionReturnType_t<T>>,
52 RETURN_TYPE>;
53}
54
55template <class T, class RETURN_TYPE>
56constexpr bool IsMeshFunctionCallable(long /*unused*/) {
57 return false;
58}
59
60} // namespace internal
61
69template <class T, class R = void>
70inline constexpr bool isMeshFunction =
71 !std::is_reference_v<T> && std::is_copy_constructible_v<T> &&
72 std::is_move_constructible_v<T> &&
73 internal::IsMeshFunctionCallable<T, R>(0);
74
79template <class R>
81 internal::VectorElement_t<internal::MeshFunctionReturnType_t<R>>;
82
83} // namespace lf::mesh::utils
84
85#endif // __7e4ffaa81e244723acbfbbaea68e03b1
Contains helper functions and classes that all operate on the interface classes defined in lf::mesh.
internal::VectorElement_t< internal::MeshFunctionReturnType_t< R > > MeshFunctionReturnType
Determine the type of objects returned by a MeshFunction.
constexpr bool isMeshFunction
Determine whether a given type fulfills the concept MeshFunction.