ToyGine2 26.2.0
Game Engine for retro consoles
Loading...
Searching...
No Matches
toy::StringLike Concept Reference

Concept satisfied when T exposes size() as size_t and c_str() as a pointer to null-terminated characters. More...

Concept definition

template<typename T>
concept StringLike = requires(const T & str) {
{ str.size() } -> std::same_as<size_t>;
{ str.c_str() } -> std::convertible_to<const char *>;
}
Concept satisfied when T exposes size() as size_t and c_str() as a pointer to null-terminated charact...
Definition string_like.hpp:75

Detailed Description

Concept satisfied when T exposes size() as size_t and c_str() as a pointer to null-terminated characters.

This concept defines the interface that any type must satisfy to be considered string-like. It requires the type to have a size() method that returns a value convertible to size_t, and a c_str() method that returns a value convertible to const char*.

Requirements

A type T satisfies StringLike if and only if:

  • T::size() returns size_t (std::same_as<size_t>).
  • T::c_str() returns std::convertible_to<const char *>.

Usage Example

#include "core.hpp"
std::string stdStr = "Hello";
static_assert(StringLike<decltype(stdStr)>);
constexpr toy::CStringView view("Hi");
static_assert(StringLike<decltype(view)>);
toy::FixedString<32> fixedStr = "World";
static_assert(StringLike<decltype(fixedStr)>);
result.assign(stdStr);
result += fixedStr;
Non-owning string view class for C-style strings.
Definition c_string_view.hpp:109
Template string class with fixed-size character buffer.
Definition fixed_string.hpp:117
constexpr FixedString< allocatedSize > & assign(const FixedString< allocatedSize > &string) noexcept
Copy assigns other string to this string.
Definition fixed_string.inl:114
Umbrella header for the engine core module.
Note
std::string, toy::CStringView, and toy::FixedString are typical representatives; other types qualify if they match the expression requirements above.
See also
toy::CStringView, toy::FixedString