diff --git a/src/gui/widgets/grid.cpp b/src/gui/widgets/grid.cpp index 046ace15795..692d51b9dfa 100644 --- a/src/gui/widgets/grid.cpp +++ b/src/gui/widgets/grid.cpp @@ -796,14 +796,14 @@ void tgrid::child_populate_dirty_list(twindow& caller, twidget* tgrid::find_widget(const tpoint& coordinate, const bool must_be_active) { - return tgrid_implementation::find_widget( + return tgrid_implementation::find_widget( *this, coordinate, must_be_active); } const twidget* tgrid::find_widget(const tpoint& coordinate, const bool must_be_active) const { - return tgrid_implementation::find_widget( + return tgrid_implementation::find_widget( *this, coordinate, must_be_active); } diff --git a/src/gui/widgets/grid_private.hpp b/src/gui/widgets/grid_private.hpp index 0af71bd41d8..9fd605e1127 100644 --- a/src/gui/widgets/grid_private.hpp +++ b/src/gui/widgets/grid_private.hpp @@ -36,6 +36,27 @@ namespace gui2 { +/** + * Helper struct to get the same constness for T and U. + * + * @param T A type to determine the constness. + * @param U Non const type to set the constness off. + */ +template +struct tconst_duplicator +{ + /** The type to use, if T not const U is also not const. */ + typedef U type; +}; + +/** Specialialized version of tconst_duplicator when T is a const type. */ +template +struct tconst_duplicator +{ + /** The type to use, const U. */ + typedef const U type; +}; + /** * Helper to implement private functions without modifing the header. * @@ -44,47 +65,20 @@ namespace gui2 { */ struct tgrid_implementation { - /** - * Wrapper function for - * twidget* tgrid::find_widget(const tpoint&, const bool). - */ - static twidget* find_widget( - tgrid& grid, const tpoint& coordinate, const bool must_be_active) - { - return find_widget_implementation - (grid, coordinate, must_be_active); - } - - /** - * Wrapper function for - * const twidget* tgrid::find_widget(const tpoint&, const bool) const. - */ - static const twidget* find_widget(const tgrid& grid, - const tpoint& coordinate, const bool must_be_active) - { - return find_widget_implementation - (grid, coordinate, must_be_active); - } - -private: - /** * Implementation for the wrappers for * [const] twidget* tgrid::find_widget(const tpoint&, const bool) [const]. * - * @param W twidget* or const twidget*. - * @param G if W == twidget* -> tgrid else const tgrid - * @param C if W == twidget* -> tgrid::tchild - * else const tgrid::tchild. + * @param W twidget or const twidget. */ - template - static W find_widget_implementation(G& grid, const tpoint& coordinate, - const bool must_be_active) + template + static W* find_widget(typename tconst_duplicator::type& grid, + const tpoint& coordinate, const bool must_be_active) { - foreach(C& child, grid.children_) { + typedef typename tconst_duplicator::type hack; + foreach(hack& child, grid.children_) { - W widget = child.widget(); + W* widget = child.widget(); if(!widget) { continue; }