Skip to content

Commit

Permalink
Added several missing [[nodiscard]]
Browse files Browse the repository at this point in the history
  • Loading branch information
rollbear committed Mar 4, 2024
1 parent da5ab44 commit d101e70
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 12 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Added several missing [[nodiscard]]

* .begin() and .end() are now constexpr for strong::range types. Thanks
Harald Achitz for reporting the missing specifiers.

Expand Down
18 changes: 9 additions & 9 deletions include/strong_type/arithmetic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ class std::numeric_limits<strong::type<T, Tag, Ms...>>
{
using type = strong::type<T, Tag, Ms...>;
public:
static constexpr type min() noexcept { return type{std::numeric_limits<T>::min()};}
static constexpr type lowest() noexcept { return type{std::numeric_limits<T>::lowest()};}
static constexpr type max() noexcept { return type{std::numeric_limits<T>::max()};}
static constexpr type epsilon() noexcept { return type{std::numeric_limits<T>::epsilon()};}
static constexpr type round_error() noexcept { return type{std::numeric_limits<T>::round_error()};}
static constexpr type infinity() noexcept { return type{std::numeric_limits<T>::infinity()};}
static constexpr type quiet_NaN() noexcept { return type{std::numeric_limits<T>::quiet_NaN()};}
static constexpr type signaling_NaN() noexcept { return type{std::numeric_limits<T>::signaling_NaN()};}
static constexpr type denorm_min() noexcept { return type{std::numeric_limits<T>::denorm_min()};}
STRONG_NODISCARD static constexpr type min() noexcept { return type{std::numeric_limits<T>::min()};}
STRONG_NODISCARD static constexpr type lowest() noexcept { return type{std::numeric_limits<T>::lowest()};}
STRONG_NODISCARD static constexpr type max() noexcept { return type{std::numeric_limits<T>::max()};}
STRONG_NODISCARD static constexpr type epsilon() noexcept { return type{std::numeric_limits<T>::epsilon()};}
STRONG_NODISCARD static constexpr type round_error() noexcept { return type{std::numeric_limits<T>::round_error()};}
STRONG_NODISCARD static constexpr type infinity() noexcept { return type{std::numeric_limits<T>::infinity()};}
STRONG_NODISCARD static constexpr type quiet_NaN() noexcept { return type{std::numeric_limits<T>::quiet_NaN()};}
STRONG_NODISCARD static constexpr type signaling_NaN() noexcept { return type{std::numeric_limits<T>::signaling_NaN()};}
STRONG_NODISCARD static constexpr type denorm_min() noexcept { return type{std::numeric_limits<T>::denorm_min()};}
};
#endif //STRONG_TYPE_ARITHMETIC_HPP
6 changes: 5 additions & 1 deletion include/strong_type/boolean.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ struct boolean
class modifier<T, impl::void_t<decltype(static_cast<bool>(std::declval<const underlying_type_t<T>>()))>>
{
public:
explicit STRONG_CONSTEXPR operator bool() const
STRONG_NODISCARD
explicit
STRONG_CONSTEXPR
operator bool()
const
noexcept(noexcept(static_cast<bool>(value_of(std::declval<const T&>()))))
{
const auto& self = static_cast<const T&>(*this);
Expand Down
8 changes: 8 additions & 0 deletions include/strong_type/difference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class difference::modifier<::strong::type<T, Tag, M...>>
return lh;
}

STRONG_NODISCARD
friend
STRONG_CONSTEXPR
type operator+(type lh, const type& rh)
Expand All @@ -152,6 +153,7 @@ class difference::modifier<::strong::type<T, Tag, M...>>
return lh;
}

STRONG_NODISCARD
friend
STRONG_CONSTEXPR
type operator-(type lh, const type& rh)
Expand All @@ -160,6 +162,7 @@ class difference::modifier<::strong::type<T, Tag, M...>>
return lh;
}

STRONG_NODISCARD
friend
STRONG_CONSTEXPR
type operator*(type lh, const T& rh)
Expand All @@ -168,6 +171,7 @@ class difference::modifier<::strong::type<T, Tag, M...>>
return lh;
}

STRONG_NODISCARD
friend
STRONG_CONSTEXPR
type operator*(const T& lh, type rh)
Expand All @@ -176,6 +180,7 @@ class difference::modifier<::strong::type<T, Tag, M...>>
return rh;
}

STRONG_NODISCARD
friend
STRONG_CONSTEXPR
type operator/(type lh, const T& rh)
Expand All @@ -184,6 +189,7 @@ class difference::modifier<::strong::type<T, Tag, M...>>
return lh;
}

STRONG_NODISCARD
friend
STRONG_CONSTEXPR
T operator/(const type& lh, const type& rh)
Expand All @@ -192,6 +198,7 @@ class difference::modifier<::strong::type<T, Tag, M...>>
}

template <typename TT = T, typename = decltype(std::declval<TT&>() %= std::declval<const TT&>())>
STRONG_NODISCARD
friend
STRONG_CONSTEXPR
type operator%(type lh, const T& rh)
Expand All @@ -202,6 +209,7 @@ class difference::modifier<::strong::type<T, Tag, M...>>
}

template <typename TT = T, typename = decltype(std::declval<TT>() % std::declval<TT>())>
STRONG_NODISCARD
friend
STRONG_CONSTEXPR
T operator%(type lh, type rh)
Expand Down
1 change: 1 addition & 0 deletions include/strong_type/hashable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct hash<::strong::type<T, Tag, M...>>
{
using type = ::strong::type<T, Tag, M...>;

STRONG_NODISCARD
decltype(auto)
operator()(
const ::strong::hashable::modifier<type> &t)
Expand Down
7 changes: 7 additions & 0 deletions include/strong_type/range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class range::modifier<
using iterator = ::strong::type<r_iterator, Tag, strong::iterator>;
using const_iterator = ::strong::type<r_const_iterator, Tag, strong::iterator>;

STRONG_NODISCARD
constexpr
iterator
begin()
Expand All @@ -53,6 +54,7 @@ class range::modifier<
return iterator{value_of(self).begin()};
}

STRONG_NODISCARD
constexpr
iterator
end()
Expand All @@ -62,6 +64,7 @@ class range::modifier<
return iterator{value_of(self).end()};
}

STRONG_NODISCARD
constexpr
const_iterator
cbegin()
Expand All @@ -72,6 +75,7 @@ class range::modifier<
return const_iterator{value_of(self).begin()};
}

STRONG_NODISCARD
constexpr
const_iterator
cend()
Expand All @@ -82,6 +86,7 @@ class range::modifier<
return const_iterator{value_of(self).end()};
}

STRONG_NODISCARD
constexpr
const_iterator
begin()
Expand All @@ -92,6 +97,7 @@ class range::modifier<
return const_iterator{value_of(self).begin()};
}

STRONG_NODISCARD
constexpr
const_iterator
end()
Expand All @@ -103,6 +109,7 @@ class range::modifier<
}

template <typename TT = const T&>
STRONG_NODISCARD
constexpr
decltype(std::declval<TT>().size())
size()
Expand Down
6 changes: 4 additions & 2 deletions test/test_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
#include <array>

namespace {
template<typename R, typename = int>
template <typename T>
constexpr bool ignore(const T&) { return true;}
template<typename R, typename = bool>
struct has_size : std::false_type {
};

template<typename R>
struct has_size<R, decltype(std::declval<const R&>().size(),1)>
struct has_size<R, decltype(ignore(std::declval<const R&>().size()))>
: std::true_type
{
};
Expand Down

0 comments on commit d101e70

Please sign in to comment.