jeudi 17 décembre 2020

Unit testing custom STL-compatible containers and iterators

I've just implemented a custom iterator type for a custom container. The container models the C++17 ReversibleContainer, and its iterators (both const and non-const) model LegacyRandomAccessIterator.

My question is; is there some sort of built-in thing in std that I can use to test if both the container and its iterators adhere to the specified named requirements, or do I have to write all the tests myself (which is mostly doable for me but I'd rather not reinvent the wheel; and also I'm not sure I'm enough of a template wizard to really thoroughly prove that e.g. types and such are correct)?

Things like (I know this is one of many), e.g. this from the operational semantics of operator -=:

iterator a = ...;
iterator b = ...;
assert((a < b) == (b - a > 0));

And that return types are correct, etc., and such.

Aucun commentaire:

Enregistrer un commentaire