Files
gcc/libphobos/libdruntime/core/stdcpp/string_view.d
Iain Buclaw 89629b2718 d: Merge dmd, druntime 34875cd6e1, phobos ebd24da8a
D front-end changes:

        - Import dmd v2.110.0-beta.1.
        - `ref' can now be applied to local, static, extern, and global
	  variables.

D runtime changes:

        - Import druntime v2.110.0-beta.1.

Phobos changes:

        - Import phobos v2.110.0-beta.1.

gcc/d/ChangeLog:

	* dmd/MERGE: Merge upstream dmd 34875cd6e1.
	* dmd/VERSION: Bump version to v2.110.0-beta.1.
	* Make-lang.in (D_FRONTEND_OBJS): Add d/deps.o, d/timetrace.o.
	* decl.cc (class DeclVisitor): Update for new front-end interface.
	* expr.cc (class ExprVisitor): Likewise
	* typeinfo.cc (check_typeinfo_type): Likewise.

libphobos/ChangeLog:

	* libdruntime/MERGE: Merge upstream druntime 34875cd6e1.
	* src/MERGE: Merge upstream phobos ebd24da8a.
2025-01-10 22:09:00 +01:00

120 lines
2.9 KiB
D

/**
* D header file for interaction with C++ std::string_view.
*
* Copyright: Copyright (c) 2018 D Language Foundation
* License: Distributed under the
* $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
* (See accompanying file LICENSE)
* Authors: Manu Evans
* Source: $(DRUNTIMESRC core/stdcpp/string_view.d)
*/
module core.stdcpp.string_view;
import core.stdc.stddef : wchar_t;
import core.stdcpp.xutility : StdNamespace;
extern(C++, (StdNamespace)):
@nogc:
///
alias string_view = basic_string_view!char;
///
alias u16string_view = basic_string_view!wchar;
///
alias u32string_view = basic_string_view!dchar;
///
alias wstring_view = basic_string_view!wchar_t;
/**
* Character traits classes specify character properties and provide specific
* semantics for certain operations on characters and sequences of characters.
*/
extern(C++, struct) struct char_traits(CharT) {}
/**
* D language counterpart to C++ std::basic_string_view.
*
* C++ reference: $(LINK2 https://en.cppreference.com/w/cpp/string/basic_string_view, std::basic_string_view)
*/
extern(C++, class) struct basic_string_view(T, Traits = char_traits!T)
{
extern(D):
pragma(inline, true):
pure nothrow @nogc:
///
enum size_type npos = size_type.max;
///
alias size_type = size_t;
///
alias difference_type = ptrdiff_t;
///
alias value_type = T;
///
alias pointer = T*;
///
alias const_pointer = const(T)*;
///
alias as_array this;
///
alias toString = as_array;
///
this(const(T)[] str) @trusted { __data = str.ptr; __size = str.length; }
///
alias length = size;
///
alias opDollar = length;
///
size_type size() const @safe { return __size; }
///
bool empty() const @safe { return __size == 0; }
///
const(T)* data() const @safe { return __data; }
///
const(T)[] as_array() const @trusted { return __data[0 .. __size]; }
///
ref const(T) at(size_type i) const @trusted { return __data[0 .. __size][i]; }
///
ref const(T) front() const @safe { return this[0]; }
///
ref const(T) back() const @safe { return this[$-1]; }
private:
// use the proper field names from C++ so debugging doesn't get weird
version (CppRuntime_Microsoft)
{
const_pointer _Mydata;
size_type _Mysize;
alias __data = _Mydata;
alias __size = _Mysize;
}
else version (CppRuntime_GNU)
{
size_t _M_len;
const(T)* _M_str;
alias __data = _M_str;
alias __size = _M_len;
}
else version (CppRuntime_LLVM)
{
const value_type* __data;
size_type __size;
}
else
{
static assert(false, "C++ runtime not supported");
}
}