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 42 : insert(C & container, std::unique_ptr<T> && element) {
24 42 : std::pair<typename C::iterator, bool> r(container.insert(element.get()));
25 42 : element.release();
26 42 : return r;
27 : }
28 :
29 : template<typename C, typename T> inline std::pair<typename C::iterator, bool>
30 328 : 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 328 : const_cast<typename C::key_type &>(key), element.get()));
47 328 : element.release();
48 328 : return r;
49 : }
50 :
51 : template<typename C, typename T>
52 2694 : inline void push_back(C & container, std::unique_ptr<T> && element) {
53 2694 : container.push_back(element.get());
54 2694 : element.release();
55 2694 : }
56 :
57 : } }
58 :
59 : #endif
60 :
61 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|