Re: tree_node using std::vector
On 17 Mai, 01:26, Maik Beckmann <maikbeckm...@gmx.de> wrote:
Are there compilers around which STL implementations doesn't compile this
struct tree_node {
std::vector<tree_node> children;
};
??
I came across this when I've tried mingw's gcc-4.3 alpha release which was
configured with concept-checks enabled. The above code fails to compile
because tree_node is incomplete when its used inside it's definition.
So you found at least one compiler who rejects this code.
I know the standard forbids incomplete types to be used with STL
containers.
Does the above code work on any STL implemention anyway (in case mentioned
kind of concept-checks are disabled) and is thus portable?
You can definitely not nominate this as portable, because
the standard says that it will cause undefined behavior
([lib.res.on.functions]/2, last bullet). Seemingly working
code is one possible outcome of undefined behavior, see
[intro.compliance], footnote 3:
"?Correct execution? can include undefined behavior,
depending on the data being processed; see 1.3 and 1.9."
This code will probably be accepted on most compilers,
but you shouldn't ignore those who explicitly check
that - this is conforming.
Note that annoyingly we have today the same problem with
std::auto_ptr. This one I can only categorize as an
oversight.
Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]