Comparing value_type iterator in range constructor
I am writing a cosntructor range for a custom container:
MyContainer(const InputIterator& first,
const InputIterator& last,
const allocator_type& alloc = allocator_type())
and would like to check that it is InputIterator::value_type
compatible with the container value_type
. At first I 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 MyContainer::iterator
as an input iterator.
How can I check compatibility InputIterator
?
source to share
I guess you probably want std::is_constructible
:
static_assert(std::is_constructible<
value_type,
decltype(*first)
>::value, "error");
Or alternatively, std::is_assignable
depending on whether you are creating or assigning it from input iterators.
source to share