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/.
10 #ifndef INCLUDED_SC_INC_STLALGORITHM_HXX
11 #define INCLUDED_SC_INC_STLALGORITHM_HXX
16 #include <rtl/alloc.h>
21 * Custom allocator for STL container to ensure that the base address of
22 * allocated storage is aligned to a specified boundary.
24 template<typename T
, size_t Alignment
>
25 class AlignedAllocator
29 typedef size_t size_type
;
30 typedef std::ptrdiff_t difference_type
;
33 typedef const T
* const_pointer
;
34 typedef T
* void_pointer
;
37 typedef const T
& const_reference
;
39 template<typename Type2
>
42 typedef AlignedAllocator
<Type2
,Alignment
> other
;
47 template<typename Type2
>
48 AlignedAllocator(const AlignedAllocator
<Type2
,Alignment
>&) {}
50 static void construct(T
* p
, const value_type
& val
) { new(p
) value_type(val
); }
51 static void destroy(T
* p
)
54 (void)p
; // avoid bogus MSVC '12 "unreferenced formal parameter" warning
57 static size_type
max_size()
59 return std::numeric_limits
<size_type
>::max() / sizeof(value_type
);
62 bool operator== (const AlignedAllocator
&) const { return true; }
63 bool operator!= (const AlignedAllocator
&) const { return false; }
65 static pointer
allocate(size_type n
)
67 return static_cast<pointer
>(rtl_allocateAlignedMemory(Alignment
, n
*sizeof(value_type
)));
70 static void deallocate(pointer p
, size_type
)
72 rtl_freeAlignedMemory(p
);
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */