vendredi 24 avril 2015

Comparing iterator value_type in range constructor

I'm writing a range cosntructor for a custom container:

MyContainer(const InputIterator& first, 
            const InputIterator& last, 
            const allocator_type& alloc = allocator_type())

and would like to check that the the InputIterator::value_type is compatible with the container's value_type. I initially tried tried:

static_assert(!(std::is_convertible<InputIterator::value_type, value_type>::value ||
        std::is_same<InputIterator::value_type, value_type>::value), "error");

and went as far as:

using InputIteratorType = typename std::decay<InputIterator>::type;
using InputValueType = typename std::decay<InputIteratorType::value_type>::type;
static_assert(!(std::is_convertible<InputValueType, value_type>::value ||
        std::is_same<InputValueType, value_type>::value), "error");

but it always asserts, even when I use the MyContainer::iterator as the input iterator.

How can I check that the InputIterator is compatible?

Aucun commentaire:

Enregistrer un commentaire