Boost logo

Boost :

Subject: [boost] Boost.Algorithm design question
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2011-10-05 18:33:17


So, what do people prefer (and why?):

template<typename InputIterator, typename V>
bool none_of_equal ( InputIterator first, InputIterator last, V const &val )
{
    for ( ; first != last; ++first )
        if ( val == *first )
            return false;
    return true;
}

or

template<typename InputIterator, >
bool none_of_equal ( InputIterator first, InputIterator last, iterator_traits<InputIterator>::value_type const &val )
{
    for ( ; first != last; ++first )
        if ( val == *first )
            return false;
    return true;
}

In the first case, I think there's (possible) conversion from V to iterator_traits<InputIterator>::value_type each time through the loop.
In the second case, there is not.

Of course, the (mythical?) smart compiler would do the conversion once and save the result for reuse.

-- Marshall

Marshall Clow Idio Software <mailto:mclow.lists_at_[hidden]>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki


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