Why is std::sub_match derived from std::pair?
I wonder what where the reasons that lead to the decision,
that sub_match<BiIt> is publicly derived from pair<BiIt, BiIt>,
as seen in 28.9/1 of N2134?
On the first sight it seems to be astonishing, that inheritance
is used here, because std::pair is actually not designed for
that, being actually an entity usually known as "value type".
Furtheron there seem not to exist a relevant number of
advantages for this: std::pair has actually no reusable
member functions useful for the derived class.
Even the predefined comparison operators are not
reused but replaced by new ones. Thus the only visible
advantages see to be that sub_match is per-se a tuple.
Since sub_match also introduces further public data members
("bool matched;"), users could easily stumble accross
slicing error. Another point is that the Standard
obviously uses a technique, that *usually* is not
recommended one (and with no convincing advantages
as far as I see). Deriving from member-free tagging classes
like iterator_traits, unary/binary_function and similar ones
is much easier to explain than in the sub_match/pair case.
Just recently we had the thread " STL non virtual DTOR"
comp.lang.c++.moderated,
http://tinyurl.com/3xk6cv
where practically all answers had a similar tone. How
should we justify future questions going into the same
direction? It's not unusual that people argue by comparison
to existing Standard code. And in this case we don't have
the excuse anymore, that "this is just the baggage from C
or from early C++ implementations (c.f. <iostream.h>)"
Recapitulating, I really can't see that these design
decisions outweight the possible traps. I would really
appreciate, if someone could explain the reasons for
it!
Be asured that my question is a honest, desperate
one, I don't want to blame anyone personally.
Thanks in advance,
Daniel Kr?gler
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]