MCPcopy Create free account
hub / github.com/BehaviorTree/BehaviorTree.CPP / swap

Method swap

include/behaviortree_cpp/contrib/any.hpp:182–209  ·  view source on GitHub ↗

Exchange the states of *this and rhs.

Source from the content-addressed store, hash-verified

180
181 /// Exchange the states of *this and rhs.
182 void swap(any& rhs) noexcept
183 {
184 if(this->vtable != rhs.vtable)
185 {
186 any tmp(std::move(rhs));
187
188 // move from *this to rhs.
189 rhs.vtable = this->vtable;
190 if(this->vtable != nullptr)
191 {
192 this->vtable->move(this->storage, rhs.storage);
193 //this->vtable = nullptr; -- unneeded, see below
194 }
195
196 // move from tmp (previously rhs) to *this.
197 this->vtable = tmp.vtable;
198 if(tmp.vtable != nullptr)
199 {
200 tmp.vtable->move(tmp.storage, this->storage);
201 tmp.vtable = nullptr;
202 }
203 }
204 else // same types
205 {
206 if(this->vtable != nullptr)
207 this->vtable->swap(this->storage, rhs.storage);
208 }
209 }
210
211private: // Storage and Virtual Method Table
212

Callers 6

swapFunction · 0.45
expected.hppFile · 0.45
swapFunction · 0.45
emplaceFunction · 0.45
anyClass · 0.45
swapFunction · 0.45

Calls 2

moveFunction · 0.85
moveMethod · 0.45

Tested by

no test coverage detected