Boost logo

Boost :

From: John Max Skaller (skaller_at_[hidden])
Date: 2001-09-22 12:57:34


Daryle Walker wrote:
>
> I thought of these a while ago. I don't know if I'm ever going to do
> something with these ideas, but maybe one of you can take these.
>
> 1. Some types in Boost items involve a std::pair with both template
> parameters the same type. We could compact this somehow. Too bad we can't
> do:
>
> template < typename T >
> typedef std::pair<T,T> doublet;
>
> I guess we have to make a class template that inherits from std::pair and/or
> uses special conversions.

        This is a fundamental construction, its correct name
is 'the diagonal functor', represented by the Greek symbol Delta.
[There is a also a dual 'codiagnoal functor' represented by
an upside-down delta, it eliminates the case of a two alternatives
of the same type]

> 2. If we have [1], we should have a make_doublet function template that
> works like std::make_pair.

        You can do it anyhow, just define a new template.
You'd also need two transformations

        pair<T,T> <--> diag<T>
 
> 3. Should we have a pair_switch function template, that takes a
> std::pair<X,Y> and returns a std::pair<Y,X> that is the input in the reverse
> order?

        A common name is 'twist'. Again, fundamental.

        A generalisation on 'diag' is

        diag<n,T> <--> tuple<T,T,T ... T> (n times)

        A generalisation on twist is more fun:

        permute<permutation, T1, T2, T3, .. >

which reorders the types. Even more general:

        extract< [1,3,4,9,6], T1, T2, .. >

which forms

        tuple<T1, T3, T4, T9, T6>

This can actually be done I think, using primes and an integer
argument (so that n = 2*^p1 * 3* p2 * 5^p3 .., and one can
find p1, p2, p3 by factorising. This would be fun to do with
templates .. :-]

-- 
John (Max) Skaller, mailto:skaller_at_[hidden] 
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
New generation programming language Felix  http://felix.sourceforge.net
Literate Programming tool Interscript     
http://Interscript.sourceforge.net

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk