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?
I'm guessing 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're constructing or assigning from the input iterators.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With