Skip to content

Commit e8a48b9

Browse files
committed
UFCS try to match with calling get() method on obj
In example of using fopen the code looks like: main: () -> int = { myfile := fopen("file-opened-with-c-function.txt", "w"); myfile.fprintf("Unified Function Call Syntax Rocks!\n\n"); myfile.fclose(); } there is a need to call fclose at the end of scope. We can introduce better_fopen that will return unique_prt with fclose as a deleter. main: () -> int = { myfile := better_fopen("file-opened-with-c-function.txt", "w"); myfile.fprintf("Unified Function Call Syntax Rocks!\n\n"); } That will ensure closing but will not work with UFCS. In this change we added a check (after other matches failed) if there is a call to get() method that match a function signature.
1 parent 8e6ac5c commit e8a48b9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/cpp2util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ class out {
460460
[](auto&& obj, auto&& ...params) { \
461461
if constexpr (requires{ std::forward<decltype(obj)>(obj).FUNCNAME(std::forward<decltype(params)>(params)...); }) { \
462462
return std::forward<decltype(obj)>(obj).FUNCNAME(std::forward<decltype(params)>(params)...); \
463+
} else if constexpr ( requires{ FUNCNAME(std::forward<decltype(obj)>(obj), std::forward<decltype(params)>(params)...); }){ \
464+
return FUNCNAME(std::forward<decltype(obj)>(obj), std::forward<decltype(params)>(params)...); \
465+
} else if constexpr (requires{ FUNCNAME(std::forward<decltype(obj.get())>(obj.get()),std::forward<decltype(params)>(params)...); }) { \
466+
return FUNCNAME(std::forward<decltype(obj.get())>(obj.get()), std::forward<decltype(params)>(params)...); \
463467
} else { \
464468
return FUNCNAME(std::forward<decltype(obj)>(obj), std::forward<decltype(params)>(params)...); \
465469
} \
@@ -469,6 +473,10 @@ class out {
469473
[](auto&& obj) { \
470474
if constexpr (requires{ std::forward<decltype(obj)>(obj).FUNCNAME(); }) { \
471475
return std::forward<decltype(obj)>(obj).FUNCNAME(); \
476+
} else if constexpr ( requires{ FUNCNAME(std::forward<decltype(obj)>(obj)); }) { \
477+
return FUNCNAME(std::forward<decltype(obj)>(obj)); \
478+
} else if constexpr (requires{ FUNCNAME(std::forward<decltype(obj.get())>(obj.get())); }) { \
479+
return FUNCNAME(std::forward<decltype(obj.get())>(obj.get())); \
472480
} else { \
473481
return FUNCNAME(std::forward<decltype(obj)>(obj)); \
474482
} \

0 commit comments

Comments
 (0)