joboccara / NamedType

Implementation of strong types in C++
MIT License
769 stars 84 forks source link

use "final" if available #19

Closed DBJDBJ closed 3 years ago

DBJDBJ commented 6 years ago

I might be so bold, as to suggest this...

   #ifdef __cpp_lib_is_final
        #define FLUENT_FINAL final
 #else
       #define FLUENT_FINAL
 #endif

Little optimization and big, clear message from interface author:

         template <
                       typename T, 
                       typename Parameter, 
                       template<typename> class... Skills
                   >
      class FLUENT_EBCO NamedType FLUENT_FINAL
            : public Skills<NamedType<T, Parameter, Skills...>>...
       {
       } ;

Regards ...

CelticMinstrel commented 3 years ago

I disagree. Declaring your named type like this seems like a valid strategy to me:

using namespace fluent;
struct MyType : public NamedType<int, Addable, Comparable> {
  using NamedType<int, Addable, Comparable>::NamedType;
  // Potentially add other, special capabilities
};

It also has the bonus of shortening your compiler's error messages if you used a lot of "skills".

DBJDBJ commented 3 years ago

Huh? What is the connection with having or not having final?

CelticMinstrel commented 3 years ago

I'm not quite sure what you're asking, but marking the NamedType class as final would mean that the above example code fails to compile.