How to partially specialize class template on template template
argument in C++11?
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi!
I'm trying to model well known functional concepts in C++11 (looking
at Monad and Arrow classes in Haskell.) I've declared a class template
Arrow on a template template parameter. A specialization of the
template shall provide details for its arguments, see example
"FUNCTION" below:
template<template<typename, typename> class A>
struct Arrow;
// FUNCTION
template<typename A, typename B>
using arrow = std::function<B (A)>;
template<> struct Arrow<arrow> { /*...*/ }; // OK
Now I want to do a partial specialization for "Kleisli arrows" that
make an Arrow out of any Monad. A Monad is a unary template template
class, see here:
// KLEISLI
template<template<typename> class M, typename B, typename C>
using Kleisli = std::function<M<C> (B)>;
I could now fully specialize Arrow for any single Monad like below,
but all specializations would have the same implementation (repeated
code).
template<typename B, typename C>
using Monad1Arrow = Kleisli<Monad1, B, C>;
template<> struct Arrow<Monad1Arrow> { /*...*/ };
// repeat for Monad2, 3, 4, 5, ...
How could I do this in general using a partial specialization?
/* For any Monad M the Kleisli<M> is an Arrow. How would I
* partially specialize struct Arrow<> for this?
*/
// TRIAL 1:
template<template<typename> class M>
struct Arrow<Kleisli<M>> { /*...*/ }; // HOW TO?
// TRIAL 2:
template<typename B, typename C>
using kleisli<M> = Kleisli<M, B, C>; // HOW TO?
template<template<typename> class M>
struct Arrow<kleisli<M>> { /*...*/ };
There seems to be no way to make the syntax "Kleisli<M>" produce a
template template class argument for Arrow. Any ideas? Currently I'm
resorting to:
template<typename A> struct Arrow; // just typename
template<template<typename> class m, typename B, typename C>
struct Arrow<Kleisli<M, B, C>> { /*...*/ };
Any alternatives?
Frank
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: keyserver x-hkp://pool.sks-keyservers.net
iEYEARECAAYFAlCikY8ACgkQhAOUmAZhnmpakwCeOSMLmLMSLjXg5l/LLglA97jN
UHIAn2P4BfMjfnwmCp2hgRu1ZKLbJpQ/
=lfPy
-----END PGP SIGNATURE-----
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]