Skip to content

Commit 3901215

Browse files
committed
aligned cpp-gl to c++23
1 parent cc23d83 commit 3901215

12 files changed

Lines changed: 24 additions & 72 deletions

File tree

include/gl/algorithm/impl/bfs.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ bool bfs(
3939
using vertex_queue_type = std::queue<algorithm::vertex_info>;
4040
vertex_queue_type vertex_queue;
4141

42-
// TODO [C++23]: replace with push_range
4342
for (const auto& vinfo : initial_queue_content)
4443
vertex_queue.push(vinfo);
4544

include/gl/algorithm/impl/pfs.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ bool pfs(
4242
std::priority_queue<algorithm::vertex_info, std::vector<algorithm::vertex_info>, PQCompare>;
4343
vertex_queue_type vertex_queue(pq_compare);
4444

45-
// TODO [C++23]: replace with push_range
4645
for (const auto& vinfo : initial_queue_content)
4746
vertex_queue.push(vinfo);
4847

include/gl/impl/adjacency_list.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ class adjacency_list final {
5454
// --- vertex methods ---
5555

5656
gl_attr_force_inline void add_vertex() {
57-
this->_list.push_back(edge_list_type{});
57+
this->_list.emplace_back(edge_list_type{});
5858
}
5959

6060
inline void add_vertices(const types::size_type n) {
6161
this->_list.reserve(this->n_vertices() + n);
6262
for (types::size_type _ = constants::begin_idx; _ < n; ++_)
63-
this->_list.push_back(edge_list_type{});
63+
this->_list.emplace_back(edge_list_type{});
6464
}
6565

6666
[[nodiscard]] gl_attr_force_inline types::size_type in_degree(const types::id_type vertex_id
@@ -172,7 +172,7 @@ class adjacency_list final {
172172

173173
for (const auto& edge : adjacent_edges)
174174
if (specialized_impl::is_edge_incident_to(edge, second_id, first_id))
175-
matching_edges.push_back(std::cref(*edge));
175+
matching_edges.emplace_back(*edge);
176176

177177
matching_edges.shrink_to_fit();
178178
return matching_edges;

include/gl/impl/adjacency_matrix.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class adjacency_matrix final {
6262

6363
void add_vertex() {
6464
for (auto& row : this->_matrix)
65-
row.push_back(_make_null_edge());
65+
row.emplace_back(_make_null_edge());
6666
auto& new_row = this->_matrix.emplace_back();
6767
new_row.reserve(this->n_vertices());
6868
std::generate_n(std::back_inserter(new_row), this->n_vertices(), _make_null_edge);

include/gl/impl/specialized/adjacency_list.hpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,10 @@ struct directed_adjacency_list {
6767
const impl_type& self, const types::id_type vertex_id
6868
) {
6969
types::size_type in_deg = constants::default_size;
70-
for (types::id_type id = constants::initial_id; id < self._list.size(); ++id) {
71-
const auto& adj_edges = self._list[id];
72-
if (adj_edges.empty())
73-
continue;
74-
75-
in_deg += std::ranges::count(adj_edges, vertex_id, [](const auto& edge) {
70+
for (const auto& adjacent_edges : self._list)
71+
in_deg += std::ranges::count(adjacent_edges, vertex_id, [](const auto& edge) {
7672
return edge->second_id();
7773
});
78-
}
7974

8075
return in_deg;
8176
}
@@ -107,10 +102,9 @@ struct directed_adjacency_list {
107102
[[nodiscard]] gl_attr_force_inline static std::vector<types::size_type> out_degree_map(
108103
const impl_type& self
109104
) {
110-
const auto out_degree_view =
111-
self._list
112-
| std::views::transform([](const auto& adj_edges) { return adj_edges.size(); });
113-
return std::vector<types::size_type>(out_degree_view.begin(), out_degree_view.end());
105+
return self._list
106+
| std::views::transform([](const auto& adj_edges) { return adj_edges.size(); })
107+
| std::ranges::to<std::vector<types::size_type>>();
114108
}
115109

116110
[[nodiscard]] static std::vector<types::size_type> degree_map(const impl_type& self) {
@@ -151,9 +145,9 @@ struct directed_adjacency_list {
151145

152146
static const edge_type& add_edge(impl_type& self, edge_ptr_type edge) {
153147
auto& adjacent_edges_first = self._list[edge->first_id()];
154-
adjacent_edges_first.push_back(std::move(edge));
148+
auto& new_edge = adjacent_edges_first.emplace_back(std::move(edge));
155149
++self._n_unique_edges;
156-
return *adjacent_edges_first.back();
150+
return *new_edge;
157151
}
158152

159153
static void add_edges_from(
@@ -163,7 +157,7 @@ struct directed_adjacency_list {
163157
adjacent_edges_source.reserve(adjacent_edges_source.size() + new_edges.size());
164158

165159
for (auto& edge : new_edges)
166-
adjacent_edges_source.push_back(std::move(edge));
160+
adjacent_edges_source.emplace_back(std::move(edge));
167161

168162
self._n_unique_edges += new_edges.size();
169163
}
@@ -282,7 +276,7 @@ struct undirected_adjacency_list {
282276

283277
if (not edge->is_loop())
284278
self._list[edge->second_id()].push_back(edge);
285-
adjacent_edges_first.push_back(std::move(edge));
279+
adjacent_edges_first.emplace_back(std::move(edge));
286280

287281
++self._n_unique_edges;
288282
return *adjacent_edges_first.back();
@@ -297,7 +291,7 @@ struct undirected_adjacency_list {
297291
for (auto& edge : new_edges) {
298292
if (not edge->is_loop())
299293
self._list[edge->second_id()].push_back(edge);
300-
adjacent_edges_source.push_back(std::move(edge));
294+
adjacent_edges_source.emplace_back(std::move(edge));
301295
}
302296

303297
self._n_unique_edges += new_edges.size();

include/gl/impl/specialized/adjacency_matrix.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,8 @@ struct directed_adjacency_matrix {
9090
std::vector<types::id_type> in_degree_map(self._matrix.size(), constants::zero);
9191

9292
for (const auto& row : self._matrix)
93-
for (types::id_type id = constants::initial_id; id < self._matrix.size(); ++id)
94-
if (row[id] != nullptr)
95-
++in_degree_map[id];
93+
for (auto [id, edge_ptr] : std::views::enumerate(row))
94+
in_degree_map[id] += static_cast<types::size_type>(edge_ptr != nullptr);
9695

9796
return in_degree_map;
9897
}
@@ -187,11 +186,10 @@ struct undirected_adjacency_matrix {
187186
[[nodiscard]] gl_attr_force_inline static types::size_type degree(
188187
const impl_type& self, const types::id_type vertex_id
189188
) {
190-
const auto& loop = self._matrix[vertex_id][vertex_id];
191189
return std::ranges::count_if(
192190
self._matrix[vertex_id], [](const auto& edge) { return edge != nullptr; }
193191
)
194-
+ static_cast<types::size_type>(loop and loop->is_loop());
192+
+ static_cast<types::size_type>(self._matrix[vertex_id][vertex_id] != nullptr);
195193
}
196194

197195
[[nodiscard]] gl_attr_force_inline static std::vector<types::size_type> in_degree_map(

include/gl/io/stream_options_manipulator.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#pragma once
66

77
#include "gl/attributes/force_inline.hpp"
8-
#include "gl/util/enum.hpp"
98

109
#include <iostream>
1110

@@ -102,7 +101,7 @@ template <detail::c_bit_position_enum BitPosition>
102101
iword_type options_bitmask = 0ul;
103102
for (const auto bit_position : bit_positions)
104103
options_bitmask |=
105-
iword_bit << static_cast<bit_position_type>(util::to_underlying(bit_position));
104+
iword_bit << static_cast<bit_position_type>(std::to_underlying(bit_position));
106105
return options_bitmask;
107106
}
108107

@@ -137,7 +136,7 @@ set_option(bit_position_type bit_position) {
137136
template <detail::c_bit_position_enum BitPosition>
138137
[[nodiscard]] gl_attr_force_inline stream_options_manipulator set_option(BitPosition bit_position) {
139138
return stream_options_manipulator::from_bit_position(
140-
static_cast<bit_position_type>(util::to_underlying(bit_position)),
139+
static_cast<bit_position_type>(std::to_underlying(bit_position)),
141140
stream_options_manipulator::set
142141
);
143142
}
@@ -172,7 +171,7 @@ template <detail::c_bit_position_enum BitPosition>
172171
[[nodiscard]] gl_attr_force_inline stream_options_manipulator unset_option(BitPosition bit_position
173172
) {
174173
return stream_options_manipulator::from_bit_position(
175-
static_cast<bit_position_type>(util::to_underlying(bit_position)),
174+
static_cast<bit_position_type>(std::to_underlying(bit_position)),
176175
stream_options_manipulator::unset
177176
);
178177
}
@@ -209,7 +208,7 @@ template <detail::c_bit_position_enum BitPosition>
209208
std::ios_base& stream, BitPosition bit_position
210209
) {
211210
return stream_options_manipulator::is_option_set(
212-
stream, static_cast<bit_position_type>(util::to_underlying(bit_position))
211+
stream, static_cast<bit_position_type>(std::to_underlying(bit_position))
213212
);
214213
}
215214

include/gl/types/iterator_range.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,13 @@ class iterator_range
9898
return this->_range.second;
9999
}
100100

101-
#if __cplusplus >= 202302L
102101
[[nodiscard]] gl_attr_force_inline auto cbegin() const {
103102
return std::make_const_iterator(this->_range.first);
104103
}
105104

106105
[[nodiscard]] gl_attr_force_inline auto cend() const {
107106
return std::make_const_iterator(this->_range.second);
108107
}
109-
#endif
110108

111109
[[nodiscard]] gl_attr_force_inline distance_type distance() const
112110
requires(cache_mode::value == type_traits::cache_mode_value::eager)

include/gl/types/properties.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#pragma once
66

77
#include "gl/attributes/force_inline.hpp"
8-
#include "gl/util/enum.hpp"
98
#include "traits/concepts.hpp"
109

1110
#include <any>
@@ -186,7 +185,7 @@ class binary_color
186185
}
187186

188187
[[nodiscard]] gl_attr_force_inline std::underlying_type_t<value> to_underlying() const {
189-
return util::to_underlying(this->_value);
188+
return std::to_underlying(this->_value);
190189
}
191190

192191
[[nodiscard]] gl_attr_force_inline binary_color next() const {

include/gl/util/enum.hpp

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)