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/_cstddef/size_t.hpp>
8#include <etl/_strings/cstr.hpp>
9
10namespace etl {
11
12/// Reinterprets the objects pointed to by lhs and rhs as arrays of
13/// unsigned char and compares the first count bytes of these arrays.
14/// The comparison is done lexicographically.
15///
16/// https://en.cppreference.com/w/cpp/string/byte/memcmp
17///
18/// \ingroup cstring
19[[nodiscard]] inline auto memcmp(void const* lhs, void const* rhs, etl::size_t count) noexcept -> int
20{
21#if defined(__clang__)
22 return __builtin_memcmp(lhs, rhs, count);
23#else
24 auto const* l = static_cast<unsigned char const*>(lhs);
25 auto const* r = static_cast<unsigned char const*>(rhs);
26 return etl::detail::strncmp<unsigned char, etl::size_t>(l, r, count);
27#endif
28}
29
30} // namespace etl
31
32#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:19
Definition adjacent_find.hpp:9