Skip to content

Commit e220490

Browse files
authored
YT-CPPHGL-2: Cleanup of the CPP-GL module implementation and documentation
A small cleanup required for the development of HGL - Changed the minimum required C++ standard to C++23 - Changed the minimum required GCC version to 14 and CLang version to 18 - Replaced the usage of `std::optional<bool>` as algorithm predicate result type with a new ternary `predicate_result` type - Removed the `no_return` and `default_return` algorithm-specific types and related concepts; Introduced a `result_discriminator` type in their place - Aligned the documentation
1 parent f1829f3 commit e220490

36 files changed

Lines changed: 230 additions & 214 deletions

.github/workflows/clang.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ jobs:
1919

2020
- name: Prepare
2121
env:
22-
CC: clang-17
23-
CXX: clang++-17
22+
CC: clang-18
23+
CXX: clang++-18
2424
run: |
25-
cmake -B build -DBUILD_TESTS=ON -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC
25+
cmake -B build_clang -DBUILD_TESTS=ON -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC
2626
continue-on-error: false
2727

2828
- name: Build test executable
2929
run: |
30-
cd build && make -j 4
30+
cmake --build build_clang/ -j5
3131
continue-on-error: false
3232

3333
- name: Run tests
3434
run: |
35-
./build/tests/gl
36-
./build/tests/hgl
35+
./build_clang/tests/gl
36+
./build_clang/tests/hgl

.github/workflows/gpp.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ jobs:
1919

2020
- name: Prepare
2121
env:
22-
CC: gcc-13
23-
CXX: g++-13
22+
CC: gcc-14
23+
CXX: g++-14
2424
run: |
25-
cmake -B build -DBUILD_TESTS=ON -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC
25+
cmake -B build_gcc -DBUILD_TESTS=ON -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_C_COMPILER=$CC
2626
continue-on-error: false
2727

2828
- name: Build test executable
2929
run: |
30-
cd build && make -j 4
30+
cmake --build build_gcc/ -j5
3131
continue-on-error: false
3232

3333
- name: Run tests
3434
run: |
35-
./build/tests/gl
36-
./build/tests/hgl
35+
./build_gcc/tests/gl
36+
./build_gcc/tests/hgl

CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@ endif()
99

1010
project(cpp-gl
1111
VERSION 2.0.0
12-
DESCRIPTION "General purpose header-only template graph library for C++20"
12+
DESCRIPTION "General purpose header-only template graph library for C++23"
1313
HOMEPAGE_URL "https://github.com/SpectraL519/cpp-gl"
1414
LANGUAGES CXX
1515
)
1616

17+
set(MIN_CXX_STANDARD 23)
1718
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1819
option(BUILD_TESTS "Build project tests" OFF)
1920

2021
# Set the proper cxx standard
2122
if(NOT DEFINED CMAKE_CXX_STANDARD)
22-
set(CMAKE_CXX_STANDARD 20)
23-
elseif(CMAKE_CXX_STANDARD LESS 20)
23+
set(CMAKE_CXX_STANDARD ${MIN_CXX_STANDARD})
24+
elseif(CMAKE_CXX_STANDARD LESS ${MIN_CXX_STANDARD})
2425
message(WARNING "The defined C++ standard (${CMAKE_CXX_STANDARD}) is too low - overriding!")
25-
set(CMAKE_CXX_STANDARD 20)
26+
set(CMAKE_CXX_STANDARD ${MIN_CXX_STANDARD})
2627
endif()
2728
message(STATUS "The C++ standard is set to ${CMAKE_CXX_STANDARD}")
2829

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MIT License
22

33
Copyright (c) 2024 Jakub Musiał
4-
Project: "CPP-GL: General purpose header-only template graph library for C++20 and newer standards."
4+
Project: "CPP-GL: General purpose header-only template graph library for C++23 and newer standards."
55
https://github.com/SpectraL519/cpp-gl
66

77
Permission is hereby granted, free of charge, to any person obtaining a copy

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CPP-GL
22

3-
General purpose header-only template graph library for C++20 and newer standards.
3+
General purpose header-only template graph library for C++23 and newer standards.
44

