1
\$\begingroup\$

I am creating a boiler-plate namespace that will allow me to ensure proper coding practices are followed and avoid gotchas.

Looking over my code below; can you see any "no-no's" or gotchas? Can you also provide advice on anything I should do differently or add?

#ifndef PROJECT_INTERFACES_H_
#define PROJECT_INTERFACES_H_

// Ensure proper coding conventions are followed
namespace ProjectInterfaces
{
    class IUnitTest
    {
        protected:
            friend class RegressionTest;
            virtual bool unitTest() const = 0;
    };

    template <class T>
    class INonCopyable
    {
        protected:
            INonCopyable() { }
            ~INonCopyable() { }

        private:
            INonCopyable(const INonCopyable& iNoCopy);              // =  delete;  C++11 
            INonCopyable& operator=(const INonCopyable& iNoCopy);   // =  delete;
            INonCopyable(INonCopyable&& iNoCopy);                   // = default;
            INonCopyable& operator=(INonCopyable&& iNoCopy);        // = default; 
    };

    template <typename T>
    class IMapKey
    {
        public:
            virtual bool operator<(const T& other) const = 0;
    };
}

#endif // PROJECT_INTERFACES_H_

Code usage:

// Should these use virtual inheritence?
class MyClass : private INonCopyable<MyClass>, public IUnitTest, public IMapKey<MyClass>
{
  public:
      MyClass(const int& value) : value_(value)
      {

      }

      virtual bool operator<(const MyClass& other) const override
      {
          return value_ < other.value_;
      }

      const int getValue() const
      {
          return value_;
      }

  protected:
      virtual bool unitTest() const override 
      {
          // ...
          return true;
      }

  private:
      int value_;
};
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.