Home How has_iterator is working in given code?
Reply: 0

How has_iterator is working in given code?

user767 Published in May 22, 2018, 9:20 pm

Please consider below program:

    template <typename T>
    struct has_iterator
        template <typename U>
        static char test(typename U::iterator* x);

        template <typename U>
        static long test(U* x);

        static constexpr const bool value = sizeof(test<T>(0)) == 1;

    int main() {
        std::cout << std::boolalpha << has_iterator<std::vector<int>>::value << std::endl;
        return 0;

The output of the above program is true. Here my question is when T is std::vector<int> why static char test(typename U::iterator* x) is preffered over static long test(U* x).

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304798 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO