mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-27 20:25:44 +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. |
||
---|---|---|
.. | ||
moz.build | ||
TestArrayUtils.cpp | ||
TestAtomics.cpp | ||
TestBinarySearch.cpp | ||
TestBloomFilter.cpp | ||
TestBufferList.cpp | ||
TestCasting.cpp | ||
TestCeilingFloor.cpp | ||
TestCheckedInt.cpp | ||
TestCountPopulation.cpp | ||
TestCountZeroes.cpp | ||
TestEndian.cpp | ||
TestEnumSet.cpp | ||
TestFastBernoulliTrial.cpp | ||
TestFloatingPoint.cpp | ||
TestFunction.cpp | ||
TestInitializerList.cpp | ||
TestIntegerPrintfMacros.cpp | ||
TestIntegerRange.cpp | ||
TestJSONWriter.cpp | ||
TestLinkedList.cpp | ||
TestMacroArgs.cpp | ||
TestMacroForEach.cpp | ||
TestMathAlgorithms.cpp | ||
TestMaybe.cpp | ||
TestNotNull.cpp | ||
TestPair.cpp | ||
TestPoisonArea.cpp | ||
TestRefPtr.cpp | ||
TestRollingMean.cpp | ||
TestSaturate.cpp | ||
TestScopeExit.cpp | ||
TestSegmentedVector.cpp | ||
TestSHA1.cpp | ||
TestSplayTree.cpp | ||
TestTemplateLib.cpp | ||
TestTuple.cpp | ||
TestTypedEnum.cpp | ||
TestTypeTraits.cpp | ||
TestUniquePtr.cpp | ||
TestVariant.cpp | ||
TestVector.cpp | ||
TestWeakPtr.cpp | ||
TestXorShift128PlusRNG.cpp |