shift arithmetric operations in separate header file

This commit is contained in:
Christian Zimmermann 2018-01-15 18:31:47 +01:00
parent 0cabc9e9ab
commit c1e1c85f7a
3 changed files with 126 additions and 39 deletions

View file

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8)
project(multi_array) 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() enable_testing()

124
src/arith.h Normal file
View file

@ -0,0 +1,124 @@
#ifndef __arith_h__
#define __arith_h__
namespace MultiArrayHelper
{
// OPERATIONS (STATIC)
template <typename T>
struct plus
{
static inline T&& apply(const T& a1, const T& a2)
{
T&& res = a1 + a2;
return std::forward<T>( res );
}
static inline T&& apply(T&& a1, const T& a2)
{
T&& res = a1 + a2;
return std::forward<T>( res );
}
static inline T&& apply(const T& a1, T&& a2)
{
T&& res = a1 + a2;
return std::forward<T>( res );
}
static inline T&& apply(T&& a1, T&& a2)
{
T&& res = a1 + a2;
return std::forward<T>( res );
}
};
template <typename T>
struct minus
{
static inline T&& apply(const T& a1, const T& a2)
{
T&& res = a1 - a2;
return std::forward<T>( res );
}
static inline T&& apply(T&& a1, const T& a2)
{
T&& res = a1 - a2;
return std::forward<T>( res );
}
static inline T&& apply(const T& a1, T&& a2)
{
T&& res = a1 - a2;
return std::forward<T>( res );
}
static inline T&& apply(T&& a1, T&& a2)
{
T&& res = a1 - a2;
return std::forward<T>( res );
}
};
template <typename T>
struct multiplies
{
static inline T&& apply(const T& a1, const T& a2)
{
T&& res = a1 * a2;
return std::forward<T>( res );
}
static inline T&& apply(T&& a1, const T& a2)
{
T&& res = a1 * a2;
return std::forward<T>( res );
}
static inline T&& apply(const T& a1, T&& a2)
{
T&& res = a1 * a2;
return std::forward<T>( res );
}
static inline T&& apply(T&& a1, T&& a2)
{
T&& res = a1 * a2;
return std::forward<T>( res );
}
};
template <typename T>
struct divides
{
static inline T&& apply(const T& a1, const T& a2)
{
T&& res = a1 / a2;
return std::forward<T>( res );
}
static inline T&& apply(T&& a1, const T& a2)
{
T&& res = a1 / a2;
return std::forward<T>( res );
}
static inline T&& apply(const T& a1, T&& a2)
{
T&& res = a1 / a2;
return std::forward<T>( res );
}
static inline T&& apply(T&& a1, T&& a2)
{
T&& res = a1 / a2;
return std::forward<T>( res );
}
};
} // end namespace MultiArrayHelper
#endif

View file

@ -18,6 +18,7 @@
#include "pack_num.h" #include "pack_num.h"
#include "ranges/index_info.h" #include "ranges/index_info.h"
#include "arith.h"
namespace MultiArrayTools namespace MultiArrayTools
{ {
@ -26,44 +27,6 @@ namespace MultiArrayTools
{ {
using namespace MultiArrayHelper; using namespace MultiArrayHelper;
} }
// OPERATIONS (STATIC)
template <typename T>
struct plus
{
static T apply(const T& a1, const T& a2)
{
return a1 + a2;
}
};
template <typename T>
struct minus
{
static T apply(const T& a1, const T& a2)
{
return a1 - a2;
}
};
template <typename T>
struct multiplies
{
static T apply(const T& a1, const T& a2)
{
return a1 * a2;
}
};
template <typename T>
struct divides
{
static T apply(const T& a1, const T& a2)
{
return a1 / a2;
}
};
template <typename T> template <typename T>
Block<T> makeBlock(const T* vec, size_t stepSize, size_t blockSize); Block<T> makeBlock(const T* vec, size_t stepSize, size_t blockSize);