gtsam
Loading...
Searching...
No Matches
FastList.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8 * See LICENSE for the license information
9
10 * -------------------------------------------------------------------------- */
11
18
19#pragma once
20
22#include <list>
23#if GTSAM_ENABLE_BOOST_SERIALIZATION
24#include <boost/serialization/nvp.hpp>
25#include <boost/serialization/version.hpp>
26#if BOOST_VERSION >= 107400
27#include <boost/serialization/library_version_type.hpp>
28#endif
29#include <boost/serialization/list.hpp>
30#endif
31
32namespace gtsam {
33
42template<typename VALUE>
43class FastList: public std::list<VALUE, typename internal::FastDefaultAllocator<VALUE>::type> {
44
45public:
46
47 typedef std::list<VALUE, typename internal::FastDefaultAllocator<VALUE>::type> Base;
48
51
53 template<typename INPUTITERATOR>
54 explicit FastList(INPUTITERATOR first, INPUTITERATOR last) : Base(first, last) {}
55
57 FastList(const FastList<VALUE>& x) : Base(x) {}
58
60 FastList(const Base& x) : Base(x) {}
61
63 FastList(std::initializer_list<VALUE> l) : Base(l) {}
64
65 FastList& operator=(const FastList& other) = default;
66
67#ifdef GTSAM_ALLOCATOR_BOOSTPOOL
69 FastList(const std::list<VALUE>& x) {
70 // This if statement works around a bug in boost pool allocator and/or
71 // STL vector where if the size is zero, the pool allocator will allocate
72 // huge amounts of memory.
73 if(x.size() > 0)
74 Base::assign(x.begin(), x.end());
75 }
76#endif
77
79 operator std::list<VALUE>() const {
80 return std::list<VALUE>(this->begin(), this->end());
81 }
82
83private:
84#if GTSAM_ENABLE_BOOST_SERIALIZATION
86 friend class boost::serialization::access;
87 template<class ARCHIVE>
88 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
89 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
90 }
91#endif
92
93};
94
95}
An easy way to control which allocator is used for Fast* collections.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
FastList is a thin wrapper around std::list that uses the boost fast_pool_allocator instead of the de...
Definition FastList.h:43
FastList(INPUTITERATOR first, INPUTITERATOR last)
Constructor from a range, passes through to base class.
Definition FastList.h:54
FastList()
Default constructor.
Definition FastList.h:50
FastList(std::initializer_list< VALUE > l)
Construct from c++11 initializer list:
Definition FastList.h:63
FastList(const FastList< VALUE > &x)
Copy constructor from another FastList.
Definition FastList.h:57
FastList(const Base &x)
Copy constructor from the base list class.
Definition FastList.h:60