Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:35:51

0001 /*
0002  *  CMSSW
0003  *
0004  */
0005 
0006 #include <cassert>
0007 #include <iostream>
0008 #include <memory>
0009 #include <vector>
0010 #include "catch.hpp"
0011 
0012 #include "DataFormats/Common/interface/Wrapper.h"
0013 
0014 class CopyNoMove {
0015 public:
0016   CopyNoMove() {}
0017   CopyNoMove(CopyNoMove const&) { /* std::cout << "copied\n"; */ }
0018   CopyNoMove& operator=(CopyNoMove const&) { /*std::cout << "assigned\n";*/ return *this; }
0019 
0020 private:
0021 };
0022 
0023 class MoveNoCopy {
0024 public:
0025   MoveNoCopy() {}
0026   MoveNoCopy(MoveNoCopy const&) = delete;
0027   MoveNoCopy& operator=(MoveNoCopy const&) = delete;
0028   MoveNoCopy(MoveNoCopy&&) { /* std::cout << "moved\n";*/ }
0029   MoveNoCopy& operator=(MoveNoCopy&&) { /* std::cout << "moved\n";*/ return *this; }
0030 
0031 private:
0032 };
0033 
0034 TEST_CASE("test Wrapper", "[Wrapper]") {
0035   auto thing = std::make_unique<CopyNoMove>();
0036   edm::Wrapper<CopyNoMove> wrap(std::move(thing));
0037 
0038   auto thing2 = std::make_unique<MoveNoCopy>();
0039   edm::Wrapper<MoveNoCopy> wrap2(std::move(thing2));
0040 
0041   auto thing3 = std::make_unique<std::vector<double>>(10, 2.2);
0042   REQUIRE(thing3->size() == 10);
0043 
0044   edm::Wrapper<std::vector<double>> wrap3(std::move(thing3));
0045   REQUIRE(wrap3->size() == 10);
0046   REQUIRE(thing3.get() == 0);
0047 }