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

Add more messages for assertion failures #101

Merged
merged 1 commit into from
Dec 6, 2023
Merged
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
9 changes: 5 additions & 4 deletions include/rsl/random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ auto rng(std::seed_seq seed_sequence = {}) -> std::mt19937&;
*/
template <typename RealType>
[[nodiscard]] auto uniform_real(RealType lower, RealType upper) {
static_assert(std::is_floating_point_v<RealType>);
assert(lower < upper);
static_assert(std::is_floating_point_v<RealType>, "RealType must be a floating point type");
assert(lower < upper && "rsl::uniform_real: Lower bound be less than upper bound");
return std::uniform_real_distribution(lower, upper)(rng());
}

Expand All @@ -53,8 +53,9 @@ template <typename RealType>
*/
template <typename IntType>
[[nodiscard]] auto uniform_int(IntType lower, IntType upper) {
static_assert(std::is_integral_v<IntType>);
assert(lower <= upper);
static_assert(std::is_integral_v<IntType>, "IntType must be an integral type");
assert(lower <= upper &&
"rsl::uniform_int: Lower bound must be less than or equal to upper bound");
return std::uniform_int_distribution(lower, upper)(rng());
}

Expand Down
3 changes: 2 additions & 1 deletion include/rsl/static_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class StaticString {
* @brief Construct from a std::string
*/
StaticString(std::string const& string) : size_(std::min(string.size(), capacity)) {
assert(string.size() <= capacity);
assert(string.size() <= capacity &&
"rsl::StaticString::StaticString: Input exceeds capacity");
std::copy(string.cbegin(), string.cbegin() + std::string::difference_type(size_),
data_.begin());
}
Expand Down
3 changes: 2 additions & 1 deletion include/rsl/static_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class StaticVector {
*/
template <typename Collection>
StaticVector(Collection const& collection) : size_(std::min(collection.size(), capacity)) {
assert(collection.size() <= capacity);
assert(collection.size() <= capacity &&
"rsl::StaticVector::StaticVector: Input exceeds capacity");
std::copy(collection.cbegin(),
collection.cbegin() + typename Collection::difference_type(size_), data_.begin());
}
Expand Down