fixed swap()
This commit is contained in:
parent
c2d828cfb9
commit
32ae9a2d3d
|
|
@ -527,13 +527,13 @@ namespace cc {
|
||||||
template<typename ...Args>
|
template<typename ...Args>
|
||||||
constexpr const_vector<T, N>::reference const_vector<T, N>::emplace_back(Args&&... args)
|
constexpr const_vector<T, N>::reference const_vector<T, N>::emplace_back(Args&&... args)
|
||||||
{
|
{
|
||||||
emplace(end(), std::forward(args)...);
|
return *emplace(cend(), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, std::size_t N>
|
template<typename T, std::size_t N>
|
||||||
constexpr void const_vector<T, N>::pop_back()
|
constexpr void const_vector<T, N>::pop_back()
|
||||||
{
|
{
|
||||||
_erase_no_move(end() - 1, end());
|
std::destroy_n(end() - 1, 1);
|
||||||
--_size;
|
--_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -541,9 +541,9 @@ namespace cc {
|
||||||
template<std::size_t N2>
|
template<std::size_t N2>
|
||||||
constexpr void const_vector<T, N>::swap(const_vector<T, N2> &other)
|
constexpr void const_vector<T, N>::swap(const_vector<T, N2> &other)
|
||||||
{
|
{
|
||||||
if (_size > other._len || other._size > N) throw std::exception();
|
if (_size > other._len || other._size > N) throw std::invalid_argument("Cannot swap elements, one does not fit into the other");
|
||||||
|
|
||||||
cc::helper::swap_iter_range(begin(), end(), std::end(_arr), other.begin(), other.end(), std::end(other._arr));
|
cc::helper::swap_iter_range(begin(), end(), other.begin(), other.end());
|
||||||
std::swap(_size, other._size);
|
std::swap(_size, other._size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@ namespace cc::helper {
|
||||||
template<typename T, std::size_t N>
|
template<typename T, std::size_t N>
|
||||||
constexpr std::size_t array_size(const T(&)[N]) { return N; }
|
constexpr std::size_t array_size(const T(&)[N]) { return N; }
|
||||||
|
|
||||||
template<std::input_or_output_iterator InputIt1, std::input_or_output_iterator InputIt2, typename T = InputIt1::value_type>
|
template<std::input_or_output_iterator InputIt1, std::input_or_output_iterator InputIt2>
|
||||||
requires ((InputIt1::value_type == InputIt2::value_type)
|
requires std::is_same_v<typename std::iterator_traits<InputIt1>::value_type, typename std::iterator_traits<InputIt2>::value_type>
|
||||||
&& std::indirectly_writable<typename InputIt1::value_type, InputIt1> && std::indirectly_readable<InputIt1>
|
&& std::indirectly_writable<InputIt1, typename std::iterator_traits<InputIt2>::value_type> && std::indirectly_readable<InputIt1>
|
||||||
&& std::indirectly_writable<typename InputIt2::value_type, InputIt1> && std::indirectly_readable<InputIt2>)
|
&& std::indirectly_writable<InputIt2, typename std::iterator_traits<InputIt1>::value_type> && std::indirectly_readable<InputIt2>
|
||||||
constexpr void swap_iter_range(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
|
constexpr void swap_iter_range(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
|
||||||
{
|
{
|
||||||
auto dist1 = std::distance(first1, last1);
|
auto dist1 = std::distance(first1, last1);
|
||||||
|
|
@ -31,7 +31,7 @@ namespace cc::helper {
|
||||||
|
|
||||||
auto swap_dist = std::min(dist1, dist2);
|
auto swap_dist = std::min(dist1, dist2);
|
||||||
|
|
||||||
std::swap_ranges(first1, std::next(first1, swap_dist), first2, std::next(first2, swap_dist));
|
std::swap_ranges(first1, std::next(first1, swap_dist), first2);
|
||||||
|
|
||||||
std::advance(first1, swap_dist);
|
std::advance(first1, swap_dist);
|
||||||
std::advance(first2, swap_dist);
|
std::advance(first2, swap_dist);
|
||||||
|
|
@ -43,10 +43,10 @@ namespace cc::helper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::input_or_output_iterator InputIt1, std::input_or_output_iterator InputIt2, typename T = InputIt1::value_type>
|
template<std::input_or_output_iterator InputIt1, std::input_or_output_iterator InputIt2>
|
||||||
requires ((InputIt1::value_type == InputIt2::value_type)
|
requires std::is_same_v<typename std::iterator_traits<InputIt1>::value_type, typename std::iterator_traits<InputIt2>::value_type>
|
||||||
&& std::indirectly_writable<typename InputIt1::value_type, InputIt1> && std::indirectly_readable<InputIt1>
|
&& std::indirectly_writable<InputIt1, typename std::iterator_traits<InputIt2>::value_type> && std::indirectly_readable<InputIt1>
|
||||||
&& std::indirectly_writable<typename InputIt2::value_type, InputIt1> && std::indirectly_readable<InputIt2>)
|
&& std::indirectly_writable<InputIt2, typename std::iterator_traits<InputIt1>::value_type> && std::indirectly_readable<InputIt2>
|
||||||
constexpr void swap(InputIt1 first1, InputIt1 last1, InputIt1 end1, InputIt2 first2, InputIt2 last2, InputIt2 end2)
|
constexpr void swap(InputIt1 first1, InputIt1 last1, InputIt1 end1, InputIt2 first2, InputIt2 last2, InputIt2 end2)
|
||||||
{
|
{
|
||||||
auto max_dist = std::min(std::distance(first1, end1), std::distance(first2, end2));
|
auto max_dist = std::min(std::distance(first1, end1), std::distance(first2, end2));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue