Skip to content
This repository was archived by the owner on Dec 22, 2024. It is now read-only.

Commit ba611ef

Browse files
reverted removing overloaded_rec
1 parent 4d99ef4 commit ba611ef

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/basic/type.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ template <typename T>
281281
constexpr bool is_primitive_type = std::is_base_of_v<PrimitiveType, std::decay_t<T>>;
282282

283283
inline bool isPrimitive(const Value& v) {
284-
return std::visit(overloaded{[](auto&& a) { return is_primitive_type<decltype(a)>; },
284+
return std::visit(overloaded_rec{[](auto&& a) { return is_primitive_type<decltype(a)>; },
285285
[](Alias const& a) { return isPrimitive(a.target); }},
286286
v);
287287
}

src/basic/variant_visitor_helper.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct overloaded : Ts... {
1414
template <class... Ts>
1515
overloaded(Ts...) -> overloaded<Ts...>;
1616

17+
1718
namespace mimium {
1819
// recursive variant
1920

@@ -44,6 +45,31 @@ bool operator!=(const Box<T>& t1, const Box<T>& t2) {
4445
return !(t1 == t2);
4546
}
4647

48+
template <class T>
49+
constexpr bool isBoxed(T /*v*/) {
50+
return false;
51+
}
52+
template <class T>
53+
constexpr bool isBoxed(Box<T> /*v*/) {
54+
return true;
55+
}
56+
template <typename T>
57+
using boxenabler = std::enable_if_t<isBoxed(T())>;
58+
59+
template <class... Ts>
60+
struct overloaded_rec : Ts... {
61+
using Ts::operator()...;
62+
template <typename T>
63+
decltype(auto) operator()(Box<T> a) {
64+
return (*this)(a.getraw());
65+
}
66+
template <typename T, boxenabler<T>>
67+
decltype(auto) operator()(T&& a) {
68+
return (*this)(std::forward<decltype(a)>(a.getraw()));
69+
}
70+
};
71+
template <class... Ts>
72+
overloaded_rec(Ts...) -> overloaded_rec<Ts...>;
4773

4874
namespace rv {
4975

src/compiler/mirgenerator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace mir {
1616

1717
inline types::Value lowerType(types::Value const& t) {
1818
return std::visit(
19-
overloaded{
19+
overloaded_rec{
2020
[](auto const& i) {
2121
assert(types::is_primitive_type<decltype(i)>);
2222
return types::Value{i};

0 commit comments

Comments
 (0)