Often I came across the following situation. (Without loss of generality: I use the simplest possible case of two containers in the following example, but in implementations of geometric algorithms they are enough to describe the interconnected structures of these graphs.)
I have many values โโof two data types Aand Bthat refer to each other (not one to one at all), say, first with (own) pointers or links. Both are placed in containers using CA = std::container1< A >;and using CB = std::container2< B >;. The result of some function is a pair of instances of CAand CB. Having an instance element CA, I want to remove the reference element in the instance CBand vice versa.
struct A;
struct B;
using CA = std::container1< A >;
using CB = std::container2< B >;
I want to define A, and Bas follows:
struct A
{
int payload;
typename CB::iterator pb;
};
struct B
{
double payload;
typename CA::iterator pa;
};
PA a;
PB b;
assert(!a.empty());
assert(a.begin()->pb != b.end());
b.erase(a.begin()->pb);
Real-time example.
But at present, I cannot declare typename CB::iterator pb;in the general case just B /*const*/ * pb;or B /*const*/ & pb;because the type Bthat is part of the declaration CBis incomplete at the point of use of the typedef iteratorcontainer member CBin the definition of the aggregate A.
There is an offer of containers of incomplete types, but at present it is not part of the Standard.
For the current implementation of non-debugging versions of containers in libstdC ++ and libC ++, the above code can be compiled accurately, but this is not necessary. If successful, iterator definitions contain nothing but pointers or references to value_type. But there is no requirement in the Standard.
, std::unordered_set, - std::hash value_type .
, , - () . , , std::container3< B * > std::container2< B > .
. .
C++14 ?