55
[![g++](https://github.com/SpectraL519/cpp-gl/actions/workflows/gpp.yaml/badge.svg)](https://github.com/SpectraL519/cpp-gl/actions/workflows/g++)
66
[![clang++](https://github.com/SpectraL519/cpp-gl/actions/workflows/clang.yaml/badge.svg)](https://github.com/SpectraL519/cpp-gl/actions/workflows/clang++)
@@ -65,7 +65,7 @@ FetchContent_MakeAvailable(cpp-gl)
6565
add_executable(my_project main.cpp)
6666
6767
set_target_properties(my_project PROPERTIES
68-
CXX_STANDARD 20 # or newer
68+
CXX_STANDARD 23 # or newer
6969
CXX_STANDARD_REQUIRED YES
7070
)
7171
@@ -128,13 +128,14 @@ The instructions and requirements of working on the `CPP-GL` project can be foun
128128

129129
## Compiler support
130130

131+
<!--TODO: verify whether the min compiler version is correct for C++23-->
131132
| Compiler | Min version |
132133
| :-: | :-: |
133-
| GNU G++ | 13 |
134-
| Clang | 17 |
134+
| GNU G++ | 14 |
135+
| Clang | 18 |
135136

136137
> [!NOTE]
137-
> Although currently the project has been properly verified using only the G++ and Clang compilers it should work fine with other compilers with C++20 support like MSVC.
138+
> Although currently the project has been properly verified using only the G++ and Clang compilers it should work fine with other compilers with C++23 support like MSVC.
138139
139140
<br />
140141

docs/algoithms.md

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Algorithms
22

3-
The `CPP-GL` library provides a set of customizable graph algorithms, which are defined in the [gl/algorithms.hpp](/include/gl/algorithms.hpp) header file or in the specific header files in the [gl/algorithm/](/include/gl/algorithm/) directory.
3+
The `CPP-GL` library provides a set of customizable graph algorithms, which are defined in the [gl/algorithm.hpp](/include/gl/algorithm.hpp) header file or in the specific header files in the [gl/algorithm/](/include/gl/algorithm/) directory.
44

55
<br />
66

@@ -31,7 +31,12 @@ This section covers the specific types and type traits used for the algorithm im
3131
> [!NOTE]
3232
> All types listed below are defined in the `gl::algorithm` namespace
3333
34-
- `no_return` - A placeholder type to represent algorithms that do not return a value. It is primarily used in type traits to conditionally handle return types.
34+
- `result_discriminator` - An enumeration type used to discriminate whether the algorithm should return a result value or not.
35+
- **Members:**
36+
- `ret` - Indicates that the algorithm returns a value.
37+
- `noret` - Indicates that the algorithm does not return a value.
38+
- The `gl::algorithm` namespace [uses](https://en.cppreference.com/w/cpp/language/enum.html#using_enum_declaration) the `result_discriminator` enum, which allows for the usage of it's members directly from the `gl::algorithm` namespace, e.g. `gl::algorithm::noret`.
39+
3540
- `empty_callback` - Represents an empty callback, used as a default value where no callback functionality is needed.
3641

3742
- `vertex_callback`
@@ -68,6 +73,25 @@ This section covers the specific types and type traits used for the algorithm im
6873
- `edge: types::const_ref_wrap<EdgeType>` - a constant reference wrapper for the edge.
6974
- `source_id: types::id_type` - the ID of the source vertex of the held edge.
7075

76+
- `predicate_result`
77+
- *Description*: Represents the result of a predicate evaluation.
78+
- *Type definitions*:
79+
- `eval` - an enumeration type representing the result value.
80+
- `ok` - equivalent to `true`.
81+
- `not_ok` - equivalent to `false`.
82+
- `unknown` - represents an unknown result.
83+
- *Constructors*:
84+
- `predicate_result(const eval value)` - initializes the object with the given evaluation result.
85+
- `predicate_result(const bool value)` - initializes the object with the given boolean value.
86+
- If the value is `true`, initializes the object with `eval::ok`.
87+
- If the value is `false`, initializes the object with `eval::not_ok`.
88+
- *Member variables*:
89+
- `value: eval` - the evaluation result.
90+
- *Operators*:
91+
- `operator bool()` - returns `true` if the result is `eval::ok`, `false` otherwise.
92+
- `operator==(const eval& value) const` - returns `true` if the result's value is equal to the given value.
93+
- `operator=(const bool value)` - initializes the object with the given boolean value similarly to the boolean constructor.
94+
7195
- `predecessors_descriptor`
7296
- *Description*: A structure that holds a collection of predecessors for a set of vertices.
7397
- *Type definitions*:
@@ -93,18 +117,6 @@ This section covers the specific types and type traits used for the algorithm im
93117
> [!NOTE]
94118
> All concepts listed below are defined in the `gl::type_traits` namespace
95119
96-
- `c_alg_no_return_type`
97-
- *Description*: Checks if the type `T` is `algorithm::no_return`. Used to identify algorithms that do not return a value.
98-
- *Template parameters*:
99-
- `T` - the type to check.
100-
- *Equivalent to*: `std::same_as<T, algorithm::no_return>`
101-
102-
- `c_alg_return_graph_type`
103-
- *Description*: Checks if the type `T` is a valid return type for graph algorithms, i.e., either a graph type or `no_return`.
104-
- *Template parameters*:
105-
- `T` - the type to check.
106-
- *Equivalent to*: `c_graph<T> or c_alg_no_return_type<T>`
107-
108120
- `c_empty_callback`
109121
- *Description*: Checks if a callback type is `algorithm::empty_callback`. Used to determine when no callback is needed for an algorithm.
110122
- *Template parameters*:
@@ -169,7 +181,7 @@ This section covers the specific types and type traits used for the algorithm im
169181
- *Description*: Performs an iterative depth-first search (DFS) on the specified graph and conditionally returns a `predecessors_descriptor` instance.
170182

171183
- *Template parameters*:
172-
- `AlgReturnType: type_traits::c_alg_return_type` (default = `algorithm::default_return`) - Specifies whether the algorrithm should return the predecessors descriptor or not (can be eigher `algorithm::default_return` or `algorithm::no_return`).
184+
- `ResultDiscriminator: result_discriminator` (default = `algorithm::ret`) - Specifies whether the algorrithm should return the predecessors descriptor or not (can be eigher `algorithm::ret` or `algorithm::no_return`).
173185
- `GraphType: type_traits::c_graph` - The type of the graph on which the search is performed.
174186
- `PreVisitCallback: type_traits::c_optional_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called before visiting a vertex.
175187
- `PostVisitCallback: type_traits::c_optional_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called after visiting a vertex.
@@ -181,24 +193,24 @@ This section covers the specific types and type traits used for the algorithm im
181193
- `post_visit: const PostVisitCallback&` (default = `{}`) - The callback function to be called after visiting a vertex.
182194

183195
- *Return type*:
184-
- `impl::alg_return_type<AlgReturnType, predecessors_descriptor>` - If `AlgReturnType` is `algorithm::no_return` - nothing will be returned (`void`). Otherwise the algorithm will return an instance of `predecessors_descriptor`.
196+
- `impl::alg_return_type<ResultDiscriminator, predecessors_descriptor>` - If `ResultDiscriminator` is `algorithm::noret` - nothing will be returned (`void`). Otherwise the algorithm will return an instance of `predecessors_descriptor`.
185197

186-
- *Defined in*: [gl/algorithm/depth_first_search.hpp](/include/gl/algorithm/deapth_first_search.hpp)
198+
- *Defined in*: [gl/algorithm/depth_first_search.hpp](/include/gl/algorithm/depth_first_search.hpp)
187199

188200
- `recursive_depth_first_search(graph, root_vertex_id_opt, pre_visit, post_visit)`
189201
- *Description*: Performs a recursive depth-first search (DFS) on the specified graph and conditionally returns a `predecessors_descriptor` instance.
190202

191203
**NOTE:** This algoithm has the same template parameters, parameters and return type as the iterative version (`depth_first_search`)
192204

193-
- *Defined in*: [gl/algorithm/depth_first_search.hpp](/include/gl/algorithm/deapth_first_search.hpp)
205+
- *Defined in*: [gl/algorithm/depth_first_search.hpp](/include/gl/algorithm/depth_first_search.hpp)
194206

195207
### Breadth-first search
196208

197209
- `breadth_first_search(graph, root_vertex_id_opt, pre_visit, post_visit)`
198210
- *Description*: Performs an breadth-first search (BFS) on the specified graph and conditionally returns a `predecessors_descriptor` instance.
199211

200212
- *Template parameters*:
201-
- `AlgReturnType: type_traits::c_alg_return_type` (default = `algorithm::default_return`) - Specifies whether the algorrithm should return the predecessors descriptor or not (can be eigher `algorithm::default_return` or `algorithm::no_return`).
213+
- `ResultDiscriminator: result_discriminator` (default = `algorithm::ret`) - Specifies whether the algorrithm should return the predecessors descriptor or not (can be eigher `algorithm::ret` or `algorithm::no_return`).
202214
- `GraphType: type_traits::c_graph` - The type of the graph on which the search is performed.
203215
- `PreVisitCallback: type_traits::c_optional_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called before visiting a vertex.
204216
- `PostVisitCallback: type_traits::c_optional_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called after visiting a vertex.
@@ -210,7 +222,7 @@ This section covers the specific types and type traits used for the algorithm im
210222
- `post_visit: const PostVisitCallback&` (default = `{}`) - The callback function to be called after visiting a vertex.
211223

212224
- *Return type*:
213-
- `impl::alg_return_type<AlgReturnType, predecessors_descriptor>` - If `AlgReturnType` is `algorithm::no_return` - nothing will be returned (`void`). Otherwise the algorithm will return an instance of `predecessors_descriptor`.
225+
- `impl::alg_return_type<ResultDiscriminator, predecessors_descriptor>` - If `ResultDiscriminator` is `algorithm::noret` - nothing will be returned (`void`). Otherwise the algorithm will return an instance of `predecessors_descriptor`.
214226

215227
- *Defined in*: [gl/algorithm/breadth_first_search.hpp](/include/gl/algorithm/breadth_first_search.hpp)
216228

@@ -401,7 +413,7 @@ Additionaly you can use the depth-first/breadth-first search algorithm templates
401413
- `GraphType: type_traits::c_graph` - The type of the graph on which the search is performed.
402414
- `VisitVertexPredicate: type_traits::c_optional_vertex_callback<GraphType, bool>` - The vertex visiting unary predicate type.
403415
- `VisitCallback: type_traits::c_vertex_callback<GraphType, bool, types::id_type>` - The vertex visting callback type (arguments: `vertex, source_id`).
404-
- `EnqueueVertexPred: type_traits::c_vertex_callback<GraphType, std::optional<bool>, const typename GraphType::edge_type&>` - The vertex enqueue predicate type (arguments: `vertex, in_edge`)
416+
- `EnqueueVertexPred: type_traits::c_vertex_callback<GraphType, algorithm::predicate_result, const typename GraphType::edge_type&>` - The vertex enqueue predicate type (arguments: `vertex, in_edge`)
405417
- `PreVisitCallback: type_traits::c_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called before visiting a vertex.
406418
- `PostVisitCallback: type_traits::c_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called after visiting a vertex.
407419

@@ -423,7 +435,7 @@ Additionaly you can use the depth-first/breadth-first search algorithm templates
423435
- `GraphType: type_traits::c_graph` - The type of the graph on which the search is performed.
424436
- `VisitVertexPredicate: type_traits::c_optional_vertex_callback<GraphType, bool>` - The vertex visiting unary predicate type.
425437
- `VisitCallback: type_traits::c_vertex_callback<GraphType, bool, types::id_type>` - The vertex visting callback type (arguments: `vertex, source_id`).
426-
- `EnqueueVertexPred: type_traits::c_vertex_callback<GraphType, std::optional<bool>, const typename GraphType::edge_type&>` - The vertex enqueue predicate type (arguments: `vertex, in_edge`)
438+
- `EnqueueVertexPred: type_traits::c_vertex_callback<GraphType, algorithm::predicate_result, const typename GraphType::edge_type&>` - The vertex enqueue predicate type (arguments: `vertex, in_edge`)
427439
- `PreVisitCallback: type_traits::c_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called before visiting a vertex.
428440
- `PostVisitCallback: type_traits::c_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called after visiting a vertex.
429441

@@ -452,7 +464,7 @@ Additionaly you can use the depth-first/breadth-first search algorithm templates
452464
- `InitQueueRangeType: type_traits::c_sized_range_of<algorithm::vertex_info>` (default = `std::vector<algorithm::vertex_info>`) - The type of the `vertex_info` range which will be inserted into the queue at the beginning of the algorithm.
453465
- `VisitVertexPredicate: type_traits::c_optional_vertex_callback<GraphType, bool>` - The vertex visiting unary predicate type.
454466
- `VisitCallback: type_traits::c_vertex_callback<GraphType, bool, types::id_type>` - The vertex visting callback type (arguments: `vertex, source_id`).
455-
- `EnqueueVertexPred: type_traits::c_vertex_callback<GraphType, std::optional<bool>, const typename GraphType::edge_type&>` - The vertex enqueue predicate type (arguments: `vertex, in_edge`)
467+
- `EnqueueVertexPred: type_traits::c_vertex_callback<GraphType, algorithm::predicate_result, const typename GraphType::edge_type&>` - The vertex enqueue predicate type (arguments: `vertex, in_edge`)
456468
- `PreVisitCallback: type_traits::c_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called before visiting a vertex.
457469
- `PostVisitCallback: type_traits::c_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called after visiting a vertex.
458470

@@ -483,7 +495,7 @@ Additionaly you can use the depth-first/breadth-first search algorithm templates
483495
- `InitQueueRangeType: type_traits::c_sized_range_of<algorithm::vertex_info>` (default = `std::vector<algorithm::vertex_info>`) - The type of the `vertex_info` range which will be inserted into the queue at the beginning of the algorithm.
484496
- `VisitVertexPredicate: type_traits::c_optional_vertex_callback<GraphType, bool>` - The vertex visiting unary predicate type.
485497
- `VisitCallback: type_traits::c_vertex_callback<GraphType, bool, types::id_type>` - The vertex visting callback type (arguments: `vertex, source_id`).
486-
- `EnqueueVertexPred: type_traits::c_vertex_callback<GraphType, std::optional<bool>, const typename GraphType::edge_type&>` - The vertex enqueue predicate type (arguments: `vertex, in_edge`)
498+
- `EnqueueVertexPred: type_traits::c_vertex_callback<GraphType, algorithm::predicate_result, const typename GraphType::edge_type&>` - The vertex enqueue predicate type (arguments: `vertex, in_edge`)
487499
- `PreVisitCallback: type_traits::c_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called before visiting a vertex.
488500
- `PostVisitCallback: type_traits::c_vertex_callback<GraphType, void>` (default = `algorithm::empty_callback`) - The type of the callback function called after visiting a vertex.
489501

docs/graph_elements.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,20 @@ The destructor is *defaulted*, allowing proper cleanup of the `edge_descriptor`
164164

165165
- **`incident_vertex(const vertex_type& vertex) const`**:
166166
- *Description*: Returns the vertex on the other end of the edge relative to the provided vertex. Throws an error if the provided vertex is not incident with the edge.
167-
- *Returned value*: $\begin{cases} v & \text{: vertex} = u \\ u & \text{: vertex} = v \\ \text{error} & \text{: otherwise} \end{cases}$
167+
- *Returned value*:
168+
- $v$ if $\text{vertex} = u$
169+
- $u$ if $\text{vertex} = v$
170+
- error otherwise
168171
- *Parameters*:
169172
- `vertex: const vertex_type&` – the vertex for which the opposite vertex is requested.
170173
- *Return type*: `const vertex_type&`
171174

172175
- **`incident_vertex_id(const types::id_type vertex_id) const`**:
173176
- *Description*: Returns the ID of the vertex on the other end of the edge relative to the provided vertex ID. Throws an error if the provided vertex ID is invalid.
174-
- *Returned value*: $\begin{cases} v_{id} & \text{: vertex-id} = u_{id} \\ u_{id} & \text{: vertex-id} = v_{id} \\ \text{error} & \text{: otherwise} \end{cases}$
177+
- *Returned value*:
178+
- $v_{id}$ if $\text{vertex-id} = u_{id}$
179+
- $u_{id}$ if $\text{vertex-id} = v_{id}$
180+
- error otherwise
175181
- *Parameters*:
176182
- `vertex_id: const types::id_type` – the vertex ID for which the opposite vertex ID is requested.
177183
- *Return type*: `types::id_type`
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "algorithm/breadth_first_search.hpp"
88
#include "algorithm/coloring.hpp"
9-
#include "algorithm/deapth_first_search.hpp"
9+
#include "algorithm/depth_first_search.hpp"
1010
#include "algorithm/dijkstra.hpp"
1111
#include "algorithm/mst.hpp"
1212
#include "algorithm/topological_sort.hpp"

0 commit comments

Comments
 (0)