Skip to content

Commit 0b4eb98

Browse files
committed
C++17: use [[fallthrough]] and [[nodiscard]]
1 parent c8fbb01 commit 0b4eb98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+235
-299
lines changed

include/cpp-sort/comparators/flip.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2024 Morwenn
2+
* Copyright (c) 2021-2025 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
55
#ifndef CPPSORT_COMPARATORS_FLIP_H_
@@ -12,7 +12,6 @@
1212
#include <utility>
1313
#include <cpp-sort/utility/as_function.h>
1414
#include <cpp-sort/utility/branchless_traits.h>
15-
#include "../detail/attributes.h"
1615
#include "../detail/raw_checkers.h"
1716

1817
namespace cppsort
@@ -86,7 +85,7 @@ namespace cppsort
8685
////////////////////////////////////////////////////////////
8786
// Accessor
8887

89-
CPPSORT_ATTRIBUTE_NODISCARD
88+
[[nodiscard]]
9089
constexpr auto base() const
9190
-> F
9291
{

include/cpp-sort/comparators/not_fn.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2023 Morwenn
2+
* Copyright (c) 2021-2025 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
55
#ifndef CPPSORT_COMPARATORS_NOT_FN_H_
@@ -11,7 +11,6 @@
1111
#include <type_traits>
1212
#include <utility>
1313
#include <cpp-sort/utility/as_function.h>
14-
#include "../detail/attributes.h"
1514
#include "../detail/raw_checkers.h"
1615

1716
namespace cppsort
@@ -85,7 +84,7 @@ namespace cppsort
8584
////////////////////////////////////////////////////////////
8685
// Accessor
8786

88-
CPPSORT_ATTRIBUTE_NODISCARD
87+
[[nodiscard]]
8988
constexpr auto base() const
9089
-> F
9190
{

include/cpp-sort/comparators/projection_compare.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <cpp-sort/utility/as_function.h>
1414
#include <cpp-sort/utility/branchless_traits.h>
1515
#include <cpp-sort/utility/functional.h>
16-
#include "../detail/attributes.h"
1716
#include "../detail/config.h"
1817
#include "../detail/raw_checkers.h"
1918

@@ -102,14 +101,14 @@ namespace cppsort
102101
////////////////////////////////////////////////////////////
103102
// Accessors
104103

105-
CPPSORT_ATTRIBUTE_NODISCARD
104+
[[nodiscard]]
106105
constexpr auto comparison() const
107106
-> Compare
108107
{
109108
return std::get<0>(data);
110109
}
111110

112-
CPPSORT_ATTRIBUTE_NODISCARD
111+
[[nodiscard]]
113112
constexpr auto projection() const
114113
-> Projection
115114
{

include/cpp-sort/detail/associate_iterator.h

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2022 Morwenn
2+
* Copyright (c) 2016-2025 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
55
#ifndef CPPSORT_DETAIL_ASSOCIATE_ITERATOR_H_
@@ -11,7 +11,6 @@
1111
#include <iterator>
1212
#include <utility>
1313
#include <cpp-sort/utility/iter_move.h>
14-
#include "attributes.h"
1514
#include "iterator_traits.h"
1615

1716
namespace cppsort
@@ -80,14 +79,14 @@ namespace detail
8079
return *this;
8180
}
8281

83-
CPPSORT_ATTRIBUTE_NODISCARD
82+
[[nodiscard]]
8483
auto get()
8584
-> decltype(*it)
8685
{
8786
return *it;
8887
}
8988

90-
CPPSORT_ATTRIBUTE_NODISCARD
89+
[[nodiscard]]
9190
auto get() const
9291
-> decltype(*it)
9392
{
@@ -134,14 +133,14 @@ namespace detail
134133
return *this;
135134
}
136135

137-
CPPSORT_ATTRIBUTE_NODISCARD
136+
[[nodiscard]]
138137
auto get()
139138
-> Value&
140139
{
141140
return value;
142141
}
143142

144-
CPPSORT_ATTRIBUTE_NODISCARD
143+
[[nodiscard]]
145144
auto get() const
146145
-> const Value&
147146
{
@@ -182,7 +181,7 @@ namespace detail
182181
////////////////////////////////////////////////////////////
183182
// Members access
184183

185-
CPPSORT_ATTRIBUTE_NODISCARD
184+
[[nodiscard]]
186185
auto base() const
187186
-> iterator_type
188187
{
@@ -192,14 +191,14 @@ namespace detail
192191
////////////////////////////////////////////////////////////
193192
// Element access
194193

195-
CPPSORT_ATTRIBUTE_NODISCARD
194+
[[nodiscard]]
196195
auto operator*() const
197196
-> decltype(*base())
198197
{
199198
return *_it;
200199
}
201200

202-
CPPSORT_ATTRIBUTE_NODISCARD
201+
[[nodiscard]]
203202
auto operator->() const
204203
-> pointer
205204
{
@@ -240,7 +239,7 @@ namespace detail
240239
////////////////////////////////////////////////////////////
241240
// Elements access operators
242241

243-
CPPSORT_ATTRIBUTE_NODISCARD
242+
[[nodiscard]]
244243
auto operator[](difference_type pos) const
245244
-> decltype(base()[pos])
246245
{
@@ -250,14 +249,14 @@ namespace detail
250249
////////////////////////////////////////////////////////////
251250
// Comparison operators
252251

253-
CPPSORT_ATTRIBUTE_NODISCARD
252+
[[nodiscard]]
254253
friend auto operator==(const associate_iterator& lhs, const associate_iterator& rhs)
255254
-> bool
256255
{
257256
return lhs.base() == rhs.base();
258257
}
259258

260-
CPPSORT_ATTRIBUTE_NODISCARD
259+
[[nodiscard]]
261260
friend auto operator!=(const associate_iterator& lhs, const associate_iterator& rhs)
262261
-> bool
263262
{
@@ -267,28 +266,28 @@ namespace detail
267266
////////////////////////////////////////////////////////////
268267
// Relational operators
269268

270-
CPPSORT_ATTRIBUTE_NODISCARD
269+
[[nodiscard]]
271270
friend auto operator<(const associate_iterator& lhs, const associate_iterator& rhs)
272271
-> bool
273272
{
274273
return lhs.base() < rhs.base();
275274
}
276275

277-
CPPSORT_ATTRIBUTE_NODISCARD
276+
[[nodiscard]]
278277
friend auto operator<=(const associate_iterator& lhs, const associate_iterator& rhs)
279278
-> bool
280279
{
281280
return lhs.base() <= rhs.base();
282281
}
283282

284-
CPPSORT_ATTRIBUTE_NODISCARD
283+
[[nodiscard]]
285284
friend auto operator>(const associate_iterator& lhs, const associate_iterator& rhs)
286285
-> bool
287286
{
288287
return lhs.base() > rhs.base();
289288
}
290289

291-
CPPSORT_ATTRIBUTE_NODISCARD
290+
[[nodiscard]]
292291
friend auto operator>=(const associate_iterator& lhs, const associate_iterator& rhs)
293292
-> bool
294293
{
@@ -298,31 +297,31 @@ namespace detail
298297
////////////////////////////////////////////////////////////
299298
// Arithmetic operators
300299

301-
CPPSORT_ATTRIBUTE_NODISCARD
300+
[[nodiscard]]
302301
friend auto operator+(associate_iterator it, difference_type size)
303302
-> associate_iterator
304303
{
305304
it += size;
306305
return it;
307306
}
308307

309-
CPPSORT_ATTRIBUTE_NODISCARD
308+
[[nodiscard]]
310309
friend auto operator+(difference_type size, associate_iterator it)
311310
-> associate_iterator
312311
{
313312
it += size;
314313
return it;
315314
}
316315

317-
CPPSORT_ATTRIBUTE_NODISCARD
316+
[[nodiscard]]
318317
friend auto operator-(associate_iterator it, difference_type size)
319318
-> associate_iterator
320319
{
321320
it -= size;
322321
return it;
323322
}
324323

325-
CPPSORT_ATTRIBUTE_NODISCARD
324+
[[nodiscard]]
326325
friend auto operator-(const associate_iterator& lhs, const associate_iterator& rhs)
327326
-> difference_type
328327
{
@@ -339,7 +338,7 @@ namespace detail
339338
iter_swap(lhs.base(), rhs.base());
340339
}
341340

342-
CPPSORT_ATTRIBUTE_NODISCARD
341+
[[nodiscard]]
343342
friend auto iter_move(associate_iterator it)
344343
-> associated_value<
345344
value_type_t<typename value_type_t<Iterator>::iterator_type>,
@@ -361,7 +360,7 @@ namespace detail
361360
// Construction function
362361

363362
template<typename Iterator>
364-
CPPSORT_ATTRIBUTE_NODISCARD
363+
[[nodiscard]]
365364
auto make_associate_iterator(Iterator it)
366365
-> associate_iterator<Iterator>
367366
{

include/cpp-sort/detail/attributes.h

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

include/cpp-sort/detail/bitops.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015-2023 Morwenn
2+
* Copyright (c) 2015-2025 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
55
#ifndef CPPSORT_DETAIL_BITOPS_H_
@@ -11,7 +11,6 @@
1111
#include <cstddef>
1212
#include <limits>
1313
#include <type_traits>
14-
#include "attributes.h"
1514
#include "config.h"
1615
#include "type_traits.h"
1716

@@ -21,7 +20,7 @@ namespace detail
2120
{
2221
// Cast signed value to unsigned one
2322
template<typename Integer>
24-
CPPSORT_ATTRIBUTE_NODISCARD
23+
[[nodiscard]]
2524
constexpr auto as_unsigned(Integer value)
2625
-> std::make_unsigned_t<Integer>
2726
{

include/cpp-sort/detail/config.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,8 @@
154154
////////////////////////////////////////////////////////////
155155
// CPPSORT_DEPRECATED
156156

157-
// [[deprecated]] is available since C++14, hence why this
158-
// macro is not in attributes.h: we hide it behind a macro
159-
// to make sure that it can be silenced
157+
// We hide [[deprecated]] behind a macro to make sure that
158+
// it can be silenced
160159

161160
#ifndef CPPSORT_DEPRECATED
162161
# ifndef CPPSORT_DISABLE_DEPRECATION_WARNINGS

include/cpp-sort/detail/empty_sorter.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2023 Morwenn
2+
* Copyright (c) 2021-2025 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
55
#ifndef CPPSORT_DETAIL_EMPTY_SORTER_H_
@@ -15,7 +15,6 @@
1515
#include <cpp-sort/sorter_traits.h>
1616
#include <cpp-sort/utility/functional.h>
1717
#include <cpp-sort/utility/sorting_networks.h>
18-
#include "attributes.h"
1918
#include "type_traits.h"
2019

2120
namespace cppsort
@@ -51,7 +50,7 @@ namespace detail
5150
empty_sorter_impl
5251
{
5352
template<typename DifferenceType=std::ptrdiff_t>
54-
CPPSORT_ATTRIBUTE_NODISCARD
53+
[[nodiscard]]
5554
static constexpr auto index_pairs() noexcept
5655
-> std::array<utility::index_pair<DifferenceType>, 0>
5756
{

0 commit comments

Comments
 (0)