Call to implicitly-deleted default constructor of ‘unordered_set< vector >‘

It’s because unordered_set is using std::hash template to compute hash for its entries and there is no std::hash for pairs. You have to define custom hash to use unordered_set. struct vector_hash { template <class T1, class T2> std::size_t operator () (std::pair<T1, T2> const &v) const { return std::hash<T1>()(v.size()); } }; and then declare your unordered_set … Read more

Inserting into an unordered_set with custom hash function

First problem: You are passing string as the second template argument for your instantiation of the unordered_set<> class template. The second argument should be the type of your hasher functor, and std::string is not a callable object. Perhaps meant to write: unordered_set<Interval, /* string */ Hash> test; // ^^^^^^^^^^^^ // Why this? Also, I would … Read more

Using a std::unordered_set of std::unique_ptr

You can also use a deleter that optionally doesn’t do anything. template<class T> struct maybe_deleter{ bool _delete; explicit maybe_deleter(bool doit = true) : _delete(doit){} void operator()(T* p) const{ if(_delete) delete p; } }; template<class T> using set_unique_ptr = std::unique_ptr<T, maybe_deleter<T>>; template<class T> set_unique_ptr<T> make_find_ptr(T* raw){ return set_unique_ptr<T>(raw, maybe_deleter<T>(false)); } // … int* raw = new … Read more

How can I use a C++ unordered_set for a custom class?

Since this is the top Google result on Stack Overflow for C++ unordered_set of objects I’ll post a simple yet completely illustrative and copy/paste runnable example: // UnorderedSetOfObjects.cpp #include <iostream> #include <vector> #include <unordered_set> struct Point { int x; int y; Point() { } Point(int x, int y) { this->x = x; this->y = y; … Read more

How can I make an unordered set of pairs of integers in C++?

There is no standard way of computing a hash on a pair. Add this definition to your file: struct pair_hash { inline std::size_t operator()(const std::pair<int,int> & v) const { return v.first*31+v.second; } }; Now you can use it like this: std::unordered_set< std::pair<int, int>, pair_hash> u_edge_; This works, because pair<T1,T2> defines equality. For custom classes that … Read more

How to specialize std::hash::operator() for user-defined type in unordered containers?

You are expressly allowed and encouraged to add specializations to namespace std*. The correct (and basically only) way to add a hash function is this: namespace std { template <> struct hash<Foo> { size_t operator()(const Foo & x) const { /* your code here, e.g. “return hash<int>()(x.value);” */ } }; } (Other popular specializations that … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)