I start to define tree node. This is incomplete type (struct
/class
) at the moment of define of "children" field. Or another way is to use type erasure, but it's ugly at my mind. Yet another way is to use pointers, but it still is not a thing I want. So I tried to implement it by means of standard container library's container: vector (<=> default priority_queue), deque (<=> default stack, queue), list, forward_list, set, multiset. Unordered associative containers is not interesting, due to lack of ready to use hash combiner in standard library/STL. BTW, associative containers not interesting too, due to its keys cannot be modified.
#include <iostream>
#include <vector>
#include <deque>
#include <list>
#include <forward_list>
#include <set>
#include <cstdlib>
struct R;
using V = std::deque< R >;
struct R
{
int i;
V v;
};
int
main()
{
R r;
V v;
return EXIT_SUCCESS;
}
The code compiles for all the containers (even for set and multiset) except deque (and, of course, stack, queue): the error says, that deque internals uses the size of value_type
(as far as I can infer, to define the memory chunk size and to match system page size).
Are there requirements to not depend on element type completeness for implementations of containers in the actual standard? Is it undefined behaviour to use that containers, which successfully comiled among code above? Or can I still rely on their correctness?