#ifndef NALL_UTILITY_HPP #define NALL_UTILITY_HPP #include #include namespace nall { template struct base_from_member { T value; base_from_member(T value_) : value(value_) {} }; template class optional { public: bool valid; T value; public: inline operator bool() const { return valid; } inline const T& operator()() const { if(!valid) throw; return value; } inline optional& operator=(const optional &source) { valid = source.valid; value = source.value; return *this; } inline optional() : valid(false) {} inline optional(bool valid, const T &value) : valid(valid), value(value) {} }; template inline T* allocate(unsigned size, const T &value) { T *array = new T[size]; for(unsigned i = 0; i < size; i++) array[i] = value; return array; } } #endif