From c1e1c85f7a2e9d25e592bd3e1bbb0514d185d5af Mon Sep 17 00:00:00 2001 From: Christian Zimmermann Date: Mon, 15 Jan 2018 18:31:47 +0100 Subject: [PATCH] shift arithmetric operations in separate header file --- CMakeLists.txt | 2 +- src/arith.h | 124 ++++++++++++++++++++++++++++++++++++ src/multi_array_operation.h | 39 +----------- 3 files changed, 126 insertions(+), 39 deletions(-) create mode 100644 src/arith.h diff --git a/CMakeLists.txt b/CMakeLists.txt index daab850..0887a80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8) project(multi_array) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++11 -Wpedantic -O3") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++11 -Wpedantic -Wno-uninitialized -O3") enable_testing() diff --git a/src/arith.h b/src/arith.h new file mode 100644 index 0000000..ff79bfe --- /dev/null +++ b/src/arith.h @@ -0,0 +1,124 @@ + +#ifndef __arith_h__ +#define __arith_h__ + +namespace MultiArrayHelper +{ + // OPERATIONS (STATIC) + template + struct plus + { + static inline T&& apply(const T& a1, const T& a2) + { + T&& res = a1 + a2; + return std::forward( res ); + } + + static inline T&& apply(T&& a1, const T& a2) + { + T&& res = a1 + a2; + return std::forward( res ); + } + + static inline T&& apply(const T& a1, T&& a2) + { + T&& res = a1 + a2; + return std::forward( res ); + } + + static inline T&& apply(T&& a1, T&& a2) + { + T&& res = a1 + a2; + return std::forward( res ); + } + + }; + + template + struct minus + { + static inline T&& apply(const T& a1, const T& a2) + { + T&& res = a1 - a2; + return std::forward( res ); + } + + static inline T&& apply(T&& a1, const T& a2) + { + T&& res = a1 - a2; + return std::forward( res ); + } + + static inline T&& apply(const T& a1, T&& a2) + { + T&& res = a1 - a2; + return std::forward( res ); + } + + static inline T&& apply(T&& a1, T&& a2) + { + T&& res = a1 - a2; + return std::forward( res ); + } + }; + + template + struct multiplies + { + static inline T&& apply(const T& a1, const T& a2) + { + T&& res = a1 * a2; + return std::forward( res ); + } + + static inline T&& apply(T&& a1, const T& a2) + { + T&& res = a1 * a2; + return std::forward( res ); + } + + static inline T&& apply(const T& a1, T&& a2) + { + T&& res = a1 * a2; + return std::forward( res ); + } + + static inline T&& apply(T&& a1, T&& a2) + { + T&& res = a1 * a2; + return std::forward( res ); + } + }; + + template + struct divides + { + static inline T&& apply(const T& a1, const T& a2) + { + T&& res = a1 / a2; + return std::forward( res ); + } + + static inline T&& apply(T&& a1, const T& a2) + { + T&& res = a1 / a2; + return std::forward( res ); + } + + static inline T&& apply(const T& a1, T&& a2) + { + T&& res = a1 / a2; + return std::forward( res ); + } + + static inline T&& apply(T&& a1, T&& a2) + { + T&& res = a1 / a2; + return std::forward( res ); + } + }; + + +} // end namespace MultiArrayHelper + +#endif diff --git a/src/multi_array_operation.h b/src/multi_array_operation.h index a4d399a..01c42f4 100644 --- a/src/multi_array_operation.h +++ b/src/multi_array_operation.h @@ -18,6 +18,7 @@ #include "pack_num.h" #include "ranges/index_info.h" +#include "arith.h" namespace MultiArrayTools { @@ -26,44 +27,6 @@ namespace MultiArrayTools { using namespace MultiArrayHelper; } - - // OPERATIONS (STATIC) - template - struct plus - { - static T apply(const T& a1, const T& a2) - { - return a1 + a2; - } - }; - - template - struct minus - { - static T apply(const T& a1, const T& a2) - { - return a1 - a2; - } - }; - - template - struct multiplies - { - static T apply(const T& a1, const T& a2) - { - return a1 * a2; - } - }; - - template - struct divides - { - static T apply(const T& a1, const T& a2) - { - return a1 / a2; - } - }; - template Block makeBlock(const T* vec, size_t stepSize, size_t blockSize);