Barry said:
Markus said:
[std:
20.4.1 The default allocator [lib.default.allocator]
template <class T> class allocator {
public:
...
typedef T value_type;
-- End-std]
So, actually allocator has a bug.
No.
Sort of. The allocator requirements in the standard have (or
had) a bug. The general requirements (which apply to any
allocator you write as well) specify behavior over T and U,
where T and U are specified as "any type". In practice, of
course, if T and U have reference type, the allocator cannot be
made to work, and if they have const type, the allocator cannot
be made useful. The latest draft of the standard corrects this;
the requirements for an allocator (default or other) are only
defined for non-const, non-reference types.
5.2.8 [Type identification]
(5) The top-level cv-qualifiers of the lvalue expression or the type-id that
is the operand of typeid are always ignored.
It actually also gives examples like "typeid(D) == typeid(const D); //
yields true"
Thank you. I didn't know about this.
Well, but MSVC8 really removes the constness using type
traits. Don't know what's the purpose.
Dinkumware was probably trying to do something useful in face of
ambiguities and problems in the standard.
This has been (somewhat) cleaned up in the current draft, but
I'm still not too sure about one thing: the current draft has
been modified to remove the Assignable requirement for
std::list. Presumably, an std::list< int const > will be legal.
But the requirements for allocators are not specified for const
types, and std::list uses an allocator. (I should probably
raise the question in comp.std.c++.)
[std:
20.4.1 The default allocator [lib.default.allocator]
template <class T> class allocator {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef T value_type;
-- End-std]
The standard does NOT constrain that T for allocator should be Assignable.
The current standard doesn't constrain that T not be a
reference, either, although that would make reference_type a
reference to a reference (which doesn't exist).