all repos — fluxbox @ 3c050c3d99d5def5bed329c88b966fe0c78fefcc

custom fork of the fluxbox windowmanager

Add explicit ReturnType cast to operator() of FbTk::Slots

without this it wasn't possible to construct a Slot returning void from functors returning some
real value because the compiler would complain about "return statement with a value in a function
returning void".

Theoretically, this may produce some unexpected type conversions, because static_cast is slightly
stronger than implicit cast, but I judge the risk to be negligable (the alternative would be to
provide explicit specializations for slots returning void - too much typing)
Pavel Labath pavelo@centrum.sk
commit

3c050c3d99d5def5bed329c88b966fe0c78fefcc

parent

e67b9a6f833fd8af3be105ef411f8743d94e25d9

1 files changed, 5 insertions(+), 4 deletions(-)

jump to
M src/FbTk/Slot.hhsrc/FbTk/Slot.hh

@@ -80,7 +80,7 @@ typename Arg2 = SigImpl::EmptyArg, typename Arg3 = SigImpl::EmptyArg>

class SlotImpl: public Slot<ReturnType, Arg1, Arg2, Arg3> { public: virtual ReturnType operator()(Arg1 arg1, Arg2 arg2, Arg3 arg3) - { return m_functor(arg1, arg2, arg3); } + { return static_cast<ReturnType>(m_functor(arg1, arg2, arg3)); } SlotImpl(Functor functor) : m_functor(functor) {}

@@ -92,7 +92,8 @@ /// Specialization for two arguments

template<typename Functor, typename ReturnType, typename Arg1, typename Arg2> class SlotImpl<Functor, ReturnType, Arg1, Arg2, SigImpl::EmptyArg>: public Slot<ReturnType, Arg1, Arg2> { public: - virtual ReturnType operator()(Arg1 arg1, Arg2 arg2) { return m_functor(arg1, arg2); } + virtual ReturnType operator()(Arg1 arg1, Arg2 arg2) + { return static_cast<ReturnType>(m_functor(arg1, arg2)); } SlotImpl(Functor functor) : m_functor(functor) {}

@@ -104,7 +105,7 @@ /// Specialization for one argument

template<typename Functor, typename ReturnType, typename Arg1> class SlotImpl<Functor, ReturnType, Arg1, SigImpl::EmptyArg, SigImpl::EmptyArg>: public Slot<ReturnType, Arg1> { public: - virtual ReturnType operator()(Arg1 arg1) { return m_functor(arg1); } + virtual ReturnType operator()(Arg1 arg1) { return static_cast<ReturnType>(m_functor(arg1)); } SlotImpl(Functor functor) : m_functor(functor) {}

@@ -116,7 +117,7 @@ /// Specialization for no arguments

template<typename Functor, typename ReturnType> class SlotImpl<Functor, ReturnType, SigImpl::EmptyArg, SigImpl::EmptyArg, SigImpl::EmptyArg>: public Slot<ReturnType> { public: - virtual ReturnType operator()() { return m_functor(); } + virtual ReturnType operator()() { return static_cast<ReturnType>(m_functor()); } SlotImpl(Functor functor) : m_functor(functor) {}