Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using vectors with GMP

Tags:

c++

vector

gmp

I'm trying to use vectors with GMP. But when I compile anything like this, I get "[...]\bits\vector.tcc [Error] array must be initialized with a brace-enclosed initializer". Any data structure with dynamic size works - a deque would be best but I had even more errors popping up when I tried that. How do I make this stop failing?

#include <vector>
#include <gmp.h>

int main(){
mpz_t test;
mpz_init(test);
std::vector<mpz_t> a_vector;
a_vector.push_back(test);
return 0;
}
like image 424
Spitemaster Avatar asked Oct 20 '22 11:10

Spitemaster


1 Answers

Since GMP numbers are not directly assignable (in other words, you can't do mpz_t test = 0;' ormpz_t test1l; test1 = test;`, I don't believe they can be used in standard C++ container types.

If you want to do that, you may want to use the C++ interface for GMP instead: https://gmplib.org/manual/C_002b_002b-Interface-General.html

like image 199
Mats Petersson Avatar answered Oct 23 '22 04:10

Mats Petersson