1
int n=10;
vector<bool> translated_ancestors(n) ;
std::fill(begin(translated_ancestors), end(translated_ancestors), false);

编译没有错误。

但如果我改为:

ranges::fill(translated_ancestors, false) ;

它返回以下错误消息:

/home/edouda/linkedboxdraw/optimize_rectangle_positions.cpp: In function ‘void optimize_rectangle_positions(std::vector<MyRect>&, const std::vector<std::vector<MPD_Arc> >&)’:
/home/edouda/linkedboxdraw/optimize_rectangle_positions.cpp:193:65: error: no match for call to ‘(const std::ranges::__fill_fn) (std::vector<bool>&, bool)’
  193 |                         ranges::fill(translated_ancestors, false) ;
      |                                                                 ^
In file included from /usr/include/c++/10/bits/ranges_algo.h:35,
                 from /usr/include/c++/10/algorithm:64,
                 from /home/edouda/linkedboxdraw/optimize_rectangle_positions.cpp:6:
/usr/include/c++/10/bits/ranges_algobase.h:561:7: note: candidate: ‘template<class _Tp, class _Out, class _Sent>  requires (output_iterator<_Out, const _Tp&>) && (sentinel_for<_Sent, _Out>) constexpr _Out std::ranges::__fill_fn::operator()(_Out, _Sent, const _Tp&) const’
  561 |       operator()(_Out __first, _Sent __last, const _Tp& __value) const
      |       ^~~~~~~~
/usr/include/c++/10/bits/ranges_algobase.h:561:7: note:   template argument deduction/substitution failed:
/home/edouda/linkedboxdraw/optimize_rectangle_positions.cpp:193:65: note:   candidate expects 3 arguments, 2 provided
  193 |                         ranges::fill(translated_ancestors, false) ;
      |                                                                 ^
In file included from /usr/include/c++/10/bits/ranges_algo.h:35,
                 from /usr/include/c++/10/algorithm:64,
                 from /home/edouda/linkedboxdraw/optimize_rectangle_positions.cpp:6:
/usr/include/c++/10/bits/ranges_algobase.h:587:7: note: candidate: ‘constexpr std::ranges::borrowed_iterator_t<_Range> std::ranges::__fill_fn::operator()(_Range&&, const _Tp&) const [with _Tp = bool; _Range = std::vector<bool>&; std::ranges::borrowed_iterator_t<_Range> = std::conditional<true, std::_Bit_iterator, std::ranges::dangling>::type]’
  587 |       operator()(_Range&& __r, const _Tp& __value) const
      |       ^~~~~~~~
/usr/include/c++/10/bits/ranges_algobase.h:587:7: note: constraints not satisfied
In file included from /usr/include/c++/10/bits/stl_iterator_base_types.h:71,
                 from /usr/include/c++/10/bits/stl_algobase.h:65,
                 from /usr/include/c++/10/vector:60,
                 from /home/edouda/linkedboxdraw/MyRect.h:12,
                 from /home/edouda/linkedboxdraw/optimize_rectangle_positions.h:5,
                 from /home/edouda/linkedboxdraw/optimize_rectangle_positions.cpp:1:
/usr/include/c++/10/bits/iterator_concepts.h: In instantiation of ‘constexpr std::ranges::borrowed_iterator_t<_Range> std::ranges::__fill_fn::operator()(_Range&&, const _Tp&) const [with _Tp = bool; _Range = std::vector<bool>&; std::ranges::borrowed_iterator_t<_Range> = std::conditional<true, std::_Bit_iterator, std::ranges::dangling>::type]’:
/home/edouda/linkedboxdraw/optimize_rectangle_positions.cpp:193:65:   required from here
/usr/include/c++/10/bits/iterator_concepts.h:516:13:   required for the satisfaction of ‘indirectly_writable<_Iter, _Tp
’ [with _Iter = std::_Bit_iterator; _Tp = const bool&]
/usr/include/c++/10/bits/iterator_concepts.h:593:13:   required for the satisfaction of ‘output_iterator<decltype (std::__detail::__ranges_begin(declval<_Container&>())), _Tp>’ [with _Container = std::vector<bool, std::allocator<bool> >&; _Tp = const bool&]
/usr/include/c++/10/bits/range_access.h:914:13:   required for the satisfaction of ‘output_range<_Range, const _Tp&>’ [with _Range = std::vector<bool, std::allocator<bool> >&; _Tp = bool]
/usr/include/c++/10/bits/iterator_concepts.h:516:35:   in requirements with ‘_Out&& __o’, ‘_Tp&& __t’ [with _Tp = std::_Bit_iterator; _Tp = const bool&; _Out = std::_Bit_iterator]
/usr/include/c++/10/bits/iterator_concepts.h:521:4: note: the required expression ‘const_cast<const decltype(*(declval<_Tp&>)())&&>(*__o) =(forward<_Tp>)(__t)’ is invalid
  520 |  const_cast<const iter_reference_t<_Out>&&>(*__o)
      |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  521 |    = std::forward<_Tp>(__t);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/iterator_concepts.h:523:4: note: the required expression ‘const_cast<const decltype(*(declval<_Tp&>)())&&>(*(forward<_Out>)(__o))=(forward<_Tp>)(__t)’ is invalid
  522 |  const_cast<const iter_reference_t<_Out>&&>(*std::forward<_Out>(__o))
      |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  523 |    = std::forward<_Tp>(__t);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: note: set ‘-fconcepts-diagnostics-depth=’ to at least 2 for more detail
make[2]: *** [CMakeFiles/latuile.dir/build.make:167: CMakeFiles/latuile.dir/optimize_rectangle_positions.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/latuile.dir/all] Error 2
make: *** [Makefile:95: all] Error 2
4

0 回答 0