[dune-pdelab] Variadic Templates
Jö Fahlke
jorrit at jorrit.de
Sat Jun 11 19:11:09 CEST 2011
Am Fri, 10. Jun 2011, 20:41:43 +0200 schrieb Christian Engwer:
> I remember Jö describing a SFINAE construct to select a class,
> depending on the presence of a certain typedef in an other class. Not
> sure if this might help.
That would probably be something like
template<class T>
struct AlwaysVoid { typedef void Type; };
template<class T, class Dummy = void>
class SomeClass {
// Stuff that works without T::Foo
};
template<class T>
class SomeClass<T, typename AlwaysVoid<T>::Type> {
// Stuff that works with T::Foo
};
or you can make a predicate and use enable_if
template<class T, class Dummy = void>
class HasFoo : public false_type {};
template<class T>
class HasFoo<T, typename AlwaysVoid<T>::Type> : public true_type { };
template<class T, class Dummy = void>
class SomeClass {
// Stuff that works without T::Foo
};
template<class T>
class SomeClass<T, typename enable_if<HasFoo<T>::value>::Type> {
// Stuff that works with T::Foo
};
I think the alternative approach of using a bool instead of a class for Dummy
(which would allow to use Dune::AlwaysTrue) had a drawback, something along
the lines of "non-trivial integral expression in a specializations template
argument list".
Bye,
Jö.
--
http://www.heise.de/tp/deutsch/inhalt/te/17529/1.html
"Wer nichts zu verbergen hat, kann auch seine echte Emailadresse
angeben." -- Luke321 im Telepolis-Forum
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 828 bytes
Desc: Digital signature
URL: <https://lists.dune-project.org/pipermail/dune-pdelab/attachments/20110611/7503256e/attachment.sig>
More information about the dune-pdelab
mailing list