Skip to content

Commit 0332b67

Browse files
committed
Add infrastructure for working with concepts
This commit adds the `TRACCC_CONSTRAINT` macro which acts as a concept in C++20 builds, and simply acts as the `typename` keyword in builds with older standards. It also adds the `TRACCC_ENFORCE_CONCEPTS` CMake flag which will throw an error if concepts are not available.
1 parent 0ef502d commit 0332b67

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

.github/workflows/builds.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: CPU
3636
container: ghcr.io/acts-project/ubuntu2404:48
3737
cxx_standard: "20"
38-
options: -DTRACCC_USE_ROOT=FALSE
38+
options: -DTRACCC_USE_ROOT=FALSE -DTRACCC_ENFORCE_CONCEPTS=TRUE
3939
- name: HIP
4040
container: ghcr.io/acts-project/ubuntu2004_rocm:47
4141
cxx_standard: "17"
@@ -47,7 +47,7 @@ jobs:
4747
- name: CUDA
4848
container: ghcr.io/acts-project/ubuntu2204_cuda:48
4949
cxx_standard: "20"
50-
options: -DTRACCC_BUILD_CUDA=TRUE -DTRACCC_USE_ROOT=FALSE
50+
options: -DTRACCC_BUILD_CUDA=TRUE -DTRACCC_USE_ROOT=FALSE -DTRACCC_ENFORCE_CONCEPTS=TRUE
5151
- name: SYCL
5252
container: ghcr.io/acts-project/ubuntu2004_oneapi:47
5353
cxx_standard: "17"

CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ option( TRACCC_BUILD_EXAMPLES "Build the examples of traccc" TRUE )
6666
option( TRACCC_USE_SYSTEM_LIBS "Use system libraries be default" FALSE )
6767
option( TRACCC_USE_ROOT "Use ROOT in the build (if needed)" TRUE )
6868

69+
# Flag enforcing concept usage.
70+
option( TRACCC_ENFORCE_CONCEPTS "Throw an error if concepts are not available" FALSE )
71+
6972
# Clean up.
7073
unset( TRACCC_BUILD_CUDA_DEFAULT )
7174

core/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,11 @@ target_link_libraries( traccc_core
110110
# CUDA or HIP backend with SYCL.
111111
target_compile_definitions( traccc_core
112112
PUBLIC $<$<COMPILE_LANGUAGE:SYCL>:EIGEN_NO_CUDA EIGEN_NO_HIP> )
113+
114+
if ( TRACCC_ENFORCE_CONCEPTS )
115+
target_compile_definitions(
116+
traccc_core
117+
PUBLIC
118+
TRACCC_ENFORCE_CONCEPTS
119+
)
120+
endif ()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* traccc library, part of the ACTS project (R&D line)
3+
*
4+
* (c) 2024 CERN for the benefit of the ACTS project
5+
*
6+
* Mozilla Public License Version 2.0
7+
*/
8+
9+
#pragma once
10+
11+
#if __cpp_concepts >= 201907L
12+
#define TRACCC_CONSTRAINT(...) __VA_ARGS__
13+
#elif defined(TRACCC_ENFORCE_CONCEPTS)
14+
#error \
15+
"`TRACCC_ENFORCE_CONCEPTS` is set, but concepts are not available. This constitutes a fatal error."
16+
#else
17+
#define TRACCC_CONSTRAINT(...) __VA_ARGS__
18+
#endif

0 commit comments

Comments
 (0)