any.cpp 627 B

1234567891011121314151617181920212223242526
  1. #include "pocketpy/common/any.hpp"
  2. #include "pocketpy/common/utils.h"
  3. #include <cstdio>
  4. namespace pkpy {
  5. void any::__bad_any_cast(const std::type_index expected, const std::type_index actual) {
  6. PK_FATAL_ERROR("bad_any_cast: expected %s, got %s\n", expected.name(), actual.name())
  7. }
  8. any::any(any&& other) noexcept : data(other.data), _vt(other._vt) {
  9. other.data = nullptr;
  10. other._vt = nullptr;
  11. }
  12. any& any::operator= (any&& other) noexcept {
  13. if(data) _vt->deleter(data);
  14. data = other.data;
  15. _vt = other._vt;
  16. other.data = nullptr;
  17. other._vt = nullptr;
  18. return *this;
  19. }
  20. } // namespace pkpy