The problem is that you use
Distribution<float> although
Distribution<sf::Vector2f> is expected.
std::function will still try to convert it somehow, leading to an error in its depths.
Note that he documentation of
thor::Distribution<T> is simplified at that point, there's a lot of black magic going on behind the scenes. The actual constructors of
thor::Distribution<T> are declared as follows, where
AURORA_ENABLE_IF is a macro that activates the overload given the condition is true, according to
SFINAE:
template <typename U>
Distribution(U constant
AURORA_ENABLE_IF(std::is_convertible<U, T>::value));
template <typename Fn>
Distribution(Fn function
AURORA_ENABLE_IF(!std::is_convertible<Fn, T>::value));
This is a very sophisticated way of overload resolution, but it allows me to differentiate between constants and functions passed to distributions. Ideally, I would just have two overloads that take
T and
std::function<T()>, however this doesn't work with implicit conversions. People expect to write
emitter.setParticleRotation(90) although
90 is an
int and not a
float. So there would be two implicit conversions:
int ->
float ->
Distribution<float>, and this is disallowed by the C++ standard.
Actually, that gives me an idea: I can extend these checks to create a clearer error message. But tinkering with black magic is always dangerous, I need to test some time. And that brings me to a general question: Should
Distribution<T> be convertible to
Distribution<U> if
T is convertible to
U (as it is now)? Or only explicitly? Hm...