veselink1 / refl-cpp

Static reflection for C++17 (compile-time enumeration, attributes, proxies, overloads, template functions, metaprogramming).
https://veselink1.github.io/refl-cpp/md__introduction.html
MIT License
1.05k stars 76 forks source link

Invoke function with void return type #51

Closed caiwan closed 2 years ago

caiwan commented 3 years ago

The invoke functionality should be able to work with functions with void return type. Unfortunately one of my use-cases required this, so I've prepared a quick-and-dirty fix for that. I believe this can be achieved with less repetition.

veselink1 commented 3 years ago

Thanks for the pull request. We definitely want to support calling runtime::invoke with a void-returning function.

Do you think you can reduce the code duplication in your change? I would think that an if constexpr around the member invocation and another one around the return line would be enough. The type in std::optional might need to be substituted with a std::conditional_t<std::is_void_v<U>, bool, U>> or something of that form. There might be a more clever way to do it.

This will lead to a more fragmented implementation in general, but prevent duplication of the matching logic.