In regards to the boost::circular_buffer class,
I'm able to instantiate a simple one as follows:
#include<boost/circular_buffer.hpp>
int main() {
boost::circular_buffer<double> buffer;
}
The circular_buffer class is templatized with
template<typename T, typename Alloc>
class circular_buffer {
...
typedef Alloc allocator_type;
...
}
and I believe the constructor being called is
explicit circular_buffer(const allocator_type & = allocator_type()) noexcept;
What i don't understand is where buffer
is getting its default allocator? The documentation states that, if one isn't explicitly provided, the Default Alloc object is an std::allocator<T>
, but I don't see where this is being set. I'm not trying to change it, I'm just trying to understand the design of this class from a c++/software-engineering point of view.
The class receives the allocator type as a template argument:
template<typename T, typename Alloc>
class circular_buffer {
and the constructor argument just default-constructs an instance of that type.
If you use circular_buffer
without specifying the Alloc
template argument it uses the default specified in the base template declaration:
template <class T, class Alloc = BOOST_CB_DEFAULT_ALLOCATOR(T)>
class circular_buffer;
This is hiding in the circular_buffer_fwd.hpp
header. The macro evaluates to std::allocator<T>
or equivalent if the platform doesn't have that.
The circular_buffer_fwd.hpp
header takes care of setting the default allocator
template <class T, class Alloc = BOOST_CB_DEFAULT_ALLOCATOR(T)>
class circular_buffer;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With