STL运算符= Visual Studio 2010的行为更改?

gue*_*ser 4 c++ stl qt4 visual-studio-2010 qtscript

我试图用Visual Studio 2010(C++)编译QtScriptGenerator(gitorious)并遇到编译错误.在搜索解决方案时,由于VS2010实现STL和/或c ++ 0x一致性更改的变化,我偶尔会看到自VS2008以来引入的编译破坏的引用.

任何想法下面发生了什么,或者我如何解决它?如果有问题的代码似乎是QtScriptGenerator,我想我会更容易修复它..但在我看来,违规代码可能在VS2010的STL实现中,我可能需要创建一个变通方法?

PS.我对模板和STL非常不熟悉.我有嵌入式和控制台项目的背景,这些项目直到最近才被避免,以减少内存消耗和交叉编译器风险.

编辑 - 看起来可能是Visual Studio的std :: copy实现发生了变化.

    C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE\xutility(275) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'rpp::pp_output_iterator<_Container>' (or there is no acceptable conversion)
            with
            [
                _Container=std::string
            ]
            c:\qt\qtscriptgenerator\generator\parser\rpp\pp-iterator.h(75): could be 'rpp::pp_output_iterator<_Container> &rpp::pp_output_iterator<_Container>::operator =(const char &)'
            with
            [
                _Container=std::string
            ]
            while trying to match the argument list '(rpp::pp_output_iterator<_Container>, rpp::pp_output_iterator<_Container>)'
            with
            [
                _Container=std::string
            ]
            C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE\xutility(2176) : see reference to function template instantiation '_Iter &std::_Rechecked<_OutIt,_OutIt>(_Iter &,_UIter)' being compiled
            with
            [
                _Iter=rpp::pp_output_iterator<std::string>,
                _OutIt=rpp::pp_output_iterator<std::string>,
                _UIter=rpp::pp_output_iterator<std::string>
            ]
            c:\qt\qtscriptgenerator\generator\parser\rpp\pp-internal.h(83) : see reference to function template instantiation '_OutIt std::copy<std::_String_iterator<_Elem,_Traits,_Alloc>,_OutputIterator>(_InIt,_InIt,_OutIt)' being compiled
            with
            [
                _OutIt=rpp::pp_output_iterator<std::string>,
                _Elem=char,
                _Traits=std::char_traits<char>,
                _Alloc=std::allocator<char>,
                _OutputIterator=rpp::pp_output_iterator<std::string>,
                _InIt=std::_String_iterator<char,std::char_traits<char>,std::allocator<char>>
            ]
            c:\qt\qtscriptgenerator\generator\parser\rpp\pp-engine-bits.h(500) : see reference to function template instantiation 'void rpp::_PP_internal::output_line<_OutputIterator>(const std::string &,int,_OutputIterator)' being compiled
            with
            [
                _OutputIterator=rpp::pp_output_iterator<std::string>
            ]
    C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE\xutility(275) : error C2582: 'operator =' function is unavailable in 'rpp::pp_output_iterator<_Container>'
            with
            [
                _Container=std::string
            ]
Run Code Online (Sandbox Code Playgroud)

这是一些背景..

PP-internal.h

#ifndef PP_INTERNAL_H
#define PP_INTERNAL_H

#include <algorithm>
#include <stdio.h>
namespace rpp {

namespace _PP_internal
{
..
64 template <typename _OutputIterator>
65 void output_line(const std::string &__filename, int __line, _OutputIterator __result)
66 {
67   std::string __msg;
68 
69   __msg += "# ";
70 
71   char __line_descr[16];
72   pp_snprintf (__line_descr, 16, "%d", __line);
73   __msg += __line_descr;
74 
75   __msg += " \"";
76 
77   if (__filename.empty ())
78     __msg += "<internal>";
79   else
80     __msg += __filename;
81 
82   __msg += "\"\n";
83   std::copy (__msg.begin (), __msg.end (), __result);
84 }
Run Code Online (Sandbox Code Playgroud)

PP-发动机bits.h

#ifndef PP_ENGINE_BITS_H
#define PP_ENGINE_BITS_H

#include <stdio.h>

namespace rpp {

450 template <typename _InputIterator, typename _OutputIterator>
451 void pp::operator () (_InputIterator __first, _InputIterator __last, _OutputIterator __result)
452 {
..
497           if (env.current_line != was)
498             {
499               env.current_line = was;
500               _PP_internal::output_line (env.current_file, env.current_line, __result);
501             }
Run Code Online (Sandbox Code Playgroud)

..这是pp_output_iterator的定义

PP-iterator.h

#ifndef PP_ITERATOR_H
#define PP_ITERATOR_H

#include <iterator>

namespace rpp {
..
template <typename _Container>
class pp_output_iterator
    : public std::iterator<std::output_iterator_tag, void, void, void, void>
{
    std::string &_M_result;

public:
    explicit pp_output_iterator(std::string &__result):
    _M_result (__result) {}

    inline pp_output_iterator &operator=(typename _Container::const_reference __v)
    {
    if (_M_result.capacity () == _M_result.size ())
        _M_result.reserve (_M_result.capacity () << 2);

    _M_result.push_back(__v);
    return *this;
    }

    inline pp_output_iterator &operator * () { return *this; }
    inline pp_output_iterator &operator ++ () { return *this; }
    inline pp_output_iterator operator ++ (int) { return *this; }
};
Run Code Online (Sandbox Code Playgroud)

Mic*_*urr 5

我认为问题是std::copy试图在你的上面使用'copy assignment'(operator=())rpp::pp_output_iterator<>并且没有operator=()那个类模板.我应该说,有一个operator=()但它没有将正确的参数作为'复制赋值'函数(即,它不需要``rpp :: pp_output_iterator <>&parameter). I think that the existence of someoperator =()`函数将防止编译器生成默认值(我目前无法访问标准文档来验证此100%).

请注意,类型必须是可分配的(当然,除其他外),才能被视为OutputIterator:http://www.sgi.com/tech/stl/OutputIterator.html

std::copyMSVC的早期版本可能实际上没有使用赋值(仅因为OutputIterator必须支持它并不意味着std::copy必须使用它),这就是为什么它可能是VS2010中的"新"错误.(由于访问我的工具有限,我现在无法检查).