MovableScalar.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2020 Sebastien Boisvert <seb@boisvert.info>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla
  7. // Public License v. 2.0. If a copy of the MPL was not distributed
  8. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #ifndef EIGEN_MISC_MOVABLE_SCALAR_H
  10. #define EIGEN_MISC_MOVABLE_SCALAR_H
  11. #include <vector>
  12. namespace Eigen
  13. {
  14. template <typename Scalar, typename Base = std::vector<Scalar>>
  15. struct MovableScalar : public Base
  16. {
  17. MovableScalar() = default;
  18. ~MovableScalar() = default;
  19. MovableScalar(const MovableScalar&) = default;
  20. MovableScalar(MovableScalar&& other) = default;
  21. MovableScalar& operator=(const MovableScalar&) = default;
  22. MovableScalar& operator=(MovableScalar&& other) = default;
  23. MovableScalar(Scalar scalar) : Base(100, scalar) {}
  24. operator Scalar() const { return this->size() > 0 ? this->back() : Scalar(); }
  25. };
  26. template<> struct NumTraits<MovableScalar<float>> : GenericNumTraits<float> {};
  27. }
  28. #endif