diff --git a/research/try.cpp b/research/try.cpp index 5a84633a0..15c95d059 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -68,6 +68,7 @@ template #include "lib/iter-adapter-ptr-deref.hpp" #include "lib/iter-adapter-stl.hpp" #include "lib/itertools.hpp" +#include "lib/util-coll.hpp" #include #include @@ -77,6 +78,7 @@ template using std::string; using std::make_unique; +using util::max; @@ -90,27 +92,6 @@ using Strs = std::vector; constexpr auto elems = [](auto& coll) { return lib::ptrDeref (lib::iter_stl::eachElm (coll)); }; -namespace lib { - - namespace { - - template - struct RemovePtr> { typedef T Type; }; - } -} - namespace { - template - inline auto - max (IT&& elms) - { - using Val = std::remove_reference_t; - Val res = std::numeric_limits::min(); - for (auto& elm : std::forward (elms)) - if (elm > res) - res = elm; - return res; - } - } int main (int, char**) diff --git a/src/lib/iter-adapter-ptr-deref.hpp b/src/lib/iter-adapter-ptr-deref.hpp index 1d48f1cd7..f42a46284 100644 --- a/src/lib/iter-adapter-ptr-deref.hpp +++ b/src/lib/iter-adapter-ptr-deref.hpp @@ -51,6 +51,11 @@ #include +namespace std { + template + class unique_ptr; +} + namespace lib { namespace { @@ -72,6 +77,9 @@ namespace lib { template struct RemovePtr { typedef const T Type; }; + /** allow automatic dereferencing of std::unique_ptr */ + template + struct RemovePtr> { typedef T Type; }; } diff --git a/src/lib/util-coll.hpp b/src/lib/util-coll.hpp index 1aba93075..a635bc318 100644 --- a/src/lib/util-coll.hpp +++ b/src/lib/util-coll.hpp @@ -26,8 +26,11 @@ ** collections and sequences (given by iterator). Mostly, these are tiny bits of ** existing functionality, just packaged in a more fluent and readable way. ** - accessors - ** - \c first() to get the first element - ** - \c last() to access the last element + ** - util::first() to get the first element + ** - util::last() to access the last element + ** - aggregate functions + ** - util::max() compute the maximum of comparable numbers + ** - util::min() ** ** @warning some functions only available when including itertools.hpp beforehand ** @@ -43,6 +46,8 @@ #include "lib/util.hpp" #include "lib/meta/trait.hpp" +#include + namespace util { @@ -157,21 +162,60 @@ namespace util { __ensure_nonempty(ii); return lib::pull_last (ii); } -#endif +#endif /* === generic container helpers === */ - struct WeakPtrComparator - { - template - bool - operator() (std::weak_ptr const& l, std::weak_ptr const& r) const - { - return l.lock().get() < r.lock().get(); - } - }; + template + inline auto + max (IT&& elms) + { + using Val = typename std::remove_reference_t::value_type; + Val res = std::numeric_limits::min(); + for (auto const& elm : std::forward (elms)) + if (elm > res) + res = elm; + return res; + } + + template + inline auto + max (CON const& elms) + { + using Val = typename std::remove_reference_t::value_type; + Val res = std::numeric_limits::min(); + for (auto const& elm : elms) + if (elm > res) + res = elm; + return res; + } + + + template + inline auto + min (IT&& elms) + { + using Val = typename std::remove_reference_t::value_type; + Val res = std::numeric_limits::max(); + for (auto const& elm : std::forward (elms)) + if (elm < res) + res = elm; + return res; + } + + template + inline auto + min (CON const& elms) + { + using Val = typename std::remove_reference_t::value_type; + Val res = std::numeric_limits::max(); + for (auto const& elm : elms) + if (elm < res) + res = elm; + return res; + } diff --git a/src/stage/panel/timeline-panel-obsolete.hpp b/src/stage/panel/timeline-panel-obsolete.hpp index 1e2bf97b2..b762c372d 100644 --- a/src/stage/panel/timeline-panel-obsolete.hpp +++ b/src/stage/panel/timeline-panel-obsolete.hpp @@ -22,7 +22,7 @@ /** @file timeline-panel-obsolete.hpp ** This file contains the definition of the timeline panel - ** @deprecated rework of timeline widget iminent + ** @deprecated rework of timeline widget imminent */ diff --git a/src/stage/timeline/track-presenter.hpp b/src/stage/timeline/track-presenter.hpp index fec152bdc..ddbedae12 100644 --- a/src/stage/timeline/track-presenter.hpp +++ b/src/stage/timeline/track-presenter.hpp @@ -92,6 +92,7 @@ #include "stage/timeline/track-body.hpp" #include "lib/iter-adapter-ptr-deref.hpp" #include "lib/iter-adapter-stl.hpp" +#include "lib/util-coll.hpp" #include "lib/itertools.hpp" /////////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1201 : test/code... remove this #include "lib/format-cout.hpp" @@ -359,39 +360,18 @@ namespace timeline { subTrack->establishLayout (displayEvaluation); } - namespace { - template - inline auto - max (IT&& elms) - { - using Val = typename IT::value_type; - Val res = std::numeric_limits::min(); - for (auto& elm : std::forward (elms)) - if (elm > res) - res = elm; - return res; - } - } - /** */ template inline void DisplayFrame::establishExtension (CLPS clips, MRKS markers) { -// int maxVSize = max (lib::transformIterator(clips, -// [](ClipPresenter const& clip) -// { -// return clip.determineRequiredVerticalExtension(); -// })); + int maxVSize = util::max (lib::transformIterator(clips, + [](ClipPresenter const& clip) + { + return clip.determineRequiredVerticalExtension(); + })); int headSize = this->head_.get_height(); int bodySize = this->body_.calcHeight(); - - - ////////////////////TODO: was ist? -// typedef typename IT::value_type pointer; -// typedef typename RemovePtr::Type value_type; - -/// wobei IT = lib::RangeIter<__gnu_cxx::__normal_iterator*, ... } diff --git a/src/stage/widget/timeline/timeline-layout-helper.hpp b/src/stage/widget/timeline/timeline-layout-helper.hpp index 34ea7a4f6..60b025bfa 100644 --- a/src/stage/widget/timeline/timeline-layout-helper.hpp +++ b/src/stage/widget/timeline/timeline-layout-helper.hpp @@ -37,6 +37,18 @@ #include +namespace util { ///////////////////////////////////////////////////////////////////////////////TICKET #959 : obsolete helper utility inlined here directly + struct WeakPtrComparator ///< @deprecated unsafe and generally a bad idea + { + template + bool + operator() (std::weak_ptr const& l, std::weak_ptr const& r) const + { + return l.lock().get() < r.lock().get(); + } + }; +} ///////////////////////////////////////////////////////////////////////////////TICKET #959 : obsolete helper utility inlined here directly + namespace stage { namespace model { diff --git a/tests/library/util-collection-test.cpp b/tests/library/util-collection-test.cpp index eb6292598..7a60c06e9 100644 --- a/tests/library/util-collection-test.cpp +++ b/tests/library/util-collection-test.cpp @@ -98,6 +98,9 @@ namespace test { verify_accessFirstLast (container, NUM_ELMS); verify_accessFirstLast (iterator, NUM_ELMS); + + verify_Min_Max (container, NUM_ELMS); + verify_Min_Max (iterator, NUM_ELMS); } @@ -113,6 +116,25 @@ namespace test { } + template + void + verify_Min_Max (COL const& col, uint lim) + { + uint expectedMax = lim; + uint expectedMin = 1; + + CHECK (max (col) == expectedMax); + CHECK (min (col) == expectedMin); + + COL empty; + + using Val = typename COL::value_type; + + CHECK (max (empty) == std::numeric_limits::min()); + CHECK (min (empty) == std::numeric_limits::max()); + } + + void verify_typeDetectors() {