Hot answers tagged

4

Serious issues with this: Memory Management. Not using RAII to lock/unlock Memory Management Don't pass pointers it does not indicate owners. Always wrap pointers in a smart pointer. Have a look at std::unique_ptr. But for types like Data there is no need to use pointers. Simply use Data as the object type (not Data*). RAII Look up the concept of RAII. ...


3

The trick is to use a byte_repeater like here. template<typename T, std::size_t count, int byte> struct byte_repeater; template<typename T, int byte> struct byte_repeater<T, 1, byte> { static constexpr T value = byte; }; template<typename T, std::size_t count, int byte> struct byte_repeater { static constexpr auto value = (...


1

The first thing I would note is that you should point out non obvious features of your implementation. The nice thing that is not immediately obvious is that when all external references are gone the object is automatically deleted from the make_one()::values set. This is not really a requirement of a flyweight. But a nice little trick here. So if the ...


1

I'm sorry to be so straightforward: This is madness! Your code seems to indicate a sincere lack of several language features. Pointer to const You define MEM to be of type uint8_t*, but it actually points to values of const uint8_t. To account for this difference you cast the const away in both constructors. If you'd ever (accidentally) write to the ...


Only top voted, non community-wiki answers of a minimum length are eligible