question about function

i need help im trying to generate 6 numbers example like 456789,124567
i wonder if anyone could give me any advice. im using a hash
1
2
3
4
5
6
7
8
std::size_t customer::hash() const
{
    unsigned int dummy=0;
    unsigned int dummy2 =0;
    std::size_t h = dummy;
    h *= 6;
    return h ^ dummy2;
}
Please show your definition of customer. We need information about customer to determine how to correctly write a hash for it.

If you want your hash to be compatible with the standard library with no extra work (a good idea), you would specialize std::hash for your type.
1
2
3
4
5
6
7
8
9
10
# include <functional>
namespace std { 
  template <> struct hash<::customer> {
    using argument_type = ::customer;
    using result_type = std::size_t;
    result_type operator()(argument_type const& s) const noexcept {
       // compute the hash here
    }
  };
}


And then (potentially)
1
2
3
4
std::size_t customer::hash() const noexcept
{
  return std::hash<customer>{}(*this); 
}
Last edited on


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef __CUSTOMER_H__
#define __CUSTOMER_H__

#include
#include

struct customer
{
   std::string name;
   std::string phone;
   std::string address;

   std::size_t hash() const;
};

inline std::istream& operator>>(std::istream& is, customer& m)
{
   is >> m.name >> m.phone >> e.address;
   std::getline(is, e.Address);
   return is;
}

inline std::ostream& operator<<(std::ostream& os, const customer& m)
{
   os << m.name<< "\t" << m.phone << "\t" << m.address;
}
Topic archived. No new replies allowed.