mardi 4 août 2015

constexpr type forwarding fails

I am curious why the type check fails when it is forwarded using the constexpr function. I assume it has something to do with the substitution but dont know exactly because of what rule.

#include <iostream>
#include <type_traits>
#include <vector>
#include <cassert>

template <typename T, typename = void>
struct is_iterator {
    static constexpr bool value = false;
};

template <typename T>
struct is_iterator<T, typename std::enable_if<!std::is_same<typename std::iterator_traits<T>::value_type, void>::value>::type> {
    static constexpr bool value = true;
};

template <typename T>
constexpr bool isTypeIterator()
{
    return is_iterator<T>::value;
}

int main()
{
    std::vector<int> vec;
    static_assert(!is_iterator<decltype(vec)>::value, "It is clear why this works");
    static_assert(!is_type_iterator<decltype(vec)>, "I wonder why this is reversed");
}

Aucun commentaire:

Enregistrer un commentaire