Commit ed94c0e0 authored by Dominik Charousset's avatar Dominik Charousset

Fix build on MSVC

parent 2f923b93
...@@ -42,6 +42,8 @@ public: ...@@ -42,6 +42,8 @@ public:
using array_type = std::array<uint8_t, num_bytes>; using array_type = std::array<uint8_t, num_bytes>;
using u16_array_type = std::array<uint16_t, 8>;
using uint16_ilist = std::initializer_list<uint16_t>; using uint16_ilist = std::initializer_list<uint16_t>;
// -- constructors, destructors, and assignment operators -------------------- // -- constructors, destructors, and assignment operators --------------------
...@@ -121,7 +123,7 @@ private: ...@@ -121,7 +123,7 @@ private:
union { union {
std::array<uint64_t, 2> half_segments_; std::array<uint64_t, 2> half_segments_;
std::array<uint32_t, 4> quad_segments_; std::array<uint32_t, 4> quad_segments_;
std::array<uint16_t, 8> oct_segments_; u16_array_type oct_segments_;
array_type bytes_; array_type bytes_;
}; };
}; };
......
...@@ -146,29 +146,29 @@ bool ipv6_address::is_loopback() const noexcept { ...@@ -146,29 +146,29 @@ bool ipv6_address::is_loopback() const noexcept {
namespace { namespace {
using u16_iterator = const uint16_t*; using u16_iterator = ipv6_address::u16_array_type::const_iterator;
using u16_range = std::pair<u16_iterator, u16_iterator>; using u16_range = std::pair<u16_iterator, u16_iterator>;
u16_range longest_streak(u16_iterator first, u16_iterator last) { u16_range longest_streak(u16_iterator first, u16_iterator last) {
auto zero = [](uint16_t x, uint16_t y) { auto two_zeros = [](uint16_t x, uint16_t y) {
return x == 0 && y == 0; return x == 0 && y == 0;
}; };
auto not_zero = [](uint16_t x) { auto not_zero = [](uint16_t x) {
return x != 0; return x != 0;
}; };
u16_range result; u16_range result;
result.first = std::adjacent_find(first, last, zero); result.first = std::adjacent_find(first, last, two_zeros);
if (result.first == last) if (result.first == last)
return {last, last}; return {last, last};
result.second = std::find_if(result.first + 2, last, not_zero); result.second = std::find_if(result.first + 2, last, not_zero);
if (result.second == last) if (result.second == last)
return result; return result;
auto next_streak = longest_streak(result.second, last); auto next_streak = longest_streak(result.second, last);
auto distance = [](u16_range x) { auto range_size = [](u16_range x) {
return std::distance(x.first, x.second); return std::distance(x.first, x.second);
}; };
return distance(result) >= distance(next_streak) ? result : next_streak; return range_size(result) >= range_size(next_streak) ? result : next_streak;
} }
} // namespace <anonymous> } // namespace <anonymous>
...@@ -188,16 +188,16 @@ std::string to_string(ipv6_address x) { ...@@ -188,16 +188,16 @@ std::string to_string(ipv6_address x) {
}; };
auto add_chunks = [&](u16_iterator i, u16_iterator e) { auto add_chunks = [&](u16_iterator i, u16_iterator e) {
if (i != e) { if (i != e) {
add_chunk(*i++); add_chunk(*i);
for (; i != e; ++i) { for (++i; i != e; ++i) {
result += ':'; result += ':';
add_chunk(*i); add_chunk(*i);
} }
} }
}; };
// Scan for the longest streak of 0 16-bit chunks for :: shorthand. // Scan for the longest streak of 0 16-bit chunks for :: shorthand.
auto first = x.oct_segments_.begin(); auto first = x.oct_segments_.cbegin();
auto last = x.oct_segments_.end(); auto last = x.oct_segments_.cend();
auto streak = longest_streak(first, last); auto streak = longest_streak(first, last);
// Put it all together. // Put it all together.
if (streak.first == last) { if (streak.first == last) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment