以下代码在 clang-3.8 和 gcc 4.9.3 上编译良好。
#include <vector>
#include <algorithm>
#include <iterator>
class foo
{
};
class MyVec {
public:
MyVec() {}
};
class MyInsert :
public std::iterator<std::output_iterator_tag, void, void, void, void>
{
protected :
MyVec &fV;
public :
explicit MyInsert (MyVec &v) : fV(v) {}
MyInsert & operator= (void *value)
{
return *this;
}
MyInsert & operator* () { return *this; }
MyInsert & operator++ () { return *this; }
MyInsert & operator++(int) { return *this; }
};
class test
{
public:
void method()
{
MyVec retv;
std::vector<const foo*> foovec;
std::transform(foovec.begin(), foovec.end(),MyInsert(retv),[](const foo*)->void* { return nullptr;});
}
};
int main(){
return 0;
}
但是,在 VS 2015 Update 3 上编译时,它会失败并显示以下错误消息。
c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(458): error C2280: 'MyInsert &MyInsert::operator =(const MyInsert &)': attempting to reference a deleted function
test\mytests\main.cpp(33): note: compiler has generated 'MyInsert::operator =' here
c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(926): note: see reference to function template instantiation '_Iter &std::_Rechecked<_OutIt,_OutIt>(_Iter &,_UIter)' being compiled
with
[
_Iter=MyInsert,
_OutIt=MyInsert,
_UIter=MyInsert
]
c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(950): note: see reference to function template instantiation '_OutIt std::_Transform_no_deprecate1<const foo**,_OutIt,_Fn1>(_InIt,_InIt,
_OutIt,_Fn1 &,std::input_iterator_tag,std::_Any_tag)' being compiled
with
[
_OutIt=MyInsert,
_Fn1=test::method::<lambda_45e8626339fc29aadca2bf2dd3420511>,
_InIt=const foo **
]
c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(960): note: see reference to function template instantiation '_OutIt std::_Transform_no_deprecate<_InIt,_OutIt,_Fn1>(_InIt,_InIt,_OutIt,
_Fn1 &)' being compiled
with
[
_OutIt=MyInsert,
_InIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<const foo *>>>,
_Fn1=test::method::<lambda_45e8626339fc29aadca2bf2dd3420511>
]
test\mytests\main.cpp(45): note: see reference to function template instantiation '_OutIt std::transform<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<const
foo *>>>,MyInsert,test::method::<lambda_45e8626339fc29aadca2bf2dd3420511>>(_InIt,_InIt,_OutIt,_Fn1)' being compiled
with
[
_OutIt=MyInsert,
_InIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<const foo *>>>,
_Fn1=test::method::<lambda_45e8626339fc29aadca2bf2dd3420511>
]
]
我无法理解为什么它(VS 编译器)无法找到采用 void * 并在显然是一个时返回 MyInsert & 的复制赋值运算符明确规定。
深入挖掘(通过跟踪错误消息跟踪)
c:\program files (x86)\microsoft visual studio14.0\vc\include\xutility
和
c:\program files (x86)\microsoft visual studio14.0\vc\include\algorithm
还让我意识到调用 std::transformation 算法的实际函数,调用显式提供的复制赋值,之后它进入 _Rechecked 函数,然后它开始进入 xutility header 。
在此函数中,调用了复制赋值运算符,它期望(输入为 MyInsert& 并输出为 MyInsert&),由于找不到,因此将错误消息显示为正在尝试引用...。
这个分析正确吗?如果没有,那么为什么不能编译在其他主要编译器上编译的代码?也许是一个错误?
附言
我目前使用的解决方法是删除 MyInsert 类中的引用成员和非引用成员。
最佳答案
I am not able understand why it (VS Compiler) is not able to find the copy assignment operator which takes
void *and gives backMyInsert &when clearly one is explicitly provided.
采用void* 的赋值运算符不是复制 赋值运算符。
编译器确实尝试使用复制赋值运算符,但显然没有明确提供。它也不是隐式提供的,因为有一个引用成员。
输出迭代器必须满足OutputIterator的要求必须满足Iterator的要求必须满足CopyAssignable的要求这毫不奇怪地要求你有一个复制赋值运算符。这是 MyInsert 所缺少的。
why is not able to compile the code which is getting compiled on other major compilers?
虽然输出迭代器必须满足要求,但标准库实现不需要检查是否满足要求。
希望概念的正式规范将来成为标准的一部分,以改进此类情况下的错误消息。
Perhaps a bug?
错误是代码中缺少复制赋值运算符。 VS 和其他编译器在这方面都符合标准。
Current work around that I am using is to remove the reference member in MyInsert class with non-reference member.
通过删除引用成员,您允许隐式声明复制赋值运算符。这就是它起作用的原因。要在保持类型拷贝可分配的同时继续引用对象,请使用普通指针而不是引用。
关于c++ - 删除复制赋值运算符的 VS 2015 Update 3 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39352310/
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru
在railstutorial中,作者为什么选择使用这个(代码list10.25):http://ruby.railstutorial.org/chapters/updating-showing-and-deleting-usersnamespace:dbdodesc"Filldatabasewithsampledata"task:populate=>:environmentdoRake::Task['db:reset'].invokeUser.create!(:name=>"ExampleUser",:email=>"example@railstutorial.org",:passwo
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
查看Ruby的CSV库的文档,我非常确定这是可能且简单的。我只需要使用Ruby删除CSV文件的前三列,但我没有成功运行它。 最佳答案 csv_table=CSV.read(file_path_in,:headers=>true)csv_table.delete("header_name")csv_table.to_csv#=>ThenewCSVinstringformat检查CSV::Table文档:http://ruby-doc.org/stdlib-1.9.2/libdoc/csv/rdoc/CSV/Table.html
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
我有一个具有一些属性的模型:attr1、attr2和attr3。我需要在不执行回调和验证的情况下更新此属性。我找到了update_column方法,但我想同时更新三个属性。我需要这样的东西:update_columns({attr1:val1,attr2:val2,attr3:val3})代替update_column(attr1,val1)update_column(attr2,val2)update_column(attr3,val3) 最佳答案 您可以使用update_columns(attr1:val1,attr2:val2
我发现ActiveRecord::Base.transaction在复杂方法中非常有效。我想知道是否可以在如下事务中从AWSS3上传/删除文件:S3Object.transactiondo#writeintofiles#raiseanexceptionend引发异常后,每个操作都应在S3上回滚。S3Object这可能吗?? 最佳答案 虽然S3API具有批量删除功能,但它不支持事务,因为每个删除操作都可以独立于其他操作成功/失败。该API不提供任何批量上传功能(通过PUT或POST),因此每个上传操作都是通过一个独立的API调用完成的
请帮助我理解范围运算符...和..之间的区别,作为Ruby中使用的“触发器”。这是PragmaticProgrammersguidetoRuby中的一个示例:a=(11..20).collect{|i|(i%4==0)..(i%3==0)?i:nil}返回:[nil,12,nil,nil,nil,16,17,18,nil,20]还有:a=(11..20).collect{|i|(i%4==0)...(i%3==0)?i:nil}返回:[nil,12,13,14,15,16,17,18,nil,20] 最佳答案 触发器(又名f/f)是
在Ruby中是否有Gem或安全删除文件的方法?我想避免系统上可能不存在的外部程序。“安全删除”指的是覆盖文件内容。 最佳答案 如果您使用的是*nix,一个很好的方法是使用exec/open3/open4调用shred:`shred-fxuz#{filename}`http://www.gnu.org/s/coreutils/manual/html_node/shred-invocation.html检查这个类似的帖子:Writingafileshredderinpythonorruby?
我正在尝试找到一种方法来规范化字符串以将其作为文件名传递。到目前为止我有这个:my_string.mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n,'').downcase.gsub(/[^a-z]/,'_')但第一个问题:-字符。我猜这个方法还有更多问题。我不控制名称,名称字符串可以有重音符、空格和特殊字符。我想删除所有这些,用相应的字母('é'=>'e')替换重音符号,并将其余的替换为'_'字符。名字是这样的:“Prélèvements-常规”“健康证”...我希望它们像一个没有空格/特殊字符的文件名:“prelevements_routin