I have:
static const std::array<std::pair<ServerD, unsigned int>, 4> dataSizes =
{ std::make_pair(ServerD::ContentType, 1)
, std::make_pair(ServerD::RemoteAddress, 2)
, std::make_pair(ServerD::RemoteUser, 3)
, std::make_pair(ServerD::Url, 4)
};
template <unsigned int Index>
struct SizeFinder {
static const unsigned int SizeFor(ServerD data) {
return (dataSizes[Index].first == data) ? dataSizes[Index].second :
SizeFinder<Index - 1>::SizeFor(data);
}
};
template <>
struct SizeFinder<0> {
static const unsigned int SizeFor(ServerD data) {
return (dataSizes[0].first == data) ? dataSizes[0].second :
0;
}
};
Why is this not a compile time constant:
char tst[SizeFinder<4>::SizeFor(serverD)]
// Error 1 error C2975: 'BufferSize' : invalid template argument for 'isapi::`anonymous-namespace'::GetVariableFor', expected compile-time constant expression
I must make this work without constexpr. VS2013 still does not have this.
EDIT As it seems static const functions cannot compute at compile time, is there a workaround for C++ 03 ?