Removed bind_void
This is no longer needed with the compilers we support. It is needed on VS 2013, but
we dropped that. Don't know when GCC or Clang stopped needed it (if they ever did).
I'm guessing the "function that returns a value cannot be bound in a function type
that returns void" behavior wasn't an intentional design. Additionally, I don't believe
point 1 raised in the accompanying comment has ever been true... if so, pretty sure
we wouldn't have been able to build at all.
Also removed unnecessary global.hpp include from functional.hpp.
(cherry-picked from commit 17fc9d71db
)
This commit is contained in:
parent
34a18a7692
commit
68f066d94a
6 changed files with 11 additions and 90 deletions
|
@ -16,6 +16,8 @@
|
|||
|
||||
#include "gui/auxiliary/iterator/walker_grid.hpp"
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace gui2
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
#include "gui/auxiliary/iterator/walker_tree_node.hpp"
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace gui2
|
||||
|
|
|
@ -16,9 +16,11 @@
|
|||
|
||||
#include "gui/auxiliary/iterator/walker_widget.hpp"
|
||||
|
||||
#include <cassert>
|
||||
#include "global.hpp"
|
||||
#include "gui/widgets/widget.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
|
|
|
@ -336,7 +336,7 @@ void preferences_dialog::initialize_sound_option_group(const std::string& id_suf
|
|||
// the callback the setter callback is duplicated in the on-change callback. The field
|
||||
// class could possibly use some reworking to make this less redundant, but for now it
|
||||
// works well enough.
|
||||
register_bool(toggle_widget_id, true, toggle_getter, bind_void(toggle_setter, _1),
|
||||
register_bool(toggle_widget_id, true, toggle_getter, std::bind(toggle_setter, _1),
|
||||
std::bind(sound_toggle_on_change<toggle_setter>, std::ref(window), volume_widget_id, _1), true);
|
||||
|
||||
// Set up the volume slider. integer_field doesn't have a callback-on-changed mechanism.
|
||||
|
@ -487,7 +487,7 @@ void preferences_dialog::post_build(window& window)
|
|||
/* SELECT THEME */
|
||||
connect_signal_mouse_left_click(
|
||||
find_widget<button>(&window, "choose_theme", false),
|
||||
bind_void(&show_theme_dialog));
|
||||
std::bind(&show_theme_dialog));
|
||||
|
||||
//
|
||||
// SOUND PANEL
|
||||
|
|
|
@ -103,13 +103,13 @@ void screenshot_notification::pre_show(window& window)
|
|||
|
||||
button& open_b = find_widget<button>(&window, "open", false);
|
||||
connect_signal_mouse_left_click(
|
||||
open_b, bind_void(&desktop::open_object, std::ref(path_)));
|
||||
open_b, std::bind(&desktop::open_object, std::ref(path_)));
|
||||
open_b.set_active(false);
|
||||
|
||||
button& bdir_b = find_widget<button>(&window, "browse_dir", false);
|
||||
connect_signal_mouse_left_click(
|
||||
bdir_b,
|
||||
bind_void(&desktop::open_object,
|
||||
std::bind(&desktop::open_object,
|
||||
std::ref(screenshots_dir_path_)));
|
||||
|
||||
button& save_b = find_widget<button>(&window, "save", false);
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "global.hpp"
|
||||
#include <functional>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
|
@ -30,87 +29,3 @@ namespace std { // Some compilers can't handle it being specialized in the globa
|
|||
template<int N>
|
||||
struct is_placeholder<boost::arg<N>> : public integral_constant<int, N> {};
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
template<typename Ret, typename... T>
|
||||
struct apply {
|
||||
using result_type = void;
|
||||
apply(const std::function<Ret(T...)>& fcn) : fcn(fcn) {}
|
||||
apply(Ret(*fcn)(T...)) : fcn(fcn) {}
|
||||
void operator()(T... params) {
|
||||
fcn(std::forward<T>(params)...);
|
||||
}
|
||||
private:
|
||||
std::function<Ret(T...)> fcn;
|
||||
};
|
||||
|
||||
template<typename Ret, typename... T>
|
||||
apply<Ret, T...> make_apply(std::function<Ret(T...)> fcn) {
|
||||
return apply<Ret, T...>(fcn);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
struct function_base {
|
||||
using type = typename function_base<decltype(&F::operator())>::type;
|
||||
};
|
||||
|
||||
template<typename Ret, typename... P>
|
||||
struct function_base<Ret(P...)> {
|
||||
typedef Ret type(P...);
|
||||
};
|
||||
|
||||
template<typename Ret, typename... P>
|
||||
struct function_base<Ret(*)(P...)> {
|
||||
typedef Ret type(P...);
|
||||
};
|
||||
|
||||
template<typename Ret, typename Class, typename... P>
|
||||
struct function_base<Ret(Class::*)(P...)> {
|
||||
typedef Ret type(Class,P...);
|
||||
};
|
||||
|
||||
template<typename Ret, typename Class, typename... P>
|
||||
struct function_base<Ret(Class::*)(P...)const> {
|
||||
typedef Ret type(const Class,P...);
|
||||
};
|
||||
|
||||
template<typename Ret, typename Class, typename... P>
|
||||
struct function_base<Ret(Class::*)(P...)volatile > {
|
||||
typedef Ret type(volatile Class,P...);
|
||||
};
|
||||
|
||||
template<typename Ret, typename Class, typename... P>
|
||||
struct function_base<Ret(Class::*)(P...)const volatile> {
|
||||
typedef Ret type(const volatile Class,P...);
|
||||
};
|
||||
|
||||
template<typename Ret, typename... P>
|
||||
struct function_base<std::function<Ret(P...)>> {
|
||||
typedef Ret type(P...);
|
||||
};
|
||||
}
|
||||
|
||||
template<typename F, typename... P>
|
||||
auto bind_void(F fcn, P... bindings)
|
||||
#ifndef HAVE_CXX14
|
||||
-> decltype(
|
||||
std::bind(detail::make_apply(std::function<typename detail::function_base<F>::type>(fcn)), bindings...)
|
||||
)
|
||||
#endif
|
||||
{
|
||||
using T = typename detail::function_base<F>::type;
|
||||
return std::bind(detail::make_apply(std::function<T>(fcn)), bindings...);
|
||||
}
|
||||
|
||||
/* A note on why std::bind is not flexible enough:
|
||||
|
||||
1. The functions produced do not silently consume extra parameters passed to them.
|
||||
This is not a bad thing per se, but some of Wesnoth's code relied on it.
|
||||
It's useful behaviour, as well.
|
||||
|
||||
2. A function that returns a value cannot be bound in a function type that returns void.
|
||||
This is also relied upon in several places.
|
||||
|
||||
If behaviour #1 is needed, we can use boost::bind, though a lambda with unused arguments may be better.
|
||||
For behaviour #2, the bind_void function is provided.
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue