LCOV - code coverage report
Current view: top level - src/util - vector.h (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 20 20 100.0 %
Date: 2022-04-21 14:51:19 Functions: 27 27 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 17 18 94.4 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2019 The Bitcoin Core developers
#       2                 :            : // Distributed under the MIT software license, see the accompanying
#       3                 :            : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#       4                 :            : 
#       5                 :            : #ifndef BITCOIN_UTIL_VECTOR_H
#       6                 :            : #define BITCOIN_UTIL_VECTOR_H
#       7                 :            : 
#       8                 :            : #include <initializer_list>
#       9                 :            : #include <type_traits>
#      10                 :            : #include <vector>
#      11                 :            : 
#      12                 :            : /** Construct a vector with the specified elements.
#      13                 :            :  *
#      14                 :            :  * This is preferable over the list initializing constructor of std::vector:
#      15                 :            :  * - It automatically infers the element type from its arguments.
#      16                 :            :  * - If any arguments are rvalue references, they will be moved into the vector
#      17                 :            :  *   (list initialization always copies).
#      18                 :            :  */
#      19                 :            : template<typename... Args>
#      20                 :            : inline std::vector<typename std::common_type<Args...>::type> Vector(Args&&... args)
#      21                 :     836662 : {
#      22                 :     836662 :     std::vector<typename std::common_type<Args...>::type> ret;
#      23                 :     836662 :     ret.reserve(sizeof...(args));
#      24                 :            :     // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html
#      25                 :     836662 :     (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...};
#      26                 :     836662 :     return ret;
#      27                 :     836662 : }
#      28                 :            : 
#      29                 :            : /** Concatenate two vectors, moving elements. */
#      30                 :            : template<typename V>
#      31                 :            : inline V Cat(V v1, V&& v2)
#      32                 :      21959 : {
#      33                 :      21959 :     v1.reserve(v1.size() + v2.size());
#      34 [ +  + ][ +  + ]:     264631 :     for (auto& arg : v2) {
#         [ -  + ][ +  + ]
#                 [ +  + ]
#      35                 :     264631 :         v1.push_back(std::move(arg));
#      36                 :     264631 :     }
#      37                 :      21959 :     return v1;
#      38                 :      21959 : }
#      39                 :            : 
#      40                 :            : /** Concatenate two vectors. */
#      41                 :            : template<typename V>
#      42                 :            : inline V Cat(V v1, const V& v2)
#      43                 :     178153 : {
#      44                 :     178153 :     v1.reserve(v1.size() + v2.size());
#      45 [ +  + ][ +  + ]:    4172414 :     for (const auto& arg : v2) {
#         [ +  + ][ +  + ]
#      46                 :    4172414 :         v1.push_back(arg);
#      47                 :    4172414 :     }
#      48                 :     178153 :     return v1;
#      49                 :     178153 : }
#      50                 :            : 
#      51                 :            : #endif // BITCOIN_UTIL_VECTOR_H

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a