Stl compatible container

I was curious what the stl-compatible container entails (or is compatible with boost compatibility, I understand that they are either the same or very similar). I saw several examples of what people call stl-compatible (for example, this code in codeproject and, obviously, the actual stl-containers), but I'm not quite sure which components of these containers I need to have.

From what I could assemble, I need at least the following:

  • STL compatible iterators (the current stl uses only bidirectional or higher iterators, I don’t know if this is a requirement or just happens - a chance, still figuring out what to consider as a “stl compatible iterator”)

  • The mechanism for defining distributors (by default std::allocator ), as well as their proper use (still trying to figure out what this last part means)

  • public typedefs for metaprogramming (pointer type, constant pointer type, reference type, value type, reference constant type, difference type, maybe some others?). Side question: what is the difference type ?

  • 'generic' (i.e. uses metaprogramming / templates so that the container can store almost any type)

Is there anything else that I missed or, even worse, was mistaken in the above list (maybe things like const-correctness, thread safety, exception generation / handling, etc.)? Also, is there a document specification somewhere, detailing what is required if such a thing even exists?

+4
source share
1 answer
  • Iterators: The standard library defines categories of iterators. You want to provide iterators that model one of these categories. Depending on your point of view, the istream_iterator and ostream_iterator streams allow you to create containers that do not provide bidirectional iterators.

  • Basically, you use allocate allocate(n) to allocate space for objects n and deallocate(p, n) to free up space for objects n pointed to by p . Usually you do not use construct or destroy allocator members.

  • Yes, there are several others (for example, associative containers define key_type ). difference_type is a type that can represent the difference between two pointers. It is usually supplied with a dispenser, so the container will only have something like typedef:

    typedef Allocator :: difference_type difference_type;

  • Not necessarily (or even at all) any metaprogramming involved, just (fairly basic) general programming. Ie, you define a template, but you don’t have to do any calculations at compile time (this will be metaprogramming).

The current standard does not say anything about thread safety. The ultimate reference to what is required is the C ++ standard itself. You can download the current draft of the upcoming C ++ 0x ( N3242 ) standard for free. Container requirements are given in section 23.2. You can also look at Josuttis. The C ++ Standard Library is a slightly softer read than the standard itself.

Update: of course, C ++ 11 (just a little after it was originally written) added threads and some definitions of thread safety, data calculations, etc. This indicates roughly what most people have already done anyway: parallel reading is allowed, but the recording should be exclusive.

+5
source

Source: https://habr.com/ru/post/1345488/


All Articles