I'm trying to use a non-type template parameter which type is a template instance like this:
template<size_t num> class BitValue { ... };
class Foo {
// works
template<template<size_t> class BitValue, size_t num>
bool get(BitValue<num> && t) { ... }
// fails
template<typename T> bool
template<Bitvalue<num> bit> bool get() { ... };
template<template <size_t> Bitvalue bit> bool get() { ... };
template<template <size_t> class Bitvalue bit> bool get() { ... };
template<template <size_t> BitValue, size_t num, Bitvalue<num> bit> bool get() { ... };
};
You might say: Why not use the foo.get(value)
? Foo represents a kind of bitfield that has multi-bit values and single-big values. I want foo.get<...>() for all members of the bitfield for consistency.
Why not use `foo.get<typeof(value)>'? foo.get<MultiBitType>() returns the value of the multi-bit field. foo.get<SingleBitType>() returns the raw value of the single-bit type. But unfortunately some of the bits are negated. So foo.get<NegatedValue>() should return !foo.get<typeof(NegatedValue)>().
Any ideas if it is possible to have a template non-type template parameter at all? And if so how?
get()
whereget<X>()
return X bits whileget()
returns exactly one bit? – myautnum
that is important but get() also needs the value ofBitValue<num> value
. – Goswin von Brederlow