From 0059eb1e2e779f6537c1da9d9ff4679e19e23628 Mon Sep 17 00:00:00 2001 From: Sean Silva Date: Fri, 22 Mar 2013 23:41:29 +0000 Subject: [PATCH] [docs] Document usage of SmallVectorImpl in interfaces. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@177775 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ProgrammersManual.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/ProgrammersManual.rst b/docs/ProgrammersManual.rst index 4fc45979330..eed12e94be3 100644 --- a/docs/ProgrammersManual.rst +++ b/docs/ProgrammersManual.rst @@ -626,6 +626,33 @@ SmallVectors are most useful when on the stack. SmallVector also provides a nice portable and efficient replacement for ``alloca``. +.. note:: + + Prefer to use ``SmallVectorImpl`` in interfaces. + + In APIs that don't care about the "small size" (most?), prefer to use + the ``SmallVectorImpl`` class, which is basically just the "vector + header" (and methods) without the elements allocated after it. Note that + ``SmallVector`` inherits from ``SmallVectorImpl`` so the + conversion is implicit and costs nothing. E.g. + + .. code-block:: c++ + + // BAD: Clients cannot pass e.g. SmallVector. + hardcodedSmallSize(SmallVector &Out); + // GOOD: Clients can pass any SmallVector. + allowsAnySmallSize(SmallVectorImpl &Out); + + void someFunc() { + SmallVector Vec; + hardcodedSmallSize(Vec); // Error. + allowsAnySmallSize(Vec); // Works. + } + + Even though it has "``Impl``" in the name, this is so widely used that + it really isn't "private to the implementation" anymore. A name like + ``SmallVectorHeader`` would be more appropriate. + .. _dss_vector: -- 2.34.1