Skip to content

Commit

Permalink
Make nodiscard pass (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-PLACET authored Feb 11, 2025
1 parent 38e43a9 commit ad38206
Show file tree
Hide file tree
Showing 60 changed files with 518 additions and 534 deletions.
3 changes: 1 addition & 2 deletions include/sparrow/array_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@

namespace sparrow
{
SPARROW_API cloning_ptr<array_wrapper> array_factory(arrow_proxy proxy);

[[nodiscard]] SPARROW_API cloning_ptr<array_wrapper> array_factory(arrow_proxy proxy);
}
16 changes: 8 additions & 8 deletions include/sparrow/arrow_interface/arrow_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace sparrow
*/
template <class B>
requires std::constructible_from<arrow_array_private_data::BufferType, B>
ArrowArray make_arrow_array(
[[nodiscard]] ArrowArray make_arrow_array(
int64_t length,
int64_t null_count,
int64_t offset,
Expand Down Expand Up @@ -112,7 +112,7 @@ namespace sparrow

template <class B>
requires std::constructible_from<arrow_array_private_data::BufferType, B>
ArrowArray make_arrow_array(
[[nodiscard]] ArrowArray make_arrow_array(
int64_t length,
int64_t null_count,
int64_t offset,
Expand All @@ -133,17 +133,17 @@ namespace sparrow
return array;
}

inline ArrowArray make_empty_arrow_array()
[[nodiscard]] inline ArrowArray make_empty_arrow_array()
{
using buffer_type = arrow_array_private_data::BufferType;
return make_arrow_array(0, 0, 0, buffer_type{}, 0u, nullptr, nullptr);
}

SPARROW_API void release_arrow_array(ArrowArray* array);

SPARROW_API sparrow::buffer_view<uint8_t> get_bitmap_buffer(const ArrowArray& array);
[[nodiscard]] SPARROW_API sparrow::buffer_view<uint8_t> get_bitmap_buffer(const ArrowArray& array);

SPARROW_API std::vector<sparrow::buffer_view<uint8_t>>
[[nodiscard]] SPARROW_API std::vector<sparrow::buffer_view<uint8_t>>
get_arrow_array_buffers(const ArrowArray& array, const ArrowSchema& schema);

/**
Expand All @@ -160,7 +160,7 @@ namespace sparrow
/**
* Create a deep copy of the source ArrowArray. The buffers, children and dictionary are deep copied.
*/
inline ArrowArray copy_array(const ArrowArray& source_array, const ArrowSchema& source_schema)
[[nodiscard]] inline ArrowArray copy_array(const ArrowArray& source_array, const ArrowSchema& source_schema)
{
ArrowArray target{};
copy_array(source_array, source_schema, target);
Expand All @@ -171,7 +171,7 @@ namespace sparrow
* Moves the content of source into a stack-allocated array, and
* reset the source to an empty ArrowArray.
*/
inline ArrowArray move_array(ArrowArray&& source)
[[nodiscard]] inline ArrowArray move_array(ArrowArray&& source)
{
ArrowArray target = make_empty_arrow_array();
swap(source, target);
Expand All @@ -182,7 +182,7 @@ namespace sparrow
* Moves the content of source into a stack-allocated array, and
* reset the source to an empty ArrowArray.
*/
inline ArrowArray move_array(ArrowArray& source)
[[nodiscard]] inline ArrowArray move_array(ArrowArray& source)
{
return move_array(std::move(source));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ namespace sparrow
{

/// @returns `true` if the format of an `ArrowArray` for a given data type is valid, `false` otherwise.
inline bool validate_format_with_arrow_array(data_type, const ArrowArray&)
[[nodiscard]] inline bool validate_format_with_arrow_array(data_type, const ArrowArray&)
{
return true;
/* THE CODE USED TO MAKES WRONG ASSUMPTIONS AND NEEDS TO BE REFACTORED IN A SEPERATE PR*/
}

constexpr bool has_bitmap(data_type dt)
[[nodiscard]] constexpr bool has_bitmap(data_type dt)
{
switch (dt)
{
Expand Down
12 changes: 6 additions & 6 deletions include/sparrow/arrow_interface/arrow_array_schema_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace sparrow
* @return The number of elements in `value`.
*/
template <class T>
constexpr int64_t ssize(const T& value);
[[nodiscard]] constexpr int64_t ssize(const T& value);

/**
* Get a raw pointer from a smart pointer, a range, an object or a pointer.
Expand All @@ -87,7 +87,7 @@ namespace sparrow
* If the variable is an object, the pointer is returned by calling the address-of operator.
*/
template <typename T, typename U>
constexpr T* get_raw_ptr(U& var);
[[nodiscard]] constexpr T* get_raw_ptr(U& var);

/**
* Create a vector of pointers to elements from a range.
Expand All @@ -101,7 +101,7 @@ namespace sparrow
*/
template <class T, std::ranges::input_range Range, class Allocator = std::allocator<T*>>
requires(!std::ranges::view<Range>)
constexpr std::vector<T*, Allocator> to_raw_ptr_vec(Range& range);
[[nodiscard]] constexpr std::vector<T*, Allocator> to_raw_ptr_vec(Range& range);

/**
* Create a vector of pointers to elements from a std::optional<range>.
Expand All @@ -115,7 +115,7 @@ namespace sparrow
*/
template <class T, class Optional, class Allocator = std::allocator<T*>>
requires(mpl::is_type_instance_of_v<Optional, std::optional>)
constexpr std::vector<T*, Allocator> to_raw_ptr_vec(Optional& optional);
[[nodiscard]] constexpr std::vector<T*, Allocator> to_raw_ptr_vec(Optional& optional);

/**
* Create a vector of pointers to elements of a tuple.
Expand All @@ -131,7 +131,7 @@ namespace sparrow
*/
template <class T, class Tuple, class Allocator = std::allocator<T*>>
requires mpl::is_type_instance_of_v<Tuple, std::tuple>
constexpr std::vector<T*, Allocator> to_raw_ptr_vec(Tuple& tuple);
[[nodiscard]] constexpr std::vector<T*, Allocator> to_raw_ptr_vec(Tuple& tuple);

/**
* Check if all elements of a range or std::optional<range> are valid by caling their bool operator. If
Expand All @@ -142,7 +142,7 @@ namespace sparrow
|| (mpl::is_type_instance_of_v<T, std::optional>
&& mpl::testable<std::ranges::range_value_t<typename T::value_type>>)
|| (std::ranges::range<T> && mpl::testable<std::ranges::range_value_t<T>>)
constexpr bool all_element_are_true(const T& elements);
[[nodiscard]] constexpr bool all_element_are_true(const T& elements);

/******************
* Implementation *
Expand Down
6 changes: 3 additions & 3 deletions include/sparrow/arrow_interface/arrow_schema/private_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ namespace sparrow
arrow_schema_private_data(F format, N name, M metadata, std::size_t children_size = 0);

[[nodiscard]] const char* format_ptr() const noexcept;
FormatType& format() noexcept;
[[nodiscard]] FormatType& format() noexcept;
[[nodiscard]] const char* name_ptr() const noexcept;
NameType& name() noexcept;
[[nodiscard]] NameType& name() noexcept;
[[nodiscard]] const char* metadata_ptr() const noexcept;
MetadataType& metadata() noexcept;
[[nodiscard]] MetadataType& metadata() noexcept;

private:

Expand Down
20 changes: 10 additions & 10 deletions include/sparrow/buffer/allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ namespace sparrow
[[nodiscard]] T* allocate(std::size_t n);
void deallocate(T* p, std::size_t n);

any_allocator select_on_container_copy_construction() const;
[[nodiscard]] any_allocator select_on_container_copy_construction() const;

bool equal(const any_allocator& rhs) const;
[[nodiscard]] bool equal(const any_allocator& rhs) const;

private:

struct interface
{
[[nodiscard]] virtual T* allocate(std::size_t) = 0;
virtual void deallocate(T*, std::size_t) = 0;
virtual std::unique_ptr<interface> clone() const = 0;
virtual bool equal(const interface&) const = 0;
[[nodiscard]] virtual std::unique_ptr<interface> clone() const = 0;
[[nodiscard]] virtual bool equal(const interface&) const = 0;
virtual ~interface() = default;
};

Expand All @@ -119,12 +119,12 @@ namespace sparrow
m_alloc.deallocate(p, n);
}

std::unique_ptr<interface> clone() const override
[[nodiscard]] std::unique_ptr<interface> clone() const override
{
return std::make_unique<impl<A>>(m_alloc);
}

bool equal(const interface& rhs) const override
[[nodiscard]] bool equal(const interface& rhs) const override
{
if (std::type_index(typeid(*this)) == std::type_index(typeid(rhs)))
{
Expand All @@ -138,19 +138,19 @@ namespace sparrow
variant<std::allocator<T>, std::pmr::polymorphic_allocator<T>, std::unique_ptr<interface>>;

template <class A>
std::unique_ptr<interface> make_storage(A&& alloc) const
[[nodiscard]] std::unique_ptr<interface> make_storage(A&& alloc) const
{
return std::make_unique<impl<std::decay_t<A>>>(std::forward<A>(alloc));
}

template <class A>
requires can_any_allocator_sbo<A, T>
A&& make_storage(A&& alloc) const
[[nodiscard]] A&& make_storage(A&& alloc) const
{
return std::forward<A>(alloc);
}

storage_type copy_storage(const storage_type& rhs) const
[[nodiscard]] storage_type copy_storage(const storage_type& rhs) const
{
return std::visit(
overloaded{
Expand All @@ -168,7 +168,7 @@ namespace sparrow
}

template <class F>
decltype(auto) visit_storage(F&& f)
[[nodiscard]] decltype(auto) visit_storage(F&& f)
{
return std::visit(
[&f](auto&& arg)
Expand Down
65 changes: 33 additions & 32 deletions include/sparrow/buffer/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

namespace sparrow
{

/**
* Base class for buffer.
*
Expand Down Expand Up @@ -80,10 +79,10 @@ namespace sparrow
template <allocator A>
constexpr buffer_base(buffer_base&& rhs, const A& a);

constexpr allocator_type& get_allocator() noexcept;
constexpr const allocator_type& get_allocator() const noexcept;
constexpr buffer_data& get_data() noexcept;
constexpr const buffer_data& get_data() const noexcept;
[[nodiscard]] constexpr allocator_type& get_allocator() noexcept;
[[nodiscard]] constexpr const allocator_type& get_allocator() const noexcept;
[[nodiscard]] constexpr buffer_data& get_data() noexcept;
[[nodiscard]] constexpr const buffer_data& get_data() const noexcept;

constexpr pointer allocate(size_type n);
constexpr void deallocate(pointer p, size_type n);
Expand Down Expand Up @@ -177,49 +176,50 @@ namespace sparrow

// Element access

constexpr reference operator[](size_type i);
constexpr const_reference operator[](size_type i) const;
[[nodiscard]] constexpr reference operator[](size_type i);
[[nodiscard]] constexpr const_reference operator[](size_type i) const;

constexpr reference front();
constexpr const_reference front() const;
[[nodiscard]] constexpr reference front();
[[nodiscard]] constexpr const_reference front() const;

constexpr reference back();
constexpr const_reference back() const;
[[nodiscard]] constexpr reference back();
[[nodiscard]] constexpr const_reference back() const;

// TODO: make this non template and make a buffer_caster class
template <class U = T>
constexpr U* data() noexcept;
[[nodiscard]] constexpr U* data() noexcept;

// TODO: make this non template and make a buffer_caster class
template <class U = T>
constexpr const U* data() const noexcept;
[[nodiscard]] constexpr const U* data() const noexcept;

// Iterators

constexpr iterator begin() noexcept;
constexpr iterator end() noexcept;

constexpr const_iterator begin() const noexcept;
constexpr const_iterator end() const noexcept;
[[nodiscard]] constexpr iterator begin() noexcept;
[[nodiscard]] constexpr iterator end() noexcept;

constexpr const_iterator cbegin() const noexcept;
constexpr const_iterator cend() const noexcept;
[[nodiscard]] constexpr const_iterator begin() const noexcept;
[[nodiscard]] constexpr const_iterator end() const noexcept;

constexpr reverse_iterator rbegin() noexcept;
constexpr reverse_iterator rend() noexcept;
[[nodiscard]] constexpr const_iterator cbegin() const noexcept;
[[nodiscard]] constexpr const_iterator cend() const noexcept;

constexpr const_reverse_iterator rbegin() const noexcept;
constexpr const_reverse_iterator rend() const noexcept;
[[nodiscard]] constexpr reverse_iterator rbegin() noexcept;
[[nodiscard]] constexpr reverse_iterator rend() noexcept;

constexpr const_reverse_iterator crbegin() const noexcept;
constexpr const_reverse_iterator crend() const noexcept;
[[nodiscard]] constexpr const_reverse_iterator rbegin() const noexcept;
[[nodiscard]] constexpr const_reverse_iterator rend() const noexcept;

[[nodiscard]] constexpr const_reverse_iterator crbegin() const noexcept;
[[nodiscard]] constexpr const_reverse_iterator crend() const noexcept;
[[nodiscard]]
// Capacity

constexpr bool empty() const noexcept;
constexpr size_type capacity() const noexcept;
constexpr size_type size() const noexcept;
constexpr size_type max_size() const noexcept;
[[nodiscard]] constexpr bool
empty() const noexcept;
[[nodiscard]] constexpr size_type capacity() const noexcept;
[[nodiscard]] constexpr size_type size() const noexcept;
[[nodiscard]] constexpr size_type max_size() const noexcept;
constexpr void reserve(size_type new_cap);
constexpr void shrink_to_fit();

Expand Down Expand Up @@ -280,9 +280,10 @@ namespace sparrow

static constexpr size_type check_init_length(size_type n, const allocator_type& a);

static constexpr size_type max_size_impl(const allocator_type& a) noexcept;
[[nodiscard]] static constexpr size_type max_size_impl(const allocator_type& a) noexcept;

static constexpr pointer default_initialize(pointer begin, size_type n, allocator_type& a);
[[nodiscard]] static constexpr pointer
default_initialize(pointer begin, size_type n, allocator_type& a);

static constexpr pointer
fill_initialize(pointer begin, size_type n, const value_type& v, allocator_type& a);
Expand Down
Loading

0 comments on commit ad38206

Please sign in to comment.