In C, we can initialize a table with:
int array[3]={1,2,3};
How can we do such a thing with NTL vectors?
I guess I have declared the vector and already set its length.
For instance:
vec_ZZ vector;
vector.SetLength(3);
Thanks for your help.
In C, we can initialize a table with:
int array[3]={1,2,3};
How can we do such a thing with NTL vectors?
I guess I have declared the vector and already set its length.
For instance:
vec_ZZ vector;
vector.SetLength(3);
Thanks for your help.
Refer the manual here http://www.shoup.net/ntl/doc/vector.txt
I dont think you can initialize the way you want it because when you declare
Vec<T> v;
It creates an empty vector of size zero. If we have to initialize it then you will have assign another vector to it or set a length and add values to it.
Vec<T> v;
is an object and you can assign only an object. May be you inherit Vec class and overload the =
operator so that you can assign array to it.
As I mentioned in my earlier answer you can inherit the Vec class as shown below.
using namespace NTL;
class MyVec : public Vec<int>
{
public:
MyVec(std::initializer_list<int> input);
};
MyVec::MyVec(std::initializer_list<int> input)
{
int n = input.size();
this->SetLength(n);
std::vector<int> v;
v.insert(v.end(), input.begin(), input.end());
for(int i=0; i<n; i++)
this->put(i, v[i]);
}
int main()
{
MyVec v = {1,2,3};
for(int i=0; i<v.length(); i++)
cout << v[i] << " ";
return 0;
}
Dont forget to use the C++11 flag when compiling..
I use ubuntu env and I use the following
g++ -std=c++11 test.cpp -l ntl