Skip to content

Commit

Permalink
simplifies derefholder, fixes operator bool
Browse files Browse the repository at this point in the history
I needed to static_cast the unique_ptr..
  • Loading branch information
ryanhaining committed Sep 9, 2015
1 parent 90f30db commit b285ed2
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions internal/iterbase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace iter {
template <typename T, typename = void>
struct ArrowHelper {
using type = void;
void operator()(T&) const noexcept { }
void operator()(T&) const noexcept {}
};

template <typename T>
Expand Down Expand Up @@ -202,8 +202,7 @@ namespace iter {
// get() returns a reference to the held item
// get_ptr() returns a pointer to the held item
// reset() replaces the currently held item

template <typename T, typename = void>
template <typename T>
class DerefHolder {
private:
static_assert(!std::is_lvalue_reference<T>::value,
Expand Down Expand Up @@ -244,18 +243,16 @@ namespace iter {
}

explicit operator bool() const {
return this->item_p;
return static_cast<bool>(this->item_p);
}
};

// Specialization for when T is an lvalue ref. Keep this in mind
// wherever a T appears.
// Specialization for when T is an lvalue ref
template <typename T>
class DerefHolder<T,
typename std::enable_if<std::is_lvalue_reference<T>::value>::type> {
class DerefHolder<T&> {
public:
using reference = T;
using pointer = typename std::remove_reference<T>::type*;
using reference = T&;
using pointer = T*;

private:
pointer item_p{};
Expand All @@ -271,7 +268,7 @@ namespace iter {
return this->item_p;
}

void reset(T item) {
void reset(reference item) {
this->item_p = &item;
}

Expand Down

0 comments on commit b285ed2

Please sign in to comment.