diff --git a/include/mapbox/eternal.hpp b/include/mapbox/eternal.hpp index e02a569..2e384d6 100644 --- a/include/mapbox/eternal.hpp +++ b/include/mapbox/eternal.hpp @@ -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; } @@ -331,6 +331,19 @@ static constexpr auto hash_map(const std::pair (&items)[ } // namespace eternal } // namespace mapbox +namespace std { + +template +struct iterator_traits<::mapbox::eternal::iterator> { + 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 { diff --git a/test/data.hpp b/test/data.hpp index 4a6c786..1b9e838 100644 --- a/test/data.hpp +++ b/test/data.hpp @@ -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::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 \ diff --git a/test/map.test.cpp b/test/map.test.cpp index dfaa38f..11a3911 100644 --- a/test/map.test.cpp +++ b/test/map.test.cpp @@ -1,5 +1,7 @@ #include "data.hpp" +#include + #include @@ -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[]) {