3

while reading answer to one question on MS Connect site I noticed the following part of the reply:

This is one of a few breaking changes in the Standard Library that I'm aware of (the other major ones are immutable sets, and 2D vector construction).

Answer can be considered legit with high probability since it is from MS employee that works on implementing STL.

So does anybody knows what exactly he refers to?

NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277
  • 1
    Possibly related: http://stackoverflow.com/q/8939320/636019 – ildjarn Jun 22 '12 at 16:09
  • 1
    Provide a link to the Connect issue, or if it's private, at least properly cite the engineer you're quoting. – Ben Voigt Jun 22 '12 at 16:11
  • Also possibly related: http://stackoverflow.com/q/5759232/636019 – ildjarn Jun 22 '12 at 16:18
  • @ Ben it is irrelevant imno since it is not about this Q, but : http://connect.microsoft.com/VisualStudio/feedback/details/691756/std-make-pair-error-in-vc11 – NoSenseEtAl Jun 22 '12 at 16:26
  • 3
    Stephan left his email address in the answer you link to, and invites you to email him if you have any further questions regarding his answer. He's a nice guy, he won't bite. – Howard Hinnant Jun 22 '12 at 17:53
  • Yeah I know (he is my fav C9 superstar :) ), but he is super busy so I would feel bad interrupting him while he works on implementing STL. :) – NoSenseEtAl Jun 22 '12 at 20:22
  • I asked, and he answered immediately. Which was super nice, and also pleasantly surprising, as it was a question on something he wrote a year ago. :) I've copied the answer below. – Quuxplusone Sep 14 '12 at 21:56

1 Answers1

4

I emailed Stephan and asked what he was talking about. Here's his answer (edited for formatting). It didn't sound like he was planning to post the answer here; if he does, I'll delete this copy.

Everything from here down is Stephan speaking.

I was referring to this:

#include <vector>
using namespace std;

int main() {
    vector<vector<int>> v(11, 22);
}

It compiles with VC10 SP1 (following C++03), but not with VC11 RTM (following C++11): [snip error message dump]

C++03 23.1.1 [lib.sequence.reqmts]/9 said:

For every sequence defined in this clause and in clause 21:
— the constructor
template <class InputIterator> X(InputIterator f, InputIterator l, const Allocator& a = Allocator())
shall have the same effect as:
X(static_cast<typename X::size_type>(f), static_cast<typename X::value_type>(l), a)
if InputIterator is an integral type.

This transformed vector<vector<int>> v(11, 22) to vector<vector<int>> v(static_cast<size_t>(11), static_cast<vector<int>>(22)), which is valid. (static_cast is capable of invoking explicit constructors, like vector's size constructor.)

C++11 23.2.3 [sequence.reqmts]/14 says:

For every sequence container defined in this Clause and in Clause 21:
— If the constructor
template <class InputIterator> X(InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type())
is called with a type InputIterator that does not qualify as an input iterator, then the constructor shall not participate in overload resolution.

This removes the (InIt, InIt) ctor from overload resolution. That leaves (size_type n, const T& value), where T is vector<int>. However, that would try to implicitly convert 22 to a temporary vector<int> (in order to bind it to const T&). The explicitness of vector's size constructor forbids that.

Reading the other SO question, this is a different issue.

STL

Community
  • 1
  • 1
Quuxplusone
  • 23,928
  • 8
  • 94
  • 159