Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions examples/chapter11_07a/src/util/STL/impl/allocator_impl.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2007 - 2013.
// Copyright Christopher Kormanyos 2007 - 2026.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#ifndef ALLOCATOR_IMPL_2010_02_23_H_
#define ALLOCATOR_IMPL_2010_02_23_H_
#ifndef ALLOCATOR_IMPL_2010_02_23_H
#define ALLOCATOR_IMPL_2010_02_23_H

#include <cstddef>
#include <iterator>
Expand All @@ -16,7 +16,7 @@
namespace std
{
template<typename iterator_type, typename allocator_type>
inline void destroy_range(iterator_type first, iterator_type last, allocator_type a)
inline void destroy_range(iterator_type first, iterator_type last, allocator_type& a)
{
while(first != last)
{
Expand All @@ -27,12 +27,15 @@
}

template<typename iterator_type, typename allocator_type>
inline void deallocate_range(iterator_type first, iterator_type last, allocator_type a)
inline void deallocate_range(iterator_type first, iterator_type last, allocator_type& a)
{
const std::size_t count = static_cast<std::size_t>(std::distance(first, last));
if(first != last)
{
const std::size_t count = static_cast<std::size_t>(std::distance(first, last));

a.deallocate(first, count);
a.deallocate(first, count);
}
}
}

#endif // ALLOCATOR_IMPL_2010_02_23_H_
#endif // ALLOCATOR_IMPL_2010_02_23_H
53 changes: 39 additions & 14 deletions examples/chapter11_07a/src/util/STL/vector
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,18 @@
range_construct(first, last, typename std::iterator_traits<input_iterator>::iterator_category());
}

vector(const vector& other) : my_allocator(other.my_allocator),
my_first(allocate_storage(my_allocator, other.size())),
my_last (end_pointer(my_first, other.size())),
my_end (my_last)
vector(const vector& other) : my_allocator(other.my_allocator),
my_first(allocate_storage(my_allocator, other.size())),
my_last (end_pointer(my_first, other.size())),
my_end (my_last)
{
copy_construct(other.my_first, other.my_last, my_first);
}

vector(const vector& other, const allocator_type& a) : my_allocator(a),
my_first(allocate_storage(my_allocator, other.size())),
my_last (end_pointer(my_first, other.size())),
my_end (my_last)
my_first(allocate_storage(my_allocator, other.size())),
my_last (end_pointer(my_first, other.size())),
my_end (my_last)
{
copy_construct(other.my_first, other.my_last, my_first);
}
Expand All @@ -138,9 +138,9 @@
}

vector(vector&& other, const allocator_type& a) : my_allocator(a),
my_first(nullptr),
my_last (nullptr),
my_end (nullptr)
my_first(nullptr),
my_last (nullptr),
my_end (nullptr)
{
if(my_allocator == other.my_allocator)
{
Expand All @@ -164,7 +164,7 @@
const allocator_type& a = allocator_type()) : my_allocator(a),
my_first(allocate_storage(my_allocator, lst.size())),
my_last (end_pointer(my_first, lst.size())),
my_end (my_last)
my_end (my_last)
{
copy_construct(lst.begin(), lst.end(), my_first);
}
Expand Down Expand Up @@ -332,8 +332,9 @@
template<typename input_iterator>
void assign(input_iterator first, input_iterator last)
{
clear();
for(; first != last; ++first) { push_back(*first); }
assign_range(first,
last,
typename std::iterator_traits<input_iterator>::iterator_category());
}

void push_back(const value_type& value)
Expand Down Expand Up @@ -474,6 +475,31 @@
}
}

template<typename input_iterator>
void assign_range(input_iterator first,
input_iterator last,
std::input_iterator_tag)
{
clear();
for(; first != last; ++first) { push_back(*first); }
}

template<typename forward_iterator>
void assign_range(forward_iterator first,
forward_iterator last,
std::forward_iterator_tag)
{
const size_type count = static_cast<size_type>(std::distance(first, last));

clear();
reserve(count);

for(; first != last; ++first)
{
push_back(*first);
}
}

template<typename input_iterator>
void range_construct(input_iterator first,
input_iterator last,
Expand Down Expand Up @@ -501,7 +527,6 @@
construct(destination, *first);
}
}

};

