You can (over-)generalise your parameter from having the two boolean states to any value type instead:
template<typename Value>
class Accessor {
public:
Accessor(Value& data)
: data(data)
{}
template<typename T, EnableIf<std::is_convertible<T&, Value&>>...>
Accessor(Accessor<T> const& other)
: data(other.data)
{}
Value& data;
};
Obviously this isn’t any different than what you have, except under another guise: instead of Accessor<false>
and Accessor<true>
, you have Accessor<DataType>
and Accessor<DataType const>
.
The benefit is familiarity: all of e.g. std::unique_ptr<T>
, std::shared_ptr<T>
, std::reference_wrapper<T>
(and even T*
) behave the same way. In particular, this famialiarity should hopefully extend to compiler errors about a lack of conversion from Accessor<DataType const>
to Accessor<DataType>
, much like you can’t convert from int const*
to int*
.