Efficient and simple comparison operators for structs : <p>The application I am working on currently has a large number structs which contain data which is input from various sources such as data bases and files. For example like this:</p>

<pre><code>struct A 
{
    float val1;
    std::string val2;
    int val3;

    bool operator &lt; (const A&amp; other) const;
};
</code></pre>

<p>For processing, these structs are stored up in STL-containers, such as maps and therefore need a comparison operator. These are all the same and using simple boolean logic they can be written like this:</p>

<pre><code>bool A:operator &lt; (const A&amp; o) const {
    return val1 &lt; o.val1 || 
        (val1 == o.val1 &amp;&amp; ( val2 &lt; o.val2 || 
            (val2 == o.val2 &amp;&amp; ( val3 &lt; o.val3 ) ) );
}
</code></pre>

<p>This seems efficient, but has several drawbacks:</p>

<ol>
<li>These expressions get huge if the structs as a dozen or more members.</li>
<li>It is cumbersome to write and maintain if members change.</li>
<li>It needs to be done for every struct separately.</li>
</ol>

<p>Is there a more maintainable way to compare structs like this?</p>
