MACAddress: Use all_of to implement is_zero

Problem:
- `is_zero()` is implemented by checking each value in the array by
  hand. This is error-prone and less expressive than using an
  algorithm.

Solution:
- Implement `is_zero()` in terms of `all_of`.
This commit is contained in:
Lenny Maiorani 2020-11-16 18:36:01 -07:00 committed by Andreas Kling
parent 6e7e16a7ed
commit 178190ab52

View file

@ -26,6 +26,7 @@
#pragma once
#include <AK/AllOf.h>
#include <AK/Array.h>
#include <AK/Assertions.h>
#include <AK/String.h>
@ -79,7 +80,7 @@ public:
constexpr bool is_zero() const
{
return m_data[0] == 0 && m_data[1] == 0 && m_data[2] == 0 && m_data[3] == 0 && m_data[4] == 0 && m_data[5] == 0;
return AK::all_of(m_data.begin(), m_data.end(), [](const auto octet) { return octet == 0; });
}
private: