Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions include/cpp2util.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,22 +459,13 @@ class out {
//-----------------------------------------------------------------------
//
#define CPP2_UFCS(FUNCNAME,PARAM1,...) \
[](auto&& obj, auto&& ...params) { \
if constexpr (requires{ std::forward<decltype(obj)>(obj).FUNCNAME(std::forward<decltype(params)>(params)...); }) { \
return std::forward<decltype(obj)>(obj).FUNCNAME(std::forward<decltype(params)>(params)...); \
[](auto&& obj __VA_OPT__(, auto&& ...params)) { \
if constexpr (requires{ std::forward<decltype(obj)>(obj).FUNCNAME( __VA_OPT__(std::forward<decltype(params)>(params)...) ); }) { \
return std::forward<decltype(obj)>(obj).FUNCNAME( __VA_OPT__(std::forward<decltype(params)>(params)...) ); \
} else { \
return FUNCNAME(std::forward<decltype(obj)>(obj), std::forward<decltype(params)>(params)...); \
return FUNCNAME(std::forward<decltype(obj)>(obj) __VA_OPT__(, std::forward<decltype(params)>(params)...) ); \
} \
}(PARAM1, __VA_ARGS__)

#define CPP2_UFCS_0(FUNCNAME,PARAM1) \
[](auto&& obj) { \
if constexpr (requires{ std::forward<decltype(obj)>(obj).FUNCNAME(); }) { \
return std::forward<decltype(obj)>(obj).FUNCNAME(); \
} else { \
return FUNCNAME(std::forward<decltype(obj)>(obj)); \
} \
}(PARAM1)
}(PARAM1 __VA_OPT__(, __VA_ARGS__))


//-----------------------------------------------------------------------
Expand Down
8 changes: 1 addition & 7 deletions source/cppfront.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1624,13 +1624,7 @@ class cppfront
// The ( has its expr_list and op_close
assert (n.ops[1].expr_list && n.ops[1].op_close);

// If there are no additional arguments, use the CPP2_UFCS_0 version
if (!n.ops[1].expr_list->expressions.empty()) {
printer.print_cpp2("CPP2_UFCS(", n.position());
}
else {
printer.print_cpp2("CPP2_UFCS_0(", n.position());
}
printer.print_cpp2("CPP2_UFCS(", n.position());

// Make the "funcname" the first argument to CPP2_UFCS
emit(*n.ops[0].id_expr);
Expand Down