[libc] Enhance ArrayRef + unittests
authorGuillaume Chatelet <gchatelet@google.com>
Wed, 21 Apr 2021 13:25:24 +0000 (13:25 +0000)
committerGuillaume Chatelet <gchatelet@google.com>
Wed, 21 Apr 2021 13:25:24 +0000 (13:25 +0000)
commitfa404ae43a6f7ed256a47257aeccc760d16dc0c9
tree8cfbac4186fdb8aecbf87ba068b373a9c9b6f330
parentca9b7e2e2f0897dade16d785dafadbf75deaf405
[libc] Enhance ArrayRef + unittests

This patch mostly adds unittests for `ArrayRef` and `MutableArrayRef`, additionnaly:
 - We mimic the behavior of `std::vector` and disallow CV qualified type (`ArrayRef<const X>` is not allowed).
   This is to make sure that the type traits are always valid (e.g. `value_type`, `pointer`, ...).
 - In the previous implementation `ArrayRef` would define `value_type` as `const T` but this is not correct, it should be `T` for both `MutableArrayRef` and `ArrayRef`.
 - We add the `equals` method to ease testing,
 - We define the constructor taking an `Array` outside of the base implementation to ensure we match `const Array<T>&` and not `Array<const T>&` in the case of `ArrayRef`.

Differential Revision: https://reviews.llvm.org/D100732
libc/test/utils/CPP/CMakeLists.txt
libc/test/utils/CPP/arrayref_test.cpp [new file with mode: 0644]
libc/utils/CPP/ArrayRef.h