Line data Source code
1 : #ifndef FEFAD5F6_9902_4DB6_B0B1_0F8AC3FE433F
2 : #define FEFAD5F6_9902_4DB6_B0B1_0F8AC3FE433F
3 :
4 : #include "base/first_include.h" // IWYU pragma: keep
5 : #include "base/interface_contract.h" // IWYU pragma: keep
6 : #include "base/require_copy_intf.h"
7 : #include "base/require_move_intf.h"
8 : #include "math/linalg/errors.h" // IWYU pragma: keep
9 :
10 : namespace tracking
11 : {
12 : namespace math
13 : {
14 : namespace contract
15 : {
16 : #if __cplusplus == 202002L
17 : // clang-format off
18 : namespace matrix
19 : {
20 : template<typename T>
21 : concept has_setOnes_member_func = requires {
22 : { std::declval<T>().setOnes() } -> std::same_as<void>;
23 : };
24 : template<typename T>
25 : concept has_ones_static_member_func = requires {
26 : { T::Ones() } -> std::same_as<T>;
27 : };
28 : template<typename T>
29 : concept has_setZeros_member_func = requires {
30 : { std::declval<T>().setZeros() } -> std::same_as<void>;
31 : };
32 : template<typename T>
33 : concept has_zeros_static_member_func = requires {
34 : { T::Zeros() } -> std::same_as<T>;
35 : };
36 : template<typename T>
37 : concept has_transpose_member_func = requires {
38 : { std::declval<T>().transpose() } -> std::same_as<typename T::transpose_type&>;
39 : };
40 : template<typename T>
41 : concept has_round_brackets_const_op_int_int = requires {
42 : { std::declval<const T>().operator()(std::declval<int>(), std::declval<int>()) }
43 : -> std::same_as<tl::expected<typename T::value_type, Errors>>;
44 : };
45 : template<typename T>
46 : concept has_round_brackets_op_int_int = requires {
47 : { std::declval<T>().operator()(std::declval<int>(), std::declval<int>()) }
48 : -> std::same_as<tl::expected<std::reference_wrapper<typename T::value_type>, Errors>>;
49 : };
50 : }
51 : // clang-format on
52 : #endif //__cplusplus == 202002L
53 :
54 : template <typename ImplType>
55 : struct MatrixIntf
56 : : public base::contract::RequireCopyIntf<ImplType>
57 : , public base::contract::RequireMoveIntf<ImplType>
58 : {
59 4464 : MatrixIntf()
60 : : base::contract::RequireCopyIntf<ImplType>()
61 4464 : , base::contract::RequireMoveIntf<ImplType>()
62 :
63 : {
64 : static_assert(std::is_floating_point<typename ImplType::value_type>() || std::is_integral<typename ImplType::value_type>());
65 : static_assert(ImplType::Rows > 0);
66 : static_assert(ImplType::Cols > 0);
67 :
68 : #if __cplusplus == 202002L
69 : static_assert(matrix::has_setOnes_member_func<ImplType>, ERR_MSG_MISSING_FUNCTION);
70 : static_assert(matrix::has_ones_static_member_func<ImplType>, ERR_MSG_MISSING_FUNCTION);
71 : static_assert(matrix::has_setZeros_member_func<ImplType>, ERR_MSG_MISSING_FUNCTION);
72 : static_assert(matrix::has_zeros_static_member_func<ImplType>, ERR_MSG_MISSING_FUNCTION);
73 :
74 : // Conditionally check for non-Vector types
75 : if constexpr (ImplType::Cols > 1) // Vector has Cols == 1
76 : {
77 : static_assert(matrix::has_round_brackets_const_op_int_int<ImplType>, ERR_MSG_MISSING_FUNCTION);
78 : static_assert(matrix::has_round_brackets_op_int_int<ImplType>, ERR_MSG_MISSING_FUNCTION);
79 : static_assert(matrix::has_transpose_member_func<ImplType>, ERR_MSG_MISSING_FUNCTION);
80 : }
81 : #endif //__cplusplus == 202002L
82 : }
83 : };
84 :
85 : } // namespace contract
86 : } // namespace math
87 : } // namespace tracking
88 :
89 :
90 : #endif // FEFAD5F6_9902_4DB6_B0B1_0F8AC3FE433F
|