NotAll my comments are very minor:
###Dry Code:
Your constructor/assignment operator are not DRY.
constexpr explicit gray_code(value_type value) noexcept:
value( (value >> 1) ^ value )
{}
auto operator=(value_type other) & noexcept
-> gray_code&
{
value = (other >> 1) ^ other;
return *this;
}
If things change you have to modify the code in multiple places. You should wrap the work in a function. That both these methods use:
constexpr explicit gray_code(value_type value) noexcept:
value( convertValueToGrey(value) )
{}
auto operator=(value_type other) & noexcept
-> gray_code&
{
value = convertValueToGrey(other);
return *this;
}
###New Return Type:
Not sure I like the new style of return:
I personal don't think it is as clear (but that may be me and I need to get used to it). Personally I currently only use the new style when the return type is being derived.
PS###Public Member Variables: The last & symbol what
Your value is public:
Not sure if this is on purpose? You have assignment that does it meanconversion on the way in and a conversion operator to adjust the value on the way out. Do you really want to allow access to the raw value for manipulation without supervision?
gray_code& operator=(value_type other) &struct noexceptgray_code
// ^^^ {
What does thatvalue_type mean?value;
The###Costly Conversion
The conversion back to value_type seems a bit heavy:
// Variable containing the gray code
value_type value;
mutable value_type convertedValue; // Created on construction/assignment.
// Marked as mutable to indicate that
// it is not part of the state of the
// object but rather a cached value.
operator value_type() const noexcept {return convertedValue;}
Your constructor/assignment operator are not DRY.
constexpr explicit gray_code(value_type value) noexcept:
value( (value >> 1) ^ value )
{}
auto operator=(value_type other) & noexcept
-> gray_code&
{
value = (other >> 1) ^ other;
return *this;
}
If things change you have to modify the code in multiple places. You should wrap the work in a function. That both these methods use:
constexpr explicit gray_code(value_type value) noexcept:
value( convertValueToGrey(value) )
{}
auto operator=(value_type other) & noexcept
-> gray_code&
{
value = convertValueToGrey(other);
return *this;
}
Your value is public:
Not sure if this is on purpose? You have assignment that does conversion on the way in and a conversion operator to adjust the value on the way out. Do you really want to allow access to the raw value for manipulation without supervision?
struct gray_code
{
value_type value;