[136] | 1 | // This file is part of Eigen, a lightweight C++ template library
|
---|
| 2 | // for linear algebra.
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 2013 Hauke Heibel <hauke.heibel@gmail.com>
|
---|
| 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 | #include "main.h"
|
---|
| 11 |
|
---|
| 12 | #include <Eigen/Core>
|
---|
| 13 |
|
---|
| 14 | #ifdef EIGEN_HAVE_RVALUE_REFERENCES
|
---|
| 15 | template <typename MatrixType>
|
---|
| 16 | void rvalue_copyassign(const MatrixType& m)
|
---|
| 17 | {
|
---|
| 18 |
|
---|
| 19 | typedef typename internal::traits<MatrixType>::Scalar Scalar;
|
---|
| 20 |
|
---|
| 21 | // create a temporary which we are about to destroy by moving
|
---|
| 22 | MatrixType tmp = m;
|
---|
| 23 | long src_address = reinterpret_cast<long>(tmp.data());
|
---|
| 24 |
|
---|
| 25 | // move the temporary to n
|
---|
| 26 | MatrixType n = std::move(tmp);
|
---|
| 27 | long dst_address = reinterpret_cast<long>(n.data());
|
---|
| 28 |
|
---|
| 29 | if (MatrixType::RowsAtCompileTime==Dynamic|| MatrixType::ColsAtCompileTime==Dynamic)
|
---|
| 30 | {
|
---|
| 31 | // verify that we actually moved the guts
|
---|
| 32 | VERIFY_IS_EQUAL(src_address, dst_address);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | // verify that the content did not change
|
---|
| 36 | Scalar abs_diff = (m-n).array().abs().sum();
|
---|
| 37 | VERIFY_IS_EQUAL(abs_diff, Scalar(0));
|
---|
| 38 | }
|
---|
| 39 | #else
|
---|
| 40 | template <typename MatrixType>
|
---|
| 41 | void rvalue_copyassign(const MatrixType&) {}
|
---|
| 42 | #endif
|
---|
| 43 |
|
---|
| 44 | void test_rvalue_types()
|
---|
| 45 | {
|
---|
| 46 | CALL_SUBTEST_1(rvalue_copyassign( MatrixXf::Random(50,50).eval() ));
|
---|
| 47 | CALL_SUBTEST_1(rvalue_copyassign( ArrayXXf::Random(50,50).eval() ));
|
---|
| 48 |
|
---|
| 49 | CALL_SUBTEST_1(rvalue_copyassign( Matrix<float,1,Dynamic>::Random(50).eval() ));
|
---|
| 50 | CALL_SUBTEST_1(rvalue_copyassign( Array<float,1,Dynamic>::Random(50).eval() ));
|
---|
| 51 |
|
---|
| 52 | CALL_SUBTEST_1(rvalue_copyassign( Matrix<float,Dynamic,1>::Random(50).eval() ));
|
---|
| 53 | CALL_SUBTEST_1(rvalue_copyassign( Array<float,Dynamic,1>::Random(50).eval() ));
|
---|
| 54 |
|
---|
| 55 | CALL_SUBTEST_2(rvalue_copyassign( Array<float,2,1>::Random().eval() ));
|
---|
| 56 | CALL_SUBTEST_2(rvalue_copyassign( Array<float,3,1>::Random().eval() ));
|
---|
| 57 | CALL_SUBTEST_2(rvalue_copyassign( Array<float,4,1>::Random().eval() ));
|
---|
| 58 |
|
---|
| 59 | CALL_SUBTEST_2(rvalue_copyassign( Array<float,2,2>::Random().eval() ));
|
---|
| 60 | CALL_SUBTEST_2(rvalue_copyassign( Array<float,3,3>::Random().eval() ));
|
---|
| 61 | CALL_SUBTEST_2(rvalue_copyassign( Array<float,4,4>::Random().eval() ));
|
---|
| 62 | }
|
---|