tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
strchr.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2020 Tobias Hienzsch
3
4#ifndef TETL_CSTRING_STRCHR_HPP
5#define TETL_CSTRING_STRCHR_HPP
6
7#include <etl/_config/all.hpp>
8
9#include <etl/_contracts/check.hpp>
10#include <etl/_cstddef/size_t.hpp>
11#include <etl/_strings/cstr.hpp>
12#include <etl/_type_traits/is_constant_evaluated.hpp>
13
14namespace etl {
15
16/// \ingroup cstring
17/// @{
18
19/// Finds the first occurrence of the character static_cast<char>(ch) in
20/// the byte string pointed to by str.
21///
22/// The terminating null character is considered to be a part of the
23/// string and can be found if searching for '\0'.
24///
25/// https://en.cppreference.com/w/cpp/string/byte/strchr
26///
27/// \ingroup cstring
28[[nodiscard]] constexpr auto strchr(char const* str, int ch) -> char const*
29{
30 TETL_PRECONDITION(str != nullptr);
32#if __has_builtin(__builtin_strchr)
33 return __builtin_strchr(str, ch);
34#endif
35 }
36 return etl::detail::strchr<char const>(str, ch);
37}
38
39[[nodiscard]] constexpr auto strchr(char* str, int ch) -> char*
40{
41 TETL_PRECONDITION(str != nullptr);
43#if __has_builtin(__builtin_strchr)
44 return __builtin_strchr(str, ch);
45#endif
46 }
47 return etl::detail::strchr<char>(str, ch);
48}
49
50/// @}
51
52} // namespace etl
53
54#endif // TETL_CSTRING_STRCHR_HPP
constexpr auto strchr(char *str, int ch) -> char *
Definition strchr.hpp:39
constexpr auto strchr(char const *str, int ch) -> char const *
Definition strchr.hpp:28
Definition adjacent_find.hpp:9
constexpr auto is_constant_evaluated() noexcept -> bool
Detects whether the function call occurs within a constant-evaluated context. Returns true if the eva...
Definition is_constant_evaluated.hpp:17