net/StaticSocketAddress: add constexpr

This commit is contained in:
Max Kellermann 2024-01-05 22:52:05 +01:00 committed by Max Kellermann
parent b15b2125e2
commit 0fd6f83766

View File

@ -1,8 +1,7 @@
// SPDX-License-Identifier: BSD-2-Clause
// author: Max Kellermann <max.kellermann@gmail.com>
#ifndef STATIC_SOCKET_ADDRESS_HXX
#define STATIC_SOCKET_ADDRESS_HXX
#pragma once
#include "SocketAddress.hxx" // IWYU pragma: export
#include "Features.hxx"
@ -24,7 +23,7 @@ private:
struct sockaddr_storage address;
public:
StaticSocketAddress() = default;
constexpr StaticSocketAddress() noexcept = default;
explicit StaticSocketAddress(SocketAddress src) noexcept {
*this = src;
@ -61,11 +60,11 @@ public:
return sizeof(address);
}
size_type GetSize() const noexcept {
constexpr size_type GetSize() const noexcept {
return size;
}
void SetSize(size_type _size) noexcept {
constexpr void SetSize(size_type _size) noexcept {
assert(_size > 0);
assert(size_t(_size) <= sizeof(address));
@ -75,19 +74,19 @@ public:
/**
* Set the size to the maximum value for this class.
*/
void SetMaxSize() {
constexpr void SetMaxSize() {
SetSize(GetCapacity());
}
int GetFamily() const noexcept {
constexpr int GetFamily() const noexcept {
return address.ss_family;
}
bool IsDefined() const noexcept {
constexpr bool IsDefined() const noexcept {
return GetFamily() != AF_UNSPEC;
}
void Clear() noexcept {
constexpr void Clear() noexcept {
size = sizeof(address.ss_family);
address.ss_family = AF_UNSPEC;
}
@ -130,5 +129,3 @@ public:
return !(*this == other);
}
};
#endif