MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
marvin_Concepts.h
Go to the documentation of this file.
1// ========================================================================================================
2// _______ _______ ______ ___ ___ _______ _______
3// | | | _ | __ \ | |_ _| | |
4// | | | < | |_| |_| |
5// |__|_|__|___|___|___|__|\_____/|_______|__|____|
6//
7// This file is part of the Marvin open source library and is licensed under the terms of the MIT License.
8//
9// ========================================================================================================
10
11#ifndef MARVIN_CONCEPTS_H
12#define MARVIN_CONCEPTS_H
13#include <iterator>
14#include <type_traits>
15#include <cstddef>
16#include <complex>
17#include <concepts>
18#include <span>
19#include <vector>
20#include <random>
21namespace marvin {
22
26 template <class T>
27 concept FloatType = std::is_floating_point_v<T>;
28
29 template <class T>
30 concept ComplexFloatType = std::same_as<T, std::complex<float>> || std::same_as<T, std::complex<double>>;
31
32 template <class T>
34
38 template <class T>
39 concept NumericType = std::is_integral_v<T> || std::is_floating_point_v<T>;
40
44 template <class T>
45 concept FixedWidthSignedInteger = std::same_as<std::int8_t, T> ||
46 std::same_as<std::int16_t, T> ||
47 std::same_as<std::int32_t, T> ||
48 std::same_as<std::int64_t, T>;
49
50
54 template <class T>
55 concept ArrayLike = requires(T a, size_t i) {
56 typename T::value_type;
57 typename T::iterator;
58 requires std::contiguous_iterator<typename T::iterator>;
59 requires !std::same_as<std::string, T>;
60 { a.size() } -> std::same_as<size_t>;
61 { a[i] } -> std::same_as<typename T::value_type&>;
62 { a.data() } -> std::same_as<typename T::value_type*>;
63 };
64
68 template <class T>
69 concept FloatArrayLike = requires {
70 requires ArrayLike<T>;
72 };
73
77 template <class T>
78 concept SmartPointerType = requires(T a) {
79 typename T::element_type;
80 a.get();
81 a.reset();
82 a.operator*();
83 a.operator->();
84 };
85
86
91 template <size_t N>
92 constexpr bool isPowerOfTwo() {
93 if constexpr (N == 1) {
94 return true;
95 } else if constexpr (N == 0 || N % 2 != 0) {
96 return false;
97 } else {
98 return isPowerOfTwo<N / 2>();
99 }
100 }
101
102 template <class T>
103 concept RandomEngineType = std::same_as<T, std::mt19937> || std::same_as<T, std::mt19937_64> ||
104 std::same_as<T, std::minstd_rand0> || std::same_as<T, std::minstd_rand> ||
105 std::same_as<T, std::ranlux24_base> || std::same_as<T, std::ranlux48_base>;
106} // namespace marvin
107#endif
Constrains T to a type that defines a const_iterator as a child, has an implementation of operator[](...
Definition marvin_Concepts.h:55
Definition marvin_Concepts.h:30
Constrains T to be a fixed width signed int.
Definition marvin_Concepts.h:45
Constrains T to be an Array like, with a Float-like value type.
Definition marvin_Concepts.h:69
Contrains T to be either a float or a double.
Definition marvin_Concepts.h:27
Constrains T to be any numeric type.
Definition marvin_Concepts.h:39
Definition marvin_Concepts.h:103
Definition marvin_Concepts.h:33
Constrains T to a class that implements get(), reset() operator*() and operator->().
Definition marvin_Concepts.h:78
A mostly harmless top-level namespace.
Definition marvin_BufferView.h:15
constexpr bool isPowerOfTwo()
Definition marvin_Concepts.h:92