libcruft-util/cruft/util/concepts/string.hpp

46 lines
1.2 KiB
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2022, Danny Robson <danny@nerdcruft.net>
*/
#pragma once
#include <concepts>
#include <string>
#include <string_view>
namespace cruft::concepts {
/// A literal c-string character array.
template <typename T>
concept c_string =
std::is_array_v<std::remove_cvref_t<T>> and
std::is_same_v<
std::remove_cvref_t<
std::remove_all_extents_t<
std::remove_cvref_t<T>
>
>,
char
>;
/// A type that behaves like a string. ie, a sequence of characters
template <typename T>
concept stringy =
std::same_as<T, std::string> or
std::same_as<T, std::string_view> or
std::same_as<T, char const*> or
std::same_as<T, char *> or
c_string<T>;
/// A type that behaves like a string _and_ has a null terminator
template <typename T>
concept null_stringy =
std::same_as<T, std::string> or
std::same_as<T, char const*> or
std::same_as<T, char *>;
}