1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_COMPHELPER_STL_TYPES_HXX
20 #define INCLUDED_COMPHELPER_STL_TYPES_HXX
22 #include <sal/config.h>
26 #include <string_view>
28 #include <rtl/ustring.hxx>
29 #include <rtl/ustrbuf.hxx>
30 #include <o3tl/string_view.hxx>
32 namespace com::sun::star::uno
{ template <typename
> class Reference
; }
37 // comparison functors
42 bool m_bCaseSensitive
;
44 UStringMixLess(bool bCaseSensitive
= true):m_bCaseSensitive(bCaseSensitive
){}
45 bool operator() (std::u16string_view x
, std::u16string_view y
) const
50 return o3tl::compareToIgnoreAsciiCase(x
, y
) < 0;
53 bool isCaseSensitive() const {return m_bCaseSensitive
;}
58 bool const m_bCaseSensitive
;
61 UStringMixEqual(bool bCaseSensitive
= true):m_bCaseSensitive(bCaseSensitive
){}
62 bool operator() (std::u16string_view lhs
, std::u16string_view rhs
) const
64 return m_bCaseSensitive
? lhs
== rhs
: o3tl::equalsIgnoreAsciiCase( lhs
, rhs
);
66 bool isCaseSensitive() const {return m_bCaseSensitive
;}
69 /// by-value less functor for std::set<std::unique_ptr<T>>
70 template<class T
> struct UniquePtrValueLess
72 bool operator()(std::unique_ptr
<T
> const& lhs
,
73 std::unique_ptr
<T
> const& rhs
) const
77 return (*lhs
) < (*rhs
);
79 // The following are so we can search in std::set without allocating a temporary entry on the heap
80 typedef bool is_transparent
;
81 bool operator()(T
const& lhs
,
82 std::unique_ptr
<T
> const& rhs
) const
87 bool operator()(std::unique_ptr
<T
> const& lhs
,
95 /// by-value implementation of std::foo<std::unique_ptr<T>>::operator==
96 template<template<typename
, typename
...> class C
, typename T
, typename
... Etc
>
97 bool ContainerUniquePtrEquals(
98 C
<std::unique_ptr
<T
>, Etc
...> const& lhs
,
99 C
<std::unique_ptr
<T
>, Etc
...> const& rhs
)
101 return lhs
.size() == rhs
.size()
102 && std::equal(lhs
.begin(), lhs
.end(), rhs
.begin(),
103 [](const auto& p1
, const auto& p2
) { return *p1
== *p2
; });
107 template <class Tp
, class Arg
>
110 typedef void (Tp::*_fun_type
)(Arg
);
112 explicit mem_fun1_t(_fun_type pf
) : M_f(pf
) {}
113 void operator()(Tp
* p
, Arg x
) const { (p
->*M_f
)(x
); }
118 template <class Tp
, class Arg
>
119 inline mem_fun1_t
<Tp
,Arg
> mem_fun(void (Tp::*f
)(Arg
))
121 return mem_fun1_t
<Tp
,Arg
>(f
);
124 /** output iterator that appends OUStrings into an OUStringBuffer.
126 class OUStringBufferAppender
129 typedef OUStringBufferAppender Self
;
130 typedef ::std::output_iterator_tag iterator_category
;
131 typedef void value_type
;
132 typedef void reference
;
133 typedef void pointer
;
134 typedef size_t difference_type
;
136 OUStringBufferAppender(OUStringBuffer
& i_rBuffer
)
137 : m_rBuffer(&i_rBuffer
) { }
138 Self
& operator=(std::u16string_view i_rStr
)
140 m_rBuffer
->append( i_rStr
);
143 Self
& operator*() { return *this; } // so operator= works
144 Self
& operator++() { return *this; }
147 OUStringBuffer
* m_rBuffer
;
150 /** algorithm similar to std::copy, but inserts a separator between elements.
152 template< typename ForwardIter
, typename OutputIter
, typename T
>
153 OutputIter
intersperse(
154 ForwardIter start
, ForwardIter end
, OutputIter out
, T
const & separator
)
162 while (start
!= end
) {
175 #endif // INCLUDED_COMPHELPER_STL_TYPES_HXX
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */