The following code of mine should detect whether T
has begin
and end
methods:
template
struct is_contai
This probably should be a comment, but I don't have enough points
@MSalters
Even though your is_container
works (almost) and I've used your code myself, I've discovered two problems in it.
First is that type deque
is detected as a container (in gcc-4.7). It seems that deque
has begin
/end
members and const_iterator
type defined.
2nd problem is that this code is invalid according to GCC devs. I qoute: values of default arguments are not part of the function type and do not take part in deduction. See GCC bug 51989
I am currently using this (C++11 only) for is_container
:
template
struct is_container {
template <
typename U,
typename S = decltype (((U*)0)->size()),
typename I = typename U::const_iterator
>
static char test(U* u);
template static long test(...);
enum { value = sizeof test(0) == 1 };
};