Loading TemplateTest/main.cpp +51 −5 Original line number Original line Diff line number Diff line #define CONSOLE_COLORED_OUTPUT #define CONSOLE_COLORED_OUTPUT #include "../src/Debug/Debug.h" #include "../src/Debug/Debug.h" #include "../src/Traits/TraitsAlgorithm/TraitsAlgorithm.h" //#include "../src/Traits/Traits.h" #include "../src/UnstructuredMesh/UnstructuredMesh.h" #include "../src/UnstructuredMesh/UnstructuredMesh.h" #include "../src/Traits/MemberApproach/MemberApproach.h" #include "../src/Traits/MemberApproach/MemberApproach.h" #include "../src/Traits/Traits.h" #include "../src/Singleton/Singleton.h" #include "../src/Singleton/Singleton.h" #include <chrono> #include <chrono> #include <functional> #include <functional> Loading Loading @@ -296,7 +297,7 @@ struct ExportTest { MAKE_ATTRIBUTE_TRAIT(ExportTest, attrInt, attrDouble, attrChar, attrStr, attrTempData, attrVec); MAKE_ATTRIBUTE_TRAIT(ExportTest, attrInt, attrDouble, attrChar, attrStr, attrTempData, attrVec); MAKE_ATTRIBUTE_TRAIT_ARITHMETIC(ExportTest, attrInt, attrDouble, attrTempData); MAKE_ATTRIBUTE_TRAIT_ARITHMETIC(ExportTest, attrInt, attrDouble, attrTempData); #include "../src/Traits/TraitsAlgorithm/TraitsAlgorithm.h" struct dataStruct { struct dataStruct { int iD; int iD; Loading Loading @@ -334,10 +335,43 @@ struct NumStruct2 { double data2; double data2; NumStruct2(double d1 = 0.0, double d2 = 0.0): data1(d1), data2(d2){} NumStruct2(double d1 = 0.0, double d2 = 0.0): data1(d1), data2(d2){} template<unsigned int... Idxs> auto& operator[](integer_sequence<unsigned int, Idxs...>){ return getTraitedAttribute<Idxs...>(*this); } }; }; MAKE_ATTRIBUTE_TRAIT(NumStruct2, data1, data2); MAKE_ATTRIBUTE_TRAIT(NumStruct2, data1, data2); struct TraitedStruct { Vector<3, double>sarr = {1,2,3}; }; MAKE_ATTRIBUTE_TRAIT(TraitedStruct, sarr); namespace ns { class TraitedClass{ public: double d1 = 1; double d2 = 2; TraitedStruct ts; public: explicit TraitedClass() {DBGMSG("TC construtor");} //TraitedClass(const TraitedClass& rhs) = default; //TraitedClass(TraitedClass&&) = default; friend class Traits<TraitedClass>; template<unsigned int... Idxs> auto& operator[](integer_sequence<unsigned int, Idxs...>){ return getTraitedAttribute<Idxs...>(*this); } }; } MAKE_ATTRIBUTE_TRAIT(ns::TraitedClass, d1, d2, ts); void testTraitsAlgorithms() { void testTraitsAlgorithms() { ExportTest e1, e2; ExportTest e1, e2; ExportTest res = e1 + e2; ExportTest res = e1 + e2; Loading @@ -351,8 +385,20 @@ void testTraitsAlgorithms() { max(-(ns + 4 * ns2)), max(-(ns + 4 * ns2)), max(abs(-(ns + 4 * ns2))), max(abs(-(ns + 4 * ns2))), log(ns), exp(log(ns)), log(ns), exp(log(ns)), pow(sqrt(ns), 2) pow(sqrt(ns), 2), abs(pow(e1,2)) ); ); DBGVAR(abs(ns::TraitedClass())); std::vector<ns::TraitedClass> vv; vv.resize(5, ns::TraitedClass()); integer_sequence<unsigned int, 0> d1; integer_sequence<unsigned int, 1> d2; integer_sequence<unsigned int, 2,0> sarr; DBGVAR(abs(vv), pow(vv,2.5), ns[d1], vv[0][d1], vv[0][d2], vv[0][sarr]); } } Loading Loading @@ -2374,8 +2420,8 @@ int main() //testPrivateTrait(); //testPrivateTrait(); //testJson(); //testJson(); //testTestTraits(); //testTestTraits(); //testTraitsAlgorithms(); testTraitsAlgorithms(); testNumericTraitsPerformance(); //testNumericTraitsPerformance(); //testTraitsTuple(); //testTraitsTuple(); //testFactorial(); //testFactorial(); return 0; return 0; Loading src/Traits/Traits.h +2 −2 Original line number Original line Diff line number Diff line Loading @@ -313,13 +313,13 @@ struct TraitedAttributeGetter<Index>{ } //Impl } //Impl template <typename ArythmeticTraitT, unsigned int ...Indexes, typename = typename std::enable_if<HasDefaultArithmeticTraits<ArythmeticTraitT>::value>::type> template <unsigned int ...Indexes, typename ArythmeticTraitT, typename = typename std::enable_if<HasDefaultArithmeticTraits<ArythmeticTraitT>::value>::type> auto& getTraitedAttribute(ArythmeticTraitT& arg){ auto& getTraitedAttribute(ArythmeticTraitT& arg){ return Impl::TraitedAttributeGetter<Indexes...>::get(arg); return Impl::TraitedAttributeGetter<Indexes...>::get(arg); } } template <typename ArythmeticTraitT, unsigned int ...Indexes, typename = typename std::enable_if<HasDefaultArithmeticTraits<ArythmeticTraitT>::value>::type> template <unsigned int ...Indexes, typename ArythmeticTraitT, typename = typename std::enable_if<HasDefaultArithmeticTraits<ArythmeticTraitT>::value>::type> auto& getTraitedAttribute(ArythmeticTraitT* arg){ auto& getTraitedAttribute(ArythmeticTraitT* arg){ return Impl::TraitedAttributeGetter<Indexes...>::get(arg); return Impl::TraitedAttributeGetter<Indexes...>::get(arg); } } Loading src/Traits/TraitsAlgorithm/TraitsAlgorithm.h +100 −48 Original line number Original line Diff line number Diff line Loading @@ -463,9 +463,9 @@ operator/(TraitT&& op1, const Real& op2) noexcept { template< typename T1, typename T2 > template< typename T1, typename T2 > struct Pow struct Pow { { static auto evaluate( const T1& a, const T2& b ) -> decltype( std::pow(a,b) ) static auto evaluate( const T1& a, const T2& b ) -> decltype( pow(a,b) ) { { return std::pow(a,b); return pow(a,b); } } }; }; Loading Loading @@ -510,6 +510,49 @@ pow(const Real& op1, TraitT&& op2) noexcept { } } /* template <typename T, typename Real> typename std::enable_if< !std::is_class<T>::value, T >::type pow(const T& arg, const Real& p) noexcept { return std::pow(arg, p); } */ template <typename T, typename Real> typename std::enable_if< IsIndexable<T>::value, T >::type pow(const T& array, const Real& p) noexcept { T resArray(array); for (decltype (resArray.size()) index = 0; index < resArray.size(); index++){ resArray[index] = pow(resArray[index], p); } return resArray; } template <typename T,typename Real> typename std::enable_if< IsTNLIndexable<T>::value, T >::type pow(const T& array, const Real& p) noexcept { T resArray(array); for (decltype (resArray.getSize()) index = 0; index < resArray.getSize(); index++){ resArray[index] = pow(resArray[index], p); } return resArray; } //// //// /// Exp /// Exp Loading Loading @@ -554,7 +597,7 @@ exp(const TraitT& op1) noexcept { //// //// /// Exp /// Log /// /// template< typename T1 > template< typename T1 > Loading Loading @@ -790,12 +833,16 @@ operator-(TraitT&& op1) noexcept { template< typename T1 > template< typename T1 > struct Abs struct Abs { { static auto evaluate( const T1& a ) -> decltype( std::abs(a) ) { static auto evaluate( const T1& a ) -> T1 { return std::abs(a); return abs(a); } } }; }; template <typename TraitT> template <typename TraitT> typename std::enable_if<HasDefaultArithmeticTraits<TraitT>::value, TraitT>::type typename std::enable_if<HasDefaultArithmeticTraits<TraitT>::value, TraitT>::type abs(const TraitT& op1) noexcept { abs(const TraitT& op1) noexcept { Loading @@ -816,6 +863,51 @@ abs(TraitT&& op1) noexcept { template <typename T> typename std::enable_if< !std::is_class<T>::value, T >::type abs(const T& arg) noexcept { return std::abs(arg); } template <typename T> typename std::enable_if< IsIndexable<T>::value, T >::type abs(const T& array) noexcept { T resArray(array); for (decltype (resArray.size()) index = 0; index < resArray.size(); index++){ resArray[index] = abs(resArray[index]); } return resArray; } /* template <typename T> typename std::enable_if< IsTNLIndexable<T>::value, T >::type abs(const T& array) noexcept { T resArray(array); for (decltype (resArray.getSize()) index = 0; index < resArray.getSize(); index++){ resArray[index] = abs(resArray[index]); } return resArray; } */ Loading Loading @@ -1003,50 +1095,10 @@ min(const TraitT& op1) noexcept { template <typename T> typename std::enable_if< !std::is_class<T>::value, T >::type abs(const T& arg) noexcept { return std::abs(arg); } template <typename T> typename std::enable_if< IsIndexable<T>::value, T >::type abs(const T& array) noexcept { T resArray(array); for (decltype (resArray.size()) index = 0; index < resArray.size(); index++){ resArray[index] = abs(resArray[index]); } return resArray; } template <typename T> typename std::enable_if< IsTNLIndexable<T>::value, T >::type abs(const T& array) noexcept { T resArray(array); for (decltype (resArray.getSize()) index = 0; index < resArray.getSize(); index++){ resArray[index] = abs(resArray[index]); } return resArray; } #endif // TRAITSALGORITHM_H #endif // TRAITSALGORITHM_H Loading
TemplateTest/main.cpp +51 −5 Original line number Original line Diff line number Diff line #define CONSOLE_COLORED_OUTPUT #define CONSOLE_COLORED_OUTPUT #include "../src/Debug/Debug.h" #include "../src/Debug/Debug.h" #include "../src/Traits/TraitsAlgorithm/TraitsAlgorithm.h" //#include "../src/Traits/Traits.h" #include "../src/UnstructuredMesh/UnstructuredMesh.h" #include "../src/UnstructuredMesh/UnstructuredMesh.h" #include "../src/Traits/MemberApproach/MemberApproach.h" #include "../src/Traits/MemberApproach/MemberApproach.h" #include "../src/Traits/Traits.h" #include "../src/Singleton/Singleton.h" #include "../src/Singleton/Singleton.h" #include <chrono> #include <chrono> #include <functional> #include <functional> Loading Loading @@ -296,7 +297,7 @@ struct ExportTest { MAKE_ATTRIBUTE_TRAIT(ExportTest, attrInt, attrDouble, attrChar, attrStr, attrTempData, attrVec); MAKE_ATTRIBUTE_TRAIT(ExportTest, attrInt, attrDouble, attrChar, attrStr, attrTempData, attrVec); MAKE_ATTRIBUTE_TRAIT_ARITHMETIC(ExportTest, attrInt, attrDouble, attrTempData); MAKE_ATTRIBUTE_TRAIT_ARITHMETIC(ExportTest, attrInt, attrDouble, attrTempData); #include "../src/Traits/TraitsAlgorithm/TraitsAlgorithm.h" struct dataStruct { struct dataStruct { int iD; int iD; Loading Loading @@ -334,10 +335,43 @@ struct NumStruct2 { double data2; double data2; NumStruct2(double d1 = 0.0, double d2 = 0.0): data1(d1), data2(d2){} NumStruct2(double d1 = 0.0, double d2 = 0.0): data1(d1), data2(d2){} template<unsigned int... Idxs> auto& operator[](integer_sequence<unsigned int, Idxs...>){ return getTraitedAttribute<Idxs...>(*this); } }; }; MAKE_ATTRIBUTE_TRAIT(NumStruct2, data1, data2); MAKE_ATTRIBUTE_TRAIT(NumStruct2, data1, data2); struct TraitedStruct { Vector<3, double>sarr = {1,2,3}; }; MAKE_ATTRIBUTE_TRAIT(TraitedStruct, sarr); namespace ns { class TraitedClass{ public: double d1 = 1; double d2 = 2; TraitedStruct ts; public: explicit TraitedClass() {DBGMSG("TC construtor");} //TraitedClass(const TraitedClass& rhs) = default; //TraitedClass(TraitedClass&&) = default; friend class Traits<TraitedClass>; template<unsigned int... Idxs> auto& operator[](integer_sequence<unsigned int, Idxs...>){ return getTraitedAttribute<Idxs...>(*this); } }; } MAKE_ATTRIBUTE_TRAIT(ns::TraitedClass, d1, d2, ts); void testTraitsAlgorithms() { void testTraitsAlgorithms() { ExportTest e1, e2; ExportTest e1, e2; ExportTest res = e1 + e2; ExportTest res = e1 + e2; Loading @@ -351,8 +385,20 @@ void testTraitsAlgorithms() { max(-(ns + 4 * ns2)), max(-(ns + 4 * ns2)), max(abs(-(ns + 4 * ns2))), max(abs(-(ns + 4 * ns2))), log(ns), exp(log(ns)), log(ns), exp(log(ns)), pow(sqrt(ns), 2) pow(sqrt(ns), 2), abs(pow(e1,2)) ); ); DBGVAR(abs(ns::TraitedClass())); std::vector<ns::TraitedClass> vv; vv.resize(5, ns::TraitedClass()); integer_sequence<unsigned int, 0> d1; integer_sequence<unsigned int, 1> d2; integer_sequence<unsigned int, 2,0> sarr; DBGVAR(abs(vv), pow(vv,2.5), ns[d1], vv[0][d1], vv[0][d2], vv[0][sarr]); } } Loading Loading @@ -2374,8 +2420,8 @@ int main() //testPrivateTrait(); //testPrivateTrait(); //testJson(); //testJson(); //testTestTraits(); //testTestTraits(); //testTraitsAlgorithms(); testTraitsAlgorithms(); testNumericTraitsPerformance(); //testNumericTraitsPerformance(); //testTraitsTuple(); //testTraitsTuple(); //testFactorial(); //testFactorial(); return 0; return 0; Loading
src/Traits/Traits.h +2 −2 Original line number Original line Diff line number Diff line Loading @@ -313,13 +313,13 @@ struct TraitedAttributeGetter<Index>{ } //Impl } //Impl template <typename ArythmeticTraitT, unsigned int ...Indexes, typename = typename std::enable_if<HasDefaultArithmeticTraits<ArythmeticTraitT>::value>::type> template <unsigned int ...Indexes, typename ArythmeticTraitT, typename = typename std::enable_if<HasDefaultArithmeticTraits<ArythmeticTraitT>::value>::type> auto& getTraitedAttribute(ArythmeticTraitT& arg){ auto& getTraitedAttribute(ArythmeticTraitT& arg){ return Impl::TraitedAttributeGetter<Indexes...>::get(arg); return Impl::TraitedAttributeGetter<Indexes...>::get(arg); } } template <typename ArythmeticTraitT, unsigned int ...Indexes, typename = typename std::enable_if<HasDefaultArithmeticTraits<ArythmeticTraitT>::value>::type> template <unsigned int ...Indexes, typename ArythmeticTraitT, typename = typename std::enable_if<HasDefaultArithmeticTraits<ArythmeticTraitT>::value>::type> auto& getTraitedAttribute(ArythmeticTraitT* arg){ auto& getTraitedAttribute(ArythmeticTraitT* arg){ return Impl::TraitedAttributeGetter<Indexes...>::get(arg); return Impl::TraitedAttributeGetter<Indexes...>::get(arg); } } Loading
src/Traits/TraitsAlgorithm/TraitsAlgorithm.h +100 −48 Original line number Original line Diff line number Diff line Loading @@ -463,9 +463,9 @@ operator/(TraitT&& op1, const Real& op2) noexcept { template< typename T1, typename T2 > template< typename T1, typename T2 > struct Pow struct Pow { { static auto evaluate( const T1& a, const T2& b ) -> decltype( std::pow(a,b) ) static auto evaluate( const T1& a, const T2& b ) -> decltype( pow(a,b) ) { { return std::pow(a,b); return pow(a,b); } } }; }; Loading Loading @@ -510,6 +510,49 @@ pow(const Real& op1, TraitT&& op2) noexcept { } } /* template <typename T, typename Real> typename std::enable_if< !std::is_class<T>::value, T >::type pow(const T& arg, const Real& p) noexcept { return std::pow(arg, p); } */ template <typename T, typename Real> typename std::enable_if< IsIndexable<T>::value, T >::type pow(const T& array, const Real& p) noexcept { T resArray(array); for (decltype (resArray.size()) index = 0; index < resArray.size(); index++){ resArray[index] = pow(resArray[index], p); } return resArray; } template <typename T,typename Real> typename std::enable_if< IsTNLIndexable<T>::value, T >::type pow(const T& array, const Real& p) noexcept { T resArray(array); for (decltype (resArray.getSize()) index = 0; index < resArray.getSize(); index++){ resArray[index] = pow(resArray[index], p); } return resArray; } //// //// /// Exp /// Exp Loading Loading @@ -554,7 +597,7 @@ exp(const TraitT& op1) noexcept { //// //// /// Exp /// Log /// /// template< typename T1 > template< typename T1 > Loading Loading @@ -790,12 +833,16 @@ operator-(TraitT&& op1) noexcept { template< typename T1 > template< typename T1 > struct Abs struct Abs { { static auto evaluate( const T1& a ) -> decltype( std::abs(a) ) { static auto evaluate( const T1& a ) -> T1 { return std::abs(a); return abs(a); } } }; }; template <typename TraitT> template <typename TraitT> typename std::enable_if<HasDefaultArithmeticTraits<TraitT>::value, TraitT>::type typename std::enable_if<HasDefaultArithmeticTraits<TraitT>::value, TraitT>::type abs(const TraitT& op1) noexcept { abs(const TraitT& op1) noexcept { Loading @@ -816,6 +863,51 @@ abs(TraitT&& op1) noexcept { template <typename T> typename std::enable_if< !std::is_class<T>::value, T >::type abs(const T& arg) noexcept { return std::abs(arg); } template <typename T> typename std::enable_if< IsIndexable<T>::value, T >::type abs(const T& array) noexcept { T resArray(array); for (decltype (resArray.size()) index = 0; index < resArray.size(); index++){ resArray[index] = abs(resArray[index]); } return resArray; } /* template <typename T> typename std::enable_if< IsTNLIndexable<T>::value, T >::type abs(const T& array) noexcept { T resArray(array); for (decltype (resArray.getSize()) index = 0; index < resArray.getSize(); index++){ resArray[index] = abs(resArray[index]); } return resArray; } */ Loading Loading @@ -1003,50 +1095,10 @@ min(const TraitT& op1) noexcept { template <typename T> typename std::enable_if< !std::is_class<T>::value, T >::type abs(const T& arg) noexcept { return std::abs(arg); } template <typename T> typename std::enable_if< IsIndexable<T>::value, T >::type abs(const T& array) noexcept { T resArray(array); for (decltype (resArray.size()) index = 0; index < resArray.size(); index++){ resArray[index] = abs(resArray[index]); } return resArray; } template <typename T> typename std::enable_if< IsTNLIndexable<T>::value, T >::type abs(const T& array) noexcept { T resArray(array); for (decltype (resArray.getSize()) index = 0; index < resArray.getSize(); index++){ resArray[index] = abs(resArray[index]); } return resArray; } #endif // TRAITSALGORITHM_H #endif // TRAITSALGORITHM_H