I have the following class structure, which tries to generate a compile time generated tree hierarchy
struct NodeBase{
virtual constexpr uint32_t size() const = 0;
virtual constexpr bool empty() const = 0;
constexpr NodeBase(){};
};
template <size_t L>
class Node : NodeBase{
private:
const uint32_t * const ptr;
const std::array<const NodeBase &, L> nodes;
public:
constexp Node(std::initializer_list<NodeBase> const ts, uint32_t const * const ptr) :
NodeBase(),
ptr(ptr),
nodes{ts}
{
};
constexpr uint32_t size() const {
return nodes.size();
}
constexpr bool empty() const {
return (ptr==nullptr) ? true : false;
}
}
// helper function should allow for template deduction
template<size_t T>
Node<T> makeNode(std::initializer_list<NodeBase> const ts, uint32_t const * const ptr){
return Node<T>(ts, ptr);
};
template <size_t L>
class Item : Node{
public:
constexpr Item() :
Node<L>({member}, nullptr)
{
};
private :
// here lies the problem
template <size_t M>
static constexpr Node<M> member = makeNode({},nullptr);
}
However, this gives the compiler (gcc 4.9.1) error: no matching function call to makeNode(, null_ptr_t), and a note to say it couldn't deduce template type.
I can fix the error by moving parameter M into the class level template, but this has some fairly horrible consequences, in that the parameter list will grow at every level of the tree hierarchy. I'm sure the compiler should be able to deduce the type, which is conditional on the length of the initialiser list provided to the constructor. Any thoughts?
Aucun commentaire:
Enregistrer un commentaire