Re: Interesting Boost Implementation Details?

David Abrahams wrote:
* The way that Boost.MPL uses partial specialization on template template parameters to peel apart lambda expressions and turn them into metafunction classes.
I thought I understand how it's done, but now that I am trying to apply this to my own problem, it seems that default template parameters may be a showstopper in applying this technique, at least in some compilers. For example if I have: template<class T> struct do_something; template<template<class> class T, class P0> struct do_something<T<P0> > {}; template<template<class, class> class T, class P0, class P1> struct do_something<T<P0, P1> > {}; GCC 3.4.2 can't figure out which specialization to use for, e.g., std::vector. At the same time VC71 is fine with this, and chooses the one with 2 parameteres. Unfortunately I am unable to find my way around the MPL source to figure out what's really done... Can you clarify this? Thanks in advance, Arkadiy

Arkadiy Vertleyb wrote:
David Abrahams wrote:
* The way that Boost.MPL uses partial specialization on template template parameters to peel apart lambda expressions and turn them into metafunction classes.
I thought I understand how it's done, but now that I am trying to apply this to my own problem, it seems that default template parameters may be a showstopper in applying this technique, at least in some compilers. For example if I have:
template<class T> struct do_something;
template<template<class> class T, class P0> struct do_something<T<P0> > {};
template<template<class, class> class T, class P0, class P1> struct do_something<T<P0, P1> > {};
GCC 3.4.2 can't figure out which specialization to use for, e.g., std::vector. At the same time VC71 is fine with this, and chooses the one with 2 parameteres.
Unfortunately I am unable to find my way around the MPL source to figure out what's really done...
Can you clarify this?
MPL uses a template_arity meta-function and specializations on the arity to work around this problem. Something like: template<class T, int N> struct do_something; template<template<class> class T, class P0> struct do_something<T<P0>, 1> { }; template<template<class, class> class T, class P0, class P1> struct do_something<T<P0, P1>, 2> { }; do_something<X, template_arity<X>::value> HTH, -- Daniel Wallin

"Daniel Wallin" <dalwan01@student.umu.se> wrote
MPL uses a template_arity meta-function and specializations on the arity to work around this problem. Something like:
template<class T, int N> struct do_something;
template<template<class> class T, class P0> struct do_something<T<P0>, 1> { };
template<template<class, class> class T, class P0, class P1> struct do_something<T<P0, P1>, 2> { };
do_something<X, template_arity<X>::value>
HTH,
It does, thanks! Arkadiy

"Arkadiy Vertleyb" <vertleyb@hotmail.com> wrote in message news:cs3j7p$jtp$1@sea.gmane.org...
"Daniel Wallin" <dalwan01@student.umu.se> wrote
MPL uses a template_arity meta-function and specializations on the arity to work around this problem. Something like:
template<class T, int N> struct do_something;
template<template<class> class T, class P0> struct do_something<T<P0>, 1> { };
template<template<class, class> class T, class P0, class P1> struct do_something<T<P0, P1>, 2> { };
do_something<X, template_arity<X>::value>
HTH,
It does, thanks!
Arkadiy
Does this mean it may (eventually) be possible to use template template params in BOOST_TYPEOF ? regards Andy Little

"Andy Little" <andy@servocomm.freeserve.co.uk> wrote in message
Does this mean it may (eventually) be possible to use template template params in BOOST_TYPEOF ?
Not yet :( What I am trying to achieve is much more modest: I want to extract template and a number of parameters from an unregistered type to achieve a more descriptive assertion. So that instead of : can't instantiate boost::typeof::encode_type<class std::map<class std::basic_string<char, struct std::char_traits<char>,class std::allocator<char> >,class std::basic_stri ng<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::l ess<class std::basic_string<char,struct std::char_traits<char>,class std::alloca tor<char> > >,class std::allocator<struct std::pair<class std::basic_string<char ,struct std::char_traits<char>,class std::allocator<char> > const ,class std::ba sic_string<char,struct std::char_traits<char>,class std::allocator<char> > >
I could get something like this: MPL standard assertion text(boost::type_of::unknown_template_4<std::map>) Kind of exersize while reading the MPL book :) One problem that I have with mpl::template_arity, though, is that it seems to be undocumented... And therefore probably an internal feature? As for your question however, the conceptual problem with template template parameters is that they can't be returned from meta-functions: template<template<class> class T> class X { // I know T here, but how do I pass it outside??? }; Of course, they can be wrapped... I am wondering whether it would be possible to use this.... But again, not yet :) Regards, Arkadiy

Arkadiy Vertleyb writes:
One problem that I have with mpl::template_arity, though, is that it seems to be undocumented... And therefore probably an internal feature?
Yes, it's an implementation detail. Currently, at least.
As for your question however, the conceptual problem with template template parameters is that they can't be returned from meta-functions:
template<template<class> class T> class X { // I know T here, but how do I pass it outside???
typedef T<_> type; or typedef mpl::quote1<T> type;
};
Of course, they can be wrapped... I am wondering whether it would be possible to use this....
Depends on what you want to do with the result. One thing you can do for sure is to instantiate it with particular arguments. -- Aleksey Gurtovoy MetaCommunications Engineering

"Aleksey Gurtovoy" <agurtovoy@meta-comm.com> wrote
Arkadiy Vertleyb writes: [...]
As for your question however, the conceptual problem with template template parameters is that they can't be returned from meta-functions:
template<template<class> class T> class X { // I know T here, but how do I pass it outside???
typedef T<_> type; or typedef mpl::quote1<T> type;
};
Of course, they can be wrapped... I am wondering whether it would be possible to use this....
Depends on what you want to do with the result. One thing you can do for sure is to instantiate it with particular arguments.
Template template metaprogramming :) Actually I want to use it as a template parameter. This is about typeof. The type was somehow encoded into mpl::vector of integeres. Now I want to decode it (pseudocode): // template<class T, int n, template<class> class Tpl> struct MyTemplate; typedef MyTemplate< typename decode_type<iter1>::type, // type template parameter decode_integral<iter2>::value, // integral template parameter decode_template<iter3>::??? // template template parameter
type;
Doesn't really seem wrapping in quote1 or instantiation with _ is going to help... This is kind of funny. Almost starts looking as the original problem with typeof, where the type is known inside the function, but can't be passed outside... Where is "sizeof" that is going to help? :) Regards, Arkadiy
participants (4)
-
Aleksey Gurtovoy
-
Andy Little
-
Arkadiy Vertleyb
-
Daniel Wallin