
On Feb 23, 2005, at 10:34 AM, christopher diggins wrote:
Christopher Diggins Object Oriented Template Library (OOTL) http://www.ootl.org ----- Original Message ----- From: "Douglas Gregor" <doug.gregor@gmail.com> To: <boost@lists.boost.org> Sent: Wednesday, February 23, 2005 8:27 AM Subject: Re: [boost] STL containers with contracts, any interest? Hi Doug,
1) The proposed PwC approach would provide consistent behaviour across STL implementations.
Isn't that more a property of the adaptor approach than PwC? You can pass any container to the adaptor, regardless of the underlying library, and it will perform the checks when it interfaces with that container. At least two of the debug modes I'd mentioned (GCC libstdc++ and STLport) use wrappers/adaptors to implement debug-mode semantics, and I suspect the others do as well. Nothing actually ties the debug modes to a particular library except a few #defines and/or some namespace shuffling.
2) The contract verification classes would make it much easier to write new classes which model STL containers and verify that they exhibit correct behaviour.
Sure.
Also consider the following code:
template<Vector_T> void MyAlgorithm(Vector_T& x) { // do stuff ... }
If we get a hand-rolled vector type (instead of an STL vector) we have no way of knowing whether or not it conforms to the expected contract even if we can check it conforms to the correct concept. Using contract classes we could instead write (using an imaginary vector_contract_concept):
template<Vector_T> void MyAlgorithm(Vector_T& x) { #ifdef DEBUG BOOST_STATIC_ASSERT(vector_contract_concept<Vector_T>::satisfied) #endif // do stuff }
I don't understand this part... it looks like a concept check (i.e., syntax), but above it sounds like you're saying that this verifies the contract (i.e., semantics). How can we check the semantics with a static assert? Doug