Re: BUG: "const _Ty&" vs "const_reference"
From: Doug Harrison [MVP] (dsh_at_mvps.org)
Date: 01/13/05
- Next message: Marc-Antoine Ruel: "Re: BUG: "const _Ty&" vs "const_reference""
- Previous message: Igor Tandetnik: "Re: "const _Ty&" vs "const_reference""
- In reply to: Marc-Antoine Ruel: "BUG: "const _Ty&" vs "const_reference""
- Next in thread: Marc-Antoine Ruel: "Re: BUG: "const _Ty&" vs "const_reference""
- Reply: Marc-Antoine Ruel: "Re: BUG: "const _Ty&" vs "const_reference""
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 13 Jan 2005 14:31:50 -0600
Marc-Antoine Ruel wrote:
>In <list> and <vector>, "const _Ty&" is used everywhere instead of
>const_reference which is defined in the class allocator. There is around 9
>errors in vector and 15 in list. I haven't looked at the other containers.
>
>This causes that if a custom allocator redefine const_reference, this is
>simply not used and const _Ty& is used instead.
>
>I looked a bit around the net but couldn't find any information related to
>this.
Look in the C++ Standard, 20.1.5, Table 32. It's a hard requirement that for
allocator<T>, reference == T& and const_reference == const T&. Since
vector/list::reference/const_reference are defined per their respective
allocators, implementations are free to substitute at will.
In addition, 20.1.5 goes on to give containers permission to assume pointer,
const_pointer, size_type, and difference_type have their ordinary
definitions. Thus, it's purely a QoI issue whether or not containers respect
these typedefs defined by their allocators.
That said, suppose you have an implementation that supports, say, near and
far pointers. Doesn't it also need near and far references? Pre-standard STL
docs described allocator reference types merely as "lvalues of T", which
would seem to support this, but the standard gives the stricter definition
mentioned earlier, which would seem to rule it out.
-- Doug Harrison Microsoft MVP - Visual C++
- Next message: Marc-Antoine Ruel: "Re: BUG: "const _Ty&" vs "const_reference""
- Previous message: Igor Tandetnik: "Re: "const _Ty&" vs "const_reference""
- In reply to: Marc-Antoine Ruel: "BUG: "const _Ty&" vs "const_reference""
- Next in thread: Marc-Antoine Ruel: "Re: BUG: "const _Ty&" vs "const_reference""
- Reply: Marc-Antoine Ruel: "Re: BUG: "const _Ty&" vs "const_reference""
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|