Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VS2019 / C++ 17, signal::disconnect compile error: syntax error: 'template' #72

Open
johny7 opened this issue Nov 14, 2023 · 1 comment

Comments

@johny7
Copy link

johny7 commented Nov 14, 2023

Using custom functor, Signals fail to compile with:
signal_template.hpp(537,50): error C2059: syntax error: 'template'

Here:

              // check for wrapped extended slot
              bound_extended_slot_function_type *fp;
              fp = (*it)->slot().slot_function().template target<bound_extended_slot_function_type>();

The reason behind is that the signal expects the functor to be the boost::function / std::function, that would contain the target() method.

Minimal example:

struct MyFunctorThisComparer
{
	MyFunctorThisComparer(const void* this_) {}
	bool operator==(const MyFunctorThisComparer& other) const { return true; }
};

struct MyFunctor
{
	typedef void result_type;

	template<typename F>
	void operator=(F) {}
	void operator()() {}

	// disconnect by comparison with custom predicate
	bool operator==(const MyFunctorThisComparer& other) const { return true; }
	operator MyFunctorThisComparer() const { return MyFunctorThisComparer { nullptr }; }
};

void signals_disconnect()
{
	boost::signals2::signal<
		void(), 
		//SignalSupport_::AllCall<typename boost::function_traits<void()>::result_type>,
		boost::signals2::optional_last_value<typename boost::function_traits<void()>::result_type>,
		int,
		std::less<int>,
		MyFunctor > s;

	s.connect( &signals_disconnect );
	s.disconnect( MyFunctorThisComparer(nullptr) );
}

I attempted here to provide the equivalence MyFunctorThisComparer predicate, that would filter out functors. In particular, it would know how to extract 'this' pointer from MyFunctor. However, it could be a more generic predicate.

Boost 1.72.0. However, I have checked the development version - it has the same lines there, so the issue is still present.

@fmhess
Copy link
Collaborator

fmhess commented Nov 17, 2023

I've never given much thought to allowing for the SlotFunction to be anything other than boost::function or std::function, although I do remember considering dropping the SlotFunction template parameter entirely. Recent changes to support c++20 means operator== won't even be used in the future (it uses the "contains" method instead). I guess it might be possible to get rid of the "target" call and just rely on "contains".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants