bsnes-libretro/nall/utility.hpp
Tim Allen 4c3f58150c Update to v101r15 release.
byuu says:

Changelog:

  - added (poorly-named) castable<To, With> template
  - Z80 debugger rewritten to make declaring instructions much simpler
  - Z80 has more instructions implemented; supports displacement on
    (IX), (IY) now
  - added `Processor::M68K::Bus` to mirror `Processor::Z80::Bus`
      - it does add a pointer indirection; so I'm not sure if I want to
        do this for all of my emulator cores ...
2016-09-04 23:51:27 +10:00

28 lines
661 B
C++

#pragma once
#include <utility>
namespace nall {
template<typename T> struct base_from_member {
base_from_member(T value) : value(value) {}
T value;
};
template<typename To, typename With> struct castable {
operator To&() { return (To&)value; }
operator const To&() const { return (const To&)value; }
operator With&() { return value; }
operator const With&() const { return value; }
auto& operator=(const With& value) { return this->value = value; }
With value;
};
template<typename T> inline auto allocate(uint size, const T& value) -> T* {
T* array = new T[size];
for(uint i = 0; i < size; i++) array[i] = value;
return array;
}
}