Skip to content

Commit

Permalink
Merge pull request #1141 from rolanddenis/cleanCPP11
Browse files Browse the repository at this point in the history
Cleaning C++11 preprocessor directives
  • Loading branch information
dcoeurjo committed Mar 10, 2016
2 parents 47952f5 + 4de3c0f commit d63a6d0
Show file tree
Hide file tree
Showing 36 changed files with 90 additions and 572 deletions.
4 changes: 3 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
## New Features / Critical Changes

## Changes
- *Configuration*
- *Configuration/General*
- Cleaning remaining preprocessor directives related to C++11 features.
(Roland Denis, [#1141](https://github.com/DGtal-team/DGtal/pull/1141))
- Travis Continuous integration will check that DGtalTools still compiles with
changes in new pull-requests. (David Coeurjolly,
[#1133](https://github.com/DGtal-team/DGtal/pull/1133))
Expand Down
69 changes: 2 additions & 67 deletions cmake/CheckCPP11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,10 @@
# Test some c++11 functionalities
# -----------------------------------------------------------------------------

try_compile( CPP11_INITIALIZER_LIST
try_compile( CPP11_COMPATIBLE
${CMAKE_BINARY_DIR}/CMakeTmp
${CMAKE_SOURCE_DIR}/cmake/src/cpp11/initializer_list.cpp
${CMAKE_SOURCE_DIR}/cmake/src/cpp11/cpp11_check.cpp
COMPILE_DEFINITIONS "-std=c++11"
OUTPUT_VARIABLE OUTPUT
)
if ( CPP11_INITIALIZER_LIST )
add_definitions("-DCPP11_INITIALIZER_LIST")
endif ( CPP11_INITIALIZER_LIST )


try_compile( CPP11_AUTO
${CMAKE_BINARY_DIR}/CMakeTmp
${CMAKE_SOURCE_DIR}/cmake/src/cpp11/auto.cpp
COMPILE_DEFINITIONS "-std=c++11"
OUTPUT_VARIABLE OUTPUT
)
if ( CPP11_AUTO )
add_definitions("-DCPP11_AUTO")
endif ( CPP11_AUTO )


try_compile( CPP11_FORWARD_LIST
${CMAKE_BINARY_DIR}/CMakeTmp
${CMAKE_SOURCE_DIR}/cmake/src/cpp11/forward_list.cpp
COMPILE_DEFINITIONS "-std=c++11"
OUTPUT_VARIABLE OUTPUT
)
if ( CPP11_FORWARD_LIST )
add_definitions("-DCPP11_FORWARD_LIST")
endif ( CPP11_FORWARD_LIST )

try_compile( CPP11_ARRAY
${CMAKE_BINARY_DIR}/CMakeTmp
${CMAKE_SOURCE_DIR}/cmake/src/cpp11/array.cpp
COMPILE_DEFINITIONS "-std=c++11"
OUTPUT_VARIABLE OUTPUT
)
if ( CPP11_ARRAY )
add_definitions("-DCPP11_ARRAY")
endif ( CPP11_ARRAY)

try_compile( CPP11_UNORDERED_SET
${CMAKE_BINARY_DIR}/CMakeTmp
${CMAKE_SOURCE_DIR}/cmake/src/cpp11/cpp11_unordered_set.cpp
COMPILE_DEFINITIONS "-std=c++0x"
OUTPUT_VARIABLE OUTPUT
)
if ( CPP11_UNORDERED_SET )
add_definitions("-DCPP11_UNORDERED_SET")
endif ( CPP11_UNORDERED_SET)

try_compile( CPP11_UNORDERED_MAP
${CMAKE_BINARY_DIR}/CMakeTmp
${CMAKE_SOURCE_DIR}/cmake/src/cpp11/cpp11_unordered_map.cpp
COMPILE_DEFINITIONS "-std=c++0x"
OUTPUT_VARIABLE OUTPUT
)
if ( CPP11_UNORDERED_MAP )
add_definitions("-DCPP11_UNORDERED_MAP")
endif ( CPP11_UNORDERED_MAP)

try_compile( CPP11_RREF_MOVE
${CMAKE_BINARY_DIR}/CMakeTmp
${CMAKE_SOURCE_DIR}/cmake/src/cpp11/rref-move.cpp
COMPILE_DEFINITIONS "-std=c++11"
OUTPUT_VARIABLE OUTPUT
)
if ( CPP11_RREF_MOVE )
add_definitions("-DCPP11_RREF_MOVE")
endif ( CPP11_RREF_MOVE )

35 changes: 4 additions & 31 deletions cmake/CheckDGtalDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,15 @@ endif( Boost_FOUND )
# -----------------------------------------------------------------------------
# Check some CPP11 features in the compiler
# -----------------------------------------------------------------------------
SET(C11_FOUND_DGTAL 0)
SET(C11_AUTO_DGTAL 0)
SET(C11_FORWARD_DGTAL 0)
SET(C11_INITIALIZER_DGTAL 0)
SET(C11_ARRAY 0)
MESSAGE(STATUS "Checking c++11 features:")
MESSAGE(STATUS "Checking C++11 compatibility:")
INCLUDE(CheckCPP11)
IF (CPP11_INITIALIZER_LIST OR CPP11_AUTO OR CP11_FORWARD_LIST)
IF (CPP11_COMPATIBLE)
IF (NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ")
ENDIF()
SET(C11_FOUND_DGTAL 1)
IF (CPP11_AUTO)
SET(C11_AUTO_DGTAL 1)
SET(C11_FEATURES "${C11_FEATURES} auto")
ENDIF()
IF (CPP11_INITIALIZER_LIST)
SET(C11_INITIALIZER_DGTAL 1)
SET(C11_FEATURES "${C11_FEATURES} initializer-list")
ENDIF()
IF (CPP11_FORWARD_LIST)
SET(C11_FORWARD_DGTAL 1)
SET(C11_FEATURES "${C11_FEATURES} std::forward-list")
ENDIF()
IF (CPP11_ARRAY)
SET(C11_ARRAY 1)
SET(C11_FEATURES "${C11_FEATURES} std::array")
ENDIF()
IF (CPP11_RREF_MOVE)
SET(C11_RREF_MOVE 1)
SET(C11_FEATURES "${C11_FEATURES} std::move rvalue-reference(&&)")
ENDIF()
MESSAGE(STATUS " [${C11_FEATURES} ]")
ADD_DEFINITIONS("-DWITH_C11 ")
MESSAGE(STATUS "OK.")
ELSE()
MESSAGE(FATAL_ERROR "Your compiler does not support any c++11 feature. Please specify another C++ compiler.")
MESSAGE(FATAL_ERROR "Your compiler does not support C++11. Please specify another C++ compiler.")
ENDIF()


Expand Down
4 changes: 1 addition & 3 deletions cmake/CheckDGtalOptionalDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ IF(WITH_ITK)
message(STATUS "ITK accepts [c++11]" )
else ( CPP11_ITK )
message(STATUS "ITK does not accept [c++11]" )
if (CPP11_AUTO OR CPP11_INITIALIZER_LIST)
MESSAGE(FATAL_ERROR "ITK was found but it appears that the package was not built with std-cpp11 extension and DGtal will not compile.")
endif(CPP11_AUTO OR CPP11_INITIALIZER_LIST)
MESSAGE(FATAL_ERROR "ITK was found but it appears that the package was not built with std-cpp11 extension and DGtal will not compile.")
endif ( CPP11_ITK )

# -------------------------------------------------------------------------
Expand Down
26 changes: 3 additions & 23 deletions cmake/DGtalConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,9 @@ IF (@COLOR_WITH_ALPHA_ARITH_DGTAL@)
ENDIF(@COLOR_WITH_ALPHA_ARITH_DGTAL@)


IF(@C11_FOUND_DGTAL@)
IF(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
ENDIF()
ADD_DEFINITIONS("-DWITH_C11 ")
SET(WITH_C11 1)
IF(@C11_AUTO_DGTAL@)
ADD_DEFINITIONS("-DCPP11_AUTO")
SET(CPP11_AUTO 1)
ENDIF(@C11_AUTO_DGTAL@)
IF(@C11_INITIALIZER_DGTAL@)
ADD_DEFINITIONS("-DCPP11_INITIALIZER_LIST")
SET(CPP11_INITIALIZER_LIST 1)
ENDIF(@C11_INITIALIZER_DGTAL@)
IF(@C11_FORWARD_DGTAL@)
ADD_DEFINITIONS("-DCPP11_FORWARD_LIST")
SET(CPP11_FORWARD_LIST 1)
ENDIF(@C11_FORWARD_DGTAL@)
IF(@C11_ARRAY_DGTAL@)
ADD_DEFINITIONS("-DCPP11_ARRAY")
SET(CPP11_ARRAY 1)
ENDIF(@C11_ARRAY_DGTAL@)
ENDIF(@C11_FOUND_DGTAL@)
IF(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
ENDIF()


IF(@GMP_FOUND_DGTAL@)
Expand Down
23 changes: 0 additions & 23 deletions cmake/src/cpp11/array.cpp

This file was deleted.

34 changes: 0 additions & 34 deletions cmake/src/cpp11/auto.cpp

This file was deleted.

73 changes: 73 additions & 0 deletions cmake/src/cpp11/cpp11_check.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
**/

#include <cstddef>
#include <array>
#include <vector>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <unordered_set>
#include <forward_list>
#include <tuple>
#include <type_traits>

// Templated aliases & tuple
template < typename T >
using Record = std::tuple< double, char, T >;

// Delayed return type & decltype.
template < typename U, typename V >
constexpr auto AddIt( U u, V v ) -> decltype( u + v ) { return u + v; }

int main()
{
constexpr auto N = 5u; // constexpr & auto
std::array<int, N> myArray; // array
std::vector<int> myVector = {1, 2, 3, 4, 5}; // initializer list

// Range-based loop
for ( auto & v : myVector )
v += N;

// New algorithms and lambdas
bool valid = std::all_of( myVector.begin(), myVector.end(), [&N] ( int v ) { return v > N; } );

// decltype, declval & rvalue ref
decltype( std::declval< std::vector<int> >()[0] ) && b = myVector[3];

// Unordered set
std::unordered_set<int> mySet;
std::unordered_multiset<int> myMultiSet;

// Unordered map
std::unordered_map<int, int> myMap;

// Forward list
std::forward_list< Record<int> > myList;

// variadic template & std::forward
myList.emplace_front( 3.14, 'a', 3 );

// type_traits & move
constexpr bool isMovable = std::is_move_assignable< decltype( AddIt(3, 3.14) ) >::value;

// nullptr
int* ptr = nullptr;


return 0;
}
24 changes: 0 additions & 24 deletions cmake/src/cpp11/cpp11_unordered_map.cpp

This file was deleted.

24 changes: 0 additions & 24 deletions cmake/src/cpp11/cpp11_unordered_set.cpp

This file was deleted.

25 changes: 0 additions & 25 deletions cmake/src/cpp11/forward_list.cpp

This file was deleted.

Loading

0 comments on commit d63a6d0

Please sign in to comment.