I'm overloading << to print custom objects (in this case, instances of a custom class Vertex). As part of this, I want to print a given integer in binary. I'd prefer for many reasons to case with std::bitset rather than run a for loop, but the problem I'm encountering is that I have a specific size that each binary should be that depends on the instance. Here's the snippet:
std::ostream &
operator<< (std::ostream& os, const Vertex& V) {
    os << "(" << std::bitset<4>(V.signature()) << ") :";
    for (int e=2; e<V.degree(); ++e) {
        os << " [" << e << "]=" << V.neighbor(e) << " ";
    }
    return os;
}
In place of the 4, I really want to put a size_t that depends on V. For example, here's what I tried:
std::ostream &
operator<< (std::ostream& os, const Vertex& V) {
    size_t B = V.degree()-1;
    os << "(" << std::bitset<B>(V.signature()) << ") :";
    for (int e=2; e<V.degree(); ++e) {
        os << " [" << e << "]=" << V.neighbor(e) << " ";
    }
    return os;
}
The error reads "Non-type template argument is not a constant expression". Is there a way to fix this without hard coding the parameter? It's not something that will be known at compile time.
 
     
    