Skip to content

Commit

Permalink
format: auto format files
Browse files Browse the repository at this point in the history
Based on bemanproject/exemplar#29, added a basic clang-format just to get started. Re-formatted inplace_vector.hpp with this new clang-format file.
  • Loading branch information
DeveloperPaul123 committed Sep 26, 2024
1 parent 5ef5301 commit 191b452
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 54 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: LLVM
104 changes: 50 additions & 54 deletions include/beman/inplace_vector/inplace_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ concept container_compatible_range_impl = requires(T &&t) {
std::ranges::end(t)
} -> std::same_as<typename std::remove_reference_t<T>::iterator>;
};
} // namespace detail
} // namespace detail
template <typename T>
constexpr bool container_compatible_range =
detail::container_compatible_range_impl<T>;
Expand Down Expand Up @@ -64,17 +64,17 @@ struct inplace_vector_destruct_base {
&&other) noexcept(std::is_nothrow_move_constructible_v<T>)
: elems(), size_(other.size()) {}

inplace_vector_destruct_base &operator=(
const inplace_vector_destruct_base
&other) noexcept(std::is_nothrow_copy_constructible_v<T> &&
std::is_nothrow_copy_assignable_v<T>) {
inplace_vector_destruct_base &
operator=(const inplace_vector_destruct_base &other) noexcept(
std::is_nothrow_copy_constructible_v<T> &&
std::is_nothrow_copy_assignable_v<T>) {
size_ = other.size_;
}

inplace_vector_destruct_base &operator=(
const inplace_vector_destruct_base
&&other) noexcept(std::is_nothrow_move_constructible_v<T> &&
std::is_nothrow_move_assignable_v<T>) {
inplace_vector_destruct_base &
operator=(const inplace_vector_destruct_base &&other) noexcept(
std::is_nothrow_move_constructible_v<T> &&
std::is_nothrow_move_assignable_v<T>) {
size_ = other.size_;
other.size_ = nullptr;
}
Expand Down Expand Up @@ -212,10 +212,10 @@ struct inplace_vector_base : public inplace_vector_destruct_base<T, Capacity> {

template <class T, std::size_t Capacity>
class inplace_vector : public inplace_vector_base<T, Capacity> {
private:
private:
using base = inplace_vector_base<T, Capacity>;

public:
public:
using value_type = T;
using pointer = T *;
using const_pointer = const T *;
Expand Down Expand Up @@ -273,7 +273,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 @@ -296,7 +296,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 @@ -316,7 +316,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
for (; first != last; ++first) {
emplace_back(*first);
}
}; // freestanding-deleted
}; // freestanding-deleted

template <typename R>
requires container_compatible_range<R>
Expand All @@ -339,7 +339,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
for (; first != last; ++first) {
emplace_back(*first);
}
}; // freestanding-deleted
}; // freestanding-deleted
constexpr void assign(size_type n, const T &u) {
if (Capacity == 0) {
assert(size() == 0 &&
Expand All @@ -357,7 +357,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 @@ -378,7 +378,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 @@ -450,7 +450,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 @@ -463,35 +463,34 @@ 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
template <class... Args>
constexpr reference emplace_back(Args &&...args) {
template <class... Args> constexpr reference emplace_back(Args &&...args) {
if (this->size() == 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
template <typename R>
requires container_compatible_range<T>
constexpr void append_range(R &&rg) {
Expand All @@ -500,7 +499,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
for (; first != last; ++first) {
emplace_back(*first);
}
}; // freestanding-deleted
}; // freestanding-deleted
constexpr void pop_back() {
if (!empty()) {
const auto end = this->end();
Expand All @@ -509,24 +508,23 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
}
};

template <class... Args>
constexpr pointer try_emplace_back(Args &&...args) {
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>) {
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>) {
constexpr pointer
try_push_back(T &&x) noexcept(std::is_nothrow_move_constructible_v<T>) {
if (this->size() == Capacity) {
return nullptr;
}
Expand All @@ -553,8 +551,8 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
return *final;
};

constexpr reference unchecked_push_back(const T &x) noexcept(
std::is_nothrow_constructible_v<T>) {
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) {
Expand All @@ -580,13 +578,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 @@ -620,9 +618,8 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
}

template <class InputIterator>
constexpr inplace_vector::iterator insert(const_iterator position,
InputIterator first,
InputIterator last) {
constexpr inplace_vector::iterator
insert(const_iterator position, InputIterator first, InputIterator last) {
const iterator pos = position;
const iterator end = this->end();
const auto count = std::distance(first, last);
Expand Down Expand Up @@ -653,7 +650,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
std::move_backward(pos, end - count, end);
std::ranges::copy(first, last, pos);
}
} // freestanding-deleted
} // freestanding-deleted
template <typename R>
requires container_compatible_range<R>
constexpr iterator insert_range(const_iterator position, R &&rg) {
Expand All @@ -667,7 +664,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
const iterator pos = position;
std::rotate(pos, old_end, this->end());
return pos;
} // freestanding-deleted
} // freestanding-deleted
constexpr iterator insert(const_iterator position,
std::initializer_list<T> il) {
const iterator pos = position;
Expand All @@ -687,7 +684,7 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
this->cange_size(count);
return pos;
}
} // freestanding-deleted
} // freestanding-deleted
constexpr iterator erase(const_iterator position) {
const iterator pos = position;
const iterator end = this->end();
Expand Down Expand Up @@ -718,9 +715,10 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
this->change_size(first - last);
return first;
}
constexpr void swap(inplace_vector &x) noexcept(
Capacity == 0 || (std::is_nothrow_swappable_v<T> &&
std::is_nothrow_move_constructible_v<T>)) {
constexpr void
swap(inplace_vector &x) noexcept(Capacity == 0 ||
(std::is_nothrow_swappable_v<T> &&
std::is_nothrow_move_constructible_v<T>)) {
if (this->size() < x.size()) {
const auto new_mid =
std::swap_ranges(this->begin(), this->end(), x.begin());
Expand All @@ -740,16 +738,14 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
this->change_size(static_cast<std::ptrdiff_t>(this->size()));
}

constexpr friend bool operator==(
const inplace_vector &x,
const inplace_vector &y) noexcept(noexcept(std::equal(x.begin(), x.end(),
y.begin(),
y.end()))) {
constexpr friend bool
operator==(const inplace_vector &x, const inplace_vector &y) noexcept(
noexcept(std::equal(x.begin(), x.end(), y.begin(), y.end()))) {
return std::equal(x.begin(), x.end(), y.begin(), y.end());
}

constexpr friend std::compare_three_way_result<T> operator<=>(
const inplace_vector &x, const inplace_vector &y) {
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());
};
constexpr friend void swap(inplace_vector &x, inplace_vector &y) noexcept(
Expand All @@ -758,4 +754,4 @@ class inplace_vector : public inplace_vector_base<T, Capacity> {
x.swap(y);
}
};
} // namespace beman::inplace_vector
} // namespace beman::inplace_vector

0 comments on commit 191b452

Please sign in to comment.