File: utility.hpp

package info (click to toggle)
higan 106-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 9,640 kB
  • sloc: cpp: 108,736; ansic: 809; makefile: 22; sh: 7
file content (27 lines) | stat: -rw-r--r-- 661 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#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;
}

}