http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51989

             Bug #: 51989
           Summary: std::deque::iterator recognised as container
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: leo...@volnitsky.com


Created attachment 26450
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26450
deque-bug.cc

I need is_container<T> template which would recognize if T is a container. 
Code below works as expected.  With exception for std::deque::iterator -  gcc
can not compile code below:

------------------------------------------------------------------
#include <iostream>
#include <type_traits>
#include <vector>
#include <list>
#include <set>
#include <deque>

    template <typename T>
struct is_container {
    template <typename U>
    static char test(
        U* u,
        typename U::const_iterator b = ((U*)0)->begin(),
        typename U::const_iterator e = ((U*)0)->end()
    );
    template <typename U> static long test(...);

    enum { value = sizeof test<T>(0) == 1 };
};

int main() {
    std::cout <<  "void\t"            << is_container< void            
>::value << '\n';
    std::cout <<  "int\t"            << is_container< int              >::value
<< '\n';
    std::cout <<  "int*\t"            << is_container< int*            
>::value << '\n';
    std::cout <<  "vector<int>\t"        << is_container< std::vector<int>
>::value << '\n';
    std::cout <<  "deque<int>\t"        << is_container< std::deque<int> 
>::value << '\n';
    std::cout <<  "set<int>::iterator\t"    << is_container<
std::set<int>::iterator >::value << '\n';
    std::cout <<  "vector<int>::iterator\t"    << is_container<
std::vector<int>::iterator >::value << '\n';

    // gcc error
    std::cout <<  "deque<int>::iterator\t"    << is_container<
std::deque<int>::iterator >::value << '\n';
}
-----------------------------------------------------------------------

Compiling it with GCC (4.7.0-alpha20111203):

gcc -std=gnu++0x -Wall deque-bug.cc   -o deque-bug

Produce following error:

deque-bug.cc: In instantiation of ‘struct
is_container<std::_Deque_iterator<int, int&, int*> >’:
deque-bug.cc:31:84:   required from here
deque-bug.cc:18:7: error: ‘struct std::_Deque_iterator<int, int&, int*>’ has no
member named ‘begin’
deque-bug.cc:18:7: error: ‘struct std::_Deque_iterator<int, int&, int*>’ has no
member named ‘end’

Attached are source and -save-temps

Reply via email to