diff --git a/assignment-client/src/assets/AutoBaker.cpp b/assignment-client/src/assets/AutoBaker.cpp index c56e00d025..fae895e635 100644 --- a/assignment-client/src/assets/AutoBaker.cpp +++ b/assignment-client/src/assets/AutoBaker.cpp @@ -10,23 +10,26 @@ // #include "AutoBaker.h" +#include <shared/Algorithms.h> + +using namespace alg; void AutoBaker::addPendingBake(AssetHash hash) { _pendingBakes.push_back(hash); + + // Maybe start baking it right away } bool AutoBaker::assetNeedsBaking(AssetHash hash) { return true; } -AutoBaker::Status AutoBaker::getAssetStatus(AssetHash hash) { - auto pendingIt = std::find(_pendingBakes.cbegin(), _pendingBakes.cend(), hash); - if (pendingIt != _pendingBakes.cend()) { +BakingStatus AutoBaker::getAssetStatus(AssetHash hash) { + if (find(_pendingBakes, hash) != std::end(_pendingBakes)) { return Pending; } - auto bakingIt = std::find(_currentlyBaking.cbegin(), _currentlyBaking.cend(), hash); - if (bakingIt != _currentlyBaking.cend()) { + if (find(_currentlyBaking, hash) != std::end(_currentlyBaking)) { return Baking; } diff --git a/libraries/shared/src/shared/Algorithms.h b/libraries/shared/src/shared/Algorithms.h index 4d486efc43..b85a3df6c5 100644 --- a/libraries/shared/src/shared/Algorithms.h +++ b/libraries/shared/src/shared/Algorithms.h @@ -9,20 +9,30 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef Algorithms_h -#define Algorithms_h +#ifndef hifi_Algorithms_h +#define hifi_Algorithms_h #include <algorithm> +#include <iterator> +#include <type_traits> namespace alg { +template <class Container, class ValueType> +auto find(const Container& container, const ValueType& value) -> decltype(std::begin(container)) { + return std::find(std::begin(container), std::end(container), value); +} +template <class Container, class Predicate> +auto find_if(const Container& container, Predicate&& predicate) -> decltype(std::begin(container)) { + return std::find_if(std::begin(container), std::end(container), std::forward<Predicate>(predicate)); +} - - - - +template <class Container, class Predicate> +auto find_if_not(const Container& container, Predicate&& predicate) -> decltype(std::begin(container)) { + return std::find_if_not(std::begin(container), std::end(container), std::forward<Predicate>(predicate)); +} } -#endif /* Algorithms_hpp */ +#endif // hifi_Algorithms_hpp