Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-09-10 09:38:14


Joaquín Mª López Muñoz <joaquin_at_[hidden]> writes:

> This should have been posted to the Users list, but seems like
> it is temporarily disabled.
>
> Say I've got a MPL sequence whose elements
> contain a nested typedef "type_list" which is also a MPL sequence
> (so, a sequence of sequences). This algorithm looks for an element
> of such a sequence having a given type in its "type_list" typedef:
>
> template<typename TypeListofTypeLists,typename Type>
> struct find_type
> {
> typedef typename mpl::find_if<
> TypeListofTypeLists,
> mpl::bind1<has_type<Tag>,mpl::_1>
> >::type iter;
>
> typedef typename iter::type type;
> };
>
> template<typename Type>
> struct has_type
> {
> template<typename TypeListofTypeListsElement>
> struct apply:mpl::contains<
> BOOST_DEDUCED_TYPENAME TypeListofTypeListsElement::type_list,
> Type>
> {};
> };
>
> This works but seems to make MSVC++ 6.0 choke under moderate
> stress. Any idea to simplify it? (unrolling, etc.) Thanx in advance

It may help to avoid metafunction forwarding:

template<typename Type>
struct has_type
{
  template<typename TypeListofTypeListsElement>
  struct apply
  {
    typedef typename TypeListofTypeListsElement::type_list inner;
    typedef typename mpl::contains<inner,Type>::type type;
  };
};

HTH,

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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