Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion include/rsl/algorithm.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef RSL_ALGORITHM_HPP
#define RSL_ALGORITHM_HPP

#include <algorithm>

Expand Down Expand Up @@ -40,3 +41,5 @@ template <typename Collection>
}

} // namespace rsl

#endif // RSL_ALGORITHM_HPP
7 changes: 6 additions & 1 deletion include/rsl/monad.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef RSL_MONAD_HPP
#define RSL_MONAD_HPP

#include <tl/expected.hpp>

Expand Down Expand Up @@ -165,6 +166,7 @@ constexpr inline bool is_optional = is_optional_impl<std::remove_cv_t<std::remov
*
* @return Return type of f
*/
// NOLINTBEGIN(modernize-use-constraints): RSL is documented as a C++17 library.
template <typename T, typename Fn, typename = std::enable_if_t<rsl::is_optional<T>>,
typename = std::enable_if_t<std::is_invocable_v<
Fn, typename std::remove_cv_t<std::remove_reference_t<T>>::value_type>>>
Expand Down Expand Up @@ -205,3 +207,6 @@ template <typename T, typename Fn, typename = std::enable_if_t<!rsl::is_optional
typename std::enable_if_t<std::is_invocable_v<Fn, T>, std::invoke_result_t<Fn, T>> {
return std::invoke(std::forward<Fn>(fn), std::forward<T>(val));
}
// NOLINTEND(modernize-use-constraints)

#endif // RSL_MONAD_HPP
5 changes: 4 additions & 1 deletion include/rsl/no_discard.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef RSL_NO_DISCARD_HPP
#define RSL_NO_DISCARD_HPP

#include <utility>

Expand Down Expand Up @@ -26,3 +27,5 @@ class NoDiscard {
};

} // namespace rsl

#endif // RSL_NO_DISCARD_HPP
5 changes: 4 additions & 1 deletion include/rsl/overload.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef RSL_OVERLOAD_HPP
#define RSL_OVERLOAD_HPP

namespace rsl {

Expand All @@ -18,3 +19,5 @@ template <class... Ts>
Overload(Ts...) -> Overload<Ts...>;

} // namespace rsl

#endif // RSL_OVERLOAD_HPP
5 changes: 4 additions & 1 deletion include/rsl/parameter_validators.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef RSL_PARAMETER_VALIDATORS_HPP
#define RSL_PARAMETER_VALIDATORS_HPP

#include <rsl/algorithm.hpp>
#include <rsl/export.hpp>
Expand Down Expand Up @@ -320,3 +321,5 @@ template <typename T>
-> rcl_interfaces::msg::SetParametersResult;

} // namespace rsl

#endif // RSL_PARAMETER_VALIDATORS_HPP
13 changes: 8 additions & 5 deletions include/rsl/queue.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef RSL_QUEUE_HPP
#define RSL_QUEUE_HPP

#include <chrono>
#include <condition_variable>
Expand Down Expand Up @@ -26,7 +27,7 @@ class Queue {
* @return Queue size
*/
[[nodiscard]] auto size() const noexcept {
auto const lock = std::lock_guard(mutex_);
auto const lock = std::scoped_lock(mutex_);
return queue_.size();
}

Expand All @@ -35,7 +36,7 @@ class Queue {
* @return True if the queue is empty, otherwise false
*/
[[nodiscard]] auto empty() const noexcept {
auto const lock = std::lock_guard(mutex_);
auto const lock = std::scoped_lock(mutex_);
return queue_.empty();
}

Expand All @@ -44,7 +45,7 @@ class Queue {
* @param value Data to push into the queue
*/
void push(T value) noexcept {
auto const lock = std::lock_guard(mutex_);
auto const lock = std::scoped_lock(mutex_);
queue_.push(std::move(value));
cv_.notify_one();
}
Expand All @@ -53,7 +54,7 @@ class Queue {
* @brief Clear the queue
*/
void clear() noexcept {
auto const lock = std::lock_guard(mutex_);
auto const lock = std::scoped_lock(mutex_);

// Swap queue with an empty queue of the same type to ensure queue_ is left in a
// default-constructed state
Expand All @@ -77,3 +78,5 @@ class Queue {
}
};
} // namespace rsl

#endif // RSL_QUEUE_HPP
5 changes: 4 additions & 1 deletion include/rsl/random.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef RSL_RANDOM_HPP
#define RSL_RANDOM_HPP

#include <rsl/export.hpp>

Expand Down Expand Up @@ -68,3 +69,5 @@ template <typename IntType>
[[nodiscard]] RSL_EXPORT auto random_unit_quaternion() -> Eigen::Quaterniond;

} // namespace rsl

#endif // RSL_RANDOM_HPP
5 changes: 4 additions & 1 deletion include/rsl/static_string.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef RSL_STATIC_STRING_HPP
#define RSL_STATIC_STRING_HPP

#include <array>
#include <cassert>
Expand Down Expand Up @@ -58,3 +59,5 @@ template <size_t capacity>
}

} // namespace rsl

#endif // RSL_STATIC_STRING_HPP
5 changes: 4 additions & 1 deletion include/rsl/static_vector.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef RSL_STATIC_VECTOR_HPP
#define RSL_STATIC_VECTOR_HPP

#include <tcb_span/span.hpp>

Expand Down Expand Up @@ -82,3 +83,5 @@ template <typename T, size_t capacity>
}

} // namespace rsl

#endif // RSL_STATIC_VECTOR_HPP
5 changes: 4 additions & 1 deletion include/rsl/strong_type.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef RSL_STRONG_TYPE_HPP
#define RSL_STRONG_TYPE_HPP

#include <utility>

Expand Down Expand Up @@ -39,3 +40,5 @@ class StrongType {
};

} // namespace rsl

#endif // RSL_STRONG_TYPE_HPP
5 changes: 4 additions & 1 deletion include/rsl/try.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef RSL_TRY_HPP
#define RSL_TRY_HPP

#include <tl/expected.hpp>

Expand Down Expand Up @@ -33,3 +34,5 @@
if (!_expected.has_value()) return tl::unexpected(_expected.error()); \
_expected.value(); \
})

#endif // RSL_TRY_HPP
1 change: 1 addition & 0 deletions src/random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ auto rng(std::seed_seq seed_sequence) -> std::mt19937& {
}

auto random_unit_quaternion() -> Eigen::Quaterniond {
// NOLINTNEXTLINE(modernize-use-std-numbers): RSL is documented as a C++17 library.
static constexpr auto pi = 3.1415926535897932385;

// From "Uniform Random Rotations", Ken Shoemake, Graphics Gems III, pg. 124-132
Expand Down
2 changes: 1 addition & 1 deletion tests/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ TEST_CASE("rsl::Queue") {
for (auto& producer : producers) producer.join();
for (auto& consumer : consumers) consumer.join();

CHECK(queue.size() == thread_count * item_count - items_removed);
CHECK(queue.size() == (thread_count * item_count) - items_removed);
}
}
}
Expand Down