October 17, 2003 Re: hello all | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jan Knepper | > Actually... I *still* think OO is great. > > STL only uses half the power of C++. If the original design was done a little > better they could have done it in such a way that STL could be used two fold: > 1. Derived from an empy base class which would be optimized out with the > compiler and STL would be STL as is. > 2. Derived from a common (replaceable) base class and STL could have been > STL, but with OO and all the OO power of C++. Let me know if I'm understanding this correctly - option 1 I definitely get, since it's old school STL. With option 2, I'd be able to use iterators in non-template code, something like this: void MyFunc(const common_iterator & begin, const common_iterator & end) { // Do stuff } I'm also assuming that common_iterator would actually be a template since you'd need to get a particular type from operator*(). common_iterator<int> doesn't seem like it'd be the same as common_iterator<string>. If so, that means template template parameters might come in handy in vector's definition (to avoid specifying the type of the container twice.) Unfortunately, you can't always count on having those - a big constraint for the original STL's designers. One advantage of your scheme is that it would allow people to more safely inherit from STL containers. (I typically just use them as plain old members, myself.) By default, they don't have virtual destructors, so inheriting from them is a bit on the dicey side. VSTL would allow the user to inject a virtual destructor into the hierarchy and eliminate that problem. It's sometimes a real pain to provide operator->(), so it could be a tough call whether or not to put operator->() in common_iterator... I'd assume the empty base class optimization is fairly pervasive now, but could it have been somewhat rare in the days when STL was first being designed? That might have made VSTL less practical for the earlier implementations of STL back in the olden days. Let me know if I've missed the boat on this - I think I've probably only touched on 10% of the value of such a feature. |
December 12, 2003 Re: hello all | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jan Knepper | Hello, Jan Knepper <jan@smartsoft.us> wrote in news:3F396AF3.74D1297A@smartsoft.us: >> > STL only uses half the power of C++. If the original design was >> > done a little better they could have done it in such a way that STL >> > could be used two fold: >> > 1. Derived from an empy base class which would be optimized out >> > with the compiler and STL would be STL as is. >> > 2. Derived from a common (replaceable) base class and STL >> > could have been STL, but with OO and all the OO power of C++. >> [...] > It is an <brag> original idea </brag>, but I heard later that someone else (might have been Scott Meyers) wrote something alike about it. This technique definitivelly looks like one of the subsets (/side effect) of "Mixin layers". Several papers and a Phd. Thesis are available (online) on this topic. -- Luc Hermitte |
Copyright © 1999-2021 by the D Language Foundation