public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/55963] std::vector<const T> fails Date: Sun, 13 Jan 2013 22:44:00 -0000 [thread overview] Message-ID: <bug-55963-4-5jfHoXtYoH@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-55963-4@http.gcc.gnu.org/bugzilla/> 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>>.
next prev parent reply other threads:[~2013-01-13 22:44 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-01-13 18:15 [Bug libstdc++/55963] New: " corey at octayn dot net 2013-01-13 18:16 ` [Bug libstdc++/55963] " corey at octayn dot net 2013-01-13 19:05 ` redi at gcc dot gnu.org 2013-01-13 22:44 ` redi at gcc dot gnu.org [this message] 2013-01-13 23:53 ` corey at octayn dot net 2013-01-14 22:29 ` redi at gcc dot gnu.org 2014-09-19 13:31 ` redi at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-55963-4-5jfHoXtYoH@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).