Make more CTL fixes

This commit is contained in:
Justine Tunney 2024-07-01 07:10:35 -07:00
parent 61370983e1
commit d0cd719375
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
4 changed files with 122 additions and 15 deletions

View file

@ -11,12 +11,12 @@ struct allocator_traits
{
using allocator_type = Alloc;
using value_type = typename Alloc::value_type;
using pointer = typename Alloc::pointer;
using const_pointer = typename Alloc::const_pointer;
using pointer = typename Alloc::value_type*;
using const_pointer = const typename Alloc::value_type*;
using void_pointer = void*;
using const_void_pointer = const void*;
using difference_type = typename Alloc::difference_type;
using size_type = typename Alloc::size_type;
using difference_type = ptrdiff_t;
using size_type = size_t;
using propagate_on_container_copy_assignment = ctl::false_type;
using propagate_on_container_move_assignment = ctl::true_type;
@ -24,10 +24,13 @@ struct allocator_traits
using is_always_equal = ctl::true_type;
template<typename T>
using rebind_alloc = typename Alloc::template rebind<T>::other;
struct rebind_alloc
{
using other = typename Alloc::template rebind<T>::other;
};
template<typename T>
using rebind_traits = allocator_traits<rebind_alloc<T>>;
using rebind_traits = allocator_traits<typename rebind_alloc<T>::other>;
static pointer allocate(Alloc& a, size_type n)
{
@ -53,7 +56,7 @@ struct allocator_traits
static size_type max_size(const Alloc& a) noexcept
{
return __PTRDIFF_MAX__ / sizeof(value_type);
return a.max_size();
}
static Alloc select_on_container_copy_construction(const Alloc& a)

View file

@ -332,6 +332,18 @@ class string
return *this;
}
string& operator+=(const char* s) noexcept
{
append(s);
return *this;
}
string& operator+=(const ctl::string s) noexcept
{
append(s);
return *this;
}
string& operator+=(const ctl::string_view s) noexcept
{
append(s);
@ -344,6 +356,11 @@ class string
return strcat(*this, s);
}
string operator+(const char* s) const noexcept
{
return strcat(*this, s);
}
string operator+(const string& s) const noexcept
{
return strcat(*this, s);
@ -354,11 +371,6 @@ class string
return strcat(*this, s);
}
string operator+(const char* s) const noexcept
{
return strcat(*this, s);
}
int compare(const ctl::string_view s) const noexcept
{
return strcmp(*this, s);

View file

@ -411,16 +411,17 @@ class vector
return erase(pos, pos + 1);
}
iterator erase(const_iterator first, const_iterator last)
constexpr iterator erase(const_iterator first, const_iterator last)
{
difference_type index = first - begin();
difference_type count = last - first;
iterator it = begin() + index;
ctl::move(it + count, end(), it);
for (iterator move_it = it + count; move_it != end(); ++move_it, ++it)
*it = ctl::move(*move_it);
for (difference_type i = 0; i < count; ++i)
ctl::allocator_traits<Allocator>::destroy(alloc_, end() - i - 1);
size_ -= count;
return it;
return begin() + index;
}
void push_back(const T& value)