Skip to content

Commit 5697ff6

Browse files
committed
Arithmetic
1 parent af54a10 commit 5697ff6

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "lax_v1/arithmetic.hpp"
2+
#include "lax_v1/force.hpp"
3+
4+
#include "config.hpp"
5+
6+
#include <type_traits>
7+
8+
static_assert(
9+
std::is_same_v<
10+
lax::force_t<lax::add_m<lax::value_t<short, 1>, lax::value_t<long, 2>>>,
11+
lax::value_t<long, 3>>);
12+
13+
static_assert(
14+
std::is_same_v<
15+
lax::force_t<lax::mod_m<lax::value_t<int, 2>, lax::value_t<int, 2>>>,
16+
lax::value_t<int, 0>>);
17+
18+
static_assert(
19+
std::is_same_v<
20+
lax::force_t<lax::mul_m<lax::value_t<int, 1>, lax::value_t<short, 2>>>,
21+
lax::value_t<int, 2>>);
22+
23+
static_assert(
24+
std::is_same_v<
25+
lax::force_t<lax::div_m<lax::value_t<short, 6>, lax::value_t<char, 2>>>,
26+
lax::value_t<int, 3>>);
27+
28+
static_assert(
29+
std::is_same_v<
30+
lax::force_t<lax::sub_m<lax::value_t<int, 3>, lax::value_t<char, 2>>>,
31+
lax::value_t<int, 1>>);
32+
33+
static_assert(std::is_same_v<lax::force_t<lax::neg_m<lax::value_t<short, 3>>>,
34+
lax::value_t<int, -3>>);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
3+
#include "lax_v1/arithmetic_synopsis.hpp"
4+
5+
#include "lax_v1/value.hpp"
6+
7+
#include <type_traits>
8+
9+
template <class LhsExpr, class RhsExpr>
10+
struct lax_v1::add_m : value_t<std::common_type_t<value_type_of_t<LhsExpr>,
11+
value_type_of_t<RhsExpr>>,
12+
value_of_v<LhsExpr> + value_of_v<RhsExpr>> {};
13+
14+
template <class LhsExpr, class RhsExpr>
15+
struct lax_v1::div_m : value_t<std::common_type_t<value_type_of_t<LhsExpr>,
16+
value_type_of_t<RhsExpr>>,
17+
value_of_v<LhsExpr> / value_of_v<RhsExpr>> {};
18+
19+
template <class LhsExpr, class RhsExpr>
20+
struct lax_v1::mod_m : value_t<std::common_type_t<value_type_of_t<LhsExpr>,
21+
value_type_of_t<RhsExpr>>,
22+
value_of_v<LhsExpr> % value_of_v<RhsExpr>> {};
23+
24+
template <class LhsExpr, class RhsExpr>
25+
struct lax_v1::mul_m : value_t<std::common_type_t<value_type_of_t<LhsExpr>,
26+
value_type_of_t<RhsExpr>>,
27+
value_of_v<LhsExpr> * value_of_v<RhsExpr>> {};
28+
29+
template <class LhsExpr, class RhsExpr>
30+
struct lax_v1::sub_m : value_t<std::common_type_t<value_type_of_t<LhsExpr>,
31+
value_type_of_t<RhsExpr>>,
32+
value_of_v<LhsExpr> - value_of_v<RhsExpr>> {};
33+
34+
template <class Expr> struct lax_v1::neg_m : auto_t<-value_of_v<Expr>> {};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
namespace lax_v1 {
4+
5+
template <class LhsExpr, class RhsExpr> struct add_m;
6+
template <class LhsExpr, class RhsExpr> struct div_m;
7+
template <class LhsExpr, class RhsExpr> struct mod_m;
8+
template <class LhsExpr, class RhsExpr> struct mul_m;
9+
template <class LhsExpr, class RhsExpr> struct sub_m;
10+
11+
template <class Expr> struct neg_m;
12+
13+
} // namespace lax_v1

0 commit comments

Comments
 (0)