I am trying to make a selection of a compilation algorithm using specialized specialization.
I am using the following code:
template <class C>
struct choose
{
typedef size_t (*type)(const C*);
static constexpr type value = java_string_hashcode<C>;
};
I specialized this structure for type char:
template <>
struct choose<char>
{
typedef size_t (*type)(const char*);
static constexpr type value = fnv_1a_32_hash;
};
But when I try to compile it, I get the following error with GCC 4.7.1:
error: field initializer is not constant
I think the problem is that the function is fnv_1a_32_hashoverloaded, even if the IMO implicit cast to size_t (*)(const char*)should solve this problem.
I finally found a workaround by renaming the overload or just by selecting the destination:
static constexpr type value = (type)fnv_1a_32_hash;
My question is : is this a compiler error? Or am I missing something? Please explain and specify specifications where necessary.
fnv_1a_32_hash implementation details:
constexpr size_t fnv_1a_32_hash(const char* p, size_t h) noexcept
{
return (*p == 0) ? h : fnv_1a_32_hash(p + 1, (h ^ *p) * fnv::prime);
}
constexpr size_t fnv_1a_32_hash(const char* p) noexcept
{
return fnv_1a_32_hash(p, fnv::offset_basis);
}