diff options
author | Sean Silva <silvas@purdue.edu> | 2013-03-22 23:41:29 +0000 |
---|---|---|
committer | Sean Silva <silvas@purdue.edu> | 2013-03-22 23:41:29 +0000 |
commit | 4ee92f9de4aac5823d9b83a95e809d7f7685902f (patch) | |
tree | fa0355d30f5f1580888cc8a89566098e3dd872a1 /llvm/docs | |
parent | 9e331c2f9c8471ade4aebb2fa4db521c94a98c91 (diff) | |
download | bcm5719-llvm-4ee92f9de4aac5823d9b83a95e809d7f7685902f.tar.gz bcm5719-llvm-4ee92f9de4aac5823d9b83a95e809d7f7685902f.zip |
[docs] Document usage of SmallVectorImpl in interfaces.
llvm-svn: 177775
Diffstat (limited to 'llvm/docs')
-rw-r--r-- | llvm/docs/ProgrammersManual.rst | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/docs/ProgrammersManual.rst b/llvm/docs/ProgrammersManual.rst index 4fc45979330..eed12e94be3 100644 --- a/llvm/docs/ProgrammersManual.rst +++ b/llvm/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<T>`` in interfaces. + + In APIs that don't care about the "small size" (most?), prefer to use + the ``SmallVectorImpl<T>`` class, which is basically just the "vector + header" (and methods) without the elements allocated after it. Note that + ``SmallVector<T, N>`` inherits from ``SmallVectorImpl<T>`` so the + conversion is implicit and costs nothing. E.g. + + .. code-block:: c++ + + // BAD: Clients cannot pass e.g. SmallVector<Foo, 4>. + hardcodedSmallSize(SmallVector<Foo, 2> &Out); + // GOOD: Clients can pass any SmallVector<Foo, N>. + allowsAnySmallSize(SmallVectorImpl<Foo> &Out); + + void someFunc() { + SmallVector<Foo, 8> 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: <vector> |