最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

In C++, how to programatically detect if there was a copy instead of a move? - Stack Overflow

programmeradmin2浏览0评论

I am working on a segment of code that is highly sensitive to copies based on the size of the variable, thus I want to ensure that the code I am writing is not copying data but only transferring ownership (or moving) from one class to another. Preferably I would like to be able to ensure this is happening via a unit test.

In particular, I am using a protocol buffer, but the example can be done generically with unique_ptr.

Here is an example of code I am trying to do:

TEST(notcopy){

auto verify_not_copied = std::make_unique<type>();
auto test_class = std::make_unique<TestClass>();

auto result = testclass.run(verify_not_copied);

if (result == verify_not_copied){ //part I dont know how to check
  return "Test success";
}else{
  return  "Test had copy";
}

}
发布评论

评论列表(0)

  1. 暂无评论