[FEA]: `cuda::small_vector`
- Dominant language
- C++
- Stars
- 2.5k
- Forks
- 486
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 295
Description
### Is this a duplicate?
- [x] I confirmed there appear to be no [duplicate issues](https://github.com/NVIDIA/cccl/issues) for this request and that I agree to the [Code of Conduct](CODE_OF_CONDUCT.md)
### Area
libcu++
### Is your feature request related to a problem? Please describe.
It is common for libraries to hold any variably-sized, owned data in a `std::vector` due to simplicity and performance. However, when such vectors are small, the overhead of allocating the objects may become intolerable.
Add a vector-like class that is optimized for the case where there are very few elements in the vector, and in those cases store them on the stack. For similar implementations, see LLVM [`SmallVector`](https://llvm.org/doxygen/classllvm_1_1SmallVector.html).
### Describe the solution you'd like
Provide a header `` which implements a class:
```c++
template <
typename T,
::cuda::std::size_t StackElements = /* implementation defined */,
typename Allocator = ::cuda::std::default_allocator
>
class small_vector;
```
Crucially, the class uses static allocator type instead of memory resources:
1. The stated purpose of the class is to almost always live in "stack" mode, with the ability to grow beyond it used as a last resort.
2. Memory resources would necessarily need to occupy space within the object, reducing the amount of available stack space by default.
### Describe alternatives you've considered
_No response_
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.