Simple-Vector v1.3.0
Concepts.hpp
Go to the documentation of this file.
1// Copyright Dominic Koepke 2021 - 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// https://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef SIMPLE_VECTOR_CONCEPTS_HPP
7#define SIMPLE_VECTOR_CONCEPTS_HPP
8
9#pragma once
10
11#include <concepts>
12#include <type_traits>
13
14namespace sl::vec
15{
26 template <class TFrom, class TTo = TFrom>
27 concept add_assignable = requires(TTo lhs, TFrom rhs)
28 {
29 { lhs += rhs };
30 };
31
38 template <class TFrom, class TTo = TFrom>
39 concept sub_assignable = requires(TTo lhs, TFrom rhs)
40 {
41 { lhs -= rhs };
42 };
43
50 template <class TFrom, class TTo = TFrom>
51 concept mul_assignable = requires(TTo lhs, TFrom rhs)
52 {
53 { lhs *= rhs };
54 };
55
62 template <class TFrom, class TTo = TFrom>
63 concept div_assignable = requires(TTo lhs, TFrom rhs)
64 {
65 { lhs /= rhs };
66 };
67
74 template <class TFrom, class TTo = TFrom>
75 concept mod_assignable = requires(TTo lhs, TFrom rhs)
76 {
77 { lhs %= rhs };
78 };
79
86 template <class TFrom, class TTo = TFrom>
87 concept addable = requires(TTo lhs, TFrom rhs)
88 {
89 { lhs + rhs } -> std::convertible_to<TTo>;
90 };
91
98 template <class TFrom, class TTo = TFrom>
99 concept subable = requires(TTo lhs, TFrom rhs)
100 {
101 { lhs - rhs } -> std::convertible_to<TTo>;
102 };
103
110 template <class TFrom, class TTo = TFrom>
111 concept mulable = requires(TTo lhs, TFrom rhs)
112 {
113 { lhs * rhs } -> std::convertible_to<TTo>;
114 };
115
122 template <class TFrom, class TTo = TFrom>
123 concept divable = requires(TTo lhs, TFrom rhs)
124 {
125 { lhs / rhs } -> std::convertible_to<TTo>;
126 };
127
134 template <class TFrom, class TTo = TFrom>
135 concept modable = requires(TTo lhs, TFrom rhs)
136 {
137 { lhs % rhs } -> std::convertible_to<TTo>;
138 };
139
149 template <class TBinaryOp, class TResult, class TArg1, class TArg2>
151 std::is_convertible_v<std::invoke_result_t<TBinaryOp&, TArg1, TArg1>, TResult> &&
152 std::is_convertible_v<std::invoke_result_t<TBinaryOp&, TArg1, TArg2>, TResult> &&
153 std::is_convertible_v<std::invoke_result_t<TBinaryOp&, TArg2, TArg1>, TResult> &&
154 std::is_convertible_v<std::invoke_result_t<TBinaryOp&, TArg2, TArg2>, TResult>;
155
161 template <class T>
162 concept value_type = std::regular<std::remove_cvref_t<T>> &&
167
178 template <class T>
180 {
181 };
182
187 template <class T>
189
194 template <class T>
196
201 template <class T>
202 struct is_vectorial : std::false_type
203 {
204 };
205
210 template <class T>
212
224 template <class T>
225 concept vectorial = is_vectorial_v<std::remove_cvref_t<T>>;
226
228}
229
230#endif
Checks if the given type can be used in mutable plus operations.
Definition: Concepts.hpp:27
Checks if the given type can be used in immutable plus operations.
Definition: Concepts.hpp:87
Checks if binary operation has all four overloads (one for each parameter constellation) and if all o...
Definition: Concepts.hpp:150
Checks if the given type can be used in mutable division operations.
Definition: Concepts.hpp:63
Checks if the given type can be used in immutable division operations.
Definition: Concepts.hpp:123
Checks if the given type can be used in mutable modulo operations.
Definition: Concepts.hpp:75
Checks if the given type can be used in immutable module operations.
Definition: Concepts.hpp:135
Checks if the given type can be used in mutable multiplication operations.
Definition: Concepts.hpp:51
Checks if the given type can be used in immutable multiplication operations.
Definition: Concepts.hpp:111
Checks if the given type can be used in mutable minus operations.
Definition: Concepts.hpp:39
Checks if the given type can be used in immutable minus operations.
Definition: Concepts.hpp:99
Checks if the given type is regular and can be used in common arithmetically operations.
Definition: Concepts.hpp:162
Concept checking for vectorial types.
Definition: Concepts.hpp:225
constexpr bool is_vectorial_v
Shortcut checking for vectorial classes.
Definition: Concepts.hpp:211
typename vector_traits< std::remove_cvref_t< T > >::value_type vector_value_t
Convenience alias type to the value_type of Vectors.
Definition: Concepts.hpp:188
constexpr auto vector_dims_v
Convenience constant to the dimensions of Vectors.
Definition: Concepts.hpp:195
Definition: Algorithm.hpp:19
Checks whether T is a vector type.
Definition: Concepts.hpp:203
Uniform interface to Vector types.
Definition: Concepts.hpp:180