/usr/lib/gcc/x86_64-linux-gnu/5/include/d/rt/util/array.d is in libphobos-5-dev 5.5.0-12ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | /**
Array utilities.
Copyright: Denis Shelomovskij 2013
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
Authors: Denis Shelomovskij
Source: $(DRUNTIMESRC src/rt/util/_array.d)
*/
module rt.util.array;
import rt.util.string;
@safe /* pure dmd @@@BUG11461@@@ */ nothrow:
void enforceTypedArraysConformable(T)(in char[] action,
in T[] a1, in T[] a2, in bool allowOverlap = false)
{
_enforceSameLength(action, a1.length, a2.length);
if(!allowOverlap)
_enforceNoOverlap(action, a1.ptr, a2.ptr, T.sizeof * a1.length);
}
void enforceRawArraysConformable(in char[] action, in size_t elementSize,
in void[] a1, in void[] a2, in bool allowOverlap = false)
{
_enforceSameLength(action, a1.length, a2.length);
if(!allowOverlap)
_enforceNoOverlap(action, a1.ptr, a2.ptr, elementSize * a1.length);
}
private void _enforceSameLength(in char[] action,
in size_t length1, in size_t length2)
{
if(length1 == length2)
return;
SizeStringBuff tmpBuff = void;
string msg = "Array lengths don't match for ";
msg ~= action;
msg ~= ": ";
msg ~= length1.sizeToTempString(tmpBuff);
msg ~= " != ";
msg ~= length2.sizeToTempString(tmpBuff);
throw new Error(msg);
}
private void _enforceNoOverlap(in char[] action,
in void* ptr1, in void* ptr2, in size_t bytes)
{
const size_t d = ptr1 > ptr2 ? ptr1 - ptr2 : ptr2 - ptr1;
if(d >= bytes)
return;
const overlappedBytes = bytes - d;
SizeStringBuff tmpBuff = void;
string msg = "Overlapping arrays in ";
msg ~= action;
msg ~= ": ";
msg ~= overlappedBytes.sizeToTempString(tmpBuff);
msg ~= " byte(s) overlap of ";
msg ~= bytes.sizeToTempString(tmpBuff);
throw new Error(msg);
}
|