xref: /aosp_15_r20/external/eigen/test/MovableScalar.h (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2020 Sebastien Boisvert <[email protected]>
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 
10 #ifndef EIGEN_MISC_MOVABLE_SCALAR_H
11 #define EIGEN_MISC_MOVABLE_SCALAR_H
12 
13 #include <vector>
14 
15 namespace Eigen
16 {
17 template <typename Scalar, typename Base = std::vector<Scalar>>
18 struct MovableScalar : public Base
19 {
20   MovableScalar() = default;
21   ~MovableScalar() = default;
22   MovableScalar(const MovableScalar&) = default;
23   MovableScalar(MovableScalar&& other) = default;
24   MovableScalar& operator=(const MovableScalar&) = default;
25   MovableScalar& operator=(MovableScalar&& other) = default;
MovableScalarMovableScalar26   MovableScalar(Scalar scalar) : Base(100, scalar) {}
27 
ScalarMovableScalar28   operator Scalar() const { return this->size() > 0 ? this->back() : Scalar(); }
29 };
30 
31 template<> struct NumTraits<MovableScalar<float>> : GenericNumTraits<float> {};
32 }
33 
34 #endif
35 
36