Added EIGEN_REF_TO_TEMPORARY define for rvalue support.

Allowed VC10 to make use of static_assert.
This commit is contained in:
Hauke Heibel 2009-09-21 19:59:58 +02:00
parent c1c780a94f
commit c6822d6723
9 changed files with 22 additions and 14 deletions

View File

@ -108,6 +108,10 @@ if(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION)
message("Disabling vectorization in tests/examples") message("Disabling vectorization in tests/examples")
endif(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION) endif(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION)
option(EIGEN_TEST_C++0x "Enables all C++0x features." OFF)
option(EIGEN_TEST_RVALUE_REF_SUPPORT "Enable rvalue references for unit tests." OFF)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
set(INCLUDE_INSTALL_DIR set(INCLUDE_INSTALL_DIR

View File

@ -538,7 +538,7 @@ class Matrix
* data pointers. * data pointers.
*/ */
template<typename OtherDerived> template<typename OtherDerived>
void swap(const MatrixBase<OtherDerived>& other); void swap(MatrixBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other);
/** \name Map /** \name Map
* These are convenience functions returning Map objects. The Map() static functions return unaligned Map objects, * These are convenience functions returning Map objects. The Map() static functions return unaligned Map objects,
@ -756,7 +756,7 @@ struct ei_matrix_swap_impl<MatrixType, OtherDerived, true>
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
template<typename OtherDerived> template<typename OtherDerived>
inline void Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::swap(const MatrixBase<OtherDerived>& other) inline void Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::swap(MatrixBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other)
{ {
enum { SwapPointers = ei_is_same_type<Matrix, OtherDerived>::ret && Base::SizeAtCompileTime==Dynamic }; enum { SwapPointers = ei_is_same_type<Matrix, OtherDerived>::ret && Base::SizeAtCompileTime==Dynamic };
ei_matrix_swap_impl<Matrix, OtherDerived, bool(SwapPointers)>::run(*this, *const_cast<MatrixBase<OtherDerived>*>(&other)); ei_matrix_swap_impl<Matrix, OtherDerived, bool(SwapPointers)>::run(*this, *const_cast<MatrixBase<OtherDerived>*>(&other));

View File

@ -592,7 +592,7 @@ template<typename Derived> class MatrixBase
{ return typename ei_eval<Derived>::type(derived()); } { return typename ei_eval<Derived>::type(derived()); }
template<typename OtherDerived> template<typename OtherDerived>
void swap(const MatrixBase<OtherDerived>& other); void swap(MatrixBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other);
template<unsigned int Added> template<unsigned int Added>
const Flagged<Derived, Added, 0> marked() const; const Flagged<Derived, Added, 0> marked() const;

View File

@ -128,15 +128,9 @@ template<typename ExpressionType> class SwapWrapper
*/ */
template<typename Derived> template<typename Derived>
template<typename OtherDerived> template<typename OtherDerived>
void MatrixBase<Derived>::swap(const MatrixBase<OtherDerived>& other) void MatrixBase<Derived>::swap(MatrixBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other)
{ {
(SwapWrapper<Derived>(derived())).lazyAssign(other); (SwapWrapper<Derived>(derived())).lazyAssign(other);
} }
#endif // EIGEN_SWAP_H #endif // EIGEN_SWAP_H

View File

@ -300,13 +300,13 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView
} }
template<typename OtherDerived> template<typename OtherDerived>
void swap(const TriangularBase<OtherDerived>& other) void swap(TriangularBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other)
{ {
TriangularView<SwapWrapper<MatrixType>,Mode>(const_cast<MatrixType&>(m_matrix)).lazyAssign(other.derived()); TriangularView<SwapWrapper<MatrixType>,Mode>(const_cast<MatrixType&>(m_matrix)).lazyAssign(other.derived());
} }
template<typename OtherDerived> template<typename OtherDerived>
void swap(const MatrixBase<OtherDerived>& other) void swap(MatrixBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other)
{ {
TriangularView<SwapWrapper<MatrixType>,Mode>(const_cast<MatrixType&>(m_matrix)).lazyAssign(other.derived()); TriangularView<SwapWrapper<MatrixType>,Mode>(const_cast<MatrixType&>(m_matrix)).lazyAssign(other.derived());
} }

View File

@ -251,6 +251,13 @@ using Eigen::ei_cos;
// needed to define it here as escaping characters in CMake add_definition's argument seems very problematic. // needed to define it here as escaping characters in CMake add_definition's argument seems very problematic.
#define EIGEN_DOCS_IO_FORMAT IOFormat(3, 0, " ", "\n", "", "") #define EIGEN_DOCS_IO_FORMAT IOFormat(3, 0, " ", "\n", "", "")
// C++0x features
#if defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(_MSC_VER) && (_MSC_VER >= 1600))
#define EIGEN_REF_TO_TEMPORARY &&
#else
#define EIGEN_REF_TO_TEMPORARY const &
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \ #define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \
using Base::operator =; \ using Base::operator =; \

View File

@ -41,7 +41,7 @@
#ifndef EIGEN_NO_STATIC_ASSERT #ifndef EIGEN_NO_STATIC_ASSERT
#ifdef __GXX_EXPERIMENTAL_CXX0X__ #if defined(__GXX_EXPERIMENTAL_CXX0X__) || (defined(_MSC_VER) && (_MSC_VER >= 1600))
// if native static_assert is enabled, let's use it // if native static_assert is enabled, let's use it
#define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG); #define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG);

View File

@ -515,7 +515,7 @@ template<typename Derived> class SparseMatrixBase : public AnyMatrixBase<Derived
{ return typename ei_eval<Derived>::type(derived()); } { return typename ei_eval<Derived>::type(derived()); }
// template<typename OtherDerived> // template<typename OtherDerived>
// void swap(const MatrixBase<OtherDerived>& other); // void swap(MatrixBase<OtherDerived> EIGEN_REF_TO_TEMPORARY other);
template<unsigned int Added> template<unsigned int Added>
const SparseFlagged<Derived, Added, 0> marked() const; const SparseFlagged<Derived, Added, 0> marked() const;

View File

@ -159,6 +159,9 @@ if(CMAKE_COMPILER_IS_GNUCXX)
else(EIGEN_COVERAGE_TESTING) else(EIGEN_COVERAGE_TESTING)
set(COVERAGE_FLAGS "") set(COVERAGE_FLAGS "")
endif(EIGEN_COVERAGE_TESTING) endif(EIGEN_COVERAGE_TESTING)
if((EIGEN_TEST_RVALUE_REF_SUPPORT OR EIGEN_TEST_C++0x) AND NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
endif((EIGEN_TEST_RVALUE_REF_SUPPORT OR EIGEN_TEST_C++0x) AND NOT MSVC)
if(CMAKE_SYSTEM_NAME MATCHES Linux) if(CMAKE_SYSTEM_NAME MATCHES Linux)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS} -g2") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS} -g2")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${COVERAGE_FLAGS} -O2 -g2") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${COVERAGE_FLAGS} -O2 -g2")