LCOV - code coverage report
Current view: top level - include/o3tl - ptr_container.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 12 12 100.0 %
Date: 2015-06-13 12:38:46 Functions: 10 19 52.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #ifndef INCLUDED_O3TL_PTR_CONTAINER_HXX
      11             : #define INCLUDED_O3TL_PTR_CONTAINER_HXX
      12             : 
      13             : #include <sal/config.h>
      14             : 
      15             : #include <memory>
      16             : #include <utility>
      17             : 
      18             : // Some glue for using std::unique_ptr with the Boost Pointer Container Library:
      19             : 
      20             : namespace o3tl { namespace ptr_container {
      21             : 
      22             : template<typename C, typename T> inline std::pair<typename C::iterator, bool>
      23          25 : insert(C & container, std::unique_ptr<T> && element) {
      24          25 :     std::pair<typename C::iterator, bool> r(container.insert(element.get()));
      25          25 :     element.release();
      26          25 :     return r;
      27             : }
      28             : 
      29             : template<typename C, typename T> inline std::pair<typename C::iterator, bool>
      30         186 : insert(
      31             :     C & container, typename C::key_type const & key,
      32             :     std::unique_ptr<T> && element)
      33             : {
      34             :     // At least Boost <= 1.56.0 boost::ptr_map_adaptor has odd key const-ness
      35             :     // discrepancy between
      36             :     //
      37             :     //   std::pair<iterator,bool> insert( key_type& k, T* x )
      38             :     //
      39             :     // and
      40             :     //
      41             :     //   template< class U >
      42             :     //   std::pair<iterator,bool> insert( const key_type& k,
      43             :     //                                    std::auto_ptr<U> x )
      44             :     std::pair<typename C::iterator, bool> r(
      45             :         container.insert(
      46         186 :             const_cast<typename C::key_type &>(key), element.get()));
      47         186 :     element.release();
      48         186 :     return r;
      49             : }
      50             : 
      51             : template<typename C, typename T>
      52        1475 : inline void push_back(C & container, std::unique_ptr<T> && element) {
      53        1475 :     container.push_back(element.get());
      54        1475 :     element.release();
      55        1475 : }
      56             : 
      57             : } }
      58             : 
      59             : #endif
      60             : 
      61             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11