Skip to content

The use of bind in Ticker.h is prone to type inference failure #6129

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

Merged
merged 6 commits into from
May 25, 2019

Conversation

dok-net
Copy link
Contributor

@dok-net dok-net commented May 22, 2019

During development of a different Schedule.h queue, it turns out that the use of std::bind has nasty issues with ambiguous type inference. The use of lambdas is generally encouraged in current C++, so this PR refactors the two spots where std::bind is used.

Copy link
Collaborator

@devyte devyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please give an example of failed type inference for these use cases?

@dok-net
Copy link
Contributor Author

dok-net commented May 24, 2019

The error message when std::bind is used looks like this:

Ticker.cpp:33: In file included from
Ticker.h: In member function void Ticker::attach_scheduled(float, Ticker::callback_function_t)
 
Ticker.h: 46:55: error: no matching function for call to 'bind(<unresolved overloaded function type>, Ticker::callback_function_t&)
   attach(seconds,std*: bind(schedule_function, callback))
Ticker.h:46: note  candidates are
 
Ticker.h:28: In file included from
Ticker.cpp:33: from
functional:1655: note  template<class _Func, class ... _BoundArgs> typename std  _Bind_helper<std  __or_<std  is_integral<typename std  decay<_Tp>  type>, std  is_enum<typename std  decay<_Tp>  type> >  value, _Func, _BoundArgs ...>  type std  bind(_Func&&, _BoundArgs&& ...)
   bind(_Func&& __f, _BoundArgs&&... __args)
functional:1655: note    template argument deduction\substitution failed

Too bad it doesn't actually list the candidates, I deduce that what's giving the compiler hiccups here is the choice of rValue reference and const reference overload signatures of schedule_function in Schedule.h, which goes like this:

bool schedule_function(std::function<void(void)>&& fn);
bool schedule_function(const std::function<void(void)>& fn);

@d-a-v d-a-v merged commit 2d9253e into esp8266:master May 25, 2019
@dok-net dok-net deleted the refactorbindtolambda branch May 27, 2019 23:19
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

Successfully merging this pull request may close these issues.

3 participants