Boost logo

Ublas :

Subject: Re: [ublas] [bindings] Workspaces
From: Rutger ter Borg (rutger_at_[hidden])
Date: 2008-12-13 04:47:22


Thomas Klimpel wrote:
> we simply need a compile time way to tell whether a value_type is
> actually a complex value_type.

You mean something such as is_complex<T>, http://tinyurl.com/5qhrgk?

>> I have thought of that. Since the value_type of the arrays are fixed
>> anyway that should be quite easy to do.
>
> It may be easy to do (if you know how to do it),

I think the facilities provided by Boost.Fusion would make it easy indeed,
this would make it look like

template< typename A, typename B, typename C >
struct workspace3 {

  typedef typename fusion::map<
    fusion::pair< typename traits::value_type< A >, A& >,
    fusion::pair< typename traits::value_type< B >, B& >,
    fusion::pair< typename traits::value_type< C >, C& > > map_type;

  workspace3( A& a, B& b, C& c ):
    m_map( fusion::map_tie<
             traits::value_type< A >,
             traits::value_type< B >
             traits::value_type< C > >( a, b, c ) );

  template< typename V >
  fusion::result_of::at_key< map_type, V >::type get_array_of() {
    return fusion::at_key<V>(m_map);
  };

  map_type m_map;
};

I haven't checked whether the above compiles, but it should be almost there.
Now this should give us, for an instantiated workspace3, access by
value_type to the workspace arrays,

... work.get_array_of< std::complex >();
... work.get_array_of< double >();
... work.get_array_of< int >();

> semantic. Whether workspace( a, b, c ) returns a boost::tuple<A&, B&,
> C&> or a workspace3<A,B,C> (or something completely different) is less
> important to me. Just to be clear, workspace( a, b ) would return
> boost::tuple<A&, B&> or a workspace2<A,B> and workspace( a ) would
> return boost::tuple<A&> or a workspace1<A>.

In this case, when returning tuples, we would loose the information that the
argument passed is actually a workspace-type. It could be that we still
need that information at some point.

Cheers,

Rutger