Skip to content

Commit

Permalink
Implemented new instruction encoding scheme that is simpler and more …
Browse files Browse the repository at this point in the history
…efficient. Fixes #17.
  • Loading branch information
jwtowner committed Aug 5, 2024
1 parent b321211 commit 67070fa
Show file tree
Hide file tree
Showing 2 changed files with 218 additions and 250 deletions.
17 changes: 4 additions & 13 deletions lug/detail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,22 +293,22 @@ template <class Fn, class = std::enable_if_t<std::is_invocable_v<Fn>>>
scope_exit(Fn) -> scope_exit<std::decay_t<Fn>>;

template <class Error, class T, class U, class V>
inline void assure_in_range(T x, U minval, V maxval)
constexpr void assure_in_range(T x, U minval, V maxval)
{
if (!((minval <= x) && (x <= maxval)))
throw Error();
}

template <class Error, class T, class U>
[[nodiscard]] inline auto checked_add(T x, U y)
[[nodiscard]] constexpr auto checked_add(T x, U y)
{
if (((std::numeric_limits<decltype(x + y)>::max)() - x) < y)
throw Error();
return x + y;
}

template<class InputIt, class UnaryPredicate>
[[nodiscard]] inline InputIt escaping_find_if(InputIt first, InputIt last, UnaryPredicate pred)
[[nodiscard]] constexpr InputIt escaping_find_if(InputIt first, InputIt last, UnaryPredicate pred)
{
for ( ; first != last; ++first) {
const int status = pred(*first);
Expand All @@ -320,17 +320,8 @@ template<class InputIt, class UnaryPredicate>
return last;
}

template <class Sequence, class T>
inline std::size_t push_back_unique(Sequence& s, T&& x)
{
if (auto i = std::find(std::cbegin(s), std::cend(s), x); i != std::cend(s))
return static_cast<std::size_t>(std::distance(std::cbegin(s), i));
s.push_back(std::forward<T>(x));
return s.size() - 1;
}

template <class Sequence>
[[nodiscard]] inline auto pop_back(Sequence& s) -> typename Sequence::value_type
[[nodiscard]] constexpr auto pop_back(Sequence& s) -> typename Sequence::value_type
{
typename Sequence::value_type result{std::move(s.back())}; // NOLINT(misc-const-correctness)
s.pop_back();
Expand Down
Loading

0 comments on commit 67070fa

Please sign in to comment.