template<typename T, typename alloc>
Expand Down
19 changes: 11 additions & 8 deletions ref_app/src/util/STL/impl/allocator_impl.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2007 - 2013.
// Copyright Christopher Kormanyos 2007 - 2026.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//

#ifndef ALLOCATOR_IMPL_2010_02_23_H_
#define ALLOCATOR_IMPL_2010_02_23_H_
#ifndef ALLOCATOR_IMPL_2010_02_23_H
#define ALLOCATOR_IMPL_2010_02_23_H

#include <cstddef>
#include <iterator>
Expand All @@ -16,7 +16,7 @@
namespace std
{
template<typename iterator_type, typename allocator_type>
inline void destroy_range(iterator_type first, iterator_type last, allocator_type a)
inline void destroy_range(iterator_type first, iterator_type last, allocator_type& a)
{
while(first != last)
{
Expand All @@ -27,12 +27,15 @@
}

template<typename iterator_type, typename allocator_type>
inline void deallocate_range(iterator_type first, iterator_type last, allocator_type a)
inline void deallocate_range(iterator_type first, iterator_type last, allocator_type& a)
{
const std::size_t count = static_cast<std::size_t>(std::distance(first, last));
if(first != last)
{
const std::size_t count = static_cast<std::size_t>(std::distance(first, last));

a.deallocate(first, count);
a.deallocate(first, count);
}
}
}

#endif // ALLOCATOR_IMPL_2010_02_23_H_
#endif // ALLOCATOR_IMPL_2010_02_23_H
53 changes: 39 additions & 14 deletions ref_app/src/util/STL/vector
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,18 @@
range_construct(first, last, typename std::iterator_traits<input_iterator>::iterator_category());
}

vector(const vector& other) : my_allocator(other.my_allocator),
my_first(allocate_storage(my_allocator, other.size())),
my_last (end_pointer(my_first, other.size())),
my_end (my_last)
vector(const vector& other) : my_allocator(other.my_allocator),
my_first(allocate_storage(my_allocator, other.size())),
my_last (end_pointer(my_first, other.size())),
my_end (my_last)
{
copy_construct(other.my_first, other.my_last, my_first);
}

vector(const vector& other, const allocator_type& a) : my_allocator(a),
my_first(allocate_storage(my_allocator, other.size())),
my_last (end_pointer(my_first, other.size())),
my_end (my_last)
my_first(allocate_storage(my_allocator, other.size())),
my_last (end_pointer(my_first, other.size())),
my_end (my_last)
{
copy_construct(other.my_first, other.my_last, my_first);
}
Expand All @@ -138,9 +138,9 @@
}

vector(vector&& other, const allocator_type& a) : my_allocator(a),
my_first(nullptr),
my_last (nullptr),
my_end (nullptr)
my_first(nullptr),
my_last (nullptr),
my_end (nullptr)
{
if(my_allocator == other.my_allocator)
{
Expand All @@ -164,7 +164,7 @@
const allocator_type& a = allocator_type()) : my_allocator(a),
my_first(allocate_storage(my_allocator, lst.size())),
my_last (end_pointer(my_first, lst.size())),
my_end (my_last)
my_end (my_last)
{
copy_construct(lst.begin(), lst.end(), my_first);
}
Expand Down Expand Up @@ -332,8 +332,9 @@
template<typename input_iterator>
void assign(input_iterator first, input_iterator last)
{
clear();
for(; first != last; ++first) { push_back(*first); }
assign_range(first,
last,
typename std::iterator_traits<input_iterator>::iterator_category());
}

void push_back(const value_type& value)
Expand Down Expand Up @@ -474,6 +475,31 @@
}
}

template<typename input_iterator>
void assign_range(input_iterator first,
input_iterator last,
std::input_iterator_tag)
{
clear();
for(; first != last; ++first) { push_back(*first); }
}

template<typename forward_iterator>
void assign_range(forward_iterator first,
forward_iterator last,
std::forward_iterator_tag)
{
const size_type count = static_cast<size_type>(std::distance(first, last));

clear();
reserve(count);

for(; first != last; ++first)
{
push_back(*first);
}
}

template<typename input_iterator>
void range_construct(input_iterator first,
input_iterator last,
Expand Down Expand Up @@ -501,7 +527,6 @@
construct(destination, *first);
}
}

};

template<typename T, typename alloc>
Expand Down
Loading
Loading