@@ -26,6 +26,16 @@ along with Daemon Source Code. If not, see <http://www.gnu.org/licenses/>.
2626#define COMMON_VECTOR_H_
2727
2828#include < ostream>
29+ #include < type_traits>
30+
31+ #include " common/CPPStandard.h"
32+
33+ // HACK: checking for CPP_INVOKE_RESULT doesn't work on MSVC
34+ #if __cplusplus >= 201703L
35+ #define invoke_result std::invoke_result
36+ #else
37+ #define invoke_result std::result_of
38+ #endif
2939
3040namespace Math {
3141
@@ -87,9 +97,9 @@ namespace Math {
8797 void Store (Type* ptr) const ;
8898
8999 // Apply a function on all elements of the vector
90- template <typename Func> Vector<Dimension, typename std::result_of <Func(Type)>::type> Apply (Func func) const ;
91- template <typename Func, typename Type2> Vector<Dimension, typename std::result_of <Func(Type, Type2)>::type> Apply2 (Func func, Vector<Dimension, Type2> other) const ;
92- template <typename Func, typename Type2, typename Type3> Vector<Dimension, typename std::result_of <Func(Type, Type2, Type3)>::type> Apply3 (Func func, Vector<Dimension, Type2> other1, Vector<Dimension, Type3> other2) const ;
100+ template <typename Func> Vector<Dimension, typename invoke_result <Func(Type)>::type> Apply (Func func) const ;
101+ template <typename Func, typename Type2> Vector<Dimension, typename invoke_result <Func(Type, Type2)>::type> Apply2 (Func func, Vector<Dimension, Type2> other) const ;
102+ template <typename Func, typename Type2, typename Type3> Vector<Dimension, typename invoke_result <Func(Type, Type2, Type3)>::type> Apply3 (Func func, Vector<Dimension, Type2> other1, Vector<Dimension, Type3> other2) const ;
93103
94104 // Reduce the elements of the vector to a single value
95105 template <typename Func> Type Reduce (Type init, Func func);
@@ -843,25 +853,25 @@ namespace Math {
843853
844854 // VectorBase::Apply/Apply2/Apply3
845855 template <size_t Dimension, typename Type> template <typename Func>
846- Vector<Dimension, typename std::result_of <Func(Type)>::type> VectorBase<Dimension, Type>::Apply(Func func) const
856+ Vector<Dimension, typename invoke_result <Func(Type)>::type> VectorBase<Dimension, Type>::Apply(Func func) const
847857 {
848- Vector<Dimension, typename std::result_of <Func (Type)>::type> out;
858+ Vector<Dimension, typename invoke_result <Func (Type)>::type> out;
849859 for (size_t i = 0 ; i < Dimension; i++)
850860 out.data [i] = func (data[i]);
851861 return out;
852862 }
853863 template <size_t Dimension, typename Type> template <typename Func, typename Type2>
854- Vector<Dimension, typename std::result_of <Func(Type, Type2)>::type> VectorBase<Dimension, Type>::Apply2(Func func, Vector<Dimension, Type2> other) const
864+ Vector<Dimension, typename invoke_result <Func(Type, Type2)>::type> VectorBase<Dimension, Type>::Apply2(Func func, Vector<Dimension, Type2> other) const
855865 {
856- Vector<Dimension, typename std::result_of <Func (Type, Type2)>::type> out;
866+ Vector<Dimension, typename invoke_result <Func (Type, Type2)>::type> out;
857867 for (size_t i = 0 ; i < Dimension; i++)
858868 out.data [i] = func (data[i], other.data [i]);
859869 return out;
860870 }
861871 template <size_t Dimension, typename Type> template <typename Func, typename Type2, typename Type3>
862- Vector<Dimension, typename std::result_of <Func(Type, Type2, Type3)>::type> VectorBase<Dimension, Type>::Apply3(Func func, Vector<Dimension, Type2> other1, Vector<Dimension, Type3> other2) const
872+ Vector<Dimension, typename invoke_result <Func(Type, Type2, Type3)>::type> VectorBase<Dimension, Type>::Apply3(Func func, Vector<Dimension, Type2> other1, Vector<Dimension, Type3> other2) const
863873 {
864- Vector<Dimension, typename std::result_of <Func (Type, Type2, Type3)>::type> out;
874+ Vector<Dimension, typename invoke_result <Func (Type, Type2, Type3)>::type> out;
865875 for (size_t i = 0 ; i < Dimension; i++)
866876 out.data [i] = func (data[i], other1.data [i], other2.data [i]);
867877 return out;
0 commit comments