On Sun, Oct 20, 2024 at 11:13 AM Ivica Siladic via Boost < boost@lists.boost.org> wrote:
What you could do here is to introduce a BOOST_MQTT5_ENABLE_BOOST_LOG macro
I don't like configuration macros. Because these create different libraries, effectively creating separate object files which have the potential to be incompatible at link-time. It is simpler for there to be only one version of the library with no configurations.
our goal is to find a more elegant, C++-style solution that achieves the same effect.
How do you feel about this? template< class Stream, class Logger = int, class TlsContext = std::monostate > class mqtt_client { Logger log_; // could use empty base optimization here public: void cancel() { if constexpr(is_logger<Logger>) log_("cancelling"); auto impl = _impl; _impl = impl->dup(); impl->cancel(); } ... To be honest though, I think you are being unnecessarily strict with the "zero overhead." There is nothing wrong with adding a single if statement to each function for logging. Really now, are you worried about the performance of adding a branch to a function which invokes an initiating function? I bet if you measure it, you will change your mind. Thanks