MySQL 9.6.0
Source Code Documentation
is_charlike.h
Go to the documentation of this file.
1// Copyright (c) 2024, 2025, Oracle and/or its affiliates.
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License, version 2.0,
5// as published by the Free Software Foundation.
6//
7// This program is designed to work with certain software (including
8// but not limited to OpenSSL) that is licensed under separate terms,
9// as designated in a particular file or component or in included license
10// documentation. The authors of MySQL hereby grant you an additional
11// permission to link the program and your derivative works with the
12// separately licensed software that they have either included with
13// the program or referenced in the documentation.
14//
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License, version 2.0, for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
24#ifndef MYSQL_META_IS_CHARLIKE_H
25#define MYSQL_META_IS_CHARLIKE_H
26
27/// @file
28/// Experimental API header
29
30#include <concepts> // same_as
31#include <cstddef> // byte
32
33/// @addtogroup GroupLibsMysqlMeta
34/// @{
35
36namespace mysql::meta {
37
38/// true if `Test`, with cvref removed, is `char`, `unsigned char`, or
39/// `std::byte`.
40///
41/// This is useful to define APIs that just take a raw pointer to a string, and
42/// don't care if the characters are signed or unsigned.
43///
44/// This is intentionally true only for these three types, and not for e.g.
45/// `int8_t`, because the C++ standard defines special cases for them. In
46/// particular, `reinterpret_cast<T *>(...)` is defined for all argument types
47/// only when `T` is `char`, `unsigned char`, or `std::byte`
48/// (http://en.cppreference.com/w/cpp/language/reinterpret_cast.html sec "Type
49/// Accessibility"; https://timsong-cpp.github.io/cppwp/n4868/basic.lval#11.3)
50template <class Test>
51concept Is_charlike = std::same_as<std::remove_cvref_t<Test>, char> ||
52 std::same_as<std::remove_cvref_t<Test>, unsigned char> ||
53 std::same_as<std::remove_cvref_t<Test>, std::byte>;
54
55/// true if `Test` is pointer to `char`, `unsigned char`, or `std::byte`, and
56/// not any array.
57template <class Test>
59 std::is_pointer_v<Test> && Is_charlike<std::remove_pointer_t<Test>>;
60
61/// True if Test has a data() member function that returns char, unsigned char,
62/// or std::byte, and has a size() member functions returning std::size_t.
63///
64/// This is useful to define APIs that take a "string", uses only the `data` and
65/// `size` members, and don't care if it is represented as `std::string`,
66/// `std::string_view`, or something else that has these members.
67template <class Test>
68concept Is_stringlike = requires(Test stringlike) {
69 { *stringlike.data() } -> Is_charlike;
70 { stringlike.size() } -> std::same_as<std::size_t>;
71 };
72
73} // namespace mysql::meta
74
75// addtogroup GroupLibsMysqlMeta
76/// @}
77
78#endif // ifndef MYSQL_META_IS_CHARLIKE_H
true if Test, with cvref removed, is char, unsigned char, or std::byte.
Definition: is_charlike.h:51
true if Test is pointer to char, unsigned char, or std::byte, and not any array.
Definition: is_charlike.h:58
True if Test has a data() member function that returns char, unsigned char, or std::byte,...
Definition: is_charlike.h:68
unsigned char byte
Blob class.
Definition: common.h:151
Definition: is_charlike.h:36