Generic Property class Some time ago I wrote a little property class for a then abandoned project. I just stumbled over it again and I would like to know if the design is using good, efficient C++.

#pragma once

#ifndef NO_THREAD_SAFETY
#include &lt;atomic&gt;
#endif

template&lt;typename T1&gt;
class Property {
public:

#ifndef NO_THREAD_SAFETY
    typedef std::atomic&lt;long&gt; PropertyID;
    typedef std::atomic&lt;T1&gt;   PropertyValue;
#else
    typedef long              PropertyID;
    typedef T1                PropertyValue;
#endif

    Property(T1 value): value(value), id(id_count++) {
    }
    Property(): value(), id(id_count++) {
    }
    Property(const Property &amp;rhs): id(id_count++) {
        value = static_cast&lt;T1&gt;(rhs.value);
    }
    Property(Property &amp;&amp;rhs): value(std::move(rhs.value)), id(id_count++) {
    }

    const Property &amp;operator=(const Property &amp;rhs) {
        value = std::move(static_cast&lt;T1&gt;(rhs.value));
        return *this;
    }
    const Property &amp;operator=(const T1 &amp;rhs) {
        value = rhs;
        return *this;
    }
    const Property &amp;operator=(T1 &amp;&amp;rhs) {
        value = std::move(rhs);
        return *this;
    }

    bool operator==(const Property &amp;rhs) const {
        return value == rhs.value;
    }
    bool operator==(const T1 &amp;rhs) const {
        return value == rhs;
    }
    bool operator&lt; (const Property &amp;rhs) const {
        return value &lt; rhs.value;
    }
    bool operator&lt; (const T1 &amp;rhs) const {
        return value &lt; rhs;
    }
    void set(const T1 &amp;value) {
        this-&gt;value = value;
    }

    T1 get() const {
        return value;
    }
    operator T1() const {
        return value;
    }
    PropertyID getID() const {
        return id;
    }

private:

    PropertyValue value;
    PropertyID id;
    static PropertyID id_count;
};

template&lt;typename T1&gt;
typename Property&lt;T1&gt;::PropertyID Property&lt;T1&gt;::id_count (0);
These are the things that stuck out to me:


Your copy constructor and move constructor don't result in an identical Property&lt;T1&gt; as they increment the id. Why is that? (There is no documentation anywhere in this that helps the consumer of your Property class.)
Your value constructor Property(T1 value) should probably initialize value with std::move(value). It has already received a copy (perhaps moved), so it is safe to move from value.
Your copy constructor uses what appears to be a superfluous static_cast&lt;T1&gt; and uses the constructor body instead of an initialization list. I would suggest this be more like the move constructor just without the call to std::move.
As nothing appears to change the value of id after it has been constructed, I don't see the benefit of id being atomic. I do understand the value of id_count being atomic, but making them both atomic seems to be asking for unnecessary overhead. Related, perhaps the usage of id_count should be moved to a static function so that it cannot be subverted.

static PropertyID getNextId() {      // assumes PropertyID is non-atomic
    static AtomicPropertyID id = 0;  // and AtomicPropertyID is conditionally atomic
    return id++;
}

I don't quite understand how Property&lt;T1&gt; is expected to be used. Does it go in a collection of properties? Is it used to declare as members of another type? If the former, the implementation of operator&lt; doesn't seem to provide any useful characteristics for finding the right property. If the latter, the encapsulation seems to be a very long winded way of conditionally making a member atomic - since there is no business logic in the setter or getter methods, and no way to provide that other than inheriting, I'm unclear what the benefit is of using this class.