Modernize code - #5114
Conversation
Require AppleClang 17.0 (aka Xcode 16.3) and Boost 1.83.
a70ad3a to
5a959d0
Compare
Use range algorithms and concepts. Remove all `std::enable_if`. Replace template partial specializations by constexpr conditionals. Remove superfluous `typename`. Move global const variables defined in header files to the corresponding source files.
Avoid modifying global variable CMAKE_CXX_STANDARD, which affects all included projects and has lower precedence over per-target options.
|
Developer's notes:
|
|
Regarding the required versions of C, C++ and CUDA (more precisely "C++/CUDA", as it controls CUDA's C++ standard), the CMake logic is now more flexible and should allow us to make a gradual transitions to C++23, for example by bumping C++ code to C++23 while keeping CUDA code at C++20 (hard requirement of CUDA 12.x). Until now, we hardcoded the Instead of hardcoding these global variables, we can set the MWE: cmake_minimum_required(VERSION 3.24)
project(MyProject LANGUAGES CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_library(core SHARED a.cc)
if("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
target_compile_features(core PUBLIC cxx_std_20)
endif()$ echo "int foo() {return 1;}" > a.cc
$ mkdir build
$ cd build
$ cmake ..
$ grep -Po ".std=[^ ]+" compile_commands.json
-std=gnu++20
$ rm -rf *
$ cmake .. -D CMAKE_CXX_STANDARD=23
$ grep -Po ".std=[^ ]+" compile_commands.json
-std=gnu++23You can check the effect in a local build of a CMake-based project with: import re
import json
with open("compile_commands.json") as f:
data = json.load(f)
summary = []
for d in data:
m = re.search("-std=[^ ]+", d["command"])
std = m.group(0) if m else "default"
summary.append((std, d["file"]))
for x in sorted(summary):
print(" ".join(x))Technical details:
|
Description of changes: