diff --git a/.bazelrc b/.bazelrc index 30229f7da7c..1c1d285ac5f 100644 --- a/.bazelrc +++ b/.bazelrc @@ -34,7 +34,7 @@ build --enable_platform_specific_config # Options for Linux. ############################################################################### -build:linux --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 +build:linux --cxxopt=-std=c++20 --host_cxxopt=-std=c++20 build:linux --cxxopt=-Wno-sign-compare --host_cxxopt=-Wno-sign-compare build:linux --cxxopt=-Wno-range-loop-construct --host_cxxopt=-Wno-range-loop-construct @@ -45,7 +45,7 @@ build:linux --cxxopt=-Wno-range-loop-construct --host_cxxopt=-Wno-range-loop-con # Sets the default Apple platform to macOS. build --apple_platform_type=macos build:macos --features=-supports_dynamic_linker -build:macos --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 +build:macos --cxxopt=-std=c++20 --host_cxxopt=-std=c++20 build:macos --cxxopt=-Wno-sign-compare --host_cxxopt=-Wno-sign-compare build:macos --cxxopt=-Wno-dangling-field --host_cxxopt=-Wno-dangling-field build:macos --cxxopt=-Wno-range-loop-construct --host_cxxopt=-Wno-range-loop-construct diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e29e4a3736..2637e1a0b84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,11 +28,7 @@ message(STATUS "${PROJECT_NAME} version: ${PROJECT_VERSION} release: ${RELEASE}" #message(STATUS "minor: ${PROJECT_VERSION_MINOR}") #message(STATUS "patch: ${PROJECT_VERSION_PATCH}") -if(MSVC) - set(CMAKE_CXX_STANDARD 20) -else() - set(CMAKE_CXX_STANDARD 17) -endif() +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/bazel/README.md b/bazel/README.md index 61e3a212c65..4ddd69d6df8 100644 --- a/bazel/README.md +++ b/bazel/README.md @@ -72,35 +72,15 @@ OR-Tools depends on several mandatory libraries. ## Compilation -You must compile OR-Tools using at least C++17 (C++20 on windows): - -* on UNIX: - - ```sh - bazel build -c opt --cxxopt=-std=c++17 ... - ``` - -* on Windows when using MSVC: - - ```sh - bazel build -c opt --cxxopt="/std:c++20" ... - ``` +```sh +bazel build -c opt //ortools/... //examples/... +``` ## Testing -You may run tests using: - -* on UNIX: - - ```sh - bazel test -c opt --cxxopt=-std=c++17 ... - ``` - -* on Windows when using MSVC: - - ```sh - bazel test -c opt --cxxopt="/std:c++20" ... - ``` +```sh +bazel test -c opt //ortools/... //examples/... +``` ## Integration diff --git a/cmake/dependencies/CMakeLists.txt b/cmake/dependencies/CMakeLists.txt index 432f7f53f8a..d164b28e070 100644 --- a/cmake/dependencies/CMakeLists.txt +++ b/cmake/dependencies/CMakeLists.txt @@ -424,7 +424,8 @@ endif() # ############################################################################## # Coinutils # ############################################################################## -# Coin-OR does not support C++17/C++20 (use of 'register' storage class specifier) + +# Coin-OR uses the 'register' storage class specifier which requires C++11. set(CMAKE_CXX_STANDARD 11) if(WIN32) set(BUILD_SHARED_LIBS OFF) @@ -532,14 +533,12 @@ if(BUILD_Cbc) message(CHECK_PASS "fetched") endif() +# End of Coin-OR dependencies, setting the properties back to their previous +# values. +set(CMAKE_CXX_STANDARD 20) if(WIN32) set(BUILD_SHARED_LIBS ON) endif() -if(MSVC) - set(CMAKE_CXX_STANDARD 20) -else() - set(CMAKE_CXX_STANDARD 17) -endif() ############### ## TESTING ## diff --git a/ortools/base/BUILD.bazel b/ortools/base/BUILD.bazel index 1137d5d7557..b6a3e0acd9b 100644 --- a/ortools/base/BUILD.bazel +++ b/ortools/base/BUILD.bazel @@ -34,12 +34,6 @@ cc_library( ], ) -cc_library( - name = "array", - hdrs = ["array.h"], - deps = ["@abseil-cpp//absl/utility"], -) - cc_library( name = "base", srcs = ["version.cc"], diff --git a/ortools/base/array.h b/ortools/base/array.h deleted file mode 100644 index a3794886ae3..00000000000 --- a/ortools/base/array.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2010-2025 Google LLC -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef ORTOOLS_BASE_ARRAY_H_ -#define ORTOOLS_BASE_ARRAY_H_ - -//! @todo(corentinl) std::to_array available in C++20. - -#include -#include -#include - -#include "absl/utility/utility.h" - -namespace gtl { - -namespace internal_array { - -template -constexpr std::array, N> to_array_internal( - T (&ts)[N], absl::index_sequence) { - return {{ts[Idx]...}}; -} - -template -constexpr std::array, N> to_array_internal( - T (&&ts)[N], absl::index_sequence) { - return {{std::move(ts[Idx])...}}; -} - -} // namespace internal_array - -template -constexpr std::array, N> to_array(T (&ts)[N]) { - return internal_array::to_array_internal(ts, absl::make_index_sequence{}); -} - -template -constexpr std::array, N> to_array(T (&&ts)[N]) { - return internal_array::to_array_internal(std::move(ts), - absl::make_index_sequence{}); -} - -} // namespace gtl - -#endif // ORTOOLS_BASE_ARRAY_H_ diff --git a/ortools/base/filesystem.cc b/ortools/base/filesystem.cc index a45dc9c1130..94dcfc89d0b 100644 --- a/ortools/base/filesystem.cc +++ b/ortools/base/filesystem.cc @@ -15,7 +15,7 @@ #include #include // IWYU pragma: keep -#include // NOLINT(build/c++17) +#include // NOLINT #include // NOLINT #include #include diff --git a/ortools/cpp/CMakeLists.txt.in b/ortools/cpp/CMakeLists.txt.in index d96b8e24f80..3218fdfee2a 100644 --- a/ortools/cpp/CMakeLists.txt.in +++ b/ortools/cpp/CMakeLists.txt.in @@ -9,11 +9,7 @@ message(STATUS "${PROJECT_NAME} version: ${PROJECT_VERSION}") #message(STATUS "minor: ${PROJECT_VERSION_MINOR}") #message(STATUS "patch: ${PROJECT_VERSION_PATCH}") -if(MSVC) - set(CMAKE_CXX_STANDARD 20) -else() - set(CMAKE_CXX_STANDARD 17) -endif() +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH True) diff --git a/ortools/math_opt/elemental/BUILD.bazel b/ortools/math_opt/elemental/BUILD.bazel index d0e9163fb67..9781f2b6e33 100644 --- a/ortools/math_opt/elemental/BUILD.bazel +++ b/ortools/math_opt/elemental/BUILD.bazel @@ -22,7 +22,6 @@ cc_library( ":arrays", ":elements", ":symmetry", - "//ortools/base:array", "@abseil-cpp//absl/strings:string_view", ], ) @@ -323,7 +322,6 @@ cc_test( srcs = ["arrays_test.cc"], deps = [ ":arrays", - "//ortools/base:array", "//ortools/base:gmock_main", "@abseil-cpp//absl/status", "@abseil-cpp//absl/strings", @@ -459,7 +457,6 @@ cc_library( visibility = ["//ortools/math_opt:__subpackages__"], deps = [ ":tagged_id", - "//ortools/base:array", "@abseil-cpp//absl/log:check", "@abseil-cpp//absl/strings:string_view", ], diff --git a/ortools/math_opt/elemental/arrays.h b/ortools/math_opt/elemental/arrays.h index 082d7c757f9..b8371d1eb4b 100644 --- a/ortools/math_opt/elemental/arrays.h +++ b/ortools/math_opt/elemental/arrays.h @@ -36,7 +36,6 @@ namespace operations_research::math_opt { // ``` template constexpr decltype(auto) ApplyOnIndexRange(Fn&& fn) { - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) return [&fn](std::integer_sequence) mutable { return fn.template operator()(); }(std::make_integer_sequence()); @@ -55,7 +54,6 @@ constexpr decltype(auto) ApplyOnIndexRange(Fn&& fn) { template constexpr decltype(auto) ForEachIndex(Fn&& fn) { return ApplyOnIndexRange( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) [&fn]() { return (fn.template operator()(), ...); }); } @@ -63,7 +61,6 @@ constexpr decltype(auto) ForEachIndex(Fn&& fn) { // last invocation. template constexpr decltype(auto) ForEach(Fn&& fn, Tuple&& tuple) { - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) return std::apply([&fn]( Ts&&... ts) { return (fn(std::forward(ts)), ...); }, std::forward(tuple)); diff --git a/ortools/math_opt/elemental/arrays_test.cc b/ortools/math_opt/elemental/arrays_test.cc index 865b28caebb..f261dfcabdf 100644 --- a/ortools/math_opt/elemental/arrays_test.cc +++ b/ortools/math_opt/elemental/arrays_test.cc @@ -23,7 +23,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "gtest/gtest.h" -#include "ortools/base/array.h" #include "ortools/base/gmock.h" namespace operations_research::math_opt { @@ -35,7 +34,6 @@ using ::testing::ElementsAre; template constexpr int Sum() { return ApplyOnIndexRange( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) []() { return (a[i] + ... + 0); }); } @@ -43,17 +41,14 @@ constexpr int Sum() { template constexpr int SumPlusOne() { return ApplyOnIndexRange( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) []() { return (a[i] + ... + 1); }); } #if __cplusplus >= 202002L -// NOLINTBEGIN(clang-diagnostic-pre-c++20-compat) TEST(ApplyOnIndexRangeTest, Sum) { - EXPECT_EQ(Sum(), 9); - EXPECT_EQ(SumPlusOne(), 10); + EXPECT_EQ(Sum(), 9); + EXPECT_EQ(SumPlusOne(), 10); } -// NOLINTEND(clang-diagnostic-pre-c++20-compat) #endif // Returns the weighted sum of the elements of an array-like object `a`, where @@ -61,39 +56,32 @@ TEST(ApplyOnIndexRangeTest, Sum) { template constexpr double ScaledSum() { return ApplyOnIndexRange( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) []() { return ((i * a[i]) + ... + 0.0); }); } #if __cplusplus >= 202002L -// NOLINTBEGIN(clang-diagnostic-pre-c++20-compat) TEST(ApplyOnIndexRangeTest, ScaledSum) { - EXPECT_EQ(ScaledSum(), 5.0); + EXPECT_EQ(ScaledSum(), 5.0); } -// NOLINTEND(clang-diagnostic-pre-c++20-compat) #endif // Returns the number of even elements in an array-like object `a`. template constexpr int CountEven() { return ApplyOnIndexRange( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) []() { return ((a[i] % 2 == 0 ? 1 : 0) + ... + 0); }); } #if __cplusplus >= 202002L -// NOLINTBEGIN(clang-diagnostic-pre-c++20-compat) TEST(ApplyOnIndexRangeTest, CountEven) { - EXPECT_EQ(CountEven(), 3); + EXPECT_EQ(CountEven(), 3); } -// NOLINTEND(clang-diagnostic-pre-c++20-compat) #endif // Returns array of doubles of the same size as `a`, where each element has been // halved. template constexpr std::array Half() { - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) return ApplyOnIndexRange([]() { return std::array( {(static_cast(a[i]) / 2.0)...}); @@ -101,19 +89,16 @@ constexpr std::array Half() { } #if __cplusplus >= 202002L -// NOLINTBEGIN(clang-diagnostic-pre-c++20-compat) TEST(ApplyOnIndexRangeTest, Half) { - EXPECT_THAT(Half(), + EXPECT_THAT(Half(), ElementsAre(2.5, 2.0, 4.0, 0.5, 5.0)); } -// NOLINTEND(clang-diagnostic-pre-c++20-compat) #endif // Returns true of all elements of `a` are even. template constexpr int AllEven() { return ApplyOnIndexRange( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) []() { return (((a[i] % 2) == 0) && ...); }); } @@ -121,23 +106,20 @@ constexpr int AllEven() { template constexpr int AnyEven() { return ApplyOnIndexRange( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) []() { return (((a[i] % 2) == 0) || ...); }); } #if __cplusplus >= 202002L -// NOLINTBEGIN(clang-diagnostic-pre-c++20-compat) TEST(ApplyOnIndexRangeTest, Even) { - EXPECT_FALSE(AllEven()); - EXPECT_TRUE(AnyEven()); + EXPECT_FALSE(AllEven()); + EXPECT_TRUE(AnyEven()); - EXPECT_TRUE(AllEven()); - EXPECT_TRUE(AnyEven()); + EXPECT_TRUE(AllEven()); + EXPECT_TRUE(AnyEven()); - EXPECT_FALSE(AllEven()); - EXPECT_FALSE(AnyEven()); + EXPECT_FALSE(AllEven()); + EXPECT_FALSE(AnyEven()); } -// NOLINTEND(clang-diagnostic-pre-c++20-compat) #endif // A example of a more complex reduce operation using `ForEachIndex`. Here, we @@ -153,7 +135,6 @@ TEST(ForEachIndexTest, CollectTest) { EXPECT_THAT( ForEachIndex<21>( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) [&may_fail, failed_indices = std::vector()]() mutable -> const std::vector& { if (!may_fail(i).ok()) { diff --git a/ortools/math_opt/elemental/attr_storage.h b/ortools/math_opt/elemental/attr_storage.h index f8d255559c5..d3b17655884 100644 --- a/ortools/math_opt/elemental/attr_storage.h +++ b/ortools/math_opt/elemental/attr_storage.h @@ -144,7 +144,6 @@ class SlicingSupport { using Key = AttrKey; void AddRowsAndColumns(const Key key) { - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) ForEachDimension([this, key]() { if (MustInsertNondefault(key, Symmetry{})) { key_nondefaults_[i][key[i]].Insert(key.template RemoveElement()); @@ -154,7 +153,6 @@ class SlicingSupport { // Requires key is currently stored with a non-default value. void ClearRowsAndColumns(Key key) { - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) ForEachDimension([this, key]() { const auto& key_elem = key[i]; auto& nondefaults = key_nondefaults_[i]; @@ -176,11 +174,9 @@ class SlicingSupport { std::vector Slice(const int64_t key_elem) const { return SliceImpl( key_elem, Symmetry{}, - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) [key_elem](KeySetExpansion... expansions) { std::vector slice((expansions.key_set.size() + ...)); Key* out = slice.data(); - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) const auto append = [key_elem, &out]( const KeySetExpansion& expansion) { expansion.key_set.ForEach( diff --git a/ortools/math_opt/elemental/attributes.h b/ortools/math_opt/elemental/attributes.h index 8f76aeacbbc..178573b1e1f 100644 --- a/ortools/math_opt/elemental/attributes.h +++ b/ortools/math_opt/elemental/attributes.h @@ -22,7 +22,6 @@ #include #include "absl/strings/string_view.h" -#include "ortools/base/array.h" #include "ortools/math_opt/elemental/arrays.h" #include "ortools/math_opt/elemental/elements.h" #include "ortools/math_opt/elemental/symmetry.h" @@ -86,7 +85,7 @@ struct BoolAttr0TypeDescriptor enum class AttrType { kMaximize }; - static constexpr auto kAttrDescriptors = gtl::to_array( + static constexpr auto kAttrDescriptors = std::to_array( {{.name = "maximize", .default_value = false, .key_types = {}}}); }; @@ -100,7 +99,7 @@ struct BoolAttr1TypeDescriptor kIndConActivateOnZero, }; - static constexpr auto kAttrDescriptors = gtl::to_array( + static constexpr auto kAttrDescriptors = std::to_array( {{.name = "variable_integer", .default_value = false, .key_types = {ElementType::kVariable}}, @@ -121,7 +120,7 @@ struct IntAttr0TypeDescriptor kObjPriority, }; - static constexpr auto kAttrDescriptors = gtl::to_array({ + static constexpr auto kAttrDescriptors = std::to_array({ {.name = "objective_priority", .default_value = 0, .key_types = {}}, }); }; @@ -135,7 +134,7 @@ struct IntAttr1TypeDescriptor kAuxObjPriority, }; - static constexpr auto kAttrDescriptors = gtl::to_array({ + static constexpr auto kAttrDescriptors = std::to_array({ {.name = "auxiliary_objective_priority", .default_value = 0, .key_types = {ElementType::kAuxiliaryObjective}}, @@ -149,7 +148,7 @@ struct DoubleAttr0TypeDescriptor enum class AttrType { kObjOffset }; - static constexpr auto kAttrDescriptors = gtl::to_array( + static constexpr auto kAttrDescriptors = std::to_array( {{.name = "objective_offset", .default_value = 0.0, .key_types = {}}}); }; @@ -171,7 +170,7 @@ struct DoubleAttr1TypeDescriptor kIndConUb, }; - static constexpr auto kAttrDescriptors = gtl::to_array({ + static constexpr auto kAttrDescriptors = std::to_array({ {.name = "variable_lower_bound", .default_value = -std::numeric_limits::infinity(), .key_types = {ElementType::kVariable}}, @@ -217,7 +216,7 @@ struct DoubleAttr2TypeDescriptor kIndConLinCoef }; - static constexpr auto kAttrDescriptors = gtl::to_array({ + static constexpr auto kAttrDescriptors = std::to_array({ {.name = "linear_constraint_coefficient", .default_value = 0.0, .key_types = {ElementType::kLinearConstraint, ElementType::kVariable}}, @@ -244,7 +243,7 @@ struct SymmetricDoubleAttr2TypeDescriptor kObjQuadCoef, }; - static constexpr auto kAttrDescriptors = gtl::to_array({ + static constexpr auto kAttrDescriptors = std::to_array({ {.name = "objective_quadratic_coefficient", .default_value = 0.0, .key_types = {ElementType::kVariable, ElementType::kVariable}}, @@ -262,7 +261,7 @@ struct SymmetricDoubleAttr3TypeDescriptor kQuadConQuadCoef, }; - static constexpr auto kAttrDescriptors = gtl::to_array({ + static constexpr auto kAttrDescriptors = std::to_array({ {.name = "quadratic_constraint_quadratic_coefficient", .default_value = 0.0, .key_types = {ElementType::kQuadraticConstraint, ElementType::kVariable, @@ -279,7 +278,7 @@ struct VariableAttr1TypeDescriptor kIndConIndicator, }; - static constexpr auto kAttrDescriptors = gtl::to_array({ + static constexpr auto kAttrDescriptors = std::to_array({ {.name = "indicator_constraint_indicator", .default_value = VariableId(), .key_types = {ElementType::kIndicatorConstraint}}, @@ -312,7 +311,6 @@ using VariableAttr1 = VariableAttr1TypeDescriptor::AttrType; template static constexpr int GetIndexIfAttr() { using Tuple = AllAttrTypeDescriptors; - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) return ApplyOnIndexRange>([]() { return ((std::is_same_v>, typename std::tuple_element_t::AttrType> diff --git a/ortools/math_opt/elemental/attributes_test.cc b/ortools/math_opt/elemental/attributes_test.cc index 4e82f856dfe..9314b4aefd0 100644 --- a/ortools/math_opt/elemental/attributes_test.cc +++ b/ortools/math_opt/elemental/attributes_test.cc @@ -45,7 +45,6 @@ TEST(ToStringTests, EachTypeCanConvert) { // with element types. TEST(SymmetryTest, AllSymmetricTypesAreCorrect) { ForEach( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) [](const Descriptor&) { for (const auto& attr : Descriptor::kAttrDescriptors) { Descriptor::Symmetry::CheckElementTypes(attr.key_types); diff --git a/ortools/math_opt/elemental/derived_data_test.cc b/ortools/math_opt/elemental/derived_data_test.cc index 5135308303c..af4f96029a6 100644 --- a/ortools/math_opt/elemental/derived_data_test.cc +++ b/ortools/math_opt/elemental/derived_data_test.cc @@ -81,7 +81,6 @@ TEST(GetElementTypesTest, Attr2HasElements) { TEST(AllAttrsTest, Indexing) { ForEachIndex( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) []() { EXPECT_EQ((AllAttrs::GetIndex>()), i); }); } @@ -140,7 +139,6 @@ TEST(AttrMapTest, Iteration) { // We should have `NumAttrs()` values `i` per attribute. std::vector expected_values; - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) ForEachIndex([&expected_values]() { for (int k = 0; k < AllAttrs::TypeDescriptor::NumAttrs(); ++k) { expected_values.push_back(i); @@ -151,7 +149,6 @@ TEST(AttrMapTest, Iteration) { TEST(CallForAttrTest, Works) { EXPECT_EQ(CallForAttr(DoubleAttr1::kVarUb, - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) []() { return static_cast(a); }), static_cast(DoubleAttr1::kVarUb)); } diff --git a/ortools/math_opt/elemental/elemental.cc b/ortools/math_opt/elemental/elemental.cc index 7affab927f5..c72f786cc31 100644 --- a/ortools/math_opt/elemental/elemental.cc +++ b/ortools/math_opt/elemental/elemental.cc @@ -38,7 +38,6 @@ namespace operations_research::math_opt { Elemental::Elemental(std::string model_name, std::string primary_objective_name) : model_name_(std::move(model_name)), primary_objective_name_(std::move(primary_objective_name)) { - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) ForEachIndex([this]() { using Descriptor = AllAttrs::TypeDescriptor; for (const auto a : Descriptor::Enumerate()) { @@ -90,15 +89,12 @@ bool Elemental::DeleteElementUntyped(const ElementType e, int64_t id) { for (auto& [unused, diff] : diffs_->UpdateAndGetAll()) { diff->DeleteElement(e, id); } - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) AllAttrs::ForEachAttr([this, e, id](AttrType a) { - ForEachIndex()>( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) - [&]() { - if (GetElementTypes(a)[i] == e) { - UpdateAttrOnElementDeleted(a, id); - } - }); + ForEachIndex()>([&]() { + if (GetElementTypes(a)[i] == e) { + UpdateAttrOnElementDeleted(a, id); + } + }); // If `a` is element-valued, we need to remove all keys that refer to the // deleted element. if constexpr (is_element_id_v>) { diff --git a/ortools/math_opt/elemental/elemental_differencer.cc b/ortools/math_opt/elemental/elemental_differencer.cc index 6b6bb4b4c1c..2081e360589 100644 --- a/ortools/math_opt/elemental/elemental_differencer.cc +++ b/ortools/math_opt/elemental/elemental_differencer.cc @@ -103,7 +103,6 @@ ElementalDifference ElementalDifference::Create( } } AllAttrs::ForEachAttr( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) [&result, &first, &second](AttrType attr) { using Key = typename AttributeDifference::Key; AttributeDifference& attr_difference = @@ -217,7 +216,6 @@ std::string ElementalDifference::Describe( } } AllAttrs::ForEachAttr( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) [&lines, &difference, &first, &second](AttrType attr) { const auto& attr_diff = difference.attr_difference(attr); auto attr_value_str = [attr](const Elemental& elemental, diff --git a/ortools/math_opt/elemental/elemental_export_model.cc b/ortools/math_opt/elemental/elemental_export_model.cc index bed35273132..aee870d5f57 100644 --- a/ortools/math_opt/elemental/elemental_export_model.cc +++ b/ortools/math_opt/elemental/elemental_export_model.cc @@ -64,7 +64,6 @@ absl::Status CanExportToProto(int64_t num_entries) { template absl::Status ForEachIndexUntilError(Fn&& fn) { absl::Status result = absl::OkStatus(); - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) ForEachIndex([&result, &fn]() { if (!result.ok()) { return; @@ -101,7 +100,6 @@ absl::Status ForEachAttrUntilError(Fn&& fn) { // in `model`. absl::Status ValidateElementsFitInProto(const Elemental& model) { return ForEachIndexUntilError( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) [&model]() -> absl::Status { constexpr auto element_type = static_cast(e); RETURN_IF_ERROR(CanExportToProto(model.NumElements(element_type))) @@ -540,7 +538,6 @@ absl::Status ValidateElementUpdatesFitInProto( const Diff& diff, const std::array, kNumElements>& new_elements) { return ForEachIndexUntilError( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) [&diff, &new_elements]() -> absl::Status { constexpr auto element_type = static_cast(e); RETURN_IF_ERROR( diff --git a/ortools/math_opt/elemental/elemental_to_string.cc b/ortools/math_opt/elemental/elemental_to_string.cc index d3cc499bd5d..6bbc58b09a1 100644 --- a/ortools/math_opt/elemental/elemental_to_string.cc +++ b/ortools/math_opt/elemental/elemental_to_string.cc @@ -120,7 +120,6 @@ std::vector DiffDebugString(const Elemental& elemental, lines.push_back(absl::StrCat(" deleted: [", absl::StrJoin(deleted_elements, ", "), "]")); } - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) AllAttrs::ForEachAttr([&lines, &elemental, &diff](Attr attr) { if (diff.modified_keys(attr).empty()) { return; diff --git a/ortools/math_opt/elemental/elements.h b/ortools/math_opt/elemental/elements.h index d641bdd4652..82380a72a9d 100644 --- a/ortools/math_opt/elemental/elements.h +++ b/ortools/math_opt/elemental/elements.h @@ -18,11 +18,11 @@ #ifndef ORTOOLS_MATH_OPT_ELEMENTAL_ELEMENTS_H_ #define ORTOOLS_MATH_OPT_ELEMENTAL_ELEMENTS_H_ +#include #include #include #include "absl/strings/string_view.h" -#include "ortools/base/array.h" #include "ortools/math_opt/elemental/tagged_id.h" namespace operations_research::math_opt { @@ -34,7 +34,7 @@ enum class ElementType { kQuadraticConstraint, kIndicatorConstraint, }; -constexpr auto kElements = gtl::to_array( +constexpr auto kElements = std::to_array( {ElementType::kVariable, ElementType::kLinearConstraint, ElementType::kAuxiliaryObjective, ElementType::kQuadraticConstraint, ElementType::kIndicatorConstraint}); diff --git a/ortools/math_opt/elemental/python/elemental.cc b/ortools/math_opt/elemental/python/elemental.cc index d28ec4e117c..0e212d86647 100644 --- a/ortools/math_opt/elemental/python/elemental.cc +++ b/ortools/math_opt/elemental/python/elemental.cc @@ -365,7 +365,6 @@ R ApplyOnIndex(Fn fn, const int index) { CHECK_GE(index, 0); CHECK_LT(index, n); std::optional result; - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) ForEachIndex([index, &fn, &result]() { if (k == index) { result = fn.template operator()(); @@ -384,7 +383,6 @@ absl::StatusOr>> DynamicSlice( const int element_id) { RETURN_IF_ERROR(ValidateSliceKeyIndex(attr, key_index)); return ApplyOnIndex()>( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) [&e, attr, element_id]() { return e.Slice(attr, element_id); }, @@ -401,7 +399,6 @@ absl::StatusOr DynamicGetSliceSize(const Elemental& e, const int element_id) { RETURN_IF_ERROR(ValidateSliceKeyIndex(attr, key_index)); return ApplyOnIndex()>( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) [&e, attr, element_id]() { return e.GetSliceSize(attr, element_id); }, @@ -633,7 +630,6 @@ PYBIND11_MODULE(cpp_elemental, py_module) { // Export attribute operations. ForEach( - // NOLINTNEXTLINE(clang-diagnostic-pre-c++20-compat) [&elemental](const Descriptor&) { using AttrType = typename Descriptor::AttrType; using ValueType = typename Descriptor::ValueType; diff --git a/ortools/routing/filter_committables.h b/ortools/routing/filter_committables.h index da4d79ffb1f..3f591cb60d8 100644 --- a/ortools/routing/filter_committables.h +++ b/ortools/routing/filter_committables.h @@ -58,7 +58,7 @@ template class CommittableArray { public: // Makes a vector with initial elements all committed to value. - CommittableArray(size_t num_elements, const T& value) + CommittableArray(size_t num_elements, const T& value) : elements_(num_elements, {value, value}), changed_(num_elements) {} // Return the size of the vector. diff --git a/ortools/sat/colab/README.md b/ortools/sat/colab/README.md index 1a5dc85d724..f4de2f358c7 100644 --- a/ortools/sat/colab/README.md +++ b/ortools/sat/colab/README.md @@ -12,7 +12,7 @@ Below you'll find three examples of Google's CP-SAT solver. Build and run locally: ``` -bazel run -c opt --cxxopt=-std=c++17 ortools/python:ortools_notebook +bazel run -c opt ortools/python:ortools_notebook ``` This will open a jupyter notebook in your browser. @@ -20,7 +20,7 @@ This will open a jupyter notebook in your browser. To use it as a server only, use the command ``` -bazel run -c opt --cxxopt=-std=c++17 ortools/python:ortools_notebook -- --no-browser +bazel run -c opt ortools/python:ortools_notebook -- --no-browser ``` And paste the resulting url in your favorite environment, like visual studio code. diff --git a/ortools/third_party_solvers/xpress_environment.cc b/ortools/third_party_solvers/xpress_environment.cc index 1885cb75967..8f8dd962d63 100644 --- a/ortools/third_party_solvers/xpress_environment.cc +++ b/ortools/third_party_solvers/xpress_environment.cc @@ -16,8 +16,7 @@ #include "ortools/third_party_solvers/xpress_environment.h" #include -// NOLINTNEXTLINE(build/c++17) -#include +#include //NOLINT #include #include #include @@ -28,7 +27,6 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/synchronization/mutex.h" -#include "ortools/base/logging.h" #include "ortools/base/status_builder.h" #include "ortools/third_party_solvers/dynamic_library.h"