ソースを参照

Add arithmetic assign operators for endian_wrapper

master
Emil-Jarosz 3年前
コミット
b864f3a3c1
1個のファイルの変更32行の追加4行の削除
  1. +32
    -4
      include/gp/math/boolean/bitops.hpp

+ 32
- 4
include/gp/math/boolean/bitops.hpp ファイルの表示

@ -39,13 +39,13 @@ struct endian_wrapper {
: value{0} {}
endian_wrapper(T v) noexcept
: value{mode == endian::native ? v : swap_endian(v)} {}
: value{adjust(v)} {}
endian_wrapper(const endian_wrapper& v) noexcept
: value{v.value} {}
endian_wrapper& operator=(T p) noexcept {
value = mode == endian::native ? p : swap_endian(p);
endian_wrapper& operator=(T v) noexcept {
value = adjust(v);
return *this;
}
@ -55,7 +55,35 @@ struct endian_wrapper {
}
operator T() const noexcept {
return mode == endian::native ? value : swap_endian(value);
return adjust(value);
}
// arithmetic assignment operators
endian_wrapper& operator+=(T rhs) noexcept {
value = adjust(adjust(value) + rhs);
return *this;
}
endian_wrapper& operator+=(endian_wrapper rhs) noexcept {
value = adjust(adjust(value) + adjust(rhs.value));
return *this;
}
endian_wrapper& operator-=(T rhs) noexcept {
value = adjust(adjust(value) - rhs);
return *this;
}
endian_wrapper& operator-=(endian_wrapper rhs) noexcept {
value = adjust(adjust(value) - adjust(rhs.value));
return *this;
}
private:
T adjust(T x) const noexcept {
return (mode == endian::native ? x : swap_endian(x));
}
};

読み込み中…
キャンセル
保存