次の方法で共有


Conformance macros in VC STL

In VC STL, there are two macros called "_HAS_IMMUTABLE_SETS" and "_HAS_STRICT_CONFORMANCE" which are defined in yvals.h. They are related to some defects in the C++ standard 2003.

1. _HAS_IMMUTABLE_SETS will influence the constness of set::iterator.

Associative containers require its elements to be sorted, so modify them will be dangerous. But the standard doesn't prohibit the programmer to do that.

In C++0x, the following statement is added for associative containter:
For associative containers where the value type is the same as the key type, both iterator and const_iterator are constant iterators
(In the standard, it is said:
Constant iterators do not satisfy the requirements for output iterators, and the result of the expression *i (for constant iterator i) cannot be used in an expression where an lvalue is required.)
That means you cannot modify the value of the elements using iterator any more.

Discussion: https://www.cpptalk.net/image-vp135370.html

2. _HAS_STRICT_CONFORMANCE will influence two places:

a. For set, multiset, map and multimap

void erase(const_iterator position);
size_type erase(const key_type& x);
void erase(const_iterator first, const_iterator last);

->

iterator erase(const_iterator position);
size_type erase(const key_type& x);
iterator erase(const_iterator first, const_iterator last);

In C++03, erase in associative containers will not return the iterator, which is incompatible with sequence containers. It is fixed in C++0x
VC's extension provides the return value for erase. _HAS_STRICT_CONFORMANCE will disable this extension.

Discussion: https://www.tech-archive.net/Archive/VC/microsoft.public.vc.stl/2005-10/msg00030.html
Further Discussion: https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#103

b. For codecvt::do_length(stateT& state, const externT* from, const externT* from_end, size_t max) const;

In C++03, codecvt<wchar_t, char, mbstate_t> and codecvt<char, char, mbstate_t> should return the lesser of max and (from_end-from).
This is weakened in C++0x. Only codecvt<char, char, mbstate_t> is required to behave like that.

BTW: VC's STL implementation is provided by Dinkumware. You can see "P.J. Plauger" at the end of each STL file.

Comments