Skip to content

Commit 1f50130

Browse files
committed
moves IMapper into impl { }
1 parent 71e3620 commit 1f50130

1 file changed

Lines changed: 61 additions & 64 deletions

File tree

imap.hpp

Lines changed: 61 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
#include <tuple>
99

1010
namespace iter {
11-
1211
namespace detail {
13-
1412
template <std::size_t Index, typename Functor, typename Tup>
1513
struct Expander {
1614
template <typename... Ts>
@@ -58,87 +56,86 @@ namespace iter {
5856

5957
} // end detail
6058

61-
// Forward declarations of IMap and imap
62-
template <typename MapFunc, typename... Containers>
63-
class IMap;
59+
namespace impl {
60+
template <typename MapFunc, typename... Containers>
61+
class IMapper;
62+
}
6463

6564
template <typename MapFunc, typename... Containers>
66-
IMap<MapFunc, Containers...> imap(MapFunc, Containers&&...);
65+
impl::IMapper<MapFunc, Containers...> imap(MapFunc, Containers&&...);
66+
}
6767

68-
template <typename MapFunc, typename... Containers>
69-
class IMap {
70-
// The imap function is the only thing allowed to create a IMap
71-
friend IMap imap<MapFunc, Containers...>(MapFunc, Containers&&...);
68+
template <typename MapFunc, typename... Containers>
69+
class iter::impl::IMapper {
70+
// The imap function is the only thing allowed to create a IMapper
71+
friend IMapper iter::imap<MapFunc, Containers...>(MapFunc, Containers&&...);
7272

73-
using ZippedType = decltype(zip(std::declval<Containers>()...));
74-
using ZippedIterType = iterator_type<ZippedType>;
73+
using ZippedType = decltype(zip(std::declval<Containers>()...));
74+
using ZippedIterType = iterator_type<ZippedType>;
7575

76-
private:
77-
MapFunc map_func;
78-
ZippedType zipped;
76+
private:
77+
MapFunc map_func;
78+
ZippedType zipped;
7979

80-
using IMapIterDeref =
81-
decltype(detail::call_with_tuple(map_func, *std::begin(zipped)));
80+
using IMapIterDeref =
81+
decltype(detail::call_with_tuple(map_func, *std::begin(zipped)));
8282

83-
// Value constructor for use only in the imap function
84-
IMap(MapFunc in_map_func, Containers&&... in_containers)
85-
: map_func(in_map_func),
86-
zipped(zip(std::forward<Containers>(in_containers)...)) {}
83+
IMapper(MapFunc in_map_func, Containers&&... in_containers)
84+
: map_func(in_map_func),
85+
zipped(zip(std::forward<Containers>(in_containers)...)) {}
8786

88-
public:
89-
class Iterator : public std::iterator<std::input_iterator_tag,
90-
typename std::remove_reference<IMapIterDeref>::type> {
91-
private:
92-
MapFunc* map_func;
93-
ZippedIterType zipiter;
94-
95-
public:
96-
Iterator(MapFunc& in_map_func, ZippedIterType&& in_zipiter)
97-
: map_func(&in_map_func), zipiter(std::move(in_zipiter)) {}
98-
99-
IMapIterDeref operator*() {
100-
return detail::call_with_tuple(*this->map_func, *(this->zipiter));
101-
}
87+
public:
88+
class Iterator : public std::iterator<std::input_iterator_tag,
89+
typename std::remove_reference<IMapIterDeref>::type> {
90+
private:
91+
MapFunc* map_func;
92+
ZippedIterType zipiter;
10293

103-
ArrowProxy<IMapIterDeref> operator->() {
104-
return {**this};
105-
}
94+
public:
95+
Iterator(MapFunc& in_map_func, ZippedIterType&& in_zipiter)
96+
: map_func(&in_map_func), zipiter(std::move(in_zipiter)) {}
10697

107-
Iterator& operator++() {
108-
++this->zipiter;
109-
return *this;
110-
}
98+
IMapIterDeref operator*() {
99+
return detail::call_with_tuple(*this->map_func, *(this->zipiter));
100+
}
111101

112-
Iterator operator++(int) {
113-
auto ret = *this;
114-
++*this;
115-
return ret;
116-
}
102+
ArrowProxy<IMapIterDeref> operator->() {
103+
return {**this};
104+
}
117105

118-
bool operator!=(const Iterator& other) const {
119-
return this->zipiter != other.zipiter;
120-
}
106+
Iterator& operator++() {
107+
++this->zipiter;
108+
return *this;
109+
}
121110

122-
bool operator==(const Iterator& other) const {
123-
return !(*this != other);
124-
}
125-
};
111+
Iterator operator++(int) {
112+
auto ret = *this;
113+
++*this;
114+
return ret;
115+
}
126116

127-
Iterator begin() {
128-
return {this->map_func, this->zipped.begin()};
117+
bool operator!=(const Iterator& other) const {
118+
return this->zipiter != other.zipiter;
129119
}
130120

131-
Iterator end() {
132-
return {this->map_func, this->zipped.end()};
121+
bool operator==(const Iterator& other) const {
122+
return !(*this != other);
133123
}
134124
};
135125

136-
// Helper function to instantiate a IMap
137-
template <typename MapFunc, typename... Containers>
138-
IMap<MapFunc, Containers...> imap(
139-
MapFunc map_func, Containers&&... containers) {
140-
return {map_func, std::forward<Containers>(containers)...};
126+
Iterator begin() {
127+
return {this->map_func, this->zipped.begin()};
141128
}
129+
130+
Iterator end() {
131+
return {this->map_func, this->zipped.end()};
132+
}
133+
};
134+
135+
template <typename MapFunc, typename... Containers>
136+
iter::impl::IMapper<MapFunc, Containers...> iter::imap(
137+
MapFunc map_func, Containers&&... containers) {
138+
return {map_func, std::forward<Containers>(containers)...};
142139
}
143140

144-
#endif // #ifndef ITER_IMAP_H_
141+
#endif

0 commit comments

Comments
 (0)