我有一个整数N,我在编译时知道.我还有一个std :: array,它包含描述N维数组形状的整数.我想在编译时使用元编程技术生成嵌套循环,如下所述.
constexpr int N {4};
constexpr std::array<int, N> shape {{1,3,5,2}};
auto f = [/* accept object which uses coords */] (auto... coords) {
// do sth with coords
};
// This is what I want to generate.
for(int i = 0; i < shape[0]; i++) {
for(int j = 0; j < shape[1]; j++) {
for(int k = 0; k < shape[2]; k++) {
for(int l = 0; l < shape[3]; l++) …
Run Code Online (Sandbox Code Playgroud) 在以下代码段中:
std::vector<double> a(100, 4.2);
auto* a_ptr = a.data();
auto b = std::move(a);
auto* b_ptr = b.data();
std::cout << ((b_ptr == a_ptr) ? "TRUE" : "FALSE") << '\n';
Run Code Online (Sandbox Code Playgroud)
C++标准保证b_ptr
总是等于a_ptr
后std::move
?在wandbox打印上运行代码TRUE
.
我有许多嵌套循环,小编号I,J,...在编译时已知,例如
for(int i = 0; i < I; ++i) {
for(int j = 0; j < J; ++j) {
// ...
// do sth with (i,j,...)
}
}
Run Code Online (Sandbox Code Playgroud)
我需要使用大小I,J,...来展开循环,这样我就可以在编译时使用每个坐标组合.
为了澄清,请考虑以下结构并采用大小为I = 2,J = 3的 2个嵌套循环.
template<int... I>
struct C {
static void f() {
// do sth
}
};
Run Code Online (Sandbox Code Playgroud)
我不能使用索引i,j(类似于上面)来索引结构C,因为它们在编译时是未知的.然而,我想要产生的正是我被允许使用索引的情况,例如
C<0,0>::f();
C<0,1>::f();
C<0,2>::f();
C<1,0>::f();
C<1,1>::f();
C<1,2>::f();
Run Code Online (Sandbox Code Playgroud)
只要产生所有组合,我并不特别关注呼叫生成的顺序.生成机制应该推广到任意数量的嵌套循环.
c++ metaprogramming template-meta-programming c++14 boost-hana
虽然理论上可以作为证明外部静态分析仪集成到Eclipse 这里(即,Cppcheck),我想知道一个更最新的解决方案是否存在不需要的插件开发?例如,现有的插件,CODAN中的可用选项或Clang Static Analyzer的上述教程的简化版本.
c++ ×4
c++14 ×2
boost-hana ×1
c++11 ×1
eclipse ×1
eclipse-cdt ×1
llvm-clang ×1
stdmove ×1
templates ×1
vector ×1