Skip to main content
2 of 3
added 24 characters in body
Jamal
  • 34.9k
  • 13
  • 133
  • 237
  1. Consider using overload resolution to resolve the proper logging-method.

    • That allows you to template that member, and maybe use perfect forwarding.
  2. Don't make useless costly copies. You can take arguments by const&.

  3. Avoid std::endl, as constant flushing also flushes any chance of good performance down the drain.

     struct Chatty {
         template<class T>
         static void log(T&& t) { std::cout << std::forward<T>(t) << '\n'; }
     };
     struct Silent {
         template<class T>
         static void log(T&&) {}
     };
    
  4. Your WidgetMaker is currently restricted to Loggingpolicies and CreationPolicies which are templates. That's a bad idea. Better accept a type-parameter like everyone else.

  5. doAll assumes the logging-method is static. Why then do you assign it to a std::function? (Yes, that function should have a signature avoiding copies, but that's a separate problem.)

    The easiest way to repair that is using a lambda. Or you can get fancy with SFINAE and maybe also allow the policy-class to only implement those parts it wants to override.

Deduplicator
  • 19.3k
  • 1
  • 31
  • 65