Files
Iain Buclaw f5351b38a8 d: Merge upstream dmd, druntime 66b93fc24a, phobos 0c28620c3
Synchronizing with the upstream release of v2.109.1.

D front-end changes:

	- Import dmd v2.109.1.
	- Copying from `const(void)[]' to `void[]' is now disallowed
	  with `-fpreview=fiximmutableconv'.
	- Import expressions are now treated as hex strings.
	- Using boolean values other than 0 or 1 in `@safe' code is now
	  deprecated.

D runtime changes:

	- Import dmd v2.109.1.

Phobos changes:

	- Import dmd v2.109.1.

gcc/d/ChangeLog:

	* dmd/MERGE: Merge upstream dmd 66b93fc24a.
	* dmd/VERSION: Bump version to v2.109.1.
	* d-builtins.cc (build_frontend_type): Update for new front-end
	interface.
	(matches_builtin_type): Likewise.
	* d-codegen.cc (identity_compare_p): Likewise.
	(call_side_effect_free_p): Likewise.
	* d-convert.cc (convert_expr): Likewise.
	(check_valist_conversion): Likewise.
	* d-lang.cc (d_types_compatible_p): Likewise.
	* d-target.cc (Target::isVectorTypeSupported): Likewise.
	(Target::isReturnOnStack): Likewise.
	(Target::preferPassByRef): Likewise.
	* decl.cc (class DeclVisitor): Likewise.
	* expr.cc (class ExprVisitor): Likewise.
	* typeinfo.cc (class TypeInfoVisitor): Likewise.
	* types.cc (class TypeVisitor): Likewise.

libphobos/ChangeLog:

	* libdruntime/MERGE: Merge upstream druntime 66b93fc24a.
	* src/MERGE: Merge upstream phobos 0c28620c3.
	* src/Makefile.am (PHOBOS_DSOURCES): Add
	std/internal/test/sumtype_example_overloads.d.
	* src/Makefile.in: Regenerate.
2025-01-05 14:40:13 +01:00

123 lines
3.4 KiB
D

/**
* D header file for interaction with C++ std::array.
*
* 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/array.d)
*/
module core.stdcpp.array;
import core.stdcpp.xutility : StdNamespace;
extern(C++, (StdNamespace)):
/**
* D language counterpart to C++ std::array.
*
* C++ reference: $(LINK2 https://en.cppreference.com/w/cpp/container/array)
*/
extern(C++, class) struct array(T, size_t N)
{
extern(D):
pragma(inline, true):
///
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;
/// Variadic constructor
this(T[N] args ...) { this[] = args[]; }
///
void fill()(auto ref const(T) value) { this[] = value; }
pure nothrow @nogc:
///
size_type size() const @safe { return N; }
///
alias length = size;
///
alias opDollar = length;
///
size_type max_size() const @safe { return N; }
///
bool empty() const @safe { return N == 0; }
///
ref inout(T) front() inout @safe { static if (N > 0) { return this[0]; } else { return as_array()[][0]; /* HACK: force OOB */ } }
///
ref inout(T) back() inout @safe { static if (N > 0) { return this[N-1]; } else { return as_array()[][0]; /* HACK: force OOB */ } }
version (CppRuntime_Microsoft)
{
///
inout(T)* data() inout @safe { return &_Elems[0]; }
///
ref inout(T)[N] as_array() inout @safe { return _Elems[0 .. N]; }
///
ref inout(T) at(size_type i) inout @safe { return _Elems[0 .. N][i]; }
private:
T[N ? N : 1] _Elems;
}
else version (CppRuntime_GNU)
{
///
inout(T)* data() inout @safe { static if (N > 0) { return &_M_elems[0]; } else { return null; } }
///
ref inout(T)[N] as_array() inout @trusted { return data()[0 .. N]; }
///
ref inout(T) at(size_type i) inout @trusted { return data()[0 .. N][i]; }
private:
static if (N > 0)
{
T[N] _M_elems;
}
else
{
struct _Placeholder {}
_Placeholder _M_placeholder;
}
}
else version (CppRuntime_LLVM)
{
///
inout(T)* data() inout @trusted { static if (N > 0) { return &__elems_[0]; } else { return cast(inout(T)*)__elems_.ptr; } }
///
ref inout(T)[N] as_array() inout @trusted { return data()[0 .. N]; }
///
ref inout(T) at(size_type i) inout @trusted { return data()[0 .. N][i]; }
private:
static if (N > 0)
{
T[N] __elems_;
}
else
{
struct _ArrayInStructT { T[1] __data_; }
align(_ArrayInStructT.alignof)
byte[_ArrayInStructT.sizeof] __elems_ = void;
}
}
else
{
static assert(false, "C++ runtime not supported");
}
}