Skip to content

Commit 8557755

Browse files
committed
Replace R.5 exception and examples with moving a BigObject to the heap to save stack
Closes isocpp#2221
1 parent f3bc9dd commit 8557755

File tree

1 file changed

+1
-18
lines changed

1 file changed

+1
-18
lines changed

CppCoreGuidelines.md

+1-18
Original file line numberDiff line numberDiff line change
@@ -9622,24 +9622,7 @@ Exception: Do not produce such a warning on a local `Unique_pointer` to an unbou
96229622

96239623
##### Exception
96249624

9625-
It is OK to create a local `const unique_ptr<T[]>` to a heap-allocated buffer, as this is a valid way to represent a scoped dynamic array.
9626-
9627-
##### Example
9628-
9629-
A valid use case for a local `const unique_ptr<T[]>` variable:
9630-
9631-
int get_median_value(const std::list<int>& integers)
9632-
{
9633-
const auto size = integers.size();
9634-
9635-
// OK: declaring a local unique_ptr<T[]>.
9636-
const auto local_buffer = std::make_unique_for_overwrite<int[]>(size);
9637-
9638-
std::copy_n(begin(integers), size, local_buffer.get());
9639-
std::nth_element(local_buffer.get(), local_buffer.get() + size/2, local_buffer.get() + size);
9640-
9641-
return local_buffer[size/2];
9642-
}
9625+
If your stack space is limited, it is OK to create a local `const unique_ptr<BigObject>` to store the object on the heap instead of the stack.
96439626

96449627
### <a name="Rr-global"></a>R.6: Avoid non-`const` global variables
96459628

0 commit comments

Comments
 (0)