tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
memcmp.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2024 Tobias Hienzsch
3
4#ifndef TETL_CSTRING_MEMCMP_HPP
5#define TETL_CSTRING_MEMCMP_HPP
6
7#include <etl/_config/all.hpp>
8
9#include <etl/_cstddef/size_t.hpp>
10#include <etl/_strings/cstr.hpp>
11
12namespace etl {
13
14/// Reinterprets the objects pointed to by lhs and rhs as arrays of
15/// unsigned char and compares the first count bytes of these arrays.
16/// The comparison is done lexicographically.
17///
18/// https://en.cppreference.com/w/cpp/string/byte/memcmp
19///
20/// \ingroup cstring
21[[nodiscard]] inline auto memcmp(void const* lhs, void const* rhs, etl::size_t count) noexcept -> int
22{
23#if __has_builtin(__builtin_memcmp)
24 return __builtin_memcmp(lhs, rhs, count);
25#else
26 auto const* l = static_cast<unsigned char const*>(lhs);
27 auto const* r = static_cast<unsigned char const*>(rhs);
28 return etl::detail::strncmp<unsigned char, etl::size_t>(l, r, count);
29#endif
30}
31
32} // namespace etl
33
34#endif // TETL_CSTRING_MEMCMP_HPP
auto memcmp(void const *lhs, void const *rhs, etl::size_t count) noexcept -> int
Reinterprets the objects pointed to by lhs and rhs as arrays of unsigned char and compares the first ...
Definition memcmp.hpp:21
Definition adjacent_find.hpp:9