utility.hpp 680 B

123456789101112131415161718192021222324252627282930
  1. #pragma once
  2. #include <utility>
  3. namespace nall {
  4. using std::tuple;
  5. template<typename T> struct base_from_member {
  6. base_from_member(T value) : value(value) {}
  7. T value;
  8. };
  9. template<typename To, typename With> struct castable {
  10. operator To&() { return (To&)value; }
  11. operator const To&() const { return (const To&)value; }
  12. operator With&() { return value; }
  13. operator const With&() const { return value; }
  14. auto& operator=(const With& value) { return this->value = value; }
  15. With value;
  16. };
  17. template<typename T> inline auto allocate(uint size, const T& value) -> T* {
  18. T* array = new T[size];
  19. for(uint i = 0; i < size; i++) array[i] = value;
  20. return array;
  21. }
  22. }