|
Boost : |
From: Howard Hinnant (hinnant_at_[hidden])
Date: 2000-09-16 16:10:40
I think it would be dangerous for boost to get on the slippery slope of
banning certain C++ language features, especially when the workaround
adversely effects the interface to a lib. In this particular example,
the interface of the partial specialization workaround is not near as
elegant as the template template interface. I do not see a compelling
reason to artificially dumb-down the interface of boost libs for those
with conforming compilers. I do however, think it is worthwhile to offer
an optional dumbed-down interface for something as sparsely supported as
template templates.
Motivating example:
Consider the compile-time list structure of 10.10.5 of "Generative
Programming". I might want to create a list, and then sort it using a
predicate. Maybe something like:
template <class T, class U>
struct by_size
{
static const bool value = sizeof(T) <= sizeof(U);
};
...
typedef make_list<short, int, char, long>::type MyList;
typedef sort<MyList, by_size>::type SortedList;
It is very nice to be able to give the predicate as a template template
parameter. No doubt you can figure out how to do this without template
templates. But gee, I really like the interface here.
Heck, I'm quickly trying to think of a "predicate_tag" style workaround
here and I'm coming up blank. But I'm sure someone will...
-Howard
jsiek_at_[hidden] wrote on 9/16/2000 2:13 AM
>Template templates are never really needed, since they
>can be replaced by using partial specialization. Instead
>of having two versions of the code, one with template templates
>and one with the partial spec. version, I think its better
>to just maintain the one version that is more portable,
>the partial spec. version. Also, the partial spec can
>be replaced with something even more portable, but that
>starts to get really messy...
>
>
>with template templates:
>
> template<class U, template <class T> Container>
> struct bar {
> typedef Container<U> foo;
> ...
> };
>
> bar<int, std::vector> b;
>
>with partial spec:
>
> template <class ContainerTag, class U>
> struct container_generator { };
>
> template <class U, class ContainerTag>
> struct bar {
> typedef typename container_generator<ContainerTag, U>::type fooX;
> ...
> };
>
> struct vector_tag { };
>
> template <class T>
> struct container_generator<vector_tag, T> {
> typedef std::vector<T> type;
> };
>
> bar<int, vector_tag> b;
>
>
>Daryle Walker writes:
> > Should we have a #define for template templates support in
>boost/config.hpp?
> > This could give some flexibility for people who may want to use template
> > templates as the best solution, but give alternate solutions if needed.
> (I
> > was think of template templates for getting the standard algorithms to
>work
> > with the range stuff.)
> >
> > --
> >
> >
> >
> >
> >
> >
>
>
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk