Boost logo

Boost :

Subject: [boost] Disable_if_type / is_pair
From: Olaf van der Spek (ml_at_[hidden])
Date: 2011-10-08 06:30:09


Hi,

I've got a find wrapper (returning a pointer instead of an iterator)
that works for map, unordered map, ptr map, etc. I'd like to extent it
to set and mult_index.

What is the recommended way to disable the second overload? I didn't
find a is_pair type_trait or disable_if_type.

I call the find() member, which for example vector doesn't have. How
should I use the free find() if a member find() isn't available?

template <class T, class U>
typename T::value_type::second_type* find_ptr(T& c, U v)
{
        typename T::iterator i = c.find(v);
        return i == c.end() ? NULL : &i->second;
}

template <class T, class U>
typename iterator_traits<typename T::iterator>::pointer find_ptr(T& c, U v)
{
        typename T::iterator i = c.find(v);
        return i == c.end() ? NULL : &*i;
}

Greetings,

Olaf


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