Skip to content

Commit b285ed2

Browse files
committed
simplifies derefholder, fixes operator bool
I needed to static_cast the unique_ptr..
1 parent 90f30db commit b285ed2

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

internal/iterbase.hpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace iter {
6363
template <typename T, typename = void>
6464
struct ArrowHelper {
6565
using type = void;
66-
void operator()(T&) const noexcept { }
66+
void operator()(T&) const noexcept {}
6767
};
6868

6969
template <typename T>
@@ -202,8 +202,7 @@ namespace iter {
202202
// get() returns a reference to the held item
203203
// get_ptr() returns a pointer to the held item
204204
// reset() replaces the currently held item
205-
206-
template <typename T, typename = void>
205+
template <typename T>
207206
class DerefHolder {
208207
private:
209208
static_assert(!std::is_lvalue_reference<T>::value,
@@ -244,18 +243,16 @@ namespace iter {
244243
}
245244

246245
explicit operator bool() const {
247-
return this->item_p;
246+
return static_cast<bool>(this->item_p);
248247
}
249248
};
250249

251-
// Specialization for when T is an lvalue ref. Keep this in mind
252-
// wherever a T appears.
250+
// Specialization for when T is an lvalue ref
253251
template <typename T>
254-
class DerefHolder<T,
255-
typename std::enable_if<std::is_lvalue_reference<T>::value>::type> {
252+
class DerefHolder<T&> {
256253
public:
257-
using reference = T;
258-
using pointer = typename std::remove_reference<T>::type*;
254+
using reference = T&;
255+
using pointer = T*;
259256

260257
private:
261258
pointer item_p{};
@@ -271,7 +268,7 @@ namespace iter {
271268
return this->item_p;
272269
}
273270

274-
void reset(T item) {
271+
void reset(reference item) {
275272
this->item_p = &item;
276273
}
277274

0 commit comments

Comments
 (0)