From 15b2a4862eb1d7772caf3b47bf38656808229af5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 2 Sep 2018 07:57:36 +0200 Subject: [PATCH] protocol/RangeArg: add Contains() --- src/db/DatabasePrint.cxx | 4 +--- src/protocol/RangeArg.hxx | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/db/DatabasePrint.cxx b/src/db/DatabasePrint.cxx index dd981bfc4..2d923c618 100644 --- a/src/db/DatabasePrint.cxx +++ b/src/db/DatabasePrint.cxx @@ -202,9 +202,7 @@ db_selection_print(Response &r, Partition &partition, if (sort == TAG_NUM_OF_ITEM_TYPES) { if (!window.IsAll()) s = [s, window, &i](const LightSong &song){ - const bool in_window = i >= window.start && i < window.end; - ++i; - if (in_window) + if (window.Contains(i++)) s(song); }; diff --git a/src/protocol/RangeArg.hxx b/src/protocol/RangeArg.hxx index 796c25959..9b1d720ac 100644 --- a/src/protocol/RangeArg.hxx +++ b/src/protocol/RangeArg.hxx @@ -42,6 +42,10 @@ struct RangeArg { constexpr bool IsAll() const noexcept { return *this == All(); } + + constexpr bool Contains(unsigned i) const noexcept { + return i >= start && i < end; + } }; #endif