Boost logo

Boost :

From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2002-02-20 04:55:26


dexsch wrote:
>
> --- In boost_at_y..., wb_at_f... wrote:
> > David Abrahams <david.abrahams_at_r...> wrote on Mon Feb 18 10:20:48
> 2002:
> > I was originally motivated by the distasteful and error-prone need
> > to duplicate some complicated type expressions in several places
> > within a function template:
> >
> > template< class T1, class T2, class T3 >
> > typename complicated_expression<T1,T2,T3>::type
> > f( T1 const &, ...) {
> > typedef typename complicated_expression<T1,T2,T3>::type
> result;
> > // ...
> > return typename other_expression<result>::type( ... );
> > }
> >
> [snip]
>
> What's wrong with declaring a template class prior to
> the template in question and creating all the typedefs
> you need in go.
>
> template <typename T1, typename T2, typename T3>
> struct ftypedefs
> {
> typedef complicated_expression<T1,T2,T3>::type result;
> typedef other_expresion<result>::type resulttype;
> };
> typedef ftypedefs<T1,T2,T3> F123;
> template <typename T1, typename T2, typename T3>
> F123::result f(const T1&,...) {
> return F123::resulttype(...); }
>
> Why on earth would you ever want to return a complicated type
> and not make that a simple typedef usable by the caller ?

I think we're getting closer. How about multiple use of template
parameters? (template typedef's are of course useful ;)

Consider:

template< typename T1, typename T2, typename T3 >
typedef complicated_type< T1, T2, another_type< T3 > T4, // see (1)
typedef another_complicated_type< T2, T3, yet_another_type< T4 > > T5,
T5 my_function( const T3& arg1, const T4& arg2 )
{
   // ...
   T4 value1 = pow( arg2, 4 );

   return T5( arg1 + arg2 + value1 );
}

(1): Note the comma instead of a semicolon

Would this be a real helper? Will it replace 'auto'-return-types? Does
it yield other suprises (good or bad)?

Regards, Daniel

--
Daniel Frey
aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de

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