2014-09-18 4 views

Antwort

12

Es ist ein Fehler in beiden VS2012 und VS2013, da es nicht mit dem C++ 11-Standard konform ist (mit _HAS_CPP0X definiert als 1):

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

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.

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

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.

Das Konstruktor sollte nicht bei allen

Mehr hier in Betracht gezogen wurden: https://stackoverflow.com/a/12432482/1938163

Als Workaround könnten Sie "helfen, die Überladung Auflösung ein bisschen", z.

std::vector<int> v(static_cast<std::vector<int>::size_type>(N), M); 
10

Seit C++ 11 der vector Konstruktor akzeptieren zwei sollte deaktiviert sein, wenn die beiden Argumente nicht Iteratoren sind. VS2013 kann dies nicht korrekt implementieren.

2

Dies ist ein Visual Studio 2013 Fehler, der Fehler erzeugt wird (see it live), dies ist nur ein kleiner Teil:

[...]

see reference to function template instantiation 'std::vector>::vector<,void>(_Iter,_Iter)' being compiled

[...]>

Es wird versucht, den Konstruktor zu verwenden, die zwei Eingangs Iteratoren nimmt. Was wäre ein Fehler, beide gcc und clang sind in Ordnung mit diesem Code.

können wir, dass in C++ 11 that constructor sollte nicht in Betracht gezogen werden:

Constructs the container with the contents of the range [first, last). This constructor does not participate in overload resolution if InputIt does not satisfy InputIterator, to avoid ambiguity with the overload 2 (since C++11)

Dies stimmt mit dem Entwurf des C++ 11-Standard Abschnitt 23.2.3Sequence Container Absatz die sagt:

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.

Verwandte Themen