我想知道vector的哪个元素是最小的,但min_element
将迭代器返回给该元素。所以我尝试了这个:
vector<int> vec = {4,5,0,1,2,3} ;
int min_element_index = min_element(vec.begin(), vec.end()) - vec.begin();
Run Code Online (Sandbox Code Playgroud)
但是,我不确定这将始终有效。我不知道向量在内存中的存储方式,我担心使用时会中断push_back
。
有没有一种方法可以为SystemVerilog原语添加断言,或者仅在包装该原语的模块(单元)中添加断言?简单地添加一个断言不会编译
primitive mux (q, d0, d1, s);
output q;
input s, d0, d1;
table
// d0 d1 s : q
0 ? 0 : 0 ;
1 ? 0 : 1 ;
? 0 1 : 0 ;
? 1 1 : 1 ;
0 0 x : 0 ;
1 1 x : 1 ;
endtable
//assert(s != x) else $error("s has value x"); - add this assertion
endprimitive
Run Code Online (Sandbox Code Playgroud)