Add generic 'contains' method, and remove incorrect FIXME.

This commit is contained in:
Stephen Anthony 2020-12-27 22:38:09 -03:30
parent 2a69ba4ed0
commit b45b997923
3 changed files with 5 additions and 7 deletions

View File

@ -32,7 +32,6 @@ namespace Common {
*/ */
struct Point struct Point
{ {
// FIXME : make this uInt32
Int32 x{0}; //!< The horizontal part of the point Int32 x{0}; //!< The horizontal part of the point
Int32 y{0}; //!< The vertical part of the point Int32 y{0}; //!< The vertical part of the point

View File

@ -170,10 +170,10 @@ namespace BSPF
return (val < lower) ? upper : (val > upper) ? lower : val; return (val < lower) ? upper : (val > upper) ? lower : val;
} }
// Test whether the vector contains the given value // Test whether a container contains the given value
template<typename T> template<typename Container>
bool contains(const std::vector<T>& v, const T& elem) { bool contains(const Container& c, typename Container::const_reference elem) {
return !(v.empty() || std::find(v.begin(), v.end(), elem) == v.end()); return std::find(c.cbegin(), c.cend(), elem) != c.end();
} }
// Convert string to given case // Convert string to given case

View File

@ -316,8 +316,7 @@ bool Widget::isWidgetInChain(Widget* w, Widget* find)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Widget::isWidgetInChain(const WidgetArray& list, Widget* find) bool Widget::isWidgetInChain(const WidgetArray& list, Widget* find)
{ {
return std::any_of(list.cbegin(), list.cend(), return BSPF::contains(list, find);
[&](Widget* w) { return w == find; });
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -