Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix werror error #40

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
60 changes: 30 additions & 30 deletions include/beman/inplace_vector/inplace_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
if (il.size() != 0) {
base::uninitialized_copy(il.begin(), il.end(), this->begin());
}
}; // freestanding-deleted
} // freestanding-deleted
constexpr inplace_vector &operator=(std::initializer_list<T> il) {
if (Capacity < il.size()) {
throw std::bad_alloc();
Expand All @@ -315,7 +315,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
}
this->change_size(diff);
return *this;
}; // freestanding-deleted
} // freestanding-deleted

template <class InputIterator>
constexpr void assign(InputIterator first, InputIterator last) {
Expand All @@ -335,7 +335,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
for (; first != last; ++first) {
emplace_back(*first);
}
}; // freestanding-deleted
} // freestanding-deleted

#if defined(__cpp_lib_containers_ranges) and defined(__cpp_concepts)
template <typename R>
Expand All @@ -359,7 +359,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
for (; first != last; ++first) {
emplace_back(*first);
}
}; // freestanding-deleted
} // freestanding-deleted
#endif

constexpr void assign(size_type n, const T &u) {
Expand All @@ -379,7 +379,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
base::uninitialized_fill(end, end + diff, u);
}
this->change_size(diff);
}; // freestanding-deleted
} // freestanding-deleted
constexpr void assign(std::initializer_list<T> il) {
if (Capacity < il.size()) {
throw std::bad_alloc();
Expand All @@ -399,7 +399,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
this->end());
}
this->change_size(diff);
}; // freestanding-deleted
} // freestanding-deleted

// [containers.sequences.inplace.vector.access], element access
constexpr reference at(size_type count) {
Expand Down Expand Up @@ -434,7 +434,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {

constexpr reverse_iterator rbegin() noexcept {
return reverse_iterator{this->end()};
};
}
constexpr const_reverse_iterator rbegin() const noexcept {
return const_reverse_iterator{this->end()};
}
Expand All @@ -452,13 +452,13 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {

constexpr const_reverse_iterator crend() const noexcept {
return const_reverse_iterator{this->begin()};
};
}

// [containers.sequences.inplace.vector.members] size/capacity
constexpr bool empty() const noexcept { return size() == 0; };
constexpr size_type size() const noexcept { return this->size_; };
static constexpr size_type max_size() noexcept { return Capacity; };
static constexpr size_type capacity() noexcept { return Capacity; };
constexpr bool empty() const noexcept { return size() == 0; }
constexpr size_type size() const noexcept { return this->size_; }
static constexpr size_type max_size() noexcept { return Capacity; }
static constexpr size_type capacity() noexcept { return Capacity; }
constexpr void resize(size_type sz) {
const auto diff = static_cast<std::ptrdiff_t>(sz - this->size());
if (diff < 0) {
Expand All @@ -471,7 +471,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
base::uninitialized_value_construct(end, end + diff);
}
this->change_size(diff);
}; // freestanding-deleted
} // freestanding-deleted
constexpr void resize(size_type sz, const T &c) {
const auto diff = static_cast<std::ptrdiff_t>(sz - this->size());
if (diff < 0) {
Expand All @@ -484,12 +484,12 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
std::uninitialized_fill(end, end + diff, c);
}
this->change_size(diff);
}; // freestanding-deleted
} // freestanding-deleted
static constexpr void reserve(size_type sz) {
if (Capacity < sz) {
throw std::bad_alloc();
}
}; // freestanding-deleted
} // freestanding-deleted
static constexpr void shrink_to_fit() noexcept {}

// [containers.sequences.inplace.vector.modifiers], modifiers
Expand All @@ -498,20 +498,20 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
throw std::bad_alloc();
}
return this->unchecked_emplace_back(std::forward<Args>(args)...);
}; // freestanding-deleted
} // freestanding-deleted

constexpr reference push_back(const T &x) {
if (this->size() == Capacity) {
throw std::bad_alloc();
}
return this->unchecked_emplace_back(x);
}; // freestanding-deleted
} // freestanding-deleted
constexpr reference push_back(T &&x) {
if (this->size() == Capacity) {
throw std::bad_alloc();
}
return this->unchecked_emplace_back(std::move(x));
}; // freestanding-deleted
} // freestanding-deleted

#if defined(__cpp_lib_containers_ranges) and defined(__cpp_concepts)
template <typename R>
Expand All @@ -522,7 +522,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
for (; first != last; ++first) {
emplace_back(*first);
}
}; // freestanding-deleted
} // freestanding-deleted
#endif

constexpr void pop_back() {
Expand All @@ -531,30 +531,30 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
std::destroy(end, end + 1);
this->change_size(-1);
}
};
}

template <class... Args> constexpr pointer try_emplace_back(Args &&...args) {
if (this->size() == Capacity) {
return nullptr;
}
return std::addressof(
this->unchecked_emplace_back(std::forward<Args>(args)...));
};
}
constexpr pointer
try_push_back(const T &x) noexcept(std::is_nothrow_copy_constructible_v<T>) {
if (this->size() == Capacity) {
return nullptr;
}
return std::addressof(this->unchecked_emplace_back(x));
};
}

constexpr pointer
try_push_back(T &&x) noexcept(std::is_nothrow_move_constructible_v<T>) {
if (this->size() == Capacity) {
return nullptr;
}
return std::addressof(this->unchecked_emplace_back(std::move(x)));
};
}

/*
template <typename R>
Expand All @@ -580,15 +580,15 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
#endif
this->change_size(1);
return *final;
};
}

constexpr reference
unchecked_push_back(const T &x) noexcept(std::is_nothrow_constructible_v<T>) {
return this->unchecked_emplace_back(x);
};
}
constexpr reference unchecked_push_back(T &&x) {
return this->unchecked_emplace_back(std::move(x));
};
}

template <class... Args>
constexpr iterator emplace(const_iterator position, Args &&...args) {
Expand All @@ -609,13 +609,13 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
*pos = std::move(temp);
}
return pos;
}; // freestanding-deleted
} // freestanding-deleted
constexpr iterator insert(const_iterator position, const T &x) {
return emplace(position, x);
}; // freestanding-deleted
} // freestanding-deleted
constexpr iterator insert(const_iterator position, T &&x) {
return emplace(position, std::move(x));
}; // freestanding-deleted
} // freestanding-deleted
constexpr iterator insert(const_iterator position, size_type n, const T &x) {
const iterator pos = position;
const iterator end = this->end();
Expand Down Expand Up @@ -781,7 +781,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
constexpr friend std::compare_three_way_result<T>
operator<=>(const inplace_vector &x, const inplace_vector &y) {
return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());
};
}
#endif

constexpr friend void swap(inplace_vector &x, inplace_vector &y) noexcept(
Expand Down
6 changes: 4 additions & 2 deletions tests/beman/inplace_vector/inplace_vector.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ void test_exceptions() {
{
try {
vec too_small{};
auto res = too_small.at(5);
too_small.at(5);
assert(false);
} catch (const std::out_of_range &) {
} catch (...) {
assert(false);
}
try {
const vec too_small{};
auto res = too_small.at(5);
too_small.at(5);
assert(false);
} catch (const std::out_of_range &) {
} catch (...) {
assert(false);
Expand Down
Loading