C++; 我尝试在C++中实现一个递增运算符重载函数运算符++/>代码。此递增运算符的主要思想是对Boost.MultiArray中的每个元素应用“递增一”操作(++)。换句话说,每个元素总是可以求和的。是可求和的概念创建如下 template<typename T> concept is_summable = requires(T x) { x + x; };
主要的实验增量运算符重载模板函数:C++; 我尝试在C++中实现一个递增运算符重载函数运算符++/>代码。此递增运算符的主要思想是对Boost.MultiArray中的每个元素应用“递增一”操作(++)。换句话说,每个元素总是可以求和的。是可求和的概念创建如下 template<typename T> concept is_summable = requires(T x) { x + x; };,c++,recursion,boost,c++-concepts,boost-multi-array,C++,Recursion,Boost,C++ Concepts,Boost Multi Array,主要的实验增量运算符重载模板函数: // Element Increment Operator template<class T> requires is_summable<T> auto operator++(T& input) { auto output = input; input++; return output; } template<class T> requires (is_multi_array<T&g
// Element Increment Operator
template<class T> requires is_summable<T>
auto operator++(T& input)
{
auto output = input;
input++;
return output;
}
template<class T> requires (is_multi_array<T> || is_sub_array<T> || is_const_sub_array<T>)
auto operator++(T& input)
{
boost::multi_array output(input);
for (decltype(+input.shape()[0]) i = 0; i < input.shape()[0]; i++)
{
input[i]++;
}
return output;
}
这个问题有没有可能的解决办法
// Element Increment Operator
template<class T> requires is_summable<T>
auto operator++(T& input)
{
auto output = input;
input++;
return output;
}
template<class T> requires (is_multi_array<T> || is_sub_array<T> || is_const_sub_array<T>)
auto operator++(T& input)
{
boost::multi_array output(input);
for (decltype(+input.shape()[0]) i = 0; i < input.shape()[0]; i++)
{
input[i]++;
}
return output;
}
// Create a 3D array that is 3 x 4 x 2
typedef boost::multi_array<double, 3> array_type;
typedef array_type::index index;
array_type A(boost::extents[3][4][2]);
// Assign values to the elements
int values = 1;
for (index i = 0; i != 3; ++i)
for (index j = 0; j != 4; ++j)
for (index k = 0; k != 2; ++k)
A[i][j][k] = values++;
for (index i = 0; i != 3; ++i)
for (index j = 0; j != 4; ++j)
for (index k = 0; k != 2; ++k)
std::cout << A[i][j][k] << std::endl;
auto test_result = A++;
for (index i = 0; i != 3; ++i)
for (index j = 0; j != 4; ++j)
for (index k = 0; k != 2; ++k)
std::cout << A[i][j][k] << std::endl;
for (index i = 0; i != 3; ++i)
for (index j = 0; j != 4; ++j)
for (index k = 0; k != 2; ++k)
std::cout << test_result[i][j][k] << std::endl;