Boost logo

Boost Users :

From: Olaf Peter (ope-devel_at_[hidden])
Date: 2021-07-02 12:17:39


using MSVC 2019 in debug mode I get an exception "cannot compare
incompatible string_view iterators for equality". Using release mode and
Clang/G++ all went fine as expected.

- Boost: 1.76
- Visual Studio 2019 16.10.3 in C++17 mode

How can it changed to be "portable" for all compiler? What's the reason
behind? Using + size or data.front() + size for e.g. end
iterator didn't compile.

Thanks in advance!

#include <boost/iterator/filter_iterator.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/range/iterator_range_core.hpp>
#include <boost/range/iterator_range_io.hpp>
#include <string_view>
#include <iostream>

template <typename RangeType>
static auto filter_range(RangeType const& range)
     struct separator_predicate {
         bool operator()(char x) { return '_' != x; }

     // FixMe: MSVC 2019 with '_CONTAINER_DEBUG_LEVEL > 0' triggers
     // assertion:
     // "cannot compare incompatible string_view iterators for equality"
     return boost::make_iterator_range(
             separator_predicate{}, range.begin(), range.end()),
             separator_predicate{}, range.end()));

using iterator_type = std::basic_string_view<char>::const_iterator;
using string_span = boost::iterator_range<iterator_type>;

int main()
     // input
     std::string_view const sv = "Hello_World";

     // algorithm get boost::iterator_range, aka string_span
     auto const range = string_span(sv);

     // here we are
     auto const range_f = filter_range(range);
     std::cout << range_f << '\n';

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at