#ifndef NALL_UTILITY_HPP #define NALL_UTILITY_HPP #include #include namespace nall { template struct enable_if { typedef T type; }; template struct enable_if {}; template struct mp_enable_if : enable_if {}; template inline void swap(T &x, T &y) { T temp(std::move(x)); x = std::move(y); y = std::move(temp); } template struct base_from_member { T value; base_from_member(T value_) : value(value_) {} }; template class optional { 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(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