Skip to content

Commit c4ea291

Browse files
committed
Add a comment to unify the UFCS macro once all compilers support it, closes #46
1 parent c44f97b commit c4ea291

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

include/cpp2util.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,23 @@ class out {
458458
//
459459
//-----------------------------------------------------------------------
460460
//
461+
462+
//--------------------------------------------------------------------
463+
// TODO: When MSVC supports __VA_OPT__ in standard mode without the
464+
// experimental /Zc:preprocessor switch, use this single macro
465+
// instead of the dual macros below that special-case _0 args
466+
// AND: Make the similarly noted change in cppfront.cpp
467+
//
468+
//#define CPP2_UFCS(FUNCNAME,PARAM1,...) \
469+
//[](auto&& obj __VA_OPT__(, auto&& ...params) ) { \
470+
// if constexpr (requires{ std::forward<decltype(obj)>(obj).FUNCNAME(__VA_OPT__(std::forward<decltype(params)>(params)...)); }) { \
471+
// return std::forward<decltype(obj)>(obj).FUNCNAME(__VA_OPT__(std::forward<decltype(params)>(params)...)); \
472+
// } else { \
473+
// return FUNCNAME(std::forward<decltype(obj)>(obj) __VA_OPT__(, std::forward<decltype(params)>(params)...)); \
474+
// } \
475+
//}(PARAM1 __VA_OPT__(, __VA_ARGS__) )
476+
477+
461478
#define CPP2_UFCS(FUNCNAME,PARAM1,...) \
462479
[](auto&& obj, auto&& ...params) { \
463480
if constexpr (requires{ std::forward<decltype(obj)>(obj).FUNCNAME(std::forward<decltype(params)>(params)...); }) { \
@@ -475,6 +492,7 @@ class out {
475492
return FUNCNAME(std::forward<decltype(obj)>(obj)); \
476493
} \
477494
}(PARAM1)
495+
//--------------------------------------------------------------------
478496

479497

480498
//-----------------------------------------------------------------------

source/cppfront.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,13 +1630,22 @@ class cppfront
16301630
// The ( has its expr_list and op_close
16311631
assert (n.ops[1].expr_list && n.ops[1].op_close);
16321632

1633+
//--------------------------------------------------------------------
1634+
// TODO: When MSVC supports __VA_OPT__ in standard mode without the
1635+
// experimental /Zc:preprocessor switch, use this single line
1636+
// instead of the dual lines below that special-case _0 args
1637+
// AND: Make the similarly noted change in cpp2util.h
1638+
//
1639+
//printer.print_cpp2("CPP2_UFCS(", n.position());
1640+
16331641
// If there are no additional arguments, use the CPP2_UFCS_0 version
16341642
if (!n.ops[1].expr_list->expressions.empty()) {
16351643
printer.print_cpp2("CPP2_UFCS(", n.position());
16361644
}
16371645
else {
16381646
printer.print_cpp2("CPP2_UFCS_0(", n.position());
16391647
}
1648+
//--------------------------------------------------------------------
16401649

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

0 commit comments

Comments
 (0)