Addition operators for length units I'm writing some code that helps me deal with units better, by having a user defined type for things like Metres, Centimetres and Millimetres. Here is the class declaration for Metres:

template &lt;typename StorageType&gt;
class Metres : public Unit&lt;StorageType&gt;
{
public:
    static Metres fromMetres (StorageType metres) noexcept;

    Metres operator+ (Metres rhs) const noexcept;
    Metres operator+ (Centimetres&lt;StorageType&gt; rhs) const noexcept;
    Metres operator+ (Millimetres&lt;StorageType&gt; rhs) const noexcept;

protected:
    using Unit&lt;StorageType&gt;::Unit;
};


However, when writing the definitions of the operator+ functions, I find myself repeating Metres&lt;StorageType&gt; quite a lot:

template &lt;typename StorageType&gt;
Metres&lt;StorageType&gt; Metres&lt;StorageType&gt;::fromMetres (StorageType metres) noexcept
{ return { metres }; }

template &lt;typename StorageType&gt;
Metres&lt;StorageType&gt; Metres&lt;StorageType&gt;::operator+ (Millimetres&lt;StorageType&gt; rhs) const noexcept
{ return { this-&gt;getRawValue() + rhs.getRawValue() / StorageType (1000) }; }

template &lt;typename StorageType&gt;
Metres&lt;StorageType&gt; Metres&lt;StorageType&gt;::operator+ (Centimetres&lt;StorageType&gt; rhs) const noexcept
{ return { this-&gt;getRawValue() + rhs.getRawValue() / StorageType (100) }; }

template &lt;typename StorageType&gt;
Metres&lt;StorageType&gt; Metres&lt;StorageType&gt;::operator+ (Metres&lt;StorageType&gt; rhs) const noexcept
{ return { this-&gt;getRawValue() + rhs.getRawValue() }; }


I can't define the functions in the class declaration, as the types Centimetres and Millimetres forward declared. If I define these classes beforehand, I end up with the same problem in a different class.

I feel like this could be done better. How can I reduce the amount of visual noise in these function definitions?



Note:
If there are any rules in C++ that allow the omission of &lt;StorageType&gt; in certain places, quotes from the standard are much appreciated.
The obvious possibility would be to just define the functions inside the class definition:

template &lt;typename StorageType&gt;
class Metres : public Unit&lt;StorageType&gt; {
public:
    static Metres fromMetres(StorageType metres) noexcept { return metres; }

    Metres operator+ (Metres rhs) const noexcept { 
        return getRawValue() + rhs.getRawValue(); 
    }

    Metres operator+ (Centimetres&lt;StorageType&gt; rhs) const noexcept { 
        getRawValue() + rhs.getRawValue() / StorageType(100); 
    }

    Metres operator+ (Millimetres&lt;StorageType&gt; rhs) const noexcept { 
        getRawValue() + rhs.getRawValue() / StorageType(1000); 
    }

protected:
    using Unit&lt;StorageType&gt;::Unit;
};


The problem (as I'd see it, anyway) stemmed from two facts: these are templates, so you needed to include the template parameters, and the bodies of the functions in question are so tiny, they basically got lost in the noise.

Both of these point to the fact that (in this case) including the function definitions inline in the class definition gains a great deal, and loses nothing.