3

I am trying to use std::set for arbitrary-length integer vectors defined from the NTL-Library and for some reason it doesn't work. It works totally fine with the ZZ integers defined by the library:

#include <NTL/ZZ.h>
#include <NTL/vec_ZZ.h>
#include <set>

NTL_CLIENT

int main(void){


    std::set<ZZ> foo;
    foo.insert(to_ZZ(1)); //works without problems

    std::set<vec_ZZ> vectorFoo;
    vec_ZZ vec;
    vectorFoo.insert(vec);  //causes compiler to crash

    return 0;
}

Does anyone know why the first insertion works and the second doesn't?

Cœur
  • 37,241
  • 25
  • 195
  • 267
john_leo
  • 157
  • 3
  • Standard Library containers usually have a requirement that there elements be copy constructible and assignable, I am not sure if same is the case with the lib you use, but seems like the second usage doesn't obey the rule. – Alok Save Jan 27 '12 at 11:17
  • Ah, OK, that could be. I can use vec_ZZ with list or vector, just not with set.... – john_leo Jan 27 '12 at 11:23
  • Causes compiler to crash?! Is there an error message? I imagine vec_ZZ needs to have a comparison operator defined. – Peter Wood Jan 27 '12 at 12:39
  • Yes, the error message is /usr/include/c++/4.4/bits/stl_function.h:230: error: no match for ‘operator<’ in ‘__x < __y’ . So I need to tell set how to compare two vectors? How do I do that? – john_leo Jan 27 '12 at 13:34

1 Answers1

2

std::set<T> is ordered by std::less<T>, which defaults to bool operator<(T,T). ZZ does define a proper operator< (they're ordered) but vec_ZZ doesn't. In fact, most NTL classes don't, not even ZZ_p. Therefore std::set<ZZ_p> is equally invalid.

MSalters
  • 173,980
  • 10
  • 155
  • 350