Add noexcept specification to list

This commit is contained in:
rexy712 2022-07-20 17:29:08 -07:00
parent dff3303733
commit 2fe6f0b4e1
3 changed files with 497 additions and 148 deletions

View File

@ -20,12 +20,14 @@
#define REXY_LLIST_HPP
#include <cstddef> //size_t, ptrdiff_t
#include "allocator.hpp" //TODO
#include "allocator.hpp"
#include "detail/hasallocator.hpp"
#include "traits.hpp"
#include <iterator> //bidirectional_iterator_tag, reverse_iterator
#include <memory> //allocator_traits
#include <initializer_list>
#include <utility> //pair
#include <type_traits>
namespace rexy{
@ -74,21 +76,58 @@ namespace rexy{
size_type m_size = 0;
public:
constexpr list(void) = default;
constexpr explicit list(const allocator_type& alloc);
REXY_CPP20_CONSTEXPR list(size_type count, const_reference value = value_type(), const allocator_type& = allocator_type());
REXY_CPP20_CONSTEXPR explicit list(size_type count, const allocator_type& alloc = allocator_type());
constexpr list(void)noexcept = default;
constexpr explicit list(const allocator_type& alloc)noexcept;
REXY_CPP20_CONSTEXPR
list(size_type count, const_reference value = value_type(), const allocator_type& = allocator_type())noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
explicit list(size_type count, const allocator_type& alloc = allocator_type())noexcept(
std::is_nothrow_default_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
template<class InputIt>
REXY_CPP20_CONSTEXPR list(InputIt first, InputIt last, const allocator_type& alloc = allocator_type());
REXY_CPP20_CONSTEXPR list(const list& other, const allocator_type& alloc = allocator_type());
REXY_CPP20_CONSTEXPR list(list&& other, const allocator_type& alloc = allocator_type());
REXY_CPP20_CONSTEXPR list(std::initializer_list<value_type> l, const allocator_type& alloc = allocator_type());
REXY_CPP20_CONSTEXPR
list(InputIt first, InputIt last, const allocator_type& alloc = allocator_type())noexcept(
std::is_nothrow_constructible_v<value_type, decltype(*first)> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR ~list(void);
REXY_CPP20_CONSTEXPR
list(const list& other, const allocator_type& alloc = allocator_type())noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR list& operator=(const list& other);
REXY_CPP20_CONSTEXPR list& operator=(list&& other);
REXY_CPP20_CONSTEXPR list& operator=(std::initializer_list<value_type> l);
REXY_CPP20_CONSTEXPR
list(list&& other, const allocator_type& alloc = allocator_type())noexcept;
REXY_CPP20_CONSTEXPR
list(std::initializer_list<value_type> l, const allocator_type& alloc = allocator_type())noexcept(
std::is_nothrow_constructible_v<value_type, decltype(*l.begin())> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
~list(void)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
list& operator=(const list& other)noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
list& operator=(list&& other)noexcept;
REXY_CPP20_CONSTEXPR
list& operator=(std::initializer_list<value_type> l)noexcept(
std::is_nothrow_constructible_v<value_type, decltype(*l.begin())> &&
is_nothrow_allocator_v<node_allocator_type>);
constexpr bool operator==(const list& other)const noexcept;
#if __cpp_impl_three_way_comparison
@ -101,17 +140,45 @@ namespace rexy{
constexpr bool operator>=(const list& other)const noexcept;
#endif
REXY_CPP20_CONSTEXPR void assign(size_type count, const_reference value);
REXY_CPP20_CONSTEXPR
void assign(size_type count, const_reference value)noexcept(
std::conditional_t<
std::is_copy_assignable_v<value_type>,
std::is_nothrow_copy_assignable<value_type>,
std::true_type>::value &&
std::is_nothrow_copy_constructible_v<value_type> &&
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
template<class InputIt>
REXY_CPP20_CONSTEXPR void assign(InputIt first, InputIt last);
REXY_CPP20_CONSTEXPR void assign(std::initializer_list<value_type> l);
REXY_CPP20_CONSTEXPR
void assign(InputIt first, InputIt last)noexcept(
std::conditional_t<
std::is_assignable_v<value_type, decltype(*first)>,
std::is_nothrow_assignable<value_type, decltype(*first)>,
std::true_type>::value &&
std::is_nothrow_constructible_v<value_type, decltype(*first)> &&
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
void assign(std::initializer_list<value_type> l)noexcept(
std::conditional_t<
std::is_assignable_v<value_type, decltype(*l.begin())>,
std::is_nothrow_assignable<value_type, decltype(*l.begin())>,
std::true_type>::value &&
std::is_nothrow_constructible_v<value_type, decltype(*l.begin())> &&
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
constexpr allocator_type get_allocator(void)const noexcept;
constexpr reference front(void);
constexpr const_reference front(void)const;
constexpr reference back(void);
constexpr const_reference back(void)const;
constexpr reference front(void)noexcept;
constexpr const_reference front(void)const noexcept;
constexpr reference back(void)noexcept;
constexpr const_reference back(void)const noexcept;
constexpr iterator begin(void)noexcept;
constexpr const_iterator begin(void)const noexcept;
@ -137,74 +204,193 @@ namespace rexy{
constexpr size_type size(void)const noexcept;
constexpr size_type max_size(void)const noexcept;
REXY_CPP20_CONSTEXPR void clear(void)noexcept;
REXY_CPP20_CONSTEXPR iterator insert(const_iterator pos, const_reference value);
REXY_CPP20_CONSTEXPR iterator insert(const_iterator pos, value_type&& value);
REXY_CPP20_CONSTEXPR iterator insert(const_iterator pos, size_type count, const_reference value);
REXY_CPP20_CONSTEXPR
void clear(void)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
iterator insert(const_iterator pos, const_reference value)noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
iterator insert(const_iterator pos, value_type&& value)noexcept(
std::is_nothrow_move_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
iterator insert(const_iterator pos, size_type count, const_reference value)noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
template<class InputIt>
REXY_CPP20_CONSTEXPR iterator insert(const_iterator pos, InputIt first, InputIt last);
REXY_CPP20_CONSTEXPR iterator insert(const_iterator pos, std::initializer_list<value_type> l);
REXY_CPP20_CONSTEXPR
iterator insert(const_iterator pos, InputIt first, InputIt last)noexcept(
std::is_nothrow_constructible_v<value_type, decltype(*first)> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
iterator insert(const_iterator pos, std::initializer_list<value_type> l)noexcept(
std::is_nothrow_constructible_v<value_type, decltype(*l.begin())> &&
is_nothrow_allocator_v<node_allocator_type>);
template<class... Args>
REXY_CPP20_CONSTEXPR iterator emplace(const_iterator pos, Args&&... args);
REXY_CPP20_CONSTEXPR
iterator emplace(const_iterator pos, Args&&... args)noexcept(
std::is_nothrow_constructible_v<value_type, Args&&...> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR iterator erase(const_iterator pos);
REXY_CPP20_CONSTEXPR iterator erase(const_iterator first, const_iterator last);
REXY_CPP20_CONSTEXPR reference push_back(const_reference value);
REXY_CPP20_CONSTEXPR reference push_back(value_type&& value);
REXY_CPP20_CONSTEXPR
iterator erase(const_iterator pos)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
iterator erase(const_iterator first, const_iterator last)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
reference push_back(const_reference value)noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
reference push_back(value_type&& value)noexcept(
std::is_nothrow_move_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
template<class... Args>
REXY_CPP20_CONSTEXPR reference emplace_back(Args&&... args);
REXY_CPP20_CONSTEXPR
reference emplace_back(Args&&... args)noexcept(
std::is_nothrow_constructible_v<value_type, Args&&...> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR void pop_back(void);
REXY_CPP20_CONSTEXPR
void pop_back(void)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
reference push_front(const_reference value)noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
reference push_front(value_type&& value)noexcept(
std::is_nothrow_move_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR reference push_front(const_reference value);
REXY_CPP20_CONSTEXPR reference push_front(value_type&& value);
template<class... Args>
REXY_CPP20_CONSTEXPR reference emplace_front(Args&&... args);
REXY_CPP20_CONSTEXPR
reference emplace_front(Args&&... args)noexcept(
std::is_nothrow_constructible_v<value_type, Args&&...> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR void pop_front(void);
REXY_CPP20_CONSTEXPR
void pop_front(void)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR void resize(size_type count);
REXY_CPP20_CONSTEXPR void resize(size_type count, value_type value);
REXY_CPP20_CONSTEXPR void swap(list& other);
REXY_CPP20_CONSTEXPR
void resize(size_type count)noexcept(
std::is_nothrow_default_constructible_v<value_type> &&
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR void merge(list&& other);
REXY_CPP20_CONSTEXPR
void resize(size_type count, value_type value)noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
void swap(list& other)noexcept;
REXY_CPP20_CONSTEXPR
void merge(list&& other)noexcept;
template<class Comp>
REXY_CPP20_CONSTEXPR void merge(list&& other, Comp comp);
REXY_CPP20_CONSTEXPR
void merge(list&& other, Comp comp)noexcept;
REXY_CPP20_CONSTEXPR void splice(const_iterator pos, list&& other);
REXY_CPP20_CONSTEXPR void splice(const_iterator pos, list&& other, const_iterator it);
REXY_CPP20_CONSTEXPR void splice(const_iterator pos, list&& other, const_iterator first, const_iterator last);
REXY_CPP20_CONSTEXPR size_type remove(const_reference value);
REXY_CPP20_CONSTEXPR
void splice(const_iterator pos, list&& other)noexcept;
REXY_CPP20_CONSTEXPR
void splice(const_iterator pos, list&& other, const_iterator it)noexcept;
REXY_CPP20_CONSTEXPR
void splice(const_iterator pos, list&& other, const_iterator first, const_iterator last)noexcept;
REXY_CPP20_CONSTEXPR
size_type remove(const_reference value)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
template<class UnaryPred>
REXY_CPP20_CONSTEXPR size_type remove_if(UnaryPred p);
REXY_CPP20_CONSTEXPR
size_type remove_if(UnaryPred p)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR void reverse(void)noexcept;
REXY_CPP20_CONSTEXPR
void reverse(void)noexcept;
REXY_CPP20_CONSTEXPR
size_type unique(void)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR size_type unique(void);
template<class BinaryPred>
REXY_CPP20_CONSTEXPR size_type unique(BinaryPred p);
REXY_CPP20_CONSTEXPR
size_type unique(BinaryPred p)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
void sort(void)noexcept;
REXY_CPP20_CONSTEXPR void sort(void);
template<class Comp>
REXY_CPP20_CONSTEXPR void sort(Comp comp);
REXY_CPP20_CONSTEXPR
void sort(Comp comp)noexcept;
private:
template<class InputIt>
REXY_CPP20_CONSTEXPR void iterator_initialize_(InputIt first, InputIt last);
REXY_CPP20_CONSTEXPR void constant_initialize_(size_type count, const_reference value);
REXY_CPP20_CONSTEXPR void default_initialize_(size_type count);
REXY_CPP20_CONSTEXPR
void iterator_initialize_(InputIt first, InputIt last)noexcept(
std::is_nothrow_constructible_v<value_type, decltype(*first)> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
void constant_initialize_(size_type count, const_reference value)noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
REXY_CPP20_CONSTEXPR
void default_initialize_(size_type count)noexcept(
std::is_nothrow_default_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>);
template<class Comp>
static iterator mergesort(iterator first, size_type firstlen, Comp comp);
static std::pair<iterator,size_type> ms_split(iterator it, size_type len);
static iterator mergesort(iterator first, size_type firstlen, Comp comp)noexcept;
static std::pair<iterator,size_type> ms_split(iterator it, size_type len)noexcept;
static void insert_node_(detail::list_node_base* prev, detail::list_node_base* n);
static void remove_node_(detail::list_node_base* rm);
static detail::list_node_base* get_next_then_move_node_(detail::list_node_base* dest, detail::list_node_base* n);
static void insert_node_(detail::list_node_base* prev, detail::list_node_base* n)noexcept;
static void remove_node_(detail::list_node_base* rm)noexcept;
static detail::list_node_base* get_next_then_move_node_(detail::list_node_base* dest, detail::list_node_base* n)noexcept;
};
}

View File

@ -173,62 +173,91 @@ namespace rexy{
}
template<class T, class Alloc>
constexpr list<T,Alloc>::list(const allocator_type& alloc):
constexpr list<T,Alloc>::list(const allocator_type& alloc)noexcept:
node_allocator_type(alloc){}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR list<T,Alloc>::list(size_type count, const_reference value, const allocator_type& alloc):
REXY_CPP20_CONSTEXPR
list<T,Alloc>::list(size_type count, const_reference value, const allocator_type& alloc)noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>):
node_allocator_type(alloc)
{
constant_initialize_(count, value);
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR list<T,Alloc>::list(size_type count, const allocator_type& alloc):
REXY_CPP20_CONSTEXPR
list<T,Alloc>::list(size_type count, const allocator_type& alloc)noexcept(
std::is_nothrow_default_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>):
node_allocator_type(alloc)
{
default_initialize_(count);
}
template<class T, class Alloc>
template<class InputIt>
REXY_CPP20_CONSTEXPR list<T,Alloc>::list(InputIt first, InputIt last, const allocator_type& alloc):
REXY_CPP20_CONSTEXPR
list<T,Alloc>::list(InputIt first, InputIt last, const allocator_type& alloc)noexcept(
std::is_nothrow_constructible_v<value_type, decltype(*first)> &&
is_nothrow_allocator_v<node_allocator_type>):
node_allocator_type(alloc)
{
iterator_initialize_(first, last);
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR list<T,Alloc>::list(const list& other, const allocator_type& alloc):
REXY_CPP20_CONSTEXPR
list<T,Alloc>::list(const list& other, const allocator_type& alloc)noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>):
node_allocator_type(alloc)
{
iterator_initialize_(other.begin(), other.end());
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR list<T,Alloc>::list(list&& other, const allocator_type& alloc):
REXY_CPP20_CONSTEXPR
list<T,Alloc>::list(list&& other, const allocator_type& alloc)noexcept:
node_allocator_type(alloc)
{
swap(other);
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR list<T,Alloc>::list(std::initializer_list<value_type> l, const allocator_type& alloc):
REXY_CPP20_CONSTEXPR
list<T,Alloc>::list(std::initializer_list<value_type> l, const allocator_type& alloc)noexcept(
std::is_nothrow_constructible_v<value_type, decltype(*l.begin())> &&
is_nothrow_allocator_v<node_allocator_type>):
node_allocator_type(alloc)
{
iterator_initialize_(l.begin(), l.end());
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR list<T,Alloc>::~list(void){
REXY_CPP20_CONSTEXPR
list<T,Alloc>::~list(void)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>)
{
clear();
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::operator=(const list& other) -> list&{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::operator=(const list& other)noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>) -> list&
{
return (*this = list(other));
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::operator=(list&& other) -> list&{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::operator=(list&& other)noexcept -> list&{
swap(other);
return *this;
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::operator=(std::initializer_list<value_type> l) -> list&{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::operator=(std::initializer_list<value_type> l)noexcept(
std::is_nothrow_constructible_v<value_type, decltype(*l.begin())> &&
is_nothrow_allocator_v<node_allocator_type>) -> list&
{
return (*this = list(l));
}
@ -267,36 +296,37 @@ namespace rexy{
#endif
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::assign(size_type count, const_reference value){
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::assign(size_type count, const_reference value)noexcept(
std::conditional_t<
std::is_copy_assignable_v<value_type>,
std::is_nothrow_copy_assignable<value_type>,
std::true_type>::value &&
std::is_nothrow_copy_constructible_v<value_type> &&
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>)
{
assign(sized_constant_iterator{value, count}, sized_constant_iterator<value_type>{{}, 0});
}
template<class T, class Alloc>
template<class InputIt>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::iterator_initialize_(InputIt first, InputIt last){
for(;first != last;++first){
emplace_back(*first);
}
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::constant_initialize_(size_type count, const_reference value){
for(;count > 0;--count){
emplace_back(value);
}
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::default_initialize_(size_type count){
for(;count > 0;--count){
emplace_back();
}
}
template<class T, class Alloc>
template<class InputIt>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::assign(InputIt first, InputIt last){
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::assign(InputIt first, InputIt last)noexcept(
std::conditional_t<
std::is_assignable_v<value_type, decltype(*first)>,
std::is_nothrow_assignable<value_type, decltype(*first)>,
std::true_type>::value &&
std::is_nothrow_constructible_v<value_type, decltype(*first)> &&
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>)
{
auto current = begin();
size_type i = 0;
for(;i < m_size && first != last;++i){
*current++ = *first++;
if constexpr(std::is_assignable_v<value_type, decltype(*first)>){
for(;i < m_size && first != last;++i){
*current++ = *first++;
}
}
if(first != last){
m_size = i;
@ -308,7 +338,16 @@ namespace rexy{
}
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::assign(std::initializer_list<value_type> l){
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::assign(std::initializer_list<value_type> l)noexcept(
std::conditional_t<
std::is_assignable_v<value_type, decltype(*l.begin())>,
std::is_nothrow_assignable<value_type, decltype(*l.begin())>,
std::true_type>::value &&
std::is_nothrow_constructible_v<value_type, decltype(*l.begin())> &&
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>)
{
assign(l.begin(), l.end());
}
@ -317,13 +356,13 @@ namespace rexy{
//Direct accessors
template<class T, class Alloc>
constexpr auto list<T,Alloc>::front(void) -> reference{return *begin();}
constexpr auto list<T,Alloc>::front(void)noexcept -> reference{return *begin();}
template<class T, class Alloc>
constexpr auto list<T,Alloc>::front(void)const -> const_reference{return *begin();}
constexpr auto list<T,Alloc>::front(void)const noexcept -> const_reference{return *begin();}
template<class T, class Alloc>
constexpr auto list<T,Alloc>::back(void) -> reference{return *(--end());}
constexpr auto list<T,Alloc>::back(void)noexcept -> reference{return *(--end());}
template<class T, class Alloc>
constexpr auto list<T,Alloc>::back(void)const -> const_reference{return *(--end());}
constexpr auto list<T,Alloc>::back(void)const noexcept-> const_reference{return *(--end());}
//Iterators
template<class T, class Alloc>
@ -339,9 +378,7 @@ namespace rexy{
template<class T, class Alloc>
constexpr auto list<T,Alloc>::cend(void)const noexcept -> const_iterator{return const_iterator{&m_sentinel};}
template<class T, class Alloc>
constexpr auto list<T,Alloc>::next(iterator i)noexcept -> iterator{
return i.next();
}
constexpr auto list<T,Alloc>::next(iterator i)noexcept -> iterator{return i.next();}
template<class T, class Alloc>
constexpr auto list<T,Alloc>::next(const_iterator i)noexcept -> const_iterator{return i.next();}
template<class T, class Alloc>
@ -370,16 +407,28 @@ namespace rexy{
constexpr auto list<T,Alloc>::max_size(void)const noexcept -> size_type{return std::numeric_limits<difference_type>::max();}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::clear(void)noexcept{
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::clear(void)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>)
{
erase(begin(), end());
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::insert(const_iterator pos, const_reference value) -> iterator{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::insert(const_iterator pos, const_reference value)noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>) -> iterator
{
return insert(pos, value_type{value});
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::insert(const_iterator pos, value_type&& value) -> iterator{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::insert(const_iterator pos, value_type&& value)noexcept(
std::is_nothrow_move_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>) -> iterator
{
auto* prev = (--pos).unconst().nod();
auto* next = prev->next;
prev->next = this->allocate(1);
@ -389,7 +438,11 @@ namespace rexy{
return iterator{prev->next};
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::insert(const_iterator pos, size_type count, const_reference value) -> iterator{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::insert(const_iterator pos, size_type count, const_reference value)noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>) -> iterator
{
auto start = pos.unconst();
for(auto i = count;i > 0;--i){
pos = ++(insert(pos, value_type{value}));
@ -398,7 +451,11 @@ namespace rexy{
}
template<class T, class Alloc>
template<class InputIt>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::insert(const_iterator pos, InputIt first, InputIt last) -> iterator{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::insert(const_iterator pos, InputIt first, InputIt last)noexcept(
std::is_nothrow_constructible_v<value_type, decltype(*first)> &&
is_nothrow_allocator_v<node_allocator_type>) -> iterator
{
auto start = pos.unconst();
while(first != last){
pos = ++(insert(pos, *first++));
@ -406,13 +463,21 @@ namespace rexy{
return start;
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::insert(const_iterator pos, std::initializer_list<value_type> l) -> iterator{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::insert(const_iterator pos, std::initializer_list<value_type> l)noexcept(
std::is_nothrow_constructible_v<value_type, decltype(*l.begin())> &&
is_nothrow_allocator_v<node_allocator_type>) -> iterator
{
return insert(pos, l.begin(), l.end());
}
template<class T, class Alloc>
template<class... Args>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::emplace(const_iterator pos, Args&&... args) -> iterator{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::emplace(const_iterator pos, Args&&... args)noexcept(
std::is_nothrow_constructible_v<value_type, Args&&...> &&
is_nothrow_allocator_v<node_allocator_type>) -> iterator
{
auto* prev = (--pos).unconst().nod();
auto* next = prev->next;
prev->next = this->allocate(1);
@ -423,7 +488,11 @@ namespace rexy{
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::erase(const_iterator pos) -> iterator{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::erase(const_iterator pos)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>) -> iterator
{
auto* n = pos.unconst().nod();
auto* next = n->next;
@ -434,7 +503,11 @@ namespace rexy{
return iterator{next};
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::erase(const_iterator first, const_iterator last) -> iterator{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::erase(const_iterator first, const_iterator last)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>) -> iterator
{
while(first != last){
first = erase(first);
}
@ -442,49 +515,91 @@ namespace rexy{
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::push_back(const_reference value) -> reference{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::push_back(const_reference value)noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>) -> reference
{
return *insert(cend(), value);
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::push_back(value_type&& value) -> reference{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::push_back(value_type&& value)noexcept(
std::is_nothrow_move_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>) -> reference
{
return *insert(cend(), std::move(value));
}
template<class T, class Alloc>
template<class... Args>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::emplace_back(Args&&... args) -> reference{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::emplace_back(Args&&... args)noexcept(
std::is_nothrow_constructible_v<value_type, Args&&...> &&
is_nothrow_allocator_v<node_allocator_type>) -> reference
{
return *emplace(cend(), std::forward<Args>(args)...);
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::pop_back(void){
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::pop_back(void)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>)
{
erase(--cend());
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::push_front(const_reference value) -> reference{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::push_front(const_reference value)noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>) -> reference
{
return insert(cbegin(), value);
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::push_front(value_type&& value) -> reference{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::push_front(value_type&& value)noexcept(
std::is_nothrow_move_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>) -> reference
{
return insert(cbegin(), std::move(value));
}
template<class T, class Alloc>
template<class... Args>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::emplace_front(Args&&... args) -> reference{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::emplace_front(Args&&... args)noexcept(
std::is_nothrow_constructible_v<value_type, Args&&...> &&
is_nothrow_allocator_v<node_allocator_type>) -> reference
{
return emplace(cbegin(), std::forward<Args>(args)...);
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::pop_front(void){
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::pop_front(void)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>)
{
erase(cbegin());
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::resize(size_type count){
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::resize(size_type count)noexcept(
std::is_nothrow_default_constructible_v<value_type> &&
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>)
{
resize(count, value_type{});
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::resize(size_type count, value_type value){
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::resize(size_type count, value_type value)noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>)
{
while(count > m_size){
insert(cend(), value);
}
@ -494,18 +609,21 @@ namespace rexy{
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::swap(list& other){
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::swap(list& other)noexcept{
std::swap(m_sentinel, other.m_sentinel);
std::swap(m_size, other.m_size);
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::merge(list&& other){
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::merge(list&& other)noexcept{
merge(std::move(other), [](const_reference a, const_reference b){return a < b;});
}
template<class T, class Alloc>
template<class Comp>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::merge(list&& other, Comp comp){
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::merge(list&& other, Comp comp)noexcept{
if(&other == this){
return;
}
@ -524,11 +642,13 @@ namespace rexy{
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::splice(const_iterator pos, list&& other){
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::splice(const_iterator pos, list&& other)noexcept{
splice(pos, std::move(other), other.begin(), other.end());
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::splice(const_iterator pos, list&& other, const_iterator it){
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::splice(const_iterator pos, list&& other, const_iterator it)noexcept{
auto oit = it.unconst();
auto prev = (--pos).unconst();
remove_node_(oit.nod());
@ -538,7 +658,8 @@ namespace rexy{
--other.m_size;
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::splice(const_iterator pos, list&& other, const_iterator first, const_iterator last){
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::splice(const_iterator pos, list&& other, const_iterator first, const_iterator last)noexcept{
for(auto oit = first;oit != last;){
auto onext = oit.next();
splice(pos, std::move(other), oit);
@ -547,7 +668,11 @@ namespace rexy{
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::remove(const_reference value) -> size_type{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::remove(const_reference value)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>) -> size_type
{
return remove_if(
[&value](const_reference r) -> bool{
return r == value;
@ -556,7 +681,11 @@ namespace rexy{
}
template<class T, class Alloc>
template<class UnaryPred>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::remove_if(UnaryPred pred) -> size_type{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::remove_if(UnaryPred pred)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>) -> size_type
{
size_type count = 0;
for(auto it = begin();it != end();){
if(pred(*it)){
@ -570,7 +699,8 @@ namespace rexy{
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::reverse(void)noexcept{
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::reverse(void)noexcept{
auto* it = begin().nod();
std::swap(m_sentinel.next, m_sentinel.prev);
@ -580,7 +710,11 @@ namespace rexy{
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::unique(void) -> size_type{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::unique(void)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>) -> size_type
{
return unique(
[](const_reference first, const_reference second) -> bool{
return first == second;
@ -589,7 +723,11 @@ namespace rexy{
}
template<class T, class Alloc>
template<class BinaryPred>
REXY_CPP20_CONSTEXPR auto list<T,Alloc>::unique(BinaryPred pred) -> size_type{
REXY_CPP20_CONSTEXPR
auto list<T,Alloc>::unique(BinaryPred pred)noexcept(
std::is_nothrow_destructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>) -> size_type
{
size_type count = 0;
for(auto it = begin();it != end();++it){
auto next = it.next();
@ -602,20 +740,54 @@ namespace rexy{
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::sort(void){
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::sort(void)noexcept{
mergesort(begin(), m_size, [](const_reference first, const_reference second)->bool{
return first < second;
});
}
template<class T, class Alloc>
template<class Comp>
REXY_CPP20_CONSTEXPR void list<T,Alloc>::sort(Comp comp){
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::sort(Comp comp)noexcept{
mergesort(begin(), m_size, comp);
}
template<class T, class Alloc>
template<class InputIt>
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::iterator_initialize_(InputIt first, InputIt last)noexcept(
std::is_nothrow_constructible_v<value_type, decltype(*first)> &&
is_nothrow_allocator_v<node_allocator_type>)
{
for(;first != last;++first){
emplace_back(*first);
}
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::constant_initialize_(size_type count, const_reference value)noexcept(
std::is_nothrow_copy_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>)
{
for(;count > 0;--count){
emplace_back(value);
}
}
template<class T, class Alloc>
REXY_CPP20_CONSTEXPR
void list<T,Alloc>::default_initialize_(size_type count)noexcept(
std::is_nothrow_default_constructible_v<value_type> &&
is_nothrow_allocator_v<node_allocator_type>)
{
for(;count > 0;--count){
emplace_back();
}
}
template<class T, class Alloc>
template<class Comp>
auto list<T,Alloc>::mergesort(iterator first, size_type firstlen, Comp comp) -> iterator{
auto list<T,Alloc>::mergesort(iterator first, size_type firstlen, Comp comp)noexcept -> iterator{
if(firstlen == 1)
return first;
auto [second, secondlen] = ms_split(first, firstlen);
@ -651,7 +823,7 @@ namespace rexy{
}
template<class T, class Alloc>
auto list<T,Alloc>::ms_split(iterator it, size_type len) -> std::pair<iterator,size_type>{
auto list<T,Alloc>::ms_split(iterator it, size_type len)noexcept -> std::pair<iterator,size_type>{
size_type second_half_len = len / 2;
size_type dist = len - second_half_len;
for(auto i = dist;i > 0;--i){
@ -661,19 +833,19 @@ namespace rexy{
}
template<class T, class Alloc>
void list<T,Alloc>::insert_node_(detail::list_node_base* prev, detail::list_node_base* n){
void list<T,Alloc>::insert_node_(detail::list_node_base* prev, detail::list_node_base* n)noexcept{
n->next = prev->next;
n->prev = prev;
prev->next->prev = n;
prev->next = n;
}
template<class T, class Alloc>
void list<T,Alloc>::remove_node_(detail::list_node_base* rm){
void list<T,Alloc>::remove_node_(detail::list_node_base* rm)noexcept{
rm->prev->next = rm->next;
rm->next->prev = rm->prev;
}
template<class T, class Alloc>
detail::list_node_base* list<T,Alloc>::get_next_then_move_node_(detail::list_node_base* dest, detail::list_node_base* n){
detail::list_node_base* list<T,Alloc>::get_next_then_move_node_(detail::list_node_base* dest, detail::list_node_base* n)noexcept{
auto* next = n->next;
remove_node_(n);
insert_node_(dest, n);

View File

@ -24,7 +24,6 @@
#include <cstddef> //std::size_t,ptrdiff
#include <climits> //CHAR_BIT
#include <iterator> //reverse_iterator
#include <iostream> //ostream
#include <initializer_list>
#include "steal.hpp"
@ -526,12 +525,4 @@ namespace rexy{
#include "string_base.tpp"
namespace{
template<class Char, class Alloc>
std::ostream& operator<<(std::ostream& os, const rexy::basic_string<Char,Alloc>& str){
return os << str.c_str();
}
}
#endif