////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2025-2026. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/container for documentation. // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_CONTAINER_EXPERIMENTAL_SEGMENTED_REPLACE_IF_HPP #define BOOST_CONTAINER_EXPERIMENTAL_SEGMENTED_REPLACE_IF_HPP #ifndef BOOST_CONFIG_HPP # include #endif #if defined(BOOST_HAS_PRAGMA_ONCE) # pragma once #endif #include #include #include #include namespace boost { namespace container { template void segmented_replace_if(FwdIt first, Sent last, Pred pred, const T& BOOST_RESTRICT new_val); namespace detail_algo { template typename algo_enable_if_c< !Tag::value || is_sentinel::value>::type BOOST_CONTAINER_FORCEINLINE segmented_replace_if_dispatch(FwdIt first, Sent last, Pred pred, const T& BOOST_RESTRICT new_val, Tag, Cat) { BOOST_CONTAINER_SEGMENTED_UNROLL(4) for(; first != last; ++first) if(pred(*first)) *first = new_val; } template void segmented_replace_if_dispatch (SegIter first, SegIter last, Pred pred, const T& BOOST_RESTRICT new_val, segmented_iterator_tag, Cat) { typedef segmented_iterator_traits traits; typedef typename traits::local_iterator local_iterator; typedef typename traits::segment_iterator segment_iterator; typedef typename segmented_iterator_traits::is_segmented_iterator is_local_seg_t; typedef typename iterator_traits::iterator_category local_cat_t; segment_iterator sfirst = traits::segment(first); segment_iterator slast = traits::segment(last); if(sfirst == slast) { (segmented_replace_if_dispatch)(traits::local(first), traits::local(last), pred, new_val, is_local_seg_t(), local_cat_t()); } else { (segmented_replace_if_dispatch)(traits::local(first), traits::end(sfirst), pred, new_val, is_local_seg_t(), local_cat_t()); for(++sfirst; sfirst != slast; ++sfirst) (segmented_replace_if_dispatch)(traits::begin(sfirst), traits::end(sfirst), pred, new_val, is_local_seg_t(), local_cat_t()); (segmented_replace_if_dispatch)(traits::begin(sfirst), traits::local(last), pred, new_val, is_local_seg_t(), local_cat_t()); } } } // namespace detail_algo //! Replaces every element satisfying \c pred with \c new_val in [first, last). template BOOST_CONTAINER_FORCEINLINE void segmented_replace_if(FwdIt first, Sent last, Pred pred, const T& BOOST_RESTRICT new_val) { typedef segmented_iterator_traits traits; detail_algo::segmented_replace_if_dispatch (first, last, pred, new_val, typename traits::is_segmented_iterator(), typename iterator_traits::iterator_category()); } } // namespace container } // namespace boost #include #endif // BOOST_CONTAINER_EXPERIMENTAL_SEGMENTED_REPLACE_IF_HPP