I've searched but failed to find the right answer (which is for sure somewhere present).
I have a class A which defines a struct strName which consists of a string and two uints. Now I want to keep and unordered_set of this struct. (And e.g. initialize it in the contructor or somewhere else in class A). The hasher/equality functions are defined as lambda expressions.
A.hpp
#include <set>
#include <unordered_set>
#include <string>
class A
{
public:
private:
typedef struct
{
std::string str;
u_int8_t n1;
u_int32_t n2;
}strName;
constexpr static size_t hashStruct = [](const strName& structObj) -> const size_t
{
size_t hash = 42; //will update this of course to proper hash function
return hash;
};
constexpr static bool equalStruct = [](const strName& s0, const strName& s1) -> const bool
{
bool b0 = s0.str == s1.str;
bool b1 = s0.n1 == s1.n1;
bool b2 = s0.n2 == s1.n2;
return (b0 && b1 && b2);
};
std::unordered_set<strName, decltype(hashStruct), decltype(equalStruct)> member_i_want_to_declare;
};
main.cpp
#include "A.hpp"
int main(int argc, char* const argv[])
{
A a();
}
When I do this like this, I get as error: error: invalid user-defined conversion from ‘A::<lambda(const A::strName&)>’ to ‘size_t’ {aka ‘long unsigned int’} [-fpermissive]};
Can someone give me some clues what I do wrong? I tried some things like making the lambda expressions static and so, but this give different errors.