[eigen] Using C++11 features

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


I have found that C++11 features are only partially implemented (on many compilers). Hence, I use CMake to detect if a particular C++11 feature is available, and if so use it. For example, see
https://projects.coin-or.org/CppAD/browser/trunk/cppad/CMakeLists.txt
where the following code checks for the C++11 null_ptr feature:

# -----------------------------------------------------------------------------
# cppad_has_nullptr
#
# CHECK_CXX_SOURCE_RUNS(source variable)
SET(CMAKE_REQUIRED_INCLUDES  "")
SET(CMAKE_REQUIRED_LIBRARIES "")
SET(CMAKE_REQUIRED_FLAGS     ${cppad_cxx_flags})
SET(source "
int main(void)
{    char *c = nullptr;
     return 0;
}" )
CHECK_CXX_SOURCE_RUNS("${source}" nullptr_ok)
IF( nullptr_ok )
     SET(cppad_has_nullptr 1)
ELSE( nullptr_ok )
     SET(cppad_has_nullptr 0)
ENDIF( nullptr_ok )
MESSAGE(STATUS "cppad_has_nullptr = ${cppad_has_nullptr}" )



On 10/30/2013 3:17 PM, Christoph Hertzberg wrote:
On 30.10.2013 20:02, Jim Garrison wrote:
On 10/30/2013 03:20 AM, Christoph Hertzberg wrote:
Generally, I agree that we should use more C++11 features in the future.
It does however bear the risk that projects using those features
immediately lose compatibility to older compilers (which unfortunately
are still common e.g. for embedded systems) -- that's especially the
case if we introduce new core functionality depending on C++11.

Actually, this is one of the reasons I suggested using a #define to
enable Eigen's C++11 features.  If one must manually define
EIGEN_ENABLE_CXX11, it will remove the risk that a project begins using
C++11 features without realizing it.

Yes, that's actually a good point. There were some points, where we need to detect C++11 to circumvent incompatibilities (something about allocators, IIRC). So maybe an only user-defined EIGEN_ENABLE_CXX11 and an auto-detected EIGEN_HAS_CXX11.

Another issue is that some compiler versions claim to support C++11
through their __cplusplus macro, but do not support all C++11 features.

Yes, I'm afraid that some problems will appear, once more people start experimenting with C++11 and with more exotic compilers (AFAIK, no major compiler has it enabled by default as of now?)


BTW: Please just answer to the list, I'm getting every mail twice ...

Christoph







Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/