Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion include/decodeless/allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class linear_memory_resource {
using parent_allocator = ResOrAlloc;

// Non-reallocating parent allocator constructor must take an initial size
#if _MSC_VER < 1930
// MSVC 2019 doesn't allow a trailing requires clause on a function of a
// templated class. Adding a dummy template like this avoids error C7599.
template<class U = ResOrAlloc>
Comment on lines +58 to +61
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

LGTM! Consider marking this as a temporary workaround.

The compiler version check and template workaround effectively addresses the MSVC 2019 limitation with trailing requires clauses.

Consider adding a TODO comment to remove this workaround once MSVC 2019 support is no longer needed:

 #if _MSC_VER < 1930
+    // TODO: Remove this workaround once MSVC 2019 support is dropped
     // MSVC 2019 doesn't allow a trailing requires clause on a function of a
     // templated class. Adding a dummy template like this avoids error C7599.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#if _MSC_VER < 1930
// MSVC 2019 doesn't allow a trailing requires clause on a function of a
// templated class. Adding a dummy template like this avoids error C7599.
template<class U = ResOrAlloc>
#if _MSC_VER < 1930
// TODO: Remove this workaround once MSVC 2019 support is dropped
// MSVC 2019 doesn't allow a trailing requires clause on a function of a
// templated class. Adding a dummy template like this avoids error C7599.
template<class U = ResOrAlloc>

#endif
linear_memory_resource(size_t initialSize, const ResOrAlloc& parent = ResOrAlloc())
requires allocator<ResOrAlloc>
: m_parent(parent)
Expand All @@ -68,6 +73,9 @@ class linear_memory_resource {

// Non-reallocating parent memory_resource constructor must take an initial
// size
#if _MSC_VER < 1930
template<class U = ResOrAlloc>
#endif
linear_memory_resource(size_t initialSize, ResOrAlloc&& parent)
requires memory_resource<ResOrAlloc>
: m_parent(std::move(parent))
Expand All @@ -80,17 +88,26 @@ class linear_memory_resource {
}

// Reallocating parent allocator may default construct
#if _MSC_VER < 1930
template<class U = ResOrAlloc>
#endif
linear_memory_resource()
requires realloc_allocator<ResOrAlloc>
= default;
: m_parent() {}

// Reallocating parent allocator can be copied
#if _MSC_VER < 1930
template<class U = ResOrAlloc>
#endif
linear_memory_resource(const ResOrAlloc& parent)
requires realloc_allocator<ResOrAlloc>
: m_parent(parent) {}

// Reallocating parent memory_resource must be moved into the linear
// resource
#if _MSC_VER < 1930
template<class U = ResOrAlloc>
#endif
linear_memory_resource(ResOrAlloc&& parent)
requires realloc_memory_resource<ResOrAlloc>
: m_parent(std::move(parent)) {}
Expand Down