From de280879034cd19dc6bbfbdc6aef54286c64a8e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 4 Aug 2018 17:52:30 +0200 Subject: [PATCH] Animation: make Player usable on MSVC. MSVC 2015 and 2017 is clueless when it comes to trying to deduce the template parameters (C2893: Failed to specialize function template). It works when calling add explicitly, but that makes the API hard to use and inconsistent between platforms. The only possible workaround is to make add() take *anything*, casting it to proper TrackView type and then calling add() with explicit template parameters. This also neatly resolves the Track/TrackView overload, as the static_cast is either a no-op or it invokes the conversion operator on Track. The original code also reportedly makes the Intellisense freezing like hell and adding this overload fixes the freezes. Three birds with one stone. The Player class definition is now full of typedefs, with the amount of comments about why the typedefs are there much bigger than the actual code. Oh well. --- src/Magnum/Animation/Player.h | 47 +++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/src/Magnum/Animation/Player.h b/src/Magnum/Animation/Player.h index abe459e03..5aaafbb6c 100644 --- a/src/Magnum/Animation/Player.h +++ b/src/Magnum/Animation/Player.h @@ -370,9 +370,26 @@ template Player& add(const Track& track, R& destination) { return add(TrackView{track}, destination); } + #else + /* MSVC 2015 and 2017 is clueless when it comes to trying to deduce the + template parameters (C2893: Failed to specialize function template). + It works when calling add explicitly, but that makes the API + hard to use and inconsistent between platforms. The only possible + workaround is to make add() take *anything*, casting it to proper + TrackView type and then calling add() with explicit template + parameters. This also neatly resolves the Track/TrackView overload, + as the static_cast is either a no-op or it invokes the conversion + operator on Track. The original code also reportedly makes the + Intellisense freezing like hell and adding this overload fixes the + freezes. Three birds with one stone. */ + template Player& add(const Track& track, R& destination) { + return add(static_cast&>(track), destination); + } + #endif /** * @brief Add a track with a result callback @@ -406,10 +423,14 @@ template Player& addWithCallback(const Track& track, void(*callback)(const K&, const R&, void*), void* userData = nullptr); - #else /* See above why */ + #elif !defined(CORRADE_MSVC2017_COMPATIBILITY) /* See above why */ template Player& addWithCallback(const Track& track, Callback callback, void* userData = nullptr) { return addWithCallback(TrackView{track}, callback, userData); } + #else /* see the add() function for explanation */ + template Player& addWithCallback(const Track& track, Callback callback, void* userData = nullptr) { + return addWithCallback(static_cast&>(track), callback, userData); + } #endif /** @@ -435,10 +456,14 @@ template Player& addWithCallback(const Track& track, void(*callback)(const K&, const R&, U&), U& userData); - #else /* See above why */ + #elif !defined(CORRADE_MSVC2017_COMPATIBILITY) /* See above why */ template Player& addWithCallback(const Track& track, Callback callback, U& userData) { return addWithCallback(TrackView{track}, callback, userData); } + #else /* see the add() function for explanation */ + template Player& addWithCallback(const Track& track, Callback callback, U& userData) { + return addWithCallback(static_cast&>(track), callback, userData); + } #endif /** @@ -470,10 +495,14 @@ template Player& addWithCallbackOnChange(const Track& track, void(*callback)(const K&, const R&, void*), R& destination, void* userData = nullptr); - #else /* See above why */ + #elif !defined(CORRADE_MSVC2017_COMPATIBILITY) /* See above why */ template Player& addWithCallbackOnChange(const Track& track, Callback callback, R& destination, void* userData = nullptr) { return addWithCallbackOnChange(TrackView{track}, callback, destination, userData); } + #else /* see the add() function for explanation */ + template Player& addWithCallbackOnChange(const Track& track, Callback callback, R& destination, void* userData = nullptr) { + return addWithCallbackOnChange(static_cast&>(track), callback, destination, userData); + } #endif /** @@ -499,10 +528,14 @@ template Player& addWithCallbackOnChange(const Track& track, void(*callback)(const K&, const R&, void*), R& destination, U& userData); - #else + #elif !defined(CORRADE_MSVC2017_COMPATIBILITY) /* See above why */ template Player& addWithCallbackOnChange(const Track& track, Callback callback, R& destination, U& userData) { return addWithCallbackOnChange(TrackView{track}, callback, destination, userData); } + #else /* see the add() function for explanation */ + template Player& addWithCallbackOnChange(const Track& track, Callback callback, R& destination, U& userData) { + return addWithCallbackOnChange(static_cast&>(track), callback, destination, userData); + } #endif /** @@ -541,10 +574,14 @@ template Player& addRawCallback(const Track& track, void(*callback)(const TrackViewStorage&, K, std::size_t&, void*, void(*)(), void*), void* destination, void(*userCallback)(), void* userData); - #else + #elif !defined(CORRADE_MSVC2017_COMPATIBILITY) /* See above why */ template Player& addRawCallback(const Track& track, Callback callback, void* destination, void(*userCallback)(), void* userData) { return addRawCallback(TrackView{track}, callback, destination, userCallback, userData); } + #else /* see the add() function for explanation */ + template Player& addRawCallback(const Track& track, Callback callback, void* destination, void(*userCallback)(), void* userData) { + return addRawCallback(static_cast&>(track), callback, destination, userCallback, userData); + } #endif /**