I saw Herb's paper:
http://www.gotw.ca/publications/N1185.pdf
But it's not adopted.
Anyway, vector<bool> sucks, and we know it. How about to entirely
remove it?
--
I don't believe it could break users- as far as I'm aware, the vector<bool> specialization offers strictly less functionality than a real vector<bool>.
I will oppose deprecating vector<bool> until we put in place something for clients of vector<bool> to migrate to. That something should have much the same API as vector<bool> to ease said migration. I.e. clients of vector<bool> should have to do little more than change the name of the container.
Additionally we could add sweetener to encourage the migration. For example we could mandate that bit_vector<Allocator> (or whatever the new name is) is hyper efficient when used with std::algorithms such as:
I don't believe it could break users- as far as I'm aware, the vector<bool> specialization offers strictly less functionality than a real vector<bool>.
std::vector<bool> bvec{ ... };
bvec[2].flip();
Personally, I agree with Howard; we should add a class that has all of this functionality (presumably with some degree of required sizing) that would be a drop-in replacement for those who need the sizing features of vector<bool>. But the question remains: even with a drop-in replacement, how much code will be broken because of this?
I completely agree with that approach. Removing std::auto_ptr seems
realistic now (from the pov of the standard). Existing library
implementations will decide individually how long they will conserve
the definition, depending on their customers.
On Tue, May 28, 2013 at 4:00 PM, Nicol Bolas <jmck...@gmail.com> wrote:
> std::vector<bool> bvec{ ... };
> bvec[2].flip();
I noticed that. It's OK to be fixed within `vector<T>`.
> Personally, I agree with Howard; we should add a class that has all of this
> functionality (presumably with some degree of required sizing) that would be
> a drop-in replacement for those who need the sizing features of
> vector<bool>. But the question remains: even with a drop-in replacement, how
> much code will be broken because of this?
I like the idea of providing a replacement, but I don't think a 'drop-in
replacement' is a requirement. `vector<bool>` still works, and users
can rewrite their code if they want.
I will oppose deprecating vector<bool> until we put in place something for clients of vector<bool> to migrate to. That something should have much the same API as vector<bool> to ease said migration. I.e. clients of vector<bool> should have to do little more than change the name of the container.
Additionally we could add sweetener to encourage the migration. For example we could mandate that bit_vector<Allocator> (or whatever the new name is) is hyper efficient when used with std::algorithms such as:
On May 28, 2013, at 4:00 PM, Nicol Bolas <jmck...@gmail.com> wrote:Personally, I agree with Howard; we should add a class that has all of this functionality (presumably with some degree of required sizing) that would be a drop-in replacement for those who need the sizing features of vector<bool>. But the question remains: even with a drop-in replacement, how much code will be broken because of this?Model this after the auto_ptr -> unique_ptr transition: Step 1: Introduce bit_vector (or whatever) and deprecate the vector<bool> specialization. /Somehow/ motivate people to migrate.
Step 2: Not to be done for at least 5-10 years after Step 1, remove the vector<bool> specialization.
how much code will be broken because of this?After Step 1, none. After Step 2, as much code as there is that: A. Failed to migrate during the lengthy period that vector<bool> is deprecated, and B. As much code that actually cares that vector<bool> was specialized.
Hopefully, little code will be broken. While I wouldn't dream of removing auto_ptr today, I have the impression that the auto_ptr -> unique_ptr migration is going well, thanks to the added sweetener unique_ptr has. Removing auto_ptr for C++17 is a possibility. If not then, then maybe C++2x. Howard
Le 28/05/13 22:12, Howard Hinnant a écrit :
I think that we will need also to add a std::new_vector<T> that behaves like std::vector<T> but doesn't have the bool specialization and deprecate std::vector :->On May 28, 2013, at 4:00 PM, Nicol Bolas <jmck...@gmail.com> wrote:Personally, I agree with Howard; we should add a class that has all of this functionality (presumably with some degree of required sizing) that would be a drop-in replacement for those who need the sizing features of vector<bool>. But the question remains: even with a drop-in replacement, how much code will be broken because of this?Model this after the auto_ptr -> unique_ptr transition: Step 1: Introduce bit_vector (or whatever) and deprecate the vector<bool> specialization. /Somehow/ motivate people to migrate.
I saw Herb's paper:
http://www.gotw.ca/publications/N1185.pdf
But it's not adopted.
Anyway, vector<bool> sucks, and we know it. How about to entirely
remove it?
Le 28/05/13 22:12, Howard Hinnant a écrit :
I think that we will need also to add a std::new_vector<T> that behaves like std::vector<T> but doesn't have the bool specialization and deprecate std::vector :->On May 28, 2013, at 4:00 PM, Nicol Bolas <jmck...@gmail.com> wrote:Personally, I agree with Howard; we should add a class that has all of this functionality (presumably with some degree of required sizing) that would be a drop-in replacement for those who need the sizing features of vector<bool>. But the question remains: even with a drop-in replacement, how much code will be broken because of this?Model this after the auto_ptr -> unique_ptr transition: Step 1: Introduce bit_vector (or whatever) and deprecate the vector<bool> specialization. /Somehow/ motivate people to migrate.
http://www.gotw.ca/publications/N1185.pdf
But it's not adopted.
Anyway, vector<bool> sucks, and we know it. How about to entirely
remove it?
We simply add another specialization to `vector` called "vector<std::real_bool, Allocator>". If you create a `vector` with the `std::real_bool` type, then you get exactly what you would have gotten if `vector<bool>` weren't a specialization: an actual `vector` that contains actual `bool`s. The `value_type` of `vector<std::real_bool>` would be `bool`, and so forth.
We don't have to get rid of `vector<bool>` to get what we want. We just have to call it something else. And since this `std::real_bool` type can't be used in existing code (defining new things in the `std` namespace is undefined behavior), it can't conflict with anything now.
The downside is that a template function that takes a `vector<T>`, where `T` is some type, may assume that `T` is the `value_type` of the `vector`, which it would not be in the case of `std::real_bool`.
On 29 May 2013 12:42, Nicol Bolas <jmck...@gmail.com> wrote:http://www.gotw.ca/publications/N1185.pdf
But it's not adopted.
Anyway, vector<bool> sucks, and we know it. How about to entirely
remove it?
We simply add another specialization to `vector` called "vector<std::real_bool, Allocator>". If you create a `vector` with the `std::real_bool` type, then you get exactly what you would have gotten if `vector<bool>` weren't a specialization: an actual `vector` that contains actual `bool`s. The `value_type` of `vector<std::real_bool>` would be `bool`, and so forth.
We don't have to get rid of `vector<bool>` to get what we want. We just have to call it something else. And since this `std::real_bool` type can't be used in existing code (defining new things in the `std` namespace is undefined behavior), it can't conflict with anything now.
The downside is that a template function that takes a `vector<T>`, where `T` is some type, may assume that `T` is the `value_type` of the `vector`, which it would not be in the case of `std::real_bool`.
-1.
The primary argument (so far) for removing the vector<bool> specialization is uniformity with the rest of vector.
As you point out, your solution still doesn't achieve it.
While the standard strives for high levels of backwards compatibility, it need not be 100% (heck, C++11 vector is not 100% backwards compatible with C++03 vector), and we shouldn't be adding more warts. The standard is the right place to fix this, and we should fix it and not just put a band aid on it.
I thought the primary argument was to be able to create a `vector` of `bool`s. I don't care about "uniformity"; what I care about is making a `vector` that actually contains `bool`s.
And how long will that take? C++14 is closed for new stuff, and the whole "deprecation/removal" process will require at least 2 revisions. So it would be C++20 at least before we can finally create a real `vector` of real `bool`s.
On 29 May 2013 14:21, Nicol Bolas <jmck...@gmail.com> wrote:
I thought the primary argument was to be able to create a `vector` of `bool`s. I don't care about "uniformity"; what I care about is making a `vector` that actually contains `bool`s.
Then why bother spelling it "vector<bool>", if not to be used in a generic and uniform context? It is unlikely the committee is willing to swap one specialization of vector<bool> for another. I am well aware that there are other ways to hack in std::real_bool (such as by using a traits class), but it's still a hack. If it is that important, propose a different class to do this not spelled "vector<bool>".
> And how long will that take? C++14 is closed for new stuff, and the wholeThe "removal" touches no working interfaces -- very
> "deprecation/removal" process will require at least 2 revisions. So it would
> be C++20 at least before we can finally create a real `vector` of real
> `bool`s.
important -- this is not a removal (from some degree).
I'm going to draft a simple proposal anyway, and see if it's OK
for a TS/C++17.
Considering the implementation and adoption
period, the users (are there any?) should have enough time to
switch to a boost::dynamic_bitset, or even some replacement
we are going to provide in the standard.
I'm going to go with "no" on that.
I don't think that works because v[i] has a different type and>
> Well, I suppose it would be a different type of hack, but those
> who care about having a vector of bools could just write a
> bool-wrapping struct and put that into a vector.
selects different overload sets and instantiations.
The "removal" touches no working interfaces -- veryimportant -- this is not a removal (from some degree).
I'm going to draft a simple proposal anyway, and see if it's OK
for a TS/C++17.
Until it is a proposal, it's your time to waste, but so far every committee member who has spoken in this thread is against just removing it from C++17 on the technicality that the space optimization is not required by the standard. I'm pretty sure such a proposal will not take up much committee time.
Removing useful functionality that users depend on without providing a suitable replacement is very unlikely to pass. (And much as I like Boost, pointing users to Boost is not an acceptable substitute.)
On 29 May 2013 12:20, Vicente J. Botet Escriba <vicent...@wanadoo.fr> wrote:
Le 28/05/13 22:12, Howard Hinnant a écrit :
I think that we will need also to add a std::new_vector<T> that behaves like std::vector<T> but doesn't have the bool specialization and deprecate std::vector :->On May 28, 2013, at 4:00 PM, Nicol Bolas <jmck...@gmail.com> wrote:Personally, I agree with Howard; we should add a class that has all of this functionality (presumably with some degree of required sizing) that would be a drop-in replacement for those who need the sizing features of vector<bool>. But the question remains: even with a drop-in replacement, how much code will be broken because of this?Model this after the auto_ptr -> unique_ptr transition: Step 1: Introduce bit_vector (or whatever) and deprecate the vector<bool> specialization. /Somehow/ motivate people to migrate.
-100.
* Annoying 99% of all C++ users is a horrible, horrible idea.
* I'd hate to use a code base that had two different, unrelated types for doing the exact same thing, since ultimately these things end up interfaces. Actually, I already have that, as people are trying to migrate from Boost over to std (such as shared_ptr), and it is anything but easy (because we are dependent on libraries developed for/by other groups, and changing those interfaces is a scheduling nightmare).
What I don't understand it, what is the difference between removing
the optimization words and removing the specialization +
supporting vector<bool>'s extra interfaces in vector<T> when T == bool.
When I say "optimization words" I mean the words those break the
container natural to allow the optimization. If you remove the those words,
the optimization is disabled. The real users can longer count on it.
That's my initial thought. I don't like to bother vector<T>, either (although it does not pollute the actual interfaces). But the problem
is, how to address the "current users"?
Le 29/05/13 19:37, Nevin Liber a écrit :
On 29 May 2013 12:20, Vicente J. Botet Escriba <vicent...@wanadoo.fr> wrote:
Le 28/05/13 22:12, Howard Hinnant a écrit :
I think that we will need also to add a std::new_vector<T> that behaves like std::vector<T> but doesn't have the bool specialization andOn May 28, 2013, at 4:00 PM, Nicol Bolas <jmck...@gmail.com> wrote:Personally, I agree with Howard; we should add a class that has all of this functionality (presumably with some degree of required sizing) that would be a drop-in replacement for those who need the sizing features of vector<bool>. But the question remains: even with a drop-in replacement, how much code will be broken because of this?Model this after the auto_ptr -> unique_ptr transition: Step 1: Introduce bit_vector (or whatever) and deprecate the vector<bool> specialization. /Somehow/ motivate people to migrate.
* I'd hate to use a code base that had two different, unrelated types for doing the exact same thing, since ultimately these things end up interfaces. Actually, I already have that, as people are trying to migrate from Boost over to std (such as shared_ptr), and it is anything but easy (because we are dependent on libraries developed for/by other groups, and changing those interfaces is a scheduling nightmare).
You are right. What we would need is 'single' type that behaves as the current vector<T> except for bool and that behaves as vector<bool> if vector was not specialized. I don't know if we can specialize an alias and if the following is correct
template <typename T, typename Allocator>
class new_vector { the same definition as vector<T, Allocator> now };
template <typename T, typename Allocator>
alias vector= new_vector<T, Allocator> ;
template < typename Allocator>
class vector<bool, Allocator> { the same definition as now } ;
If this is correct,
I saw Herb's paper:
http://www.gotw.ca/publications/N1185.pdf
But it's not adopted.
Anyway, vector<bool> sucks, and we know it. How about to entirely
remove it?
- Define that vector<bool>::iterator has an API to access more than one bit at a time,
--
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
-- Bengt Gustafsson CEO, Beamways AB Westmansgatan 37A 582 16 Linköping, Sweden +46 13 465 10 85 www.beamways.com
I was just trying to be pragmatic about solving the actual problems we are discussing, which should be problems that are of interest to real programmer's use of the language. I freely admit that the vector<bool> specialization is a wart but I don't see that this actually creates a lot of problems in the real world. Could anyone exemplify a reasonable usage that fails in a hard to detect way?
The real problems I could detect with vector<bool> were that the performance of algorithms like count() is significantly less than it could be. I suggested how this could be solved in a way that is totally invisible to the programmer. I also suggested that the API required could be standardized to allow user-defined algorithms to take advantage of the speedup.
From a practical programmer's standpoint I think it is very neat that vector<bool> hides the fact that there is a special implementation underneath.
void OperateOnBoolArray(const bool *array, size_t count);
vector<bool> stuff = {...};
OperateOnBoolArray(stuff.data(), stuff.size());
template<class T>
void Proc()
{
vector<T> arr = {...};
OperateOnArray(arr.data(), arr.size());
}
If another very similar but different class is introduced I can't see that this would make the language easier to understand or use.
If bit_vector is introduced all template code that uses vector<T> and would benefit from a packed structure would need to be specialized for bool. Is that really better?
On Mon, Aug 26, 2013 at 9:22 AM, Nicol Bolas <jmck...@gmail.com> wrote:
> They can do a find-replace on "vector<bool>" with
> "bit_vector", and their code should immediately work as before. It needs to
> be a drop-in replacement so that they can stop using `vector<bool>`.
What I don't understand is why all of you think a drop-in replacement
of `vector<bool>` is possible. `vector<bool>` is already proven to
be wrong. Its iterator does not even meet the ForwardIterator
requirement. Change the whole iterator categories just to unblock
proxy iterator? Dave already tried -- not accepted. `vector<bool>`
is just a mistake, a drop-in replacement of an mistake is also wrong.
Howard
On Aug 26, 2013, at 8:58 PM, Zhihao Yuan <z...@miator.net> wrote:
> Ah, I see... We should be able to specialize iterator_traits to unblock
> proxy iterators...
And actually we already have done this for input iterators and output iterators. We just have this legacy requirement hanging around that forward iterators (and bi and rand) must return a value_type& from operator*() (const value_type& for non-mutable variants). The T& return from forward iterator operator*() is kind of like dandelions. It kind of looks pretty. And it is very hard to get rid of. :-) But I think we should make an effort to do so.
On Mon, Aug 26, 2013 at 7:10 PM, Nicol Bolas <jmck...@gmail.com> wrote:
> `bit_vector` can do whatever it wants, because it's not a real vector. It
> can spit out "pseudo-iterators". It can do whatever. It can have the
> interface it has, and nobody has any explicit expectations that this
> interface matches that of the containers as defined by chapter 23.
So you mean it's Okey for bitvector's begin() to produce an
object which can be used in any STL algorithms but such an object
fits into no iterator categories? Don't you think that's an anti-pattern
of STL design?
I do think that the specialization was a mistake from the beginning, but I think that we should move on with an apology and concentrate on making it perform as expected from a packed representation, which requires the API I mentioned before. Also I think that the suggestion to remove it would never pass the committe scrutinization.
Zhihao Yuan skrev 2013-08-27 01:57:
> On Mon, Aug 26, 2013 at 7:22 PM, Howard Hinnant
> <howard....@gmail.com> wrote:
>> Question for Zhihao:
>>
>> Why does forward iterator's operator*() have to return a value_type& ?
>>
>> I'm well aware that this is what C++98/03/11 requires. That's not what I'm asking. I'm asking what is the benefit of this requirement in the C++1y context? What problem does this requirement solve?
> Afaics, it makes the pointed object modifiable. And move_iterator
> significantly benefits from it. (Here is something I'm not sure:
> move_iterator requires only InputIterator, while dereferencing an
> InputIterator may return anything convertible to T -- is there anything
> broken here?)
>
No, he must be refering to something else, as the return value of
vector<bool>::iterator::operator* does indeed make the pointed object
modifiable.
I don't like when people speak in riddles to make other people feel like
idiots! Please instead try to explain the issue at hand as clearly as
you can.
The prime example I have been given of the badness of the vector<bool>
specialization is that it does not have a .data() method. So be it, but
in what case is using .data() preferred to using iterators?
vector<T> t{...};
T* tp = &t[0];
tp += 3;
*tp == t[3];
Because it's part of std::vector's interface. std::vector *requires* that this code works:
vector<T> t{...};
T* tp = &t[0];
tp += 3;
*tp == t[3];
And that will work for all T... so long as T is not `bool`.
It is not for you to decide whether this is good code or not.
There is no reason why this should be the case. A space-optimized object can be used separately.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
Personally I am indifferent, as I don't use vector<bool>. But I don't want the standard to be changed under the feet of people,
In addition I think that C++ should focus on being an outstanding performer, which is why I suggested to include APIs to allow fast implementations of algorithms in a portable way.
Personally I am indifferent, as I don't use vector<bool>. But I don't want the standard to be changed under the feet of people, and I dislike that more than it being clumsy as it is.