std::unordered_set speed comparison with vector

Pages: 12
> Most all the containers have begin iterators (except the Container Adaptors),
> so won't that nearly always be a valid construct?

Yes, is_sequence<T>::value would (and should) be true for standard sequence containers, c-style arrays. It would be false for types that can't be iterated over starting with std::begin


> Or is_same just can't be used at all with template parameters

Something like this would work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
template < typename... ARGS, template < typename... > class SEQ  > // standard containers
void foo( const SEQ<ARGS...>& seq, typename SEQ<ARGS...>::iterator* = 0  )
{
    using value_type = typename SEQ<ARGS...>::value_type ;
    using allocator_type = typename SEQ<ARGS...>::allocator_type ;

    if( std::is_same< SEQ<ARGS...>, std::vector<value_type,allocator_type > >::value )
        std::cout << "vector!\n" ;
    else std::cout << "not vector, something else\n" ;

    // etc.
}

template < typename T, std::size_t N > void foo( T (&seq)[N] ) { /* ... */ } // c-style array

template < typename T, std::size_t N > void foo( const std::array<T,N>& seq ) { /* ... */ } // std::array<> 

http://coliru.stacked-crooked.com/a/ec880c1a234cc4c2
Topic archived. No new replies allowed.
Pages: 12