mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
b3d842431f
This patch implements mozilla::NotNull, which is similar but not identicial to gsl::not_null. The current draft(?) implementation of gsl::not_null is at https://github.com/Microsoft/GSL/blob/master/include/gsl.h. The main difference is that not_null allows implicit conversion from T to not_null<T>. In contrast, NotNull only allows explicit conversion from T to NotNull<T> via WrapNotNull(). The rationale for this is that when converting from a less-constrained type to a more constrained type, implicit conversion is undesirable. For example, if I changed a function f from this: f(int* aPtr); to this: f(gsl::not_null<int*> aPtr); no call sites would have to be modified. But if I changed it to this: f(mozilla::NotNull<int*> aPtr); call sites *would* need to be modified. This is a good thing! It forces the author to audit the call sites for non-nullness, and encourages them to back-propagate NotNull throughout the code. The other difference between not_null and NotNull is that not_null disables pointer arithmetic, which means it cannot be used with array pointers. I have not implemented this restriction for NotNull because it seems arbitrary and unnecessary. |
||
---|---|---|
.. | ||
decimal | ||
double-conversion | ||
staticruntime | ||
tests | ||
Alignment.h | ||
AllocPolicy.h | ||
AlreadyAddRefed.h | ||
Array.h | ||
ArrayUtils.h | ||
Assertions.h | ||
Atomics.h | ||
Attributes.h | ||
BinarySearch.h | ||
BloomFilter.h | ||
BufferList.h | ||
Casting.h | ||
ChaosMode.cpp | ||
ChaosMode.h | ||
Char16.h | ||
CheckedInt.h | ||
Compiler.h | ||
Compression.cpp | ||
Compression.h | ||
DebugOnly.h | ||
EndianUtils.h | ||
EnumeratedArray.h | ||
EnumeratedRange.h | ||
EnumSet.h | ||
FastBernoulliTrial.h | ||
FloatingPoint.cpp | ||
FloatingPoint.h | ||
Function.h | ||
GuardObjects.h | ||
HashFunctions.cpp | ||
HashFunctions.h | ||
IndexSequence.h | ||
InitializerList.h | ||
IntegerPrintfMacros.h | ||
IntegerRange.h | ||
IntegerTypeTraits.h | ||
JSONWriter.cpp | ||
JSONWriter.h | ||
Likely.h | ||
LinkedList.h | ||
LinuxSignal.h | ||
lz4.c | ||
lz4.h | ||
MacroArgs.h | ||
MacroForEach.h | ||
MathAlgorithms.h | ||
Maybe.h | ||
MaybeOneOf.h | ||
MemoryChecking.h | ||
MemoryReporting.h | ||
Move.h | ||
moz.build | ||
NotNull.h | ||
NullPtr.h | ||
NumericLimits.h | ||
objs.mozbuild | ||
Opaque.h | ||
Pair.h | ||
PodOperations.h | ||
Poison.cpp | ||
Poison.h | ||
Range.h | ||
RangedArray.h | ||
RangedPtr.h | ||
ReentrancyGuard.h | ||
RefCounted.h | ||
RefCountType.h | ||
RefPtr.h | ||
ReverseIterator.h | ||
RollingMean.h | ||
Saturate.h | ||
Scoped.h | ||
ScopeExit.h | ||
SegmentedVector.h | ||
SHA1.cpp | ||
SHA1.h | ||
SizePrintfMacros.h | ||
Snprintf.h | ||
SplayTree.h | ||
STYLE | ||
TaggedAnonymousMemory.cpp | ||
TaggedAnonymousMemory.h | ||
TemplateLib.h | ||
ThreadLocal.h | ||
ToString.h | ||
Tuple.h | ||
TypedEnumBits.h | ||
Types.h | ||
TypeTraits.h | ||
UniquePtr.h | ||
UniquePtrExtensions.h | ||
unused.cpp | ||
unused.h | ||
Variant.h | ||
Vector.h | ||
WeakPtr.h | ||
WindowsVersion.h | ||
XorShift128PlusRNG.h |