http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55963



--- Comment #4 from Corey Richardson <corey at octayn dot net> 2013-01-13 
23:52:59 UTC ---

A more clear error message would be really useful, the feature itself

isn't all that important to me. Thank you for giving this your

attention so quickly.



On Sun, Jan 13, 2013 at 5:43 PM, redi at gcc dot gnu.org

<gcc-bugzi...@gcc.gnu.org> wrote:

>

> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55963

>

> --- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-01-13 
> 22:43:56 UTC ---

> Looks like PJP's comment was from 2008, so I'm not sure what requirements he

> means were standardized in 2008.

>

> Looking further into it, I see that the Allocator requirements in C++11 say an

> allocator can only be instantiated with a non-const type, see

> http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#274

>

> Because vector<const T> instantiates allocator<const T> that makes it

> definitely ill-formed.

>

> So I think I'm going to add a static_assert to std::allocator that rejects

> const types, so the error is at least clear it's intentional not a bug.

>

> To make it work you could write your own thin wrapper around std::allocator

> that prevents instantiating it with const types, something like:

>

> template<typename T>

> struct allocator

>   : std::allocator<typename std::remove_const<T>::type>

> {

>   template<typename U>

>   struct rebind { typedef allocator<U> other; };

>

>   typedef T value_type;

>

>   allocator() = default;

>

>   allocator(const allocator&) = default;

>

>   template<typename U>

>     allocator(const allocator<U>&) { }

> };

>

> Then use std::vector<const int, allocator<const int>>.

>

> --

> Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email

> ------- You are receiving this mail because: -------

> You reported the bug.

Reply via email to