Hot answers tagged

6

You are implementing std::span What you are trying to implement is basically C++20's std::span. It might be worthwhile to look at how it is implemented, and copy its interface if possible, so if you ever want to change the codebase using your class to use std::span, it will be easy. I'll also use std::span as a reference and point out differences between it ...


4

Design review Your design is mostly sound. It can be simplified a little bit, and optionally made a bit more rigorous, but the basic design is not bad. The name for what you’re doing is the “Policy” design pattern. The gist is that you create a class templated on policy types, and then concrete policy classes to control the behaviour of the main class. Even ...


3

You are asking how you can guard against invalid iterators; I assume you are most concerned about iterators that have become invalid after the vector had to re-allocate when it outgrew its capacity. One solution is to store an index instead of an iterator; as long as the vector doesn't shrink the range will be valid, and its validity can be trivially checked ...


Only top voted, non community-wiki answers of a minimum length are eligible