I have some complex third-party code that uses templates. With gcc 7.3.0 it builds ok if gcc flag -std=gnu++98 is specified, but gives a compilation error otherwise (i.e. with C++11 compilation). I need to fix the C++11 compilation. Here is the code (sorry it is not complete but the header files are complex):
#define CPP11 (__cplusplus > 199711L)
namespace csl
{
namespace PostExec
{
struct Complement
{
static int64_t Execute(int64_t v)
{
return ~v;
}
};
template<size_t bitWidth, bool maskOutput>
struct Mask
{
static int64_t Execute(int64_t v)
{
return 0;
}
};
#if CPP11
template<typename P, typename... PS>
struct Compound
{
template<typename T>
static T&& Execute(T&& v)
{
if (sizeof...(PS) > 0)
{
return Compound<PS...>::Execute(P::Execute(std::forward<T>(v))); <<<< COMPILER ERROR HERE
}
return P::Execute(std::forward<T>(v));
}
};
#else
template<typename P1, typename P2>
struct Compound
{
static int64_t Execute(int64_t v)
{
return P1::Execute(P2::Execute(v));
}
};
#endif
}
}
using namespace csl;
class CModel
{
public:
void f1();
private:
void Execute() { }
static const size_t PAGE_COUNT = 1;
static size_t CurrentPage;
static CPage<1, 0> State[PAGE_COUNT];
};
void CModel::f1()
{
int64_t n[5];
StepLogicalNXOr<1, false>::Execute(Page.N[1], n[0], n[1]);
}
size_t CModel::CurrentPage = 0;
CPage <1919, 0> CModel::State[PAGE_COUNT] = {
CPage <1, 0>()
};
The compiler error (when CPP11 is defined) is:
<snip>: error: wrong number of template arguments (0, should be at least 1)
return Compound<PS...>::Execute(P::Execute(std::forward<T>(v)));
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<snip>: note: provided for ‘template<class P, class ... PS> struct csl::PostExec::Compound’
struct Compound
^~~~~~~~
I realise this is complicated but if anyone can help I will be grateful.
Aucun commentaire:
Enregistrer un commentaire