Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion include/mapbox/eternal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class iterator {
return *this;
}

constexpr std::size_t operator-(const iterator& rhs) const noexcept {
constexpr std::ptrdiff_t operator-(const iterator& rhs) const noexcept {
return pos - rhs.pos;
}

Expand Down Expand Up @@ -331,6 +331,19 @@ static constexpr auto hash_map(const std::pair<const Key, const Value> (&items)[
} // namespace eternal
} // namespace mapbox

namespace std {

template <typename Element>
struct iterator_traits<::mapbox::eternal::iterator<Element>> {
using difference_type = std::ptrdiff_t;
using value_type = typename Element::value_type;
using pointer = Element*;
using reference = Element&;
using iterator_category = std::bidirectional_iterator_tag;
};

} // namespace std

// mapbox::eternal::string

namespace mapbox {
Expand Down
7 changes: 7 additions & 0 deletions test/data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ struct Color {
return r == rhs.r && g == rhs.g && b == rhs.b &&
(a >= rhs.a ? a - rhs.a : rhs.a - a) < std::numeric_limits<float>::epsilon();
}

constexpr bool operator<(const Color& rhs) const {
return r < rhs.r ||
(!(rhs.r < r) && g < rhs.g) ||
(!(rhs.g < g) && b < rhs.b) ||
(!(rhs.b < b) && a < rhs.a);
}
};

#define COLORS \
Expand Down
4 changes: 4 additions & 0 deletions test/map.test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "data.hpp"

#include <algorithm>

#include <cassert>


Expand Down Expand Up @@ -67,6 +69,8 @@ static void test() {
for (auto range = multi_colors.equal_range("yellow"); range.first != range.second; ++range.first) {
(void)range;
}

assert(std::is_sorted(colors.begin(), colors.end()));
}

int main(int argc, char* argv[]) {
Expand Down