OffByOneScalar.h 578 B

12345678910111213141516171819202122232425262728
  1. // A Scalar with internal representation T+1 so that zero is internally
  2. // represented by T(1). This is used to test memory fill.
  3. //
  4. template<typename T>
  5. class OffByOneScalar {
  6. public:
  7. OffByOneScalar() : val_(1) {}
  8. OffByOneScalar(const OffByOneScalar& other) {
  9. *this = other;
  10. }
  11. OffByOneScalar& operator=(const OffByOneScalar& other) {
  12. val_ = other.val_;
  13. return *this;
  14. }
  15. OffByOneScalar(T val) : val_(val + 1) {}
  16. OffByOneScalar& operator=(T val) {
  17. val_ = val + 1;
  18. }
  19. operator T() const {
  20. return val_ - 1;
  21. }
  22. private:
  23. T val_;
  24. };