21#ifndef IO_SOCKET_OPTION_HPP
22#define IO_SOCKET_OPTION_HPP
34 requires std::is_trivially_copyable_v<T>
47 template <
size_type Size = sizeof(value_type)>
63 std::memcpy(storage_.data(), &val, size_);
71 template <
size_type Size>
72 requires(Size <=
sizeof(
value_type) || Size == std::dynamic_extent)
74 : size_{option.size()}
77 "option.size() must be <= sizeof(value_type)");
78 assert(option.size() > 0 && option.data() !=
nullptr &&
79 "If option.size() > 0 then option.data() must not be NULL.");
80 std::memcpy(storage_.data(), option.data(), size_);
88 template <
size_type Size>
89 requires(Size <=
sizeof(
value_type) || Size == std::dynamic_extent)
116 return *
reinterpret_cast<value_type *
>(storage_.data());
126 return reinterpret_cast<value_type *
>(storage_.data());
134 [[nodiscard]]
constexpr auto begin() noexcept -> std::
byte *
136 return storage_.begin();
144 [[nodiscard]]
constexpr auto begin() const noexcept -> const std::
byte *
146 return storage_.cbegin();
153 [[nodiscard]]
constexpr auto end() noexcept -> std::
byte *
155 return storage_.begin() + size_;
163 [[nodiscard]]
constexpr auto end() const noexcept -> const std::
byte *
165 return storage_.cbegin() + size_;
178 return (size_ == other.size_)
179 ? memcmp(storage_.data(), other.storage_.data(), size_) <=> 0
180 : size_ <=> other.size_;
190 return size_ == other.size_ &&
191 std::memcmp(storage_.data(), other.storage_.data(), size_) == 0;
196 std::array<std::byte,
sizeof(
value_type)> storage_{};
A generic wrapper for socket options.
Definition socket_option.hpp:35
auto operator<=>(const socket_option &other) const noexcept -> std::strong_ordering
Compares this socket_option with another for ordering.
Definition socket_option.hpp:175
auto operator=(const socket_option &) -> socket_option &=default
Default copy assignment operator.
constexpr auto begin() const noexcept -> const std::byte *
Gets a const iterator to the beginning of the option's byte representation.
Definition socket_option.hpp:144
socket_option(const socket_option &)=default
Default copy constructor.
constexpr auto end() noexcept -> std::byte *
Gets an iterator to the end of the option's byte representation.
Definition socket_option.hpp:153
socket_option(const value_type &val) noexcept
Constructs a socket_option from a value.
Definition socket_option.hpp:61
constexpr auto end() const noexcept -> const std::byte *
Gets a const iterator to the end of the option's byte representation.
Definition socket_option.hpp:163
constexpr auto operator->() noexcept -> value_type *
Accesses the socket option's value.
Definition socket_option.hpp:123
constexpr auto operator*() noexcept -> value_type &
Dereferences the socket option to its value.
Definition socket_option.hpp:113
std::size_t size_type
The size type for the socket option.
Definition socket_option.hpp:40
auto operator=(socket_option &&) -> socket_option &=default
Default move assignment operator.
constexpr auto begin() noexcept -> std::byte *
Gets an iterator to the beginning of the option's byte representation.
Definition socket_option.hpp:134
std::decay_t< T > value_type
The type of the socket option value.
Definition socket_option.hpp:38
auto operator==(const socket_option &other) const noexcept -> bool
Compares two socket_option objects for equality.
Definition socket_option.hpp:188
~socket_option()=default
Default destructor.
socket_option(socket_option &&)=default
Default move constructor.
The io::socket namespace provides a cross-platform abstraction for socket-level I/O operations.
Definition poll_multiplexer.hpp:36