Unable to create unordered_set with lambda function
Clash Royale CLAN TAG#URR8PPP
up vote
6
down vote
favorite
I get the error
error: call to implicitly-deleted default constructor of '__compressed_pair_elem<(lambda at
main.cpp:181:16), 1>': _Base1(std::forward<_Tp>(__t)), _Base2()
with the following code. What's the mistake I am making and I couldn't understand the error as well.
using namespace std;
auto my_hash = (vector<int> const& vec)
size_t seed = vec.size();
for(auto& i : vec)
seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);
return seed;
;
using MySet = unordered_set<vector<int>, decltype(my_hash)>;
int main()
vector<int> a1,2,3;
MySet s;
return 0;
c++ c++11 c++14
add a comment |Â
up vote
6
down vote
favorite
I get the error
error: call to implicitly-deleted default constructor of '__compressed_pair_elem<(lambda at
main.cpp:181:16), 1>': _Base1(std::forward<_Tp>(__t)), _Base2()
with the following code. What's the mistake I am making and I couldn't understand the error as well.
using namespace std;
auto my_hash = (vector<int> const& vec)
size_t seed = vec.size();
for(auto& i : vec)
seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);
return seed;
;
using MySet = unordered_set<vector<int>, decltype(my_hash)>;
int main()
vector<int> a1,2,3;
MySet s;
return 0;
c++ c++11 c++14
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
I get the error
error: call to implicitly-deleted default constructor of '__compressed_pair_elem<(lambda at
main.cpp:181:16), 1>': _Base1(std::forward<_Tp>(__t)), _Base2()
with the following code. What's the mistake I am making and I couldn't understand the error as well.
using namespace std;
auto my_hash = (vector<int> const& vec)
size_t seed = vec.size();
for(auto& i : vec)
seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);
return seed;
;
using MySet = unordered_set<vector<int>, decltype(my_hash)>;
int main()
vector<int> a1,2,3;
MySet s;
return 0;
c++ c++11 c++14
I get the error
error: call to implicitly-deleted default constructor of '__compressed_pair_elem<(lambda at
main.cpp:181:16), 1>': _Base1(std::forward<_Tp>(__t)), _Base2()
with the following code. What's the mistake I am making and I couldn't understand the error as well.
using namespace std;
auto my_hash = (vector<int> const& vec)
size_t seed = vec.size();
for(auto& i : vec)
seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);
return seed;
;
using MySet = unordered_set<vector<int>, decltype(my_hash)>;
int main()
vector<int> a1,2,3;
MySet s;
return 0;
c++ c++11 c++14
c++ c++11 c++14
asked 26 mins ago
user3285099
627
627
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
10
down vote
Closure types are not default-constructible prior to C++20 (see P0624). You need to pass in an instance of your hasher:
constexpr std::size_t bucket_count = 512;
MySet sbucket_count, my_hash;
live example on wandbox.org
Alternatively, you can use a good old struct
:
struct Hasher
auto operator()(vector<int> const& vec) const
size_t seed = vec.size();
for(auto& i : vec)
seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);
return seed;
;
using MySet = unordered_set<vector<int>, Hasher>;
int main()
MySet s;
live example on wandbox.org
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
10
down vote
Closure types are not default-constructible prior to C++20 (see P0624). You need to pass in an instance of your hasher:
constexpr std::size_t bucket_count = 512;
MySet sbucket_count, my_hash;
live example on wandbox.org
Alternatively, you can use a good old struct
:
struct Hasher
auto operator()(vector<int> const& vec) const
size_t seed = vec.size();
for(auto& i : vec)
seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);
return seed;
;
using MySet = unordered_set<vector<int>, Hasher>;
int main()
MySet s;
live example on wandbox.org
add a comment |Â
up vote
10
down vote
Closure types are not default-constructible prior to C++20 (see P0624). You need to pass in an instance of your hasher:
constexpr std::size_t bucket_count = 512;
MySet sbucket_count, my_hash;
live example on wandbox.org
Alternatively, you can use a good old struct
:
struct Hasher
auto operator()(vector<int> const& vec) const
size_t seed = vec.size();
for(auto& i : vec)
seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);
return seed;
;
using MySet = unordered_set<vector<int>, Hasher>;
int main()
MySet s;
live example on wandbox.org
add a comment |Â
up vote
10
down vote
up vote
10
down vote
Closure types are not default-constructible prior to C++20 (see P0624). You need to pass in an instance of your hasher:
constexpr std::size_t bucket_count = 512;
MySet sbucket_count, my_hash;
live example on wandbox.org
Alternatively, you can use a good old struct
:
struct Hasher
auto operator()(vector<int> const& vec) const
size_t seed = vec.size();
for(auto& i : vec)
seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);
return seed;
;
using MySet = unordered_set<vector<int>, Hasher>;
int main()
MySet s;
live example on wandbox.org
Closure types are not default-constructible prior to C++20 (see P0624). You need to pass in an instance of your hasher:
constexpr std::size_t bucket_count = 512;
MySet sbucket_count, my_hash;
live example on wandbox.org
Alternatively, you can use a good old struct
:
struct Hasher
auto operator()(vector<int> const& vec) const
size_t seed = vec.size();
for(auto& i : vec)
seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);
return seed;
;
using MySet = unordered_set<vector<int>, Hasher>;
int main()
MySet s;
live example on wandbox.org
edited 21 mins ago
answered 24 mins ago


Vittorio Romeo
54.3k16140282
54.3k16140282
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53045494%2funable-to-create-unordered-set-with-lambda-function%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password