Skip to content

Commit 6594ac9

Browse files
committed
Merge branch 'master' of github.com:ryanhaining/cppitertools
2 parents 06e5923 + c11673f commit 6594ac9

21 files changed

Lines changed: 209 additions & 61 deletions

combinations.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ class iter::impl::Combinator {
9494
if (!(dumb_next(*iter, dist) != get_end(*container_p_))) {
9595
if ((iter + 1) != indices_.get().rend()) {
9696
size_t inc = 1;
97-
for (auto down = iter; down != indices_.get().rbegin() - 1;
98-
--down) {
97+
for (auto down = iter; ; --down) {
9998
(*down) = dumb_next(*(iter + 1), 1 + inc);
10099
++inc;
100+
if (down == indices_.get().rbegin())
101+
break;
101102
}
102103
} else {
103104
steps_ = COMPLETE;

combinations_with_replacement.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ class iter::impl::CombinatorWithReplacement {
7474
++(*iter);
7575
if (!(*iter != get_end(*container_p_))) {
7676
if ((iter + 1) != indices_.get().rend()) {
77-
for (auto down = iter; down != indices_.get().rbegin() - 1;
78-
--down) {
77+
for (auto down = iter; ; --down) {
7978
(*down) = dumb_next(*(iter + 1));
79+
if (down == indices_.get().rbegin())
80+
break;
8081
}
8182
} else {
8283
steps_ = COMPLETE;

examples/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Note that some examples currently use boost.optional which we do no not search for in this file.
2+
# You might have to use the "keep going" option to continue building on errors if boost.optional is not in the include path.
3+
# For example, building with MSVC (from an examples/buildMsvc directory):
4+
# set CXX=cl.exe
5+
# cmake .. -G Ninja
6+
# cmake --build . -- -k99
7+
8+
cmake_minimum_required(VERSION 3.8)
9+
project(cppitertools_examples CXX)
10+
set (CMAKE_CXX_STANDARD 17)
11+
12+
include_directories(
13+
..
14+
)
15+
16+
file(GLOB _examples_files "*_examples.cpp")
17+
18+
foreach(_file_cpp ${_examples_files})
19+
get_filename_component(_name_cpp "${_file_cpp}" NAME)
20+
get_filename_component(_name_without_extension "${_name_cpp}" NAME_WE)
21+
add_executable(${_name_without_extension} ${_file_cpp})
22+
endforeach()

examples/filterfalse_examples.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <filterfalse.hpp>
22

33
#include <vector>
4+
#include <string>
45
#include <iostream>
56

67
bool greater_than_four(int i) {

internal/iterator_wrapper.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ namespace iter {
3232

3333
template <typename Container>
3434
using IteratorWrapper = typename IteratorWrapperImplType<Container,
35-
std::is_same<impl::iterator_type<Container>,
36-
impl::iterator_end_type<Container>>{}>::type;
35+
std::is_same_v<impl::iterator_type<Container>,
36+
impl::iterator_end_type<Container>>>::type;
3737
}
3838
}
3939

4040
template <typename SubIter, typename SubEnd>
4141
class iter::impl::IteratorWrapperImpl {
4242
private:
43-
static_assert(!std::is_same<SubIter, SubEnd>{});
43+
static_assert(!std::is_same_v<SubIter, SubEnd>);
4444
SubIter& sub_iter() {
4545
auto* sub = std::get_if<SubIter>(&sub_iter_or_end_);
4646
assert(sub);

internal/iteratoriterator.hpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ namespace iter {
8080
return ret;
8181
}
8282

83-
auto operator*() -> decltype(**sub_iter) {
83+
auto operator*() const -> decltype(**sub_iter) {
8484
return **this->sub_iter;
8585
}
8686

87-
auto operator-> () -> decltype(*sub_iter) {
87+
auto operator-> () const -> decltype(*sub_iter) {
8888
return *this->sub_iter;
8989
}
9090

@@ -115,16 +115,11 @@ namespace iter {
115115
return it;
116116
}
117117

118-
friend IteratorIterator operator-(Diff n, IteratorIterator it) {
119-
it -= n;
120-
return it;
121-
}
122-
123118
Diff operator-(const IteratorIterator& rhs) const {
124119
return this->sub_iter - rhs.sub_iter;
125120
}
126121

127-
auto operator[](Diff idx) -> decltype(*sub_iter[idx]) {
122+
auto operator[](Diff idx) const -> decltype(*sub_iter[idx]) {
128123
return *sub_iter[idx];
129124
}
130125

internal/iterbase.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ namespace iter {
5151
using AsConst = decltype(std::as_const(std::declval<T&>()));
5252

5353
// iterator_type<C> is the type of C's iterator
54-
template <typename Container>
55-
using iterator_type = decltype(get_begin(std::declval<Container&>()));
54+
template <typename T> //TODO: See bug https://developercommunity.visualstudio.com/content/problem/252157/sfinae-error-depends-on-name-of-template-parameter.html for why we use T instead of Container. Should be changed back to Container when that bug is fixed in MSVC.
55+
using iterator_type = decltype(get_begin(std::declval<T&>()));
5656

5757
// iterator_type<C> is the type of C's iterator
5858
template <typename Container>

product.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,9 @@ class iter::impl::Productor {
126126
template <typename T, template <typename> class IT,
127127
template <typename> class TD>
128128
bool operator!=(const IteratorTempl<T, IT, TD>& other) const {
129-
if (sizeof...(Is) == 0) return false;
130-
131-
bool results[] = {
132-
true, (std::get<Is>(iters_) != std::get<Is>(other.iters_))...};
133-
return std::all_of(
134-
get_begin(results), get_end(results), [](bool b) { return b; });
129+
if constexpr (sizeof...(Is) == 0) return false;
130+
else
131+
return (... && (std::get<Is>(iters_) != std::get<Is>(other.iters_)));
135132
}
136133

137134
template <typename T, template <typename> class IT,

reversed.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ namespace iter {
3535
template <typename Container>
3636
using ReverseIteratorWrapper =
3737
typename ReverseIteratorWrapperImplType<Container,
38-
std::is_same<impl::reverse_iterator_type<Container>,
38+
std::is_same_v<impl::reverse_iterator_type<Container>,
3939
impl::
40-
reverse_iterator_end_type<Container>>{}>::
40+
reverse_iterator_end_type<Container>>>::
4141
type;
4242

4343
template <typename Container>

starmap.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class iter::impl::TupleStarMapper {
130130
class IteratorData {
131131
public:
132132
template <std::size_t Idx>
133-
static decltype(auto) get_and_call_with_tuple(Func& f, TupTypeT& t) {
133+
static auto get_and_call_with_tuple(Func& f, TupTypeT& t) -> decltype(std::apply(f, std::get<Idx>(t))) { //TODO: Remove duplicated expression in decltype, using decltype(auto) as return type, when all compilers correctly deduce type (i.e. MSVC cl 19.15 does not do it).
134134
return std::apply(f, std::get<Idx>(t));
135135
}
136136

0 commit comments

Comments
 (0)