SFINAE: Use fl::realloc() for trivially copyable types
| 180 | private: |
| 181 | // SFINAE: Use fl::realloc() for trivially copyable types |
| 182 | pointer reallocate_impl(pointer ptr, fl::size old_count, fl::size new_count, fl::true_type) FL_NOEXCEPT { |
| 183 | if (new_count == 0) { |
| 184 | if (ptr) { |
| 185 | deallocate(ptr, old_count); |
| 186 | } |
| 187 | return nullptr; |
| 188 | } |
| 189 | |
| 190 | // Safe to use realloc() - type is trivially copyable |
| 191 | void* result = fl::realloc(ptr, new_count * sizeof(T)); |
| 192 | if (!result) { |
| 193 | return nullptr; // Realloc failed |
| 194 | } |
| 195 | |
| 196 | T* new_ptr = static_cast<T*>(result); |
| 197 | |
| 198 | // Zero-initialize any newly allocated memory |
| 199 | if (new_count > old_count) { |
| 200 | fl::memset(new_ptr + old_count, 0, (new_count - old_count) * sizeof(T)); |
| 201 | } |
| 202 | |
| 203 | return new_ptr; |
| 204 | } |
| 205 | |
| 206 | // SFINAE: Don't use realloc() for non-trivially-copyable types |
| 207 | pointer reallocate_impl(pointer ptr, fl::size old_count, fl::size new_count, fl::false_type) FL_NOEXCEPT { |
nothing calls this directly
no test coverage detected