Skip to content

Commit 145f741

Browse files
authored
Remove matchit dependency for users. (#60)
* Remove matchit dependency for users. * Fix build. Co-authored-by: Bowen Fu <missing>
1 parent a8bc2b5 commit 145f741

File tree

12 files changed

+91
-71
lines changed

12 files changed

+91
-71
lines changed

include/mathiu/core.h

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef CORE_H
22
#define CORE_H
33

4-
#include "matchit.h"
54
#include <variant>
65
#include <memory>
76
#include <string>
@@ -10,13 +9,7 @@
109
#include <map>
1110
#include <set>
1211
#include <list>
13-
14-
#define VERBOSE_DEBUG 0
15-
#define DEBUG 1
16-
17-
#if DEBUG
18-
#include <iostream>
19-
#endif // DEBUG
12+
#include <array>
2013

2114
namespace mathiu::impl
2215
{
@@ -27,48 +20,6 @@ namespace mathiu::impl
2720

2821
} // namespace mathiu::impl
2922

30-
namespace matchit::impl
31-
{
32-
template <>
33-
class PatternTraits<mathiu::impl::ExprPtr>
34-
{
35-
using Pattern = mathiu::impl::ExprPtr;
36-
public:
37-
template <typename Value>
38-
using AppResultTuple = std::tuple<>;
39-
40-
constexpr static auto nbIdV = 0;
41-
42-
template <typename Value, typename ContextT>
43-
constexpr static auto matchPatternImpl(Value &&value, Pattern const &pattern,
44-
int32_t /* depth */,
45-
ContextT & /*context*/)
46-
{
47-
return mathiu::impl::equal(pattern, std::forward<Value>(value));
48-
}
49-
constexpr static void processIdImpl(Pattern const &, int32_t /*depth*/,
50-
IdProcess) {}
51-
};
52-
53-
template <>
54-
class IdTraits<mathiu::impl::ExprPtr>
55-
{
56-
using Type = mathiu::impl::ExprPtr;
57-
public:
58-
static auto
59-
#if defined(__has_feature)
60-
#if __has_feature(address_sanitizer)
61-
__attribute__((no_sanitize_address))
62-
#endif
63-
#endif
64-
equal(Type const &lhs, Type const &rhs)
65-
{
66-
return mathiu::impl::equal(lhs, rhs);
67-
}
68-
};
69-
70-
} // namespace matchit::impl
71-
7223
namespace mathiu
7324
{
7425
namespace impl
@@ -333,8 +284,6 @@ namespace mathiu
333284

334285
double evald(ExprPtr const &ex);
335286

336-
inline constexpr auto isRational = matchit::or_(matchit::as<int>(matchit::_), matchit::as<Fraction>(matchit::_));
337-
338287
// The <| order relation
339288
// for basic commutative transformation
340289
bool less(ExprPtr const &lhs, ExprPtr const &rhs);
@@ -414,18 +363,6 @@ namespace mathiu
414363
return substitute(substitute(ex, srcDstPairs), seqPairs...);
415364
}
416365

417-
inline auto const asDouble = matchit::meet([](auto&& e)
418-
{
419-
try{
420-
evald(e);
421-
return true;
422-
}
423-
catch (...)
424-
{
425-
return false;
426-
}
427-
});
428-
429366
inline ExprPtr interval(ExprPtr const& l, bool const lClose, ExprPtr const& r, bool const rClose)
430367
{
431368
return std::make_shared<impl::Expr const>(impl::Interval{{l, lClose}, {r, rClose}});

src/core.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "mathiu/core.h"
21
#include "matchit.h"
2+
#include "internal.h"
33
#include <numeric>
44

55
namespace mathiu::impl

src/diff.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "matchit.h"
2-
#include "mathiu/core.h"
2+
#include "internal.h"
33
#include "mathiu/diff.h"
44
#include <numeric>
55

src/function_range.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "matchit.h"
2-
#include "mathiu/core.h"
2+
#include "internal.h"
33
#include "mathiu/solve.h"
44
#include "mathiu/diff.h"
55
#include "mathiu/inequation.h"

src/inequation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "matchit.h"
2-
#include "mathiu/core.h"
2+
#include "internal.h"
33
#include "mathiu/inequation.h"
44
#include "mathiu/diff.h"
55
#include "mathiu/solve.h"

src/internal.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#ifndef INTERNAL_H
2+
#define INTERNAL_H
3+
4+
#include "mathiu/core.h"
5+
#include "matchit.h"
6+
7+
#define VERBOSE_DEBUG 0
8+
#define DEBUG 1
9+
10+
#if DEBUG
11+
#include <iostream>
12+
#endif // DEBUG
13+
14+
namespace matchit::impl
15+
{
16+
template <>
17+
class PatternTraits<mathiu::impl::ExprPtr>
18+
{
19+
using Pattern = mathiu::impl::ExprPtr;
20+
public:
21+
template <typename Value>
22+
using AppResultTuple = std::tuple<>;
23+
24+
constexpr static auto nbIdV = 0;
25+
26+
template <typename Value, typename ContextT>
27+
constexpr static auto matchPatternImpl(Value &&value, Pattern const &pattern,
28+
int32_t /* depth */,
29+
ContextT & /*context*/)
30+
{
31+
return mathiu::impl::equal(pattern, std::forward<Value>(value));
32+
}
33+
constexpr static void processIdImpl(Pattern const &, int32_t /*depth*/,
34+
IdProcess) {}
35+
};
36+
37+
template <>
38+
class IdTraits<mathiu::impl::ExprPtr>
39+
{
40+
using Type = mathiu::impl::ExprPtr;
41+
public:
42+
static auto
43+
#if defined(__has_feature)
44+
#if __has_feature(address_sanitizer)
45+
__attribute__((no_sanitize_address))
46+
#endif
47+
#endif
48+
equal(Type const &lhs, Type const &rhs)
49+
{
50+
return mathiu::impl::equal(lhs, rhs);
51+
}
52+
};
53+
54+
} // namespace matchit::impl
55+
56+
namespace mathiu
57+
{
58+
namespace impl
59+
{
60+
inline constexpr auto isRational = matchit::or_(matchit::as<int>(matchit::_), matchit::as<Fraction>(matchit::_));
61+
62+
63+
inline auto const asDouble = matchit::meet([](auto&& e)
64+
{
65+
try{
66+
evald(e);
67+
return true;
68+
}
69+
catch (...)
70+
{
71+
return false;
72+
}
73+
});
74+
75+
} // namespace impl
76+
} // namespace mathiu
77+
78+
#endif // INTERNAL_H

src/polynomial.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "matchit.h"
2-
#include "mathiu/core.h"
2+
#include "internal.h"
33
#include "mathiu/diff.h"
44
#include "mathiu/polynomial.h"
55
#include <cmath>

src/setOp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <iterator>
22
#include "matchit.h"
3-
#include "mathiu/core.h"
3+
#include "internal.h"
44
#include "mathiu/setOp.h"
55

66
namespace mathiu::impl

src/solve.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <iterator>
22
#include "matchit.h"
3-
#include "mathiu/core.h"
3+
#include "internal.h"
44
#include "mathiu/diff.h"
55
#include "mathiu/polynomial.h"
66
#include "mathiu/setOp.h"

test/mathiu/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ solve.cpp polynomial.cpp relational.cpp freeOf.cpp
44
substitute.cpp functionRange.cpp inequation.cpp
55
interval-comp.cpp
66
)
7+
target_include_directories(unittests PRIVATE
8+
${PROJECT_SOURCE_DIR}/src PRIVATE matchit)
79
target_compile_options(unittests PRIVATE ${BASE_COMPILE_FLAGS})
810
target_link_libraries(unittests PRIVATE mathiu gtest_main matchit)
911
set_target_properties(unittests PROPERTIES CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS OFF)

test/mathiu/auto-simplification.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#include "internal.h"
12
#include "mathiu.h"
3+
#include "matchit.h"
24
#include "gtest/gtest.h"
35
#include <iostream>
46
using namespace mathiu;

test/mathiu/expr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "mathiu.h"
2+
#include "matchit.h"
23
#include "gtest/gtest.h"
34
#include <string>
45
using namespace mathiu;

0 commit comments

Comments
 (0)