mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-16 17:33:59 +00:00
Clean up and expand ranges compat layer
This commit is contained in:
parent
6d97ac494e
commit
2bbcd5f814
|
@ -46,7 +46,7 @@ undo_action_container::undo_action_container()
|
|||
bool undo_action_container::undo(int side)
|
||||
{
|
||||
int last_unit_id = resources::gameboard->unit_id_manager().get_save_id();
|
||||
for(auto& p_step : utils::reversed_view(steps_)) {
|
||||
for(auto& p_step : steps_ | utils::views::reverse) {
|
||||
p_step->undo(side);
|
||||
}
|
||||
if(last_unit_id - unit_id_diff_ < 0) {
|
||||
|
|
|
@ -285,7 +285,7 @@ public:
|
|||
|
||||
virtual void recalculate() const
|
||||
{
|
||||
for(const auto& f : utils::reversed_view(facets_)) {
|
||||
for(const auto& f : facets_ | utils::views::reverse) {
|
||||
if (f->active()) {
|
||||
this->value_ = f->get_ptr();
|
||||
this->valid_ = true;
|
||||
|
|
|
@ -32,21 +32,7 @@
|
|||
#include "exceptions.hpp"
|
||||
#include "utils/const_clone.hpp"
|
||||
#include "utils/optional_reference.hpp"
|
||||
|
||||
#ifdef CONFIG_USE_STL_RANGES
|
||||
#undef CONFIG_USE_STL_RANGES
|
||||
#endif
|
||||
|
||||
#ifdef __cpp_lib_ranges // C++20
|
||||
#define CONFIG_USE_STL_RANGES
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USE_STL_RANGES
|
||||
#include <ranges>
|
||||
#else
|
||||
#include <boost/range/adaptor/map.hpp>
|
||||
#include <boost/range/adaptor/transformed.hpp>
|
||||
#endif
|
||||
#include "utils/ranges.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <iosfwd>
|
||||
|
@ -808,19 +794,11 @@ public:
|
|||
|
||||
/** In-order iteration over all children. */
|
||||
auto all_children_view() const
|
||||
#ifdef CONFIG_USE_STL_RANGES
|
||||
{ return ordered_children | std::views::transform(&config::any_tag_view<const config&>); }
|
||||
#else
|
||||
{ return ordered_children | boost::adaptors::transformed(&config::any_tag_view<const config&>); }
|
||||
#endif
|
||||
{ return ordered_children | utils::views::transform(&config::any_tag_view<const config&>); }
|
||||
|
||||
/** In-order iteration over all children. */
|
||||
auto all_children_view()
|
||||
#ifdef CONFIG_USE_STL_RANGES
|
||||
{ return ordered_children | std::views::transform(&config::any_tag_view<config&>); }
|
||||
#else
|
||||
{ return ordered_children | boost::adaptors::transformed(&config::any_tag_view<config&>); }
|
||||
#endif
|
||||
{ return ordered_children | utils::views::transform(&config::any_tag_view<config&>); }
|
||||
|
||||
#endif // __cpp_explicit_this_parameter
|
||||
|
||||
|
@ -926,11 +904,7 @@ public:
|
|||
/** A non-owning view over all child tag names. */
|
||||
auto child_name_view() const
|
||||
{
|
||||
#ifdef __cpp_lib_ranges
|
||||
return children_ | std::views::keys;
|
||||
#else
|
||||
return children_ | boost::adaptors::map_keys;
|
||||
#endif
|
||||
return children_ | utils::views::keys;
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -260,7 +260,7 @@ sdl_handler::sdl_handler(const sdl_handler &that)
|
|||
event_contexts.front().add_handler(this);
|
||||
} else if(has_joined_) {
|
||||
bool found_context = false;
|
||||
for(auto &context : utils::reversed_view(event_contexts)) {
|
||||
for(auto &context : event_contexts | utils::views::reverse) {
|
||||
if(context.has_handler(&that)) {
|
||||
found_context = true;
|
||||
context.add_handler(this);
|
||||
|
@ -279,7 +279,7 @@ sdl_handler &sdl_handler::operator=(const sdl_handler &that)
|
|||
if(that.has_joined_global_) {
|
||||
join_global();
|
||||
} else if(that.has_joined_) {
|
||||
for(auto &context : utils::reversed_view(event_contexts)) {
|
||||
for(auto &context : event_contexts | utils::views::reverse) {
|
||||
if(context.has_handler(&that)) {
|
||||
join(context);
|
||||
break;
|
||||
|
@ -340,7 +340,7 @@ void sdl_handler::join_same(sdl_handler* parent)
|
|||
leave(); // should not be in multiple event contexts
|
||||
}
|
||||
|
||||
for(auto& context : utils::reversed_view(event_contexts)) {
|
||||
for(auto& context : event_contexts | utils::views::reverse) {
|
||||
if(context.has_handler(parent)) {
|
||||
join(context);
|
||||
return;
|
||||
|
@ -362,7 +362,7 @@ void sdl_handler::leave()
|
|||
member->leave();
|
||||
}
|
||||
|
||||
for(auto& context : utils::reversed_view(event_contexts)) {
|
||||
for(auto& context : event_contexts | utils::views::reverse) {
|
||||
if(context.remove_handler(this)) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ void game_data::activate_scope_variable(std::string var_name) const
|
|||
var_name.erase(itor, var_name.end());
|
||||
}
|
||||
|
||||
for (scoped_wml_variable* v : utils::reversed_view(scoped_variables)) {
|
||||
for (scoped_wml_variable* v : scoped_variables | utils::views::reverse) {
|
||||
if (v->name() == var_name) {
|
||||
recursive_activation = true;
|
||||
if (!v->activated()) {
|
||||
|
|
|
@ -237,7 +237,7 @@ bool fire_event(const ui_event event,
|
|||
bool halt = false;
|
||||
|
||||
/***** ***** ***** Pre ***** ***** *****/
|
||||
for(const auto& [chain_target, chain_event] : utils::reversed_view(event_chain)) {
|
||||
for(const auto& [chain_target, chain_event] : event_chain | utils::views::reverse) {
|
||||
const auto& signal = dispatcher_implementation::event_signal<C>(*chain_target, chain_event);
|
||||
|
||||
for(const auto& pre_func : signal.pre_child) {
|
||||
|
|
|
@ -607,7 +607,7 @@ void sdl_event_handler::mouse(const ui_event event, const point& position)
|
|||
return;
|
||||
}
|
||||
|
||||
for(auto& dispatcher : utils::reversed_view(dispatchers_)) {
|
||||
for(auto& dispatcher : dispatchers_ | utils::views::reverse) {
|
||||
if(dispatcher->get_mouse_behavior() == dispatcher::mouse_behavior::all) {
|
||||
dispatcher->fire(event, dynamic_cast<widget&>(*dispatcher), position);
|
||||
break;
|
||||
|
@ -687,7 +687,7 @@ dispatcher* sdl_event_handler::keyboard_dispatcher()
|
|||
return keyboard_focus_;
|
||||
}
|
||||
|
||||
for(auto& dispatcher : utils::reversed_view(dispatchers_)) {
|
||||
for(auto& dispatcher : dispatchers_ | utils::views::reverse) {
|
||||
if(dispatcher->get_want_keyboard_input()) {
|
||||
return dispatcher;
|
||||
}
|
||||
|
@ -698,28 +698,28 @@ dispatcher* sdl_event_handler::keyboard_dispatcher()
|
|||
|
||||
void sdl_event_handler::touch_motion(const point& position, const point& distance)
|
||||
{
|
||||
for(auto& dispatcher : utils::reversed_view(dispatchers_)) {
|
||||
for(auto& dispatcher : dispatchers_ | utils::views::reverse) {
|
||||
dispatcher->fire(SDL_TOUCH_MOTION , dynamic_cast<widget&>(*dispatcher), position, distance);
|
||||
}
|
||||
}
|
||||
|
||||
void sdl_event_handler::touch_up(const point& position)
|
||||
{
|
||||
for(auto& dispatcher : utils::reversed_view(dispatchers_)) {
|
||||
for(auto& dispatcher : dispatchers_ | utils::views::reverse) {
|
||||
dispatcher->fire(SDL_TOUCH_UP, dynamic_cast<widget&>(*dispatcher), position);
|
||||
}
|
||||
}
|
||||
|
||||
void sdl_event_handler::touch_down(const point& position)
|
||||
{
|
||||
for(auto& dispatcher : utils::reversed_view(dispatchers_)) {
|
||||
for(auto& dispatcher : dispatchers_ | utils::views::reverse) {
|
||||
dispatcher->fire(SDL_TOUCH_DOWN, dynamic_cast<widget&>(*dispatcher), position);
|
||||
}
|
||||
}
|
||||
|
||||
void sdl_event_handler::touch_multi_gesture(const point& center, float dTheta, float dDist, uint8_t numFingers)
|
||||
{
|
||||
for(auto& dispatcher : utils::reversed_view(dispatchers_)) {
|
||||
for(auto& dispatcher : dispatchers_ | utils::views::reverse) {
|
||||
dispatcher->fire(SDL_TOUCH_MULTI_GESTURE, dynamic_cast<widget&>(*dispatcher), center, dTheta, dDist, numFingers);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ bool quit_confirmation::quit()
|
|||
{
|
||||
if(!open_) {
|
||||
open_ = true;
|
||||
for(quit_confirmation* blocker : utils::reversed_view(blockers_))
|
||||
for(quit_confirmation* blocker : blockers_ | utils::views::reverse)
|
||||
{
|
||||
if(!blocker->prompt_()) {
|
||||
open_ = false;
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "scripting/lua_preferences.hpp"
|
||||
#include "scripting/plugins/context.hpp"
|
||||
#include "scripting/plugins/manager.hpp"
|
||||
#include "utils/ranges.hpp"
|
||||
|
||||
#ifdef DEBUG_LUA
|
||||
#include "scripting/debug_lua.hpp"
|
||||
|
@ -48,7 +49,6 @@
|
|||
#include <utility>
|
||||
|
||||
#include <functional>
|
||||
#include <boost/range/adaptors.hpp>
|
||||
|
||||
#include "lua/wrapper_lauxlib.h"
|
||||
|
||||
|
@ -276,7 +276,7 @@ application_lua_kernel::request_list application_lua_kernel::thread::run_script(
|
|||
// Now we have to create the context object. It is arranged as a table of boost functions.
|
||||
auto this_context_backend = std::make_shared<lua_context_backend>();
|
||||
lua_newtable(T_); // this will be the context table
|
||||
for (const std::string & key : ctxt.callbacks_ | boost::adaptors::map_keys ) {
|
||||
for (const std::string & key : ctxt.callbacks_ | utils::views::keys ) {
|
||||
lua_pushstring(T_, key.c_str());
|
||||
lua_cpp::push_function(T_, std::bind(&impl_context_backend, std::placeholders::_1, this_context_backend, key));
|
||||
lua_settable(T_, -3);
|
||||
|
|
|
@ -17,19 +17,29 @@
|
|||
#ifdef __cpp_lib_ranges
|
||||
#include <ranges>
|
||||
#else
|
||||
#include <boost/range/adaptor/filtered.hpp>
|
||||
#include <boost/range/adaptor/map.hpp>
|
||||
#include <boost/range/adaptor/reversed.hpp>
|
||||
#include <boost/range/adaptor/transformed.hpp>
|
||||
#endif
|
||||
|
||||
namespace utils
|
||||
{
|
||||
template<typename T>
|
||||
inline auto reversed_view(T& container)
|
||||
namespace utils::views
|
||||
{
|
||||
#ifdef __cpp_lib_ranges
|
||||
return std::ranges::reverse_view(container);
|
||||
#else
|
||||
return boost::adaptors::reverse(container);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
using std::views::filter;
|
||||
using std::views::keys;
|
||||
using std::views::reverse;
|
||||
using std::views::transform;
|
||||
using std::views::values;
|
||||
|
||||
#else
|
||||
|
||||
constexpr auto filter = boost::adaptors::filtered;
|
||||
constexpr auto keys = boost::adaptors::map_keys;
|
||||
constexpr auto reverse = boost::adaptors::reversed;
|
||||
constexpr auto transform = boost::adaptors::transformed;
|
||||
constexpr auto values = boost::adaptors::map_values;
|
||||
|
||||
#endif
|
||||
} // namespace utils::views
|
||||
|
|
|
@ -105,7 +105,7 @@ void highlighter::set_mouseover_hex(const map_location& hex)
|
|||
if(side_actions_->empty()) {
|
||||
return;
|
||||
}
|
||||
for(action_ptr act : utils::reversed_view(*side_actions_)) {
|
||||
for(action_ptr act : *side_actions_ | utils::views::reverse) {
|
||||
/**@todo "is_numbering_hex" is not the "correct" criterion by which to
|
||||
* select the highlighted/selected action. It's just convenient for me
|
||||
* to use at the moment since it happens to coincide with the "correct"
|
||||
|
|
|
@ -180,7 +180,7 @@ void mapbuilder::post_visit_team(std::size_t turn)
|
|||
|
||||
// Go backwards through the actions of this turn to identify
|
||||
// which ones are moves that end a turn.
|
||||
for(action_ptr action : utils::reversed_view(applied_actions_this_turn_)) {
|
||||
for(action_ptr action : applied_actions_this_turn_ | utils::views::reverse) {
|
||||
move_ptr move = std::dynamic_pointer_cast<class move>(action);
|
||||
if(move) {
|
||||
move->set_turn_number(0);
|
||||
|
@ -200,7 +200,7 @@ void mapbuilder::post_visit_team(std::size_t turn)
|
|||
void mapbuilder::restore_normal_map()
|
||||
{
|
||||
//applied_actions_ contain only the actions that we applied to the unit map
|
||||
for(action_ptr act : utils::reversed_view(applied_actions_)) {
|
||||
for(action_ptr act : applied_actions_ | utils::views::reverse) {
|
||||
act->remove_temp_modifier(unit_map_);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user