Skip to content

Commit ea1ae77

Browse files
authored
update range-v3 to version 0.12.0 (#670)
additionally, update range-v3 example code to compile without warnings updated version taken from https://github.com/ericniebler/range-v3/blob/0.12.0/example/comprehensions.cpp
1 parent 73a49d1 commit ea1ae77

File tree

3 files changed

+93
-87
lines changed

3 files changed

+93
-87
lines changed

cmake/configs/default.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,10 @@ if(MSVC)
473473
if(MSVC_VERSION LESS 1916)
474474
hunter_default_version(range-v3 VERSION vcpkg5-p)
475475
else()
476-
hunter_default_version(range-v3 VERSION 0.11.0)
476+
hunter_default_version(range-v3 VERSION 0.12.0)
477477
endif()
478478
else()
479-
hunter_default_version(range-v3 VERSION 0.11.0)
479+
hunter_default_version(range-v3 VERSION 0.12.0)
480480
endif()
481481

482482
hunter_default_version(re2 VERSION 2022.04.01)

cmake/projects/range-v3/hunter.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ hunter_add_version(
6464
a49d6d541057d8601d70b5771567eb89832b50bf
6565
)
6666

67+
hunter_add_version(
68+
PACKAGE_NAME
69+
range-v3
70+
VERSION
71+
0.12.0
72+
URL
73+
"https://github.com/ericniebler/range-v3/archive/0.12.0.tar.gz"
74+
SHA1
75+
c7893c255a437aadae3b46661c7a814a19012746
76+
)
77+
6778
hunter_cmake_args(
6879
range-v3
6980
CMAKE_ARGS
Lines changed: 80 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Range v3 library
22
//
3-
// Copyright Eric Niebler 2013-2014
3+
// Copyright Eric Niebler 2013-present
44
//
55
// Use, modification and distribution is subject to the
66
// Boost Software License, Version 1.0. (See accompanying
@@ -16,36 +16,32 @@
1616

1717
using namespace ranges;
1818

19-
int main()
19+
int
20+
main()
2021
{
21-
// Define an infinite range containing all the Pythagorean triples:
22-
auto triples =
23-
view::for_each(view::ints(1), [](int z)
24-
{
25-
return view::for_each(view::ints(1, z + 1), [=](int x)
26-
{
27-
return view::for_each(view::ints(x, z + 1), [=](int y)
28-
{
29-
return yield_if(x*x + y * y == z * z, std::make_tuple(x, y, z));
30-
});
22+
// Define an infinite range containing all the Pythagorean triples:
23+
auto triples = views::for_each(views::iota(1), [](int z) {
24+
return views::for_each(views::iota(1, z + 1), [=](int x) {
25+
return views::for_each(views::iota(x, z + 1), [=](int y) {
26+
return yield_if(x * x + y * y == z * z,
27+
std::make_tuple(x, y, z));
28+
});
29+
});
3130
});
32-
});
3331

34-
//// This alternate syntax also works:
35-
//auto triples = ints(1) >>= [] (int z) { return
36-
// ints(1, z+1) >>= [=](int x) { return
37-
// ints(x, z+1) >>= [=](int y) { return
38-
// yield_if(x*x + y*y == z*z,
39-
// std::make_tuple(x, y, z)); };}; };
32+
//// This alternate syntax also works:
33+
// auto triples = iota(1) >>= [] (int z) { return
34+
// iota(1, z+1) >>= [=](int x) { return
35+
// iota(x, z+1) >>= [=](int y) { return
36+
// yield_if(x*x + y*y == z*z,
37+
// std::make_tuple(x, y, z)); };}; };
4038

41-
// Display the first 100 triples
42-
RANGES_FOR(auto triple, triples | view::take(100))
43-
{
44-
std::cout << '('
45-
<< std::get<0>(triple) << ','
46-
<< std::get<1>(triple) << ','
47-
<< std::get<2>(triple) << ')' << '\n';
48-
}
39+
// Display the first 100 triples
40+
RANGES_FOR(auto triple, triples | views::take(100))
41+
{
42+
std::cout << '(' << std::get<0>(triple) << ',' << std::get<1>(triple)
43+
<< ',' << std::get<2>(triple) << ')' << '\n';
44+
}
4945
}
5046

5147
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -55,75 +51,74 @@ int main()
5551
class timer
5652
{
5753
private:
58-
std::chrono::high_resolution_clock::time_point start_;
54+
std::chrono::high_resolution_clock::time_point start_;
55+
5956
public:
60-
timer()
61-
{
62-
reset();
63-
}
64-
void reset()
65-
{
66-
start_ = std::chrono::high_resolution_clock::now();
67-
}
68-
std::chrono::milliseconds elapsed() const
69-
{
70-
return std::chrono::duration_cast<std::chrono::milliseconds>(
71-
std::chrono::high_resolution_clock::now() - start_);
72-
}
73-
friend std::ostream &operator<<(std::ostream &sout, timer const &t)
74-
{
75-
return sout << t.elapsed().count() << "ms";
76-
}
57+
timer()
58+
{
59+
reset();
60+
}
61+
void reset()
62+
{
63+
start_ = std::chrono::high_resolution_clock::now();
64+
}
65+
std::chrono::milliseconds elapsed() const
66+
{
67+
return std::chrono::duration_cast<std::chrono::milliseconds>(
68+
std::chrono::high_resolution_clock::now() - start_);
69+
}
70+
friend std::ostream &operator<<(std::ostream &sout, timer const &t)
71+
{
72+
return sout << t.elapsed().count() << "ms";
73+
}
7774
};
7875

79-
void benchmark()
76+
void
77+
benchmark()
8078
{
81-
// Define an infinite range containing all the Pythagorean triples:
82-
auto triples =
83-
view::for_each(view::ints(1), [](int z)
84-
{
85-
return view::for_each(view::ints(1, z + 1), [=](int x)
86-
{
87-
return view::for_each(view::ints(x, z + 1), [=](int y)
88-
{
89-
return yield_if(x*x + y * y == z * z, std::make_tuple(x, y, z));
90-
});
79+
// Define an infinite range containing all the Pythagorean triples:
80+
auto triples = views::for_each(views::iota(1), [](int z) {
81+
return views::for_each(views::iota(1, z + 1), [=](int x) {
82+
return views::for_each(views::iota(x, z + 1), [=](int y) {
83+
return yield_if(x * x + y * y == z * z,
84+
std::make_tuple(x, y, z));
85+
});
86+
});
9187
});
92-
});
9388

94-
static constexpr int max_triples = 3000;
89+
static constexpr int max_triples = 3000;
9590

96-
timer t;
97-
int result = 0;
98-
RANGES_FOR(auto triple, triples | view::take(max_triples))
99-
{
100-
int i, j, k;
101-
std::tie(i, j, k) = triple;
102-
result += (i + j + k);
103-
}
104-
std::cout << t << '\n';
105-
std::cout << result << '\n';
91+
timer t;
92+
int result = 0;
93+
RANGES_FOR(auto triple, triples | views::take(max_triples))
94+
{
95+
int i, j, k;
96+
std::tie(i, j, k) = triple;
97+
result += (i + j + k);
98+
}
99+
std::cout << t << '\n';
100+
std::cout << result << '\n';
106101

107-
result = 0;
108-
int found = 0;
109-
t.reset();
110-
for (int z = 1;; ++z)
111-
{
112-
for (int x = 1; x <= z; ++x)
102+
result = 0;
103+
int found = 0;
104+
t.reset();
105+
for(int z = 1;; ++z)
113106
{
114-
for (int y = x; y <= z; ++y)
115-
{
116-
if (x*x + y * y == z * z)
107+
for(int x = 1; x <= z; ++x)
117108
{
118-
result += (x + y + z);
119-
++found;
120-
if (found == max_triples)
121-
goto done;
109+
for(int y = x; y <= z; ++y)
110+
{
111+
if(x * x + y * y == z * z)
112+
{
113+
result += (x + y + z);
114+
++found;
115+
if(found == max_triples)
116+
goto done;
117+
}
118+
}
122119
}
123-
}
124120
}
125-
}
126121
done:
127-
std::cout << t << '\n';
128-
std::cout << result << '\n';
122+
std::cout << t << '\n';
123+
std::cout << result << '\n';
129124
}

0 commit comments

Comments
 (0)