p***@googlemail.com
2016-03-20 22:06:04 UTC
{ edited by mod to shorten lines to ~70 characters. -mod }
I'm using g++ and Ubuntu 14.04. The case is the code for an arbitrary
hash function. The originators evidently intended it as an explicit
specialization template. However, it would not compile as is. So, I
commented out some of the
code and then it compiled and ran correctly.
While I understand the basic idea of explicit specialization, I'm
unclear about the syntax. Could someone please explain how to modify
this code, so it resembles the original, and compiles, and runs.
Also, could you inform us why they set it up in this manner.
Thanks,
------------------------------------------------------------------------
---
//template <> struct myhash{};
//
//template <> struct myhash<std::string>
class myhash {
public:
size_t operator()(const std::string &to_hash) const {
const char *in = to_hash.c_str();
size_t out=0;
while(*in != '\0') {
out*= 53; //just a prime number
out+= *in;
++in;
}
return out;
}
};
I'm using g++ and Ubuntu 14.04. The case is the code for an arbitrary
hash function. The originators evidently intended it as an explicit
specialization template. However, it would not compile as is. So, I
commented out some of the
code and then it compiled and ran correctly.
While I understand the basic idea of explicit specialization, I'm
unclear about the syntax. Could someone please explain how to modify
this code, so it resembles the original, and compiles, and runs.
Also, could you inform us why they set it up in this manner.
Thanks,
------------------------------------------------------------------------
---
//template <> struct myhash{};
//
//template <> struct myhash<std::string>
class myhash {
public:
size_t operator()(const std::string &to_hash) const {
const char *in = to_hash.c_str();
size_t out=0;
while(*in != '\0') {
out*= 53; //just a prime number
out+= *in;
++in;
}
return out;
}
};
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]