any.cpp 602 B

123456789101112131415161718192021222324
  1. #include "pocketpy/any.h"
  2. namespace pkpy{
  3. void any::__bad_any_cast(const std::type_index expected, const std::type_index actual){
  4. Str error = _S("bad_any_cast: expected ", expected.name(), ", got ", actual.name());
  5. throw std::runtime_error(error.c_str());
  6. }
  7. any::any(any&& other) noexcept: data(other.data), _vt(other._vt){
  8. other.data = nullptr;
  9. other._vt = nullptr;
  10. }
  11. any& any::operator=(any&& other) noexcept{
  12. if(data) _vt->deleter(data);
  13. data = other.data;
  14. _vt = other._vt;
  15. other.data = nullptr;
  16. other._vt = nullptr;
  17. return *this;
  18. }
  19. } // namespace pkpy