[libcxx-commits] [PATCH] D105791: [libcxx] adds `complexity_iterator`, `complexity_invocable`, and `test_algorithm`

Christopher Di Bella via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jul 11 23:59:53 PDT 2021


cjdb created this revision.
cjdb added reviewers: ldionne, zoecarver, Mordante, EricWF.
cjdb requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

`complexity_iterator` is an iterator adaptor that's used to measure
the number of applications of a predicate/projection when there's no
predicate to measure (e.g. `ranges::find`).

`complexity_invocable` is an invocable adaptor that's used to measure
the number of calls to a predicate or projection. It differs from
`unary_counting_predicate` and `binary_counting_predicate` in two
ways:

1. Most importantly, it isn't limited to predicates, and so works with invocables returning something other than Boolean values.
2. It can store lambdas and works in constexpr contexts (this is secondary, but worth noting).

`test_algorithm` is an overload set that simplifies individual algorithm
test files. While working implementing `ranges::lower_bound`, I realised
that all test cases follow a strict pattern, for all implemented algos so
far (sometimes it can be simplified):

1. set up subrange
2. set up complexity instrumentation
3. get iterator result
4. check iterator result
5. check complexity results
6. reset subrange (if input iterators allowed)
7. reset complexity instrumentation
8. check range result matches iterator result
9. check complexity results

A lot of this code can be factored out. In particular, this commit
abstracts away all the set-up and complexity-check stages. This in
turn elides the reset stages, individual leaving tests to focus on:

1. get iterator result
2. check iterator result
3. check range result matches iterator result

An optional step 2.5 might creep in, where we check complexity results
for special cases (i.e. cases where that activate certain
optimisations).

The `test_algorithm` overload set isn't complete yet, but remaining
overloads can be added on an as-needed basis.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105791

Files:
  libcxx/test/support/test_algorithm.h
  libcxx/test/support/test_iterators.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105791.357845.patch
Type: text/x-patch
Size: 7722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210712/f0c3d08a/attachment.bin>


More information about the libcxx-commits mailing list