Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coin-lemon: allow to consume coin-lemon with C++20 or higher #17338

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions recipes/coin-lemon/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@ sources:
sha256: "71b7c725f4c0b4a8ccb92eb87b208701586cf7a96156ebd821ca3ed855bad3c8"
patches:
"1.3.1":
- patch_file: "patches/cmake-add-runtime-destination_1.3.1.patch"
- patch_file: "patches/0001-remove-register-keyword.patch"
- patch_file: "patches/0001-cmake-add-runtime-destination.patch"
patch_description: "Fix install destination of dll"
patch_type: "conan"
- patch_file: "patches/0002-cpp17-compat-remove-register-keyword.patch"
patch_description: "C++17 compatibility: remove register keyword"
patch_type: "portability"
- patch_file: "patches/0003-cpp20-compat-alloc.patch"
patch_description: "C++20 compatibility: remove usage of std::allocator<T>::construct & destroy"
patch_type: "portability"
199 changes: 199 additions & 0 deletions recipes/coin-lemon/all/patches/0003-cpp20-compat-alloc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
--- a/lemon/bits/array_map.h
+++ b/lemon/bits/array_map.h
@@ -88,7 +88,11 @@ namespace lemon {
Item it;
for (nf->first(it); it != INVALID; nf->next(it)) {
int id = nf->id(it);;
+#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L)
+ std::allocator_traits<Allocator>::construct(allocator, &(values[id]), Value());
+#else
allocator.construct(&(values[id]), Value());
+#endif
}
}

@@ -102,7 +106,11 @@ namespace lemon {
Item it;
for (nf->first(it); it != INVALID; nf->next(it)) {
int id = nf->id(it);;
+#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L)
+ std::allocator_traits<Allocator>::construct(allocator, &(values[id]), value);
+#else
allocator.construct(&(values[id]), value);
+#endif
}
}

@@ -121,7 +129,11 @@ namespace lemon {
Item it;
for (nf->first(it); it != INVALID; nf->next(it)) {
int id = nf->id(it);;
+#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L)
+ std::allocator_traits<Allocator>::construct(allocator, &(values[id]), copy.values[id]);
+#else
allocator.construct(&(values[id]), copy.values[id]);
+#endif
}
}

@@ -218,15 +230,24 @@ namespace lemon {
for (nf->first(it); it != INVALID; nf->next(it)) {
int jd = nf->id(it);;
if (id != jd) {
+#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L)
+ std::allocator_traits<Allocator>::construct(allocator, &(new_values[jd]), values[jd]);
+ std::allocator_traits<Allocator>::destroy(allocator, &(values[jd]));
+#else
allocator.construct(&(new_values[jd]), values[jd]);
allocator.destroy(&(values[jd]));
+#endif
}
}
if (capacity != 0) allocator.deallocate(values, capacity);
values = new_values;
capacity = new_capacity;
}
+#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L)
+ std::allocator_traits<Allocator>::construct(allocator, &(values[id]), Value());
+#else
allocator.construct(&(values[id]), Value());
+#endif
}

// \brief Adds more new keys to the map.
@@ -260,8 +281,13 @@ namespace lemon {
}
}
if (found) continue;
+#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L)
+ std::allocator_traits<Allocator>::construct(allocator, &(new_values[id]), values[id]);
+ std::allocator_traits<Allocator>::destroy(allocator, &(values[id]));
+#else
allocator.construct(&(new_values[id]), values[id]);
allocator.destroy(&(values[id]));
+#endif
}
if (capacity != 0) allocator.deallocate(values, capacity);
values = new_values;
@@ -269,7 +295,11 @@ namespace lemon {
}
for (int i = 0; i < int(keys.size()); ++i) {
int id = nf->id(keys[i]);
+#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L)
+ std::allocator_traits<Allocator>::construct(allocator, &(values[id]), Value());
+#else
allocator.construct(&(values[id]), Value());
+#endif
}
}

@@ -279,7 +309,11 @@ namespace lemon {
// and it overrides the erase() member function of the observer base.
virtual void erase(const Key& key) {
int id = Parent::notifier()->id(key);
+#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L)
+ std::allocator_traits<Allocator>::destroy(allocator, &(values[id]));
+#else
allocator.destroy(&(values[id]));
+#endif
}

// \brief Erase more keys from the map.
@@ -289,7 +323,11 @@ namespace lemon {
virtual void erase(const std::vector<Key>& keys) {
for (int i = 0; i < int(keys.size()); ++i) {
int id = Parent::notifier()->id(keys[i]);
+#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L)
+ std::allocator_traits<Allocator>::destroy(allocator, &(values[id]));
+#else
allocator.destroy(&(values[id]));
+#endif
}
}

@@ -303,7 +341,11 @@ namespace lemon {
Item it;
for (nf->first(it); it != INVALID; nf->next(it)) {
int id = nf->id(it);;
+#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L)
+ std::allocator_traits<Allocator>::construct(allocator, &(values[id]), Value());
+#else
allocator.construct(&(values[id]), Value());
+#endif
}
}

@@ -317,7 +359,11 @@ namespace lemon {
Item it;
for (nf->first(it); it != INVALID; nf->next(it)) {
int id = nf->id(it);
+#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L)
+ std::allocator_traits<Allocator>::destroy(allocator, &(values[id]));
+#else
allocator.destroy(&(values[id]));
+#endif
}
allocator.deallocate(values, capacity);
capacity = 0;
--- a/lemon/path.h
+++ b/lemon/path.h
@@ -582,7 +582,11 @@ namespace lemon {
void clear() {
while (first != 0) {
last = first->next;
+#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L)
+ std::allocator_traits<std::allocator<Node>>::destroy(alloc, first);
+#else
alloc.destroy(first);
+#endif
alloc.deallocate(first, 1);
first = last;
}
@@ -596,7 +600,11 @@ namespace lemon {
/// \brief Add a new arc before the current path
void addFront(const Arc& arc) {
Node *node = alloc.allocate(1);
+#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L)
+ std::allocator_traits<std::allocator<Node>>::construct(alloc, node, Node());
+#else
alloc.construct(node, Node());
+#endif
node->prev = 0;
node->next = first;
node->arc = arc;
@@ -617,7 +625,11 @@ namespace lemon {
} else {
last = 0;
}
+#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L)
+ std::allocator_traits<std::allocator<Node>>::destroy(alloc, node);
+#else
alloc.destroy(node);
+#endif
alloc.deallocate(node, 1);
}

@@ -629,7 +641,11 @@ namespace lemon {
/// \brief Add a new arc behind the current path.
void addBack(const Arc& arc) {
Node *node = alloc.allocate(1);
+#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L)
+ std::allocator_traits<std::allocator<Node>>::construct(alloc, node, Node());
+#else
alloc.construct(node, Node());
+#endif
node->next = 0;
node->prev = last;
node->arc = arc;
@@ -650,7 +666,11 @@ namespace lemon {
} else {
first = 0;
}
+#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L)
+ std::allocator_traits<std::allocator<Node>>::destroy(alloc, node);
+#else
alloc.destroy(node);
+#endif
alloc.deallocate(node, 1);
}

3 changes: 1 addition & 2 deletions recipes/coin-lemon/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES CXX)

find_package(LEMON CONFIG REQUIRED)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE LEMON::LEMON)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)