From 178190ab526b5e5050bfc886bb470cb7e585f375 Mon Sep 17 00:00:00 2001 From: Lenny Maiorani Date: Mon, 16 Nov 2020 18:36:01 -0700 Subject: [PATCH] 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`. --- AK/MACAddress.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AK/MACAddress.h b/AK/MACAddress.h index d106465bc1..5b2aef64d6 100644 --- a/AK/MACAddress.h +++ b/AK/MACAddress.h @@ -26,6 +26,7 @@ #pragma once +#include #include #include #include @@ -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: