Skip to content

Commit e3c9933

Browse files
Merge pull request #53 from serge-sans-paille/fix/various-warnings
Fix/various warnings
2 parents 325449a + b178735 commit e3c9933

File tree

8 files changed

+124
-28
lines changed

8 files changed

+124
-28
lines changed

benchmarks/bench_int_set.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ static auto const* volatile Some = &Keywords;
1717

1818
static void BM_IntInFzSet(benchmark::State& state) {
1919
for (auto _ : state) {
20-
for(auto kw : *Some)
21-
volatile bool status = Keywords.count(kw);
20+
for(auto kw : *Some) {
21+
volatile bool status = Keywords.count(kw);
22+
(void) status;
23+
}
2224
}
2325
}
2426
BENCHMARK(BM_IntInFzSet);
@@ -27,8 +29,10 @@ static const std::set<int> Keywords_(Keywords.begin(), Keywords.end());
2729

2830
static void BM_IntInStdSet(benchmark::State& state) {
2931
for (auto _ : state) {
30-
for(auto kw : *Some)
31-
volatile bool status = Keywords_.count(kw);
32+
for(auto kw : *Some) {
33+
volatile bool status = Keywords_.count(kw);
34+
(void)status;
35+
}
3236
}
3337
}
3438

@@ -42,8 +46,10 @@ static const std::array<int, 32> Keywords__{{
4246
}};
4347
static void BM_IntInStdArray(benchmark::State& state) {
4448
for (auto _ : state) {
45-
for(auto kw : *Some)
46-
volatile bool status = std::find(Keywords__.begin(), Keywords__.end(), kw) != Keywords__.end();
49+
for(auto kw : *Some) {
50+
volatile bool status = std::find(Keywords__.begin(), Keywords__.end(), kw) != Keywords__.end();
51+
(void)status;
52+
}
4753
}
4854
}
4955

@@ -59,24 +65,30 @@ static auto const * volatile SomeIntsPtr = &SomeInts;
5965

6066
static void BM_IntNotInFzSet(benchmark::State& state) {
6167
for (auto _ : state) {
62-
for(auto kw : *SomeIntsPtr)
63-
volatile bool status = Keywords.count(kw);
68+
for(auto kw : *SomeIntsPtr) {
69+
volatile bool status = Keywords.count(kw);
70+
(void)status;
71+
}
6472
}
6573
}
6674
BENCHMARK(BM_IntNotInFzSet);
6775

6876
static void BM_IntNotInStdSet(benchmark::State& state) {
6977
for (auto _ : state) {
70-
for(auto kw : *SomeIntsPtr)
71-
volatile bool status = Keywords_.count(kw);
78+
for(auto kw : *SomeIntsPtr) {
79+
volatile bool status = Keywords_.count(kw);
80+
(void)status;
81+
}
7282
}
7383
}
7484
BENCHMARK(BM_IntNotInStdSet);
7585

7686
static void BM_IntNotInStdArray(benchmark::State& state) {
7787
for (auto _ : state) {
78-
for(auto kw : *SomeIntsPtr)
79-
volatile bool status = std::find(Keywords__.begin(), Keywords__.end(), kw) != Keywords__.end();
88+
for(auto kw : *SomeIntsPtr) {
89+
volatile bool status = std::find(Keywords__.begin(), Keywords__.end(), kw) != Keywords__.end();
90+
(void)status;
91+
}
8092
}
8193
}
8294
BENCHMARK(BM_IntNotInStdArray);

benchmarks/bench_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#include <benchmark/benchmark.h>
2-
BENCHMARK_MAIN();
2+
BENCHMARK_MAIN()
33

benchmarks/bench_str_set.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ static auto const* volatile Some = &Keywords;
2020

2121
static void BM_StrInFzSet(benchmark::State& state) {
2222
for (auto _ : state) {
23-
for(auto kw : *Some)
24-
volatile bool status = Keywords.count(kw);
23+
for(auto kw : *Some) {
24+
volatile bool status = Keywords.count(kw);
25+
(void)status;
26+
}
2527
}
2628
}
2729
BENCHMARK(BM_StrInFzSet);
@@ -30,8 +32,10 @@ static const std::set<frozen::string> Keywords_(Keywords.begin(), Keywords.end()
3032

3133
static void BM_StrInStdSet(benchmark::State& state) {
3234
for (auto _ : state) {
33-
for(auto kw : *Some)
34-
volatile bool status = Keywords_.count(kw);
35+
for(auto kw : *Some) {
36+
volatile bool status = Keywords_.count(kw);
37+
(void)status;
38+
}
3539
}
3640
}
3741

@@ -47,8 +51,10 @@ static const std::array<frozen::string, 32> Keywords__{
4751

4852
static void BM_StrInStdArray(benchmark::State& state) {
4953
for (auto _ : state) {
50-
for(auto kw : *Some)
51-
volatile bool status = std::find(Keywords__.begin(), Keywords__.end(), kw) != Keywords__.end();
54+
for(auto kw : *Some) {
55+
volatile bool status = std::find(Keywords__.begin(), Keywords__.end(), kw) != Keywords__.end();
56+
(void)status;
57+
}
5258
}
5359
}
5460

@@ -66,24 +72,30 @@ static auto const * volatile SomeStringsPtr = &SomeStrings;
6672

6773
static void BM_StrNotInFzSet(benchmark::State& state) {
6874
for (auto _ : state) {
69-
for(auto kw : *SomeStringsPtr)
70-
volatile bool status = Keywords.count(kw);
75+
for(auto kw : *SomeStringsPtr) {
76+
volatile bool status = Keywords.count(kw);
77+
(void)status;
78+
}
7179
}
7280
}
7381
BENCHMARK(BM_StrNotInFzSet);
7482

7583
static void BM_StrNotInStdSet(benchmark::State& state) {
7684
for (auto _ : state) {
77-
for(auto kw : *SomeStringsPtr)
78-
volatile bool status = Keywords_.count(kw);
85+
for(auto kw : *SomeStringsPtr) {
86+
volatile bool status = Keywords_.count(kw);
87+
(void)status;
88+
}
7989
}
8090
}
8191
BENCHMARK(BM_StrNotInStdSet);
8292

8393
static void BM_StrNotInStdArray(benchmark::State& state) {
8494
for (auto _ : state) {
85-
for(auto kw : *SomeStringsPtr)
86-
volatile bool status = std::find(Keywords__.begin(), Keywords__.end(), kw) != Keywords__.end();
95+
for(auto kw : *SomeStringsPtr) {
96+
volatile bool status = std::find(Keywords__.begin(), Keywords__.end(), kw) != Keywords__.end();
97+
(void)status;
98+
}
8799
}
88100
}
89101

include/frozen/bits/basic_types.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ namespace frozen {
3333

3434
namespace bits {
3535

36+
// used as a fake argument for frozen::make_set and frozen::make_map in the case of N=0
37+
struct ignored_arg {};
38+
3639
template <class T, std::size_t N>
3740
class cvector {
3841
T data [N] = {}; // zero-initialization for scalar type T, default-initialized otherwise
@@ -168,6 +171,27 @@ class carray {
168171
data_[i] = val;
169172
}
170173
};
174+
template <class T>
175+
class carray<T, 0> {
176+
177+
public:
178+
// Container typdefs
179+
using value_type = T;
180+
using reference = value_type &;
181+
using const_reference = const value_type &;
182+
using pointer = value_type *;
183+
using const_pointer = const value_type *;
184+
using iterator = pointer;
185+
using const_iterator = const_pointer;
186+
using reverse_iterator = std::reverse_iterator<iterator>;
187+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
188+
using size_type = std::size_t;
189+
using difference_type = std::ptrdiff_t;
190+
191+
// Constructors
192+
constexpr carray(void) = default;
193+
194+
};
171195

172196
} // namespace bits
173197

include/frozen/map.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ template <class Comparator> class CompareKey {
6565
return comparator_(self_key, other_key);
6666
}
6767
};
68+
6869
} // namespace impl
6970

7071
template <class Key, class Value, std::size_t N, class Compare = std::less<Key>>
@@ -177,8 +178,7 @@ class map {
177178

178179
template <class Key, class Value, class Compare>
179180
class map<Key, Value, 0, Compare> {
180-
using container_type =
181-
bits::carray<std::pair<Key, Value>, 1>; // just for the type definitions
181+
using container_type = bits::carray<std::pair<Key, Value>, 0>;
182182
impl::CompareKey<Compare> compare_;
183183

184184
public:
@@ -246,6 +246,11 @@ class map<Key, Value, 0, Compare> {
246246
constexpr key_compare value_comp() const { return compare_; }
247247
};
248248

249+
template <typename T, typename U>
250+
constexpr auto make_map(bits::ignored_arg = {}/* for consistency with the initializer below for N = 0*/) {
251+
return map<T, U, 0>{};
252+
}
253+
249254
template <typename T, typename U, std::size_t N>
250255
constexpr auto make_map(std::pair<T, U> const (&items)[N]) {
251256
return map<T, U, N>{items};

include/frozen/set.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ template <class Key, std::size_t N, class Compare = std::less<Key>> class set {
131131
};
132132

133133
template <class Key, class Compare> class set<Key, 0, Compare> {
134-
using container_type = bits::carray<Key, 1>; // just for the type definitions
134+
using container_type = bits::carray<Key, 0>; // just for the type definitions
135135
Compare const compare_;
136136

137137
public:
@@ -194,11 +194,17 @@ template <class Key, class Compare> class set<Key, 0, Compare> {
194194
constexpr const_reverse_iterator crend() const { return nullptr; }
195195
};
196196

197+
template <typename T>
198+
constexpr auto make_set(bits::ignored_arg = {}/* for consistency with the initializer below for N = 0*/) {
199+
return set<T, 0>{};
200+
}
201+
197202
template <typename T, std::size_t N>
198203
constexpr auto make_set(const T (&args)[N]) {
199204
return set<T, N>(args);
200205
}
201206

207+
202208
} // namespace frozen
203209

204210
#endif

tests/test_map.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,27 @@ TEST_CASE("frozen::map <> frozen::make_map", "[map]") {
265265
for (auto v : frozen_map)
266266
REQUIRE(frozen_map2.count(std::get<0>(v)));
267267
}
268+
269+
constexpr frozen::map<int, short, 0> frozen_empty_map = {};
270+
constexpr auto frozen_empty_map2 = frozen::make_map<int, short>();
271+
constexpr auto frozen_empty_map3 = frozen::make_map<int, short>({});
272+
273+
SECTION("checking empty map") {
274+
REQUIRE(frozen_empty_map.empty());
275+
REQUIRE(frozen_empty_map.size() == 0);
276+
REQUIRE(frozen_empty_map.begin() == frozen_empty_map.end());
277+
278+
REQUIRE(frozen_empty_map2.empty());
279+
REQUIRE(frozen_empty_map2.size() == 0);
280+
REQUIRE(frozen_empty_map2.begin() == frozen_empty_map2.end());
281+
282+
REQUIRE(frozen_empty_map3.empty());
283+
REQUIRE(frozen_empty_map3.size() == 0);
284+
REQUIRE(frozen_empty_map3.begin() == frozen_empty_map3.end());
285+
}
268286
}
269287

288+
270289
TEST_CASE("frozen::map constexpr", "[map]") {
271290
constexpr frozen::map<unsigned, unsigned, 2> ce = {{3,4}, {11,12}};
272291
static_assert(*ce.begin() == std::pair<unsigned, unsigned>{3,4}, "");

tests/test_set.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,24 @@ TEST_CASE("frozen::set <> frozen::make_set", "[set]") {
235235
for (auto v : frozen_set)
236236
REQUIRE(frozen_set2.count(v));
237237
}
238+
239+
constexpr frozen::set<short, 0> frozen_empty_set = {};
240+
constexpr auto frozen_empty_set2 = frozen::make_set<short>();
241+
constexpr auto frozen_empty_set3 = frozen::make_set<short>({});
242+
243+
SECTION("checking empty set") {
244+
REQUIRE(frozen_empty_set.empty());
245+
REQUIRE(frozen_empty_set.size() == 0);
246+
REQUIRE(frozen_empty_set.begin() == frozen_empty_set.end());
247+
248+
REQUIRE(frozen_empty_set2.empty());
249+
REQUIRE(frozen_empty_set2.size() == 0);
250+
REQUIRE(frozen_empty_set2.begin() == frozen_empty_set2.end());
251+
252+
REQUIRE(frozen_empty_set3.empty());
253+
REQUIRE(frozen_empty_set3.size() == 0);
254+
REQUIRE(frozen_empty_set3.begin() == frozen_empty_set3.end());
255+
}
238256
}
239257

240258
TEST_CASE("frozen::set constexpr", "[set]") {

0 commit comments

Comments
 (0)