2017-03-02 4 views
0

나는 힙의 일부 데이터를 가리키는 객체에 대해 move construct/assign 작업을 구현하고 있습니다.이동 생성자의 강제 테스트?

나는 move construct/assign 및 copy construct/assign을 테스트하고 있으며, 모든 것은 move 구조체를 제외하고 모든 빌드 및 모든 작업을 테스트합니다. (이동 할당이 작동 함).

디버거가 이동하지 못하는 것 같습니다. 이동 생성자 코드에 도달하지 못했습니다.

내가 누락 된 간단한 내용이있을 것이라고 확신합니까?

움직임 생성자 ...

//... 

HeapBuffer (HeapBuffer&& other)      // move 
    : data {other.data}, 
     size {other.size} 
{ 
    assert(false);    // hmm can't seem to debug to here in testing :(
    other.data = nullptr; 
    other.size = 0; 
} 

//... 

테스팅 기능 ...

ado::HeapBuffer<2048> makeHeapBuffer2048() // test move semantics 
{ 
    ado::HeapBuffer<2048> hb2048; 
    hb2048[777] = 123.0f; 
    return hb2048; 
} 

호출 테스트 ...

beginTest ("HeapBuffer move constructor"); // hmmm can't seem to get to the move constructor, 
              // strange because all the others work!?!? 
{ 
    ado::HeapBuffer<2048> hb {makeHeapBuffer2048()}; 

    expectEquals (hb[777], 123.0f); 
} 

내가 추가 할 것입니다 내가 변경하는 경우 그 이동 생성자가 ...

HeapBuffer (HeapBuffer&&) = delete; 

... 예상 지점에서 빌드가 실패합니다 (예 : 시험에 의해 트립되었다).

+1

생략 아마 "생략 복사 C++"에 대한 – Jarod42

+1

검색을 발생한다. – nwp

답변

3

생략 아마 당신은 시도 할 수 있습니다, 발생한다 :

ado::HeapBuffer<2048> moved; 
moved[777] = 123.0f; 
ado::HeapBuffer<2048> hb{std::move(moved)}; 

expectEquals (hb[777], 123.0f); 
+0

완벽하게 고맙습니다.'moved [777] = 123.0f'을 추가 했으므로 expectEquals()가 작동합니다. – ternonlerwen