Skip to content

Commit 0a2d745

Browse files
committed
chore: reordered the number concepts, so they are usable across all the math module
1 parent 253917a commit 0a2d745

File tree

8 files changed

+16
-25
lines changed

8 files changed

+16
-25
lines changed

zero/ifc/math/numbers/numbers_concepts.cppm renamed to zero/ifc/math/concepts.cppm

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
export module math.numbers:numbers.concepts;
1+
export module math:math.concepts;
22

33
import std;
4+
import math.numbers;
45
import math.symbols;
5-
import :general;
66

77
export namespace zero::math {
88
/// Concept to act as an interface for the abstract concept of 'number' in mathematics.
@@ -20,4 +20,11 @@ export namespace zero::math {
2020
T::symbol; /* Check if 'T' has a static member named 'symbol' */
2121
{ T::symbol } -> std::same_as<const MathSymbol&>; // Check if 'T::symbol' has the type MathSymbol
2222
};
23+
24+
/**
25+
* @brief Wrapper concept to constrain any kind of numerical types,
26+
* both our {@link Number} concept or any C++ numerical primitive
27+
*/
28+
template <typename T>
29+
concept Numerical = Number<T> || std::is_arithmetic_v<T>;
2330
}

zero/ifc/math/math.cppm

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
export module math;
99

10+
export import :math.concepts;
1011
export import math.ops;
1112
export import math.numbers;
1213
export import math.symbols;

zero/ifc/math/numbers/integers.cppm

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import math.ops;
55
import math.symbols;
66

77
import :general;
8-
import :numbers.concepts;
98
import :naturals;
109

1110
export namespace zero::math {

zero/ifc/math/numbers/naturals.cppm

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import std;
44
import math.symbols;
55

66
import :general;
7-
import :numbers.concepts;
87

98
export namespace zero::math {
109
/// A positive integer number

zero/ifc/math/numbers/numbers.cppm

+1-18
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,10 @@ import std;
66
import math.ops;
77
import math.symbols;
88

9-
export import :numbers.concepts;
10-
import :general;
119
import :detail;
1210

11+
export import :general;
1312
export import :naturals;
1413
export import :integers;
1514
export import :rationals;
1615

17-
export namespace zero::math {
18-
// TODO: Create individual concepts per Number type that allows to check more complex behaviour,
19-
// like overflows (is this possible with a concept??!), that they can be constructible from certain types
20-
// which allows us to reduce to only one template constructor per type instead of having lots of them
21-
22-
// class Real {
23-
// double number; // TODO handle rationals and irrationals with std::variant?
24-
// };
25-
//
26-
// class Complex {
27-
// Real real;
28-
// Real imaginary;
29-
// };
30-
31-
}
32-

zero/ifc/math/numbers/rationals.cppm

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import math.ops;
55
import math.symbols;
66

77
import :general;
8-
import :numbers.concepts;
9-
108
import :naturals;
119
import :integers;
1210

zero/tests/math/numbers_tests.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ TestSuite numbers_suite {"Numbers TS"};
77
/// Compile time tests for numbers
88
static_assert(Number<Natural>);
99
static_assert(Number<Integer>);
10+
static_assert(Numerical<Integer>);
1011
static_assert(Number<Rational>);
12+
static_assert(!Number<int>);
13+
static_assert(Numerical<int>);
1114
static_assert(!Number<std::string>);
1215

1316
void numbers_tests() {

zork_config/zork_local_linux.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@ interfaces = [
7777
{ file = 'math/linear_algebra/root.cppm', module_name = 'math.linear_algebra' },
7878
# Numbers
7979
{ file = 'math/numbers/general.cppm', partition = { module = 'math.numbers', partition_name = 'general' } },
80-
{ file = 'math/numbers/numbers_concepts.cppm', partition = { module = 'math.numbers', partition_name = 'numbers.concepts' } },
8180
{ file = 'math/numbers/naturals.cppm', partition = { module = 'math.numbers', partition_name = 'naturals' } },
8281
{ file = 'math/numbers/integers.cppm', partition = { module = 'math.numbers', partition_name = 'integers' } },
8382
{ file = 'math/numbers/rationals.cppm', partition = { module = 'math.numbers', partition_name = 'rationals' } },
8483
{ file = 'math/numbers/detail.cpp', partition = { module = 'math.numbers', partition_name = 'detail', is_internal_partition = true } },
8584
{ file = 'math/numbers/numbers.cppm', module_name = 'math.numbers' },
85+
# Concepts
86+
{ file = 'math/concepts.cppm', partition = { module = 'math', partition_name = 'math.concepts' } },
8687
# Root
8788
{ file = 'math/math.cppm' },
8889

0 commit comments

Comments
 (0)