This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/51989] New: std::deque::iterator recognised as container
- From: "leonid at volnitsky dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 25 Jan 2012 05:02:17 +0000
- Subject: [Bug c++/51989] New: std::deque::iterator recognised as container
- Auto-submitted: auto-generated
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: unassigned@gcc.gnu.org
ReportedBy: leonid@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