Improved ergonomics for aligned_ptr pointer handling

(This is mostly a test to see if overloading `operator&()` is ever something worth doing. Since this is a rather lax smart-pointer container and I can"t see any reason we"d need to pass around `aligned_ptr<T>*` instances, it might be worth doing.)

Fortune for cpprng's current commit: Blessing − 吉
lib
Avril 3 years ago
parent ed966944b8
commit fe55da9a5a
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -73,12 +73,18 @@ namespace mem
inline const T * operator->() const { return get_ptr(); }
inline T * operator->() { return get_ptr(); }
inline const T * operator&() const { return get_ptr(); }
inline T * operator&() { return get_ptr(); }
inline const T & operator*() const { return get(); }
inline T & operator*() { return get(); }
inline operator const T*() const { return get_ptr(); }
inline operator T*() { return get_ptr(); }
inline operator const T&() const { return get(); }
inline operator T&() { return get(); }
inline aligned_ptr<T>& operator=(aligned_ptr<T, H>&& other)
{
if(ptr) aligned_ptr_util::dealloc<T, H>(ptr);

@ -26,8 +26,8 @@ namespace rng
crand::crand(u64 seed) : crand(reinterpret_cast<_opaque*>(_jr_new(seed))){}
crand::crand() : crand(0xabad1dea){}
i64 crand::_sample_int() { return _jr_proc(reinterpret_cast<jr_state*>(_state.get_ptr())); } //RANGE_MIN..=RANGE_MAX
f64 crand::_sample() { return _jr_procf(reinterpret_cast<jr_state*>(_state.get_ptr())); } //0..1
i64 crand::_sample_int() { return _jr_proc(reinterpret_cast<jr_state*>(&_state)); } //RANGE_MIN..=RANGE_MAX
f64 crand::_sample() { return _jr_procf(reinterpret_cast<jr_state*>(&_state)); } //0..1
// Overrides //
u64 crand::next_u64() { return std::bit_cast<u64>(std::abs(_sample_int()) & INT32_MAX); }

Loading…
Cancel
Save