[PATCH 1/5] WIP: libstdc++: Rebase PSTL on oneDPL release 2022.12.0

Jonathan Wakely jwakely@redhat.com
Sat Nov 14 01:57:03 GMT 2026


This adds support for an OpenMP backend, which means that it's possible
to use libgomp to provide parallelism instead of depending on Intel TBB.

Currently the 26_numerics/pstl/numeric_ops/move_only.cc test FAILs, but
I'm not sure if that's a bug in the test or something that needs to be
fixed in the new pstl code. Possibly both. I added the test based on
incorrect requirements, but upstream hasn't made any changes to fix
https://github.com/uxlfoundation/oneDPL/issues/1955 so I think the code
and the test need to be updated along the lines of the P0571R2 proposal.

There is already a 2022.14.0 release, so this will need to be updated
again, but it should be a smaller diff next time.

libstdc++-v3/ChangeLog:

	* TODO
---

Sending this now so it's in time for the end of stage 1, but some
additional work is still needed.

 libstdc++-v3/include/Makefile.am              |    64 +-
 libstdc++-v3/include/Makefile.in              |    64 +-
 libstdc++-v3/include/pstl/algorithm_fwd.h     |   684 +-
 libstdc++-v3/include/pstl/algorithm_impl.h    |  3619 +--
 .../include/pstl/algorithm_ranges_impl.h      |  1429 ++
 libstdc++-v3/include/pstl/execution_defs.h    |   125 +-
 libstdc++-v3/include/pstl/execution_impl.h    |   209 +-
 libstdc++-v3/include/pstl/functional_impl.h   |    61 +
 .../include/pstl/glue_algorithm_defs.h        |   374 +-
 .../include/pstl/glue_algorithm_impl.h        |   967 +-
 .../include/pstl/glue_algorithm_ranges_defs.h |   358 +
 .../include/pstl/glue_algorithm_ranges_impl.h |  2091 ++
 .../include/pstl/glue_execution_defs.h        |    53 +-
 libstdc++-v3/include/pstl/glue_memory_defs.h  |    51 +-
 libstdc++-v3/include/pstl/glue_memory_impl.h  |   441 +-
 .../include/pstl/glue_memory_ranges_impl.h    |   205 +
 libstdc++-v3/include/pstl/glue_numeric_defs.h |   102 +-
 libstdc++-v3/include/pstl/glue_numeric_impl.h |   231 +-
 .../include/pstl/glue_numeric_ranges_defs.h   |   116 +
 .../include/pstl/glue_numeric_ranges_impl.h   |   203 +
 .../include/pstl/histogram_binhash_utils.h    |   123 +
 .../include/pstl/histogram_extension_defs.h   |    40 +
 libstdc++-v3/include/pstl/histogram_impl.h    |   153 +
 libstdc++-v3/include/pstl/iterator_defs.h     |   111 +
 libstdc++-v3/include/pstl/iterator_impl.h     |  1050 +
 libstdc++-v3/include/pstl/memory_fwd.h        |    53 +
 libstdc++-v3/include/pstl/memory_impl.h       |   193 +-
 .../include/pstl/memory_ranges_impl.h         |   278 +
 libstdc++-v3/include/pstl/numeric_fwd.h       |    79 +-
 libstdc++-v3/include/pstl/numeric_impl.h      |   358 +-
 libstdc++-v3/include/pstl/omp/parallel_for.h  |    74 +
 .../include/pstl/omp/parallel_for_each.h      |    65 +
 .../include/pstl/omp/parallel_invoke.h        |    55 +
 .../include/pstl/omp/parallel_merge.h         |   102 +
 .../include/pstl/omp/parallel_reduce.h        |    80 +
 libstdc++-v3/include/pstl/omp/parallel_scan.h |   143 +
 .../pstl/omp/parallel_stable_partial_sort.h   |    37 +
 .../include/pstl/omp/parallel_stable_sort.h   |   167 +
 .../pstl/omp/parallel_transform_reduce.h      |   118 +
 .../pstl/omp/parallel_transform_scan.h        |    37 +
 libstdc++-v3/include/pstl/omp/util.h          |   196 +
 libstdc++-v3/include/pstl/onedpl_config.h     |   392 +
 libstdc++-v3/include/pstl/parallel_backend.h  |    62 +-
 .../include/pstl/parallel_backend_omp.h       |    65 +
 .../include/pstl/parallel_backend_serial.h    |   118 +-
 .../include/pstl/parallel_backend_tasq.h      |   171 +
 .../include/pstl/parallel_backend_tbb.h       |   439 +-
 .../include/pstl/parallel_backend_utils.h     |   297 +-
 libstdc++-v3/include/pstl/parallel_impl.h     |    67 +-
 libstdc++-v3/include/pstl/pstl_config.h       |   103 +-
 .../include/pstl/ranges/nanorange.hpp         | 19384 ++++++++++++++++
 .../include/pstl/ranges/nanorange_ext.h       |   274 +
 libstdc++-v3/include/pstl/ranges_defs.h       |    96 +
 libstdc++-v3/include/pstl/tuple_impl.h        |   854 +
 .../include/pstl/unseq_backend_simd.h         |   485 +-
 libstdc++-v3/include/pstl/utils.h             |  1155 +-
 libstdc++-v3/include/pstl/utils_ranges.h      |   838 +
 libstdc++-v3/include/pstl/zip_view_impl.h     |   583 +
 libstdc++-v3/include/std/algorithm            |    70 +
 libstdc++-v3/include/std/execution            |     2 +-
 libstdc++-v3/include/std/memory               |    16 +
 libstdc++-v3/include/std/numeric              |    10 +
 .../testsuite/25_algorithms/pstl/110512.cc    |     3 +-
 .../pstl/alg_modifying_operations/replace.cc  |     2 +-
 libstdc++-v3/testsuite/util/pstl/test_utils.h |     7 +-
 65 files changed, 36669 insertions(+), 3783 deletions(-)
 create mode 100644 libstdc++-v3/include/pstl/algorithm_ranges_impl.h
 create mode 100644 libstdc++-v3/include/pstl/functional_impl.h
 create mode 100644 libstdc++-v3/include/pstl/glue_algorithm_ranges_defs.h
 create mode 100644 libstdc++-v3/include/pstl/glue_algorithm_ranges_impl.h
 create mode 100644 libstdc++-v3/include/pstl/glue_memory_ranges_impl.h
 create mode 100644 libstdc++-v3/include/pstl/glue_numeric_ranges_defs.h
 create mode 100644 libstdc++-v3/include/pstl/glue_numeric_ranges_impl.h
 create mode 100644 libstdc++-v3/include/pstl/histogram_binhash_utils.h
 create mode 100644 libstdc++-v3/include/pstl/histogram_extension_defs.h
 create mode 100644 libstdc++-v3/include/pstl/histogram_impl.h
 create mode 100644 libstdc++-v3/include/pstl/iterator_defs.h
 create mode 100644 libstdc++-v3/include/pstl/iterator_impl.h
 create mode 100644 libstdc++-v3/include/pstl/memory_fwd.h
 create mode 100644 libstdc++-v3/include/pstl/memory_ranges_impl.h
 create mode 100644 libstdc++-v3/include/pstl/omp/parallel_for.h
 create mode 100644 libstdc++-v3/include/pstl/omp/parallel_for_each.h
 create mode 100644 libstdc++-v3/include/pstl/omp/parallel_invoke.h
 create mode 100644 libstdc++-v3/include/pstl/omp/parallel_merge.h
 create mode 100644 libstdc++-v3/include/pstl/omp/parallel_reduce.h
 create mode 100644 libstdc++-v3/include/pstl/omp/parallel_scan.h
 create mode 100644 libstdc++-v3/include/pstl/omp/parallel_stable_partial_sort.h
 create mode 100644 libstdc++-v3/include/pstl/omp/parallel_stable_sort.h
 create mode 100644 libstdc++-v3/include/pstl/omp/parallel_transform_reduce.h
 create mode 100644 libstdc++-v3/include/pstl/omp/parallel_transform_scan.h
 create mode 100644 libstdc++-v3/include/pstl/omp/util.h
 create mode 100644 libstdc++-v3/include/pstl/onedpl_config.h
 create mode 100644 libstdc++-v3/include/pstl/parallel_backend_omp.h
 create mode 100644 libstdc++-v3/include/pstl/parallel_backend_tasq.h
 create mode 100644 libstdc++-v3/include/pstl/ranges/nanorange.hpp
 create mode 100644 libstdc++-v3/include/pstl/ranges/nanorange_ext.h
 create mode 100644 libstdc++-v3/include/pstl/ranges_defs.h
 create mode 100644 libstdc++-v3/include/pstl/tuple_impl.h
 create mode 100644 libstdc++-v3/include/pstl/utils_ranges.h
 create mode 100644 libstdc++-v3/include/pstl/zip_view_impl.h

diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 3c30aa21d6b5..f82ebff6cc4f 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -343,26 +343,67 @@ pstl_builddir = ./pstl
 pstl_headers = \
 	${pstl_srcdir}/algorithm_fwd.h \
 	${pstl_srcdir}/algorithm_impl.h \
+	${pstl_srcdir}/algorithm_ranges_impl.h \
 	${pstl_srcdir}/execution_defs.h \
 	${pstl_srcdir}/execution_impl.h \
+	${pstl_srcdir}/functional_impl.h \
 	${pstl_srcdir}/glue_algorithm_defs.h \
 	${pstl_srcdir}/glue_algorithm_impl.h \
+	${pstl_srcdir}/glue_algorithm_ranges_defs.h \
+	${pstl_srcdir}/glue_algorithm_ranges_impl.h \
 	${pstl_srcdir}/glue_execution_defs.h \
 	${pstl_srcdir}/glue_memory_defs.h \
 	${pstl_srcdir}/glue_memory_impl.h \
+	${pstl_srcdir}/glue_memory_ranges_impl.h \
 	${pstl_srcdir}/glue_numeric_defs.h \
+	${pstl_srcdir}/glue_numeric_ranges_impl.h \
+	${pstl_srcdir}/glue_numeric_ranges_defs.h \
 	${pstl_srcdir}/glue_numeric_impl.h \
+	${pstl_srcdir}/histogram_binhash_utils.h \
+	${pstl_srcdir}/histogram_extension_defs.h \
+	${pstl_srcdir}/histogram_impl.h \
+	${pstl_srcdir}/iterator_defs.h \
+	${pstl_srcdir}/iterator_impl.h \
+	${pstl_srcdir}/memory_fwd.h \
 	${pstl_srcdir}/memory_impl.h \
 	${pstl_srcdir}/numeric_fwd.h \
 	${pstl_srcdir}/numeric_impl.h \
+	${pstl_srcdir}/onedpl_config.h \
 	${pstl_srcdir}/parallel_backend.h \
-	${pstl_srcdir}/parallel_backend_tbb.h \
+	${pstl_srcdir}/parallel_backend_omp.h \
 	${pstl_srcdir}/parallel_backend_serial.h \
+	${pstl_srcdir}/parallel_backend_tasq.h \
+	${pstl_srcdir}/parallel_backend_tbb.h \
 	${pstl_srcdir}/parallel_backend_utils.h \
 	${pstl_srcdir}/parallel_impl.h \
 	${pstl_srcdir}/pstl_config.h \
+	${pstl_srcdir}/ranges_defs.h \
+	${pstl_srcdir}/tuple_impl.h \
 	${pstl_srcdir}/unseq_backend_simd.h \
-	${pstl_srcdir}/utils.h
+	${pstl_srcdir}/utils.h \
+	${pstl_srcdir}/utils_ranges.h \
+	${pstl_srcdir}/zip_view_impl.h
+
+pstl_omp_srcdir = ${glibcxx_srcdir}/include/pstl/omp
+pstl_omp_builddir = ./pstl/omp
+pstl_omp_headers = \
+	${pstl_omp_srcdir}/parallel_for.h \
+	${pstl_omp_srcdir}/parallel_for_each.h \
+	${pstl_omp_srcdir}/parallel_invoke.h \
+	${pstl_omp_srcdir}/parallel_merge.h \
+	${pstl_omp_srcdir}/parallel_reduce.h \
+	${pstl_omp_srcdir}/parallel_scan.h \
+	${pstl_omp_srcdir}/parallel_stable_partial_sort.h \
+	${pstl_omp_srcdir}/parallel_stable_sort.h \
+	${pstl_omp_srcdir}/parallel_transform_reduce.h \
+	${pstl_omp_srcdir}/parallel_transform_scan.h \
+	${pstl_omp_srcdir}/util.h
+
+pstl_ranges_srcdir = ${glibcxx_srcdir}/include/pstl/ranges
+pstl_ranges_builddir = ./pstl/ranges
+pstl_ranges_headers = \
+	${pstl_ranges_srcdir}/nanorange.hpp \
+	${pstl_ranges_srcdir}/nanorange_ext.h
 
 backward_srcdir = ${glibcxx_srcdir}/include/backward
 backward_builddir = ./backward
@@ -1160,7 +1201,8 @@ endif
 # List of all timestamp files.  By keeping only one copy of this list, both
 # CLEANFILES and all-local are kept up-to-date.
 allstamped = \
-	stamp-std stamp-bits stamp-bits-sup stamp-pstl stamp-c_base stamp-c_compatibility \
+	stamp-std stamp-bits stamp-bits-sup stamp-pstl stamp-pstl-omp \
+	stamp-pstl-ranges stamp-c_base stamp-c_compatibility \
 	stamp-backward stamp-ext stamp-pb stamp-tr1 stamp-tr2 stamp-decimal \
 	stamp-experimental stamp-experimental-bits stamp-debug stamp-parallel \
 	stamp-host
@@ -1200,6 +1242,16 @@ stamp-pstl: ${pstl_headers}
 	@-cd ${pstl_builddir} && $(LN_S) $? . 2>/dev/null
 	@$(STAMP) stamp-pstl
 
+stamp-pstl-omp: ${pstl_omp_headers}
+	@-mkdir -p ${pstl_omp_builddir}
+	@-cd ${pstl_omp_builddir} && $(LN_S) $? . 2>/dev/null
+	@$(STAMP) stamp-pstl-omp
+
+stamp-pstl-ranges: ${pstl_ranges_headers}
+	@-mkdir -p ${pstl_ranges_builddir}
+	@-cd ${pstl_ranges_builddir} && $(LN_S) $? . 2>/dev/null
+	@$(STAMP) stamp-pstl-ranges
+
 stamp-c_base: ${c_base_headers}
 	@-mkdir -p ${c_base_builddir}
 	@-cd ${c_base_builddir} && $(LN_S) $? . 2>/dev/null
@@ -1622,6 +1674,12 @@ if GLIBCXX_HOSTED
 	$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${pstl_builddir}
 	for file in ${pstl_headers}; do \
 	  $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${pstl_builddir}; done
+	$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${pstl_omp_builddir}
+	for file in ${pstl_omp_headers}; do \
+	  $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${pstl_omp_builddir}; done
+	$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${pstl_ranges_builddir}
+	for file in ${pstl_ranges_headers}; do \
+	  $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${pstl_ranges_builddir}; done
 endif GLIBCXX_HOSTED
 
 # By adding these files here, automake will remove them for 'make clean'
diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
index 961afd8acbeb..2148d748b6db 100644
--- a/libstdc++-v3/include/Makefile.in
+++ b/libstdc++-v3/include/Makefile.in
@@ -700,26 +700,67 @@ pstl_builddir = ./pstl
 pstl_headers = \
 	${pstl_srcdir}/algorithm_fwd.h \
 	${pstl_srcdir}/algorithm_impl.h \
+	${pstl_srcdir}/algorithm_ranges_impl.h \
 	${pstl_srcdir}/execution_defs.h \
 	${pstl_srcdir}/execution_impl.h \
+	${pstl_srcdir}/functional_impl.h \
 	${pstl_srcdir}/glue_algorithm_defs.h \
 	${pstl_srcdir}/glue_algorithm_impl.h \
+	${pstl_srcdir}/glue_algorithm_ranges_defs.h \
+	${pstl_srcdir}/glue_algorithm_ranges_impl.h \
 	${pstl_srcdir}/glue_execution_defs.h \
 	${pstl_srcdir}/glue_memory_defs.h \
 	${pstl_srcdir}/glue_memory_impl.h \
+	${pstl_srcdir}/glue_memory_ranges_impl.h \
 	${pstl_srcdir}/glue_numeric_defs.h \
+	${pstl_srcdir}/glue_numeric_ranges_impl.h \
+	${pstl_srcdir}/glue_numeric_ranges_defs.h \
 	${pstl_srcdir}/glue_numeric_impl.h \
+	${pstl_srcdir}/histogram_binhash_utils.h \
+	${pstl_srcdir}/histogram_extension_defs.h \
+	${pstl_srcdir}/histogram_impl.h \
+	${pstl_srcdir}/iterator_defs.h \
+	${pstl_srcdir}/iterator_impl.h \
+	${pstl_srcdir}/memory_fwd.h \
 	${pstl_srcdir}/memory_impl.h \
 	${pstl_srcdir}/numeric_fwd.h \
 	${pstl_srcdir}/numeric_impl.h \
+	${pstl_srcdir}/onedpl_config.h \
 	${pstl_srcdir}/parallel_backend.h \
-	${pstl_srcdir}/parallel_backend_tbb.h \
+	${pstl_srcdir}/parallel_backend_omp.h \
 	${pstl_srcdir}/parallel_backend_serial.h \
+	${pstl_srcdir}/parallel_backend_tasq.h \
+	${pstl_srcdir}/parallel_backend_tbb.h \
 	${pstl_srcdir}/parallel_backend_utils.h \
 	${pstl_srcdir}/parallel_impl.h \
 	${pstl_srcdir}/pstl_config.h \
+	${pstl_srcdir}/ranges_defs.h \
+	${pstl_srcdir}/tuple_impl.h \
 	${pstl_srcdir}/unseq_backend_simd.h \
-	${pstl_srcdir}/utils.h
+	${pstl_srcdir}/utils.h \
+	${pstl_srcdir}/utils_ranges.h \
+	${pstl_srcdir}/zip_view_impl.h
+
+pstl_omp_srcdir = ${glibcxx_srcdir}/include/pstl/omp
+pstl_omp_builddir = ./pstl/omp
+pstl_omp_headers = \
+	${pstl_omp_srcdir}/parallel_for.h \
+	${pstl_omp_srcdir}/parallel_for_each.h \
+	${pstl_omp_srcdir}/parallel_invoke.h \
+	${pstl_omp_srcdir}/parallel_merge.h \
+	${pstl_omp_srcdir}/parallel_reduce.h \
+	${pstl_omp_srcdir}/parallel_scan.h \
+	${pstl_omp_srcdir}/parallel_stable_partial_sort.h \
+	${pstl_omp_srcdir}/parallel_stable_sort.h \
+	${pstl_omp_srcdir}/parallel_transform_reduce.h \
+	${pstl_omp_srcdir}/parallel_transform_scan.h \
+	${pstl_omp_srcdir}/util.h
+
+pstl_ranges_srcdir = ${glibcxx_srcdir}/include/pstl/ranges
+pstl_ranges_builddir = ./pstl/ranges
+pstl_ranges_headers = \
+	${pstl_ranges_srcdir}/nanorange.hpp \
+	${pstl_ranges_srcdir}/nanorange_ext.h
 
 backward_srcdir = ${glibcxx_srcdir}/include/backward
 backward_builddir = ./backward
@@ -1491,7 +1532,8 @@ PCHFLAGS = -x c++-header -nostdinc++ $(CXXFLAGS) $(VTV_PCH_CXXFLAGS)
 # List of all timestamp files.  By keeping only one copy of this list, both
 # CLEANFILES and all-local are kept up-to-date.
 allstamped = \
-	stamp-std stamp-bits stamp-bits-sup stamp-pstl stamp-c_base stamp-c_compatibility \
+	stamp-std stamp-bits stamp-bits-sup stamp-pstl stamp-pstl-omp \
+	stamp-pstl-ranges stamp-c_base stamp-c_compatibility \
 	stamp-backward stamp-ext stamp-pb stamp-tr1 stamp-tr2 stamp-decimal \
 	stamp-experimental stamp-experimental-bits stamp-debug stamp-parallel \
 	stamp-host
@@ -1702,6 +1744,16 @@ stamp-pstl: ${pstl_headers}
 	@-cd ${pstl_builddir} && $(LN_S) $? . 2>/dev/null
 	@$(STAMP) stamp-pstl
 
+stamp-pstl-omp: ${pstl_omp_headers}
+	@-mkdir -p ${pstl_omp_builddir}
+	@-cd ${pstl_omp_builddir} && $(LN_S) $? . 2>/dev/null
+	@$(STAMP) stamp-pstl-omp
+
+stamp-pstl-ranges: ${pstl_ranges_headers}
+	@-mkdir -p ${pstl_ranges_builddir}
+	@-cd ${pstl_ranges_builddir} && $(LN_S) $? . 2>/dev/null
+	@$(STAMP) stamp-pstl-ranges
+
 stamp-c_base: ${c_base_headers}
 	@-mkdir -p ${c_base_builddir}
 	@-cd ${c_base_builddir} && $(LN_S) $? . 2>/dev/null
@@ -2097,6 +2149,12 @@ install-headers:
 @GLIBCXX_HOSTED_TRUE@	$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${pstl_builddir}
 @GLIBCXX_HOSTED_TRUE@	for file in ${pstl_headers}; do \
 @GLIBCXX_HOSTED_TRUE@	  $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${pstl_builddir}; done
+@GLIBCXX_HOSTED_TRUE@	$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${pstl_omp_builddir}
+@GLIBCXX_HOSTED_TRUE@	for file in ${pstl_omp_headers}; do \
+@GLIBCXX_HOSTED_TRUE@	  $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${pstl_omp_builddir}; done
+@GLIBCXX_HOSTED_TRUE@	$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${pstl_ranges_builddir}
+@GLIBCXX_HOSTED_TRUE@	for file in ${pstl_ranges_headers}; do \
+@GLIBCXX_HOSTED_TRUE@	  $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${pstl_ranges_builddir}; done
 
 # To remove directories.
 clean-local:
diff --git a/libstdc++-v3/include/pstl/algorithm_fwd.h b/libstdc++-v3/include/pstl/algorithm_fwd.h
index 1ba9555e2a01..17cefdf94137 100644
--- a/libstdc++-v3/include/pstl/algorithm_fwd.h
+++ b/libstdc++-v3/include/pstl/algorithm_fwd.h
@@ -1,20 +1,25 @@
 // -*- C++ -*-
-//===-- algorithm_fwd.h --------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_ALGORITHM_FWD_H
-#define _PSTL_ALGORITHM_FWD_H
+#ifndef _ONEDPL_ALGORITHM_FWD_H
+#define _ONEDPL_ALGORITHM_FWD_H
 
-#include <iterator>
-#include <type_traits>
 #include <utility>
+#include "iterator_defs.h"
 
-namespace __pstl
+namespace std::__onedpl
 {
 namespace __internal
 {
@@ -26,12 +31,12 @@ namespace __internal
 template <class _ForwardIterator, class _Pred>
 bool
 __brick_any_of(const _ForwardIterator, const _ForwardIterator, _Pred,
-               /*__is_vector=*/std::false_type) noexcept;
+               /*__is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator, class _Pred>
 bool
 __brick_any_of(const _RandomAccessIterator, const _RandomAccessIterator, _Pred,
-               /*__is_vector=*/std::true_type) noexcept;
+               /*__is_vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Pred>
 bool
@@ -49,57 +54,44 @@ __pattern_any_of(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIte
 
 template <class _ForwardIterator, class _Function>
 void __brick_walk1(_ForwardIterator, _ForwardIterator, _Function,
-                   /*vector=*/std::false_type) noexcept;
+                   /*vector=*/::std::false_type);
 
 template <class _RandomAccessIterator, class _Function>
 void __brick_walk1(_RandomAccessIterator, _RandomAccessIterator, _Function,
-                   /*vector=*/std::true_type) noexcept;
+                   /*vector=*/::std::true_type);
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Function>
 void
-__pattern_walk1(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Function) noexcept;
+__pattern_walk1(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Function);
+
+template <class _ExecutionPolicy, class _ForwardIterator, class _Function>
+void
+__pattern_walk1(__parallel_forward_tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Function);
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Function>
 void
 __pattern_walk1(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Function);
 
-template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Brick>
-void
-__pattern_walk_brick(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Brick) noexcept;
-
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Brick>
-void
-__pattern_walk_brick(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
-                     _Brick);
-
 //------------------------------------------------------------------------
 // walk1_n
 //------------------------------------------------------------------------
 
 template <class _ForwardIterator, class _Size, class _Function>
 _ForwardIterator __brick_walk1_n(_ForwardIterator, _Size, _Function,
-                                 /*_IsVectorTag=*/std::false_type);
+                                 /*_IsVectorTag=*/::std::false_type);
 
 template <class _RandomAccessIterator, class _DifferenceType, class _Function>
 _RandomAccessIterator __brick_walk1_n(_RandomAccessIterator, _DifferenceType, _Function,
-                                      /*vectorTag=*/std::true_type) noexcept;
+                                      /*vectorTag=*/::std::true_type);
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Function>
 _ForwardIterator
-__pattern_walk1_n(_Tag, _ExecutionPolicy&&, _ForwardIterator, _Size, _Function) noexcept;
+__pattern_walk1_n(_Tag, _ExecutionPolicy&&, _ForwardIterator, _Size, _Function);
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Size, class _Function>
 _RandomAccessIterator
 __pattern_walk1_n(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _Size, _Function);
 
-template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Brick>
-_ForwardIterator
-__pattern_walk_brick_n(_Tag, _ExecutionPolicy&&, _ForwardIterator, _Size, _Brick) noexcept;
-
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Size, class _Brick>
-_RandomAccessIterator
-__pattern_walk_brick_n(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _Size, _Brick);
-
 //------------------------------------------------------------------------
 // walk2 (pseudo)
 //
@@ -108,19 +100,19 @@ __pattern_walk_brick_n(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAcc
 
 template <class _ForwardIterator1, class _ForwardIterator2, class _Function>
 _ForwardIterator2 __brick_walk2(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _Function,
-                                /*vector=*/std::false_type) noexcept;
+                                /*vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _Function>
 _RandomAccessIterator2 __brick_walk2(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2, _Function,
-                                     /*vector=*/std::true_type) noexcept;
+                                     /*vector=*/::std::true_type) noexcept;
 
 template <class _ForwardIterator1, class _Size, class _ForwardIterator2, class _Function>
 _ForwardIterator2 __brick_walk2_n(_ForwardIterator1, _Size, _ForwardIterator2, _Function,
-                                  /*vector=*/std::false_type) noexcept;
+                                  /*vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator1, class _Size, class _RandomAccessIterator2, class _Function>
 _RandomAccessIterator2 __brick_walk2_n(_RandomAccessIterator1, _Size, _RandomAccessIterator2, _Function,
-                                       /*vector=*/std::true_type) noexcept;
+                                       /*vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Function>
 _ForwardIterator2
@@ -132,6 +124,11 @@ _RandomAccessIterator2
 __pattern_walk2(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
                 _RandomAccessIterator2, _Function);
 
+template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Function>
+_ForwardIterator2
+__pattern_walk2(__parallel_forward_tag, _ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2,
+                _Function);
+
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _Size, class _ForwardIterator2,
           class _Function>
 _ForwardIterator2
@@ -154,6 +151,11 @@ _RandomAccessIterator2
 __pattern_walk2_brick(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
                       _RandomAccessIterator2, _Brick);
 
+template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Brick>
+_ForwardIterator2
+__pattern_walk2_brick(__parallel_forward_tag, _ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1,
+                      _ForwardIterator2, _Brick);
+
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _Size, class _ForwardIterator2,
           class _Brick>
 _ForwardIterator2
@@ -173,12 +175,12 @@ __pattern_walk2_brick_n(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAc
 
 template <class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator3, class _Function>
 _ForwardIterator3 __brick_walk3(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator3, _Function,
-                                /*vector=*/std::false_type) noexcept;
+                                /*vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _RandomAccessIterator3, class _Function>
 _RandomAccessIterator3 __brick_walk3(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2,
                                      _RandomAccessIterator3, _Function,
-                                     /*vector=*/std::true_type) noexcept;
+                                     /*vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator3,
           class _Function>
@@ -192,36 +194,39 @@ _RandomAccessIterator3
 __pattern_walk3(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
                 _RandomAccessIterator2, _RandomAccessIterator3, _Function);
 
+template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator3,
+          class _Function>
+_ForwardIterator3
+__pattern_walk3(__parallel_forward_tag, _ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2,
+                _ForwardIterator3, _Function);
+
+//------------------------------------------------------------------------
+// transform_if
+//------------------------------------------------------------------------
+
+template <class _Tag, typename _ExecutionPolicy, typename _ForwardIterator1, typename _ForwardIterator2,
+          typename _Function>
+_ForwardIterator2
+__pattern_walk2_transform_if(_Tag, _ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2,
+                             _Function) noexcept;
+
+template <class _Tag, typename _ExecutionPolicy, typename _ForwardIterator1, typename _ForwardIterator2,
+          typename _ForwardIterator3, typename _Function>
+_ForwardIterator3
+__pattern_walk3_transform_if(_Tag, _ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2,
+                             _ForwardIterator3, _Function) noexcept;
+
 //------------------------------------------------------------------------
 // equal
 //------------------------------------------------------------------------
 
 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
 bool __brick_equal(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _BinaryPredicate,
-                   /* is_vector = */ std::false_type) noexcept;
+                   /* is_vector = */ ::std::false_type) noexcept;
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate>
 bool __brick_equal(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2, _BinaryPredicate,
-                   /* is_vector = */ std::true_type) noexcept;
-
-template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-bool
-__pattern_equal(_Tag, _ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2,
-                _BinaryPredicate) noexcept;
-
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
-          class _BinaryPredicate>
-bool
-__pattern_equal(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
-                _RandomAccessIterator2, _BinaryPredicate);
-
-template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-bool __brick_equal(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate,
-                   /* is_vector = */ std::false_type) noexcept;
-
-template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate>
-bool __brick_equal(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2, _RandomAccessIterator2,
-                   _BinaryPredicate, /* is_vector = */ std::true_type) noexcept;
+                   /* is_vector = */ ::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
 bool
@@ -234,17 +239,36 @@ bool
 __pattern_equal(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
                 _RandomAccessIterator2, _RandomAccessIterator2, _BinaryPredicate);
 
+template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
+bool __brick_equal(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate,
+                   /* is_vector = */ ::std::false_type) noexcept;
+
+template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate>
+bool __brick_equal(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2, _RandomAccessIterator2,
+                   _BinaryPredicate, /* is_vector = */ ::std::true_type) noexcept;
+
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
+bool
+__pattern_equal(_Tag, _ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2,
+                _BinaryPredicate) noexcept;
+
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
+          class _BinaryPredicate>
+bool
+__pattern_equal(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
+                _RandomAccessIterator2, _BinaryPredicate);
+
 //------------------------------------------------------------------------
 // find_if
 //------------------------------------------------------------------------
 
 template <class _ForwardIterator, class _Predicate>
 _ForwardIterator __brick_find_if(_ForwardIterator, _ForwardIterator, _Predicate,
-                                 /*is_vector=*/std::false_type) noexcept;
+                                 /*is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator, class _Predicate>
 _RandomAccessIterator __brick_find_if(_RandomAccessIterator, _RandomAccessIterator, _Predicate,
-                                      /*is_vector=*/std::true_type) noexcept;
+                                      /*is_vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
 _ForwardIterator
@@ -262,12 +286,12 @@ __pattern_find_if(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIt
 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
 _ForwardIterator1 __brick_find_end(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2,
                                    _BinaryPredicate,
-                                   /*__is_vector=*/std::false_type) noexcept;
+                                   /*__is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate>
 _RandomAccessIterator1 __brick_find_end(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2,
                                         _RandomAccessIterator2, _BinaryPredicate,
-                                        /*__is_vector=*/std::true_type) noexcept;
+                                        /*__is_vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
 _ForwardIterator1
@@ -278,7 +302,7 @@ template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1,
           class _BinaryPredicate>
 _RandomAccessIterator1
 __pattern_find_end(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
-                   _RandomAccessIterator2, _RandomAccessIterator2, _BinaryPredicate) noexcept;
+                   _RandomAccessIterator2, _RandomAccessIterator2, _BinaryPredicate);
 
 //------------------------------------------------------------------------
 // find_first_of
@@ -287,12 +311,12 @@ __pattern_find_end(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessI
 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
 _ForwardIterator1 __brick_find_first_of(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2,
                                         _BinaryPredicate,
-                                        /*__is_vector=*/std::false_type) noexcept;
+                                        /*__is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate>
 _RandomAccessIterator1 __brick_find_first_of(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2,
                                              _RandomAccessIterator2, _BinaryPredicate,
-                                             /*__is_vector=*/std::true_type) noexcept;
+                                             /*__is_vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
 _ForwardIterator1
@@ -303,7 +327,7 @@ template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1,
           class _BinaryPredicate>
 _RandomAccessIterator1
 __pattern_find_first_of(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
-                        _RandomAccessIterator2, _RandomAccessIterator2, _BinaryPredicate) noexcept;
+                        _RandomAccessIterator2, _RandomAccessIterator2, _BinaryPredicate);
 
 //------------------------------------------------------------------------
 // search
@@ -312,12 +336,12 @@ __pattern_find_first_of(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAc
 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
 _ForwardIterator1 __brick_search(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2,
                                  _BinaryPredicate,
-                                 /*vector=*/std::false_type) noexcept;
+                                 /*vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate>
 _RandomAccessIterator1 __brick_search(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2,
                                       _RandomAccessIterator2, _BinaryPredicate,
-                                      /*vector=*/std::true_type) noexcept;
+                                      /*vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
 _ForwardIterator1
@@ -328,7 +352,7 @@ template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1,
           class _BinaryPredicate>
 _RandomAccessIterator1
 __pattern_search(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
-                 _RandomAccessIterator2, _RandomAccessIterator2, _BinaryPredicate) noexcept;
+                 _RandomAccessIterator2, _RandomAccessIterator2, _BinaryPredicate);
 
 //------------------------------------------------------------------------
 // search_n
@@ -337,12 +361,12 @@ __pattern_search(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIte
 template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
 _ForwardIterator
 __brick_search_n(_ForwardIterator, _ForwardIterator, _Size, const _Tp&, _BinaryPredicate,
-                 /*vector=*/std::false_type) noexcept;
+                 /*vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator, class _Size, class _Tp, class _BinaryPredicate>
 _RandomAccessIterator
 __brick_search_n(_RandomAccessIterator, _RandomAccessIterator, _Size, const _Tp&, _BinaryPredicate,
-                 /*vector=*/std::true_type) noexcept;
+                 /*vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
 _ForwardIterator
@@ -353,54 +377,33 @@ template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator,
           class _BinaryPredicate>
 _RandomAccessIterator
 __pattern_search_n(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Size,
-                   const _Tp&, _BinaryPredicate) noexcept;
+                   const _Tp&, _BinaryPredicate);
 
 //------------------------------------------------------------------------
 // copy_n
 //------------------------------------------------------------------------
 
-template <class _ForwardIterator, class _Size, class _OutputIterator>
-_OutputIterator __brick_copy_n(_ForwardIterator, _Size, _OutputIterator,
-                               /*vector=*/std::false_type) noexcept;
+template <class _Tag, typename = void>
+struct __brick_copy_n;
 
-template <class _RandomAccessIterator, class _Size, class _OutputIterator>
-_OutputIterator __brick_copy_n(_RandomAccessIterator, _Size, _OutputIterator,
-                               /*vector=*/std::true_type) noexcept;
+template <class _Tag, typename = void>
+struct __brick_copy;
 
-//------------------------------------------------------------------------
-// copy
-//------------------------------------------------------------------------
-
-template <class _ForwardIterator, class _OutputIterator>
-_OutputIterator __brick_copy(_ForwardIterator, _ForwardIterator, _OutputIterator,
-                             /*vector=*/std::false_type) noexcept;
-
-template <class _RandomAccessIterator, class _OutputIterator>
-_OutputIterator __brick_copy(_RandomAccessIterator, _RandomAccessIterator, _OutputIterator,
-                             /*vector=*/std::true_type) noexcept;
-
-//------------------------------------------------------------------------
-// move
-//------------------------------------------------------------------------
-
-template <class _ForwardIterator, class _OutputIterator>
-_OutputIterator __brick_move(_ForwardIterator, _ForwardIterator, _OutputIterator,
-                             /*vector=*/std::false_type) noexcept;
-
-template <class _RandomAccessIterator, class _OutputIterator>
-_OutputIterator __brick_move(_RandomAccessIterator, _RandomAccessIterator, _OutputIterator,
-                             /*vector=*/std::true_type) noexcept;
+template <class _Tag, typename = void>
+struct __brick_move;
 
 //------------------------------------------------------------------------
 // swap_ranges
 //------------------------------------------------------------------------
 template <class _ForwardIterator, class _OutputIterator>
-_OutputIterator __brick_swap_ranges(_ForwardIterator, _ForwardIterator, _OutputIterator,
-                                    /*vector=*/std::false_type) noexcept;
+_OutputIterator
+__brick_swap_ranges(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result,
+                    /*vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator, class _OutputIterator>
-_OutputIterator __brick_swap_ranges(_RandomAccessIterator, _RandomAccessIterator, _OutputIterator,
-                                    /*vector=*/std::true_type) noexcept;
+_OutputIterator
+__brick_swap_ranges(_RandomAccessIterator __first, _RandomAccessIterator __last, _OutputIterator __result,
+                    /*vector=*/::std::true_type) noexcept;
 
 //------------------------------------------------------------------------
 // copy_if
@@ -414,66 +417,87 @@ template <class _RandomAccessIterator, class _OutputIterator, class _UnaryPredic
 _OutputIterator __brick_copy_if(_RandomAccessIterator, _RandomAccessIterator, _OutputIterator, _UnaryPredicate,
                                 /*vector=*/std::true_type) noexcept;
 
-template <class _DifferenceType, class _ForwardIterator, class _UnaryPredicate>
-std::pair<_DifferenceType, _DifferenceType>
-__brick_calc_mask_1(_ForwardIterator, _ForwardIterator, bool* __restrict, _UnaryPredicate,
-                    /*vector=*/std::false_type) noexcept;
-template <class _DifferenceType, class _RandomAccessIterator, class _UnaryPredicate>
-std::pair<_DifferenceType, _DifferenceType>
-__brick_calc_mask_1(_RandomAccessIterator, _RandomAccessIterator, bool* __restrict, _UnaryPredicate,
-                    /*vector=*/std::true_type) noexcept;
+template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _UnaryPredicate>
+std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
+__brick_bounded_copy_if(_RandomAccessIterator1, typename std::iterator_traits<_RandomAccessIterator1>::difference_type,
+                        _RandomAccessIterator2, typename std::iterator_traits<_RandomAccessIterator2>::difference_type,
+                        _UnaryPredicate, /*vector=*/std::true_type) noexcept;
 
-template <class _ForwardIterator, class _OutputIterator>
-void
-__brick_copy_by_mask(_ForwardIterator, _ForwardIterator, _OutputIterator, bool*,
+template <class _RandomAccessIterator, class _DifferenceType, class _IndexPredicate>
+std::pair<_DifferenceType, _DifferenceType>
+__brick_compute_mask(_RandomAccessIterator, _DifferenceType, _IndexPredicate, bool*,
                      /*vector=*/std::false_type) noexcept;
 
-template <class _RandomAccessIterator, class _OutputIterator>
-void
-__brick_copy_by_mask(_RandomAccessIterator, _RandomAccessIterator, _OutputIterator, bool* __restrict,
+template <class _RandomAccessIterator, class _DifferenceType, class _IndexPredicate>
+std::pair<_DifferenceType, _DifferenceType>
+__brick_compute_mask(_RandomAccessIterator, _DifferenceType, _IndexPredicate, bool*,
+                     /*vector=*/std::true_type) noexcept;
+
+template <bool, class _RandomAccessIterator1, class _RandomAccessIterator2, class _Bound, class _Assigner>
+_Bound
+__brick_copy_by_mask(_RandomAccessIterator1, _Bound, _RandomAccessIterator2, _Bound, bool*, _Assigner,
+                     /*vector=*/std::false_type) noexcept;
+
+template <bool, class _RandomAccessIterator1, class _RandomAccessIterator2, class _Bound, class _Assigner>
+_Bound
+__brick_copy_by_mask(_RandomAccessIterator1, _Bound, _RandomAccessIterator2, _Bound, bool*, _Assigner,
                      /*vector=*/std::true_type) noexcept;
 
 template <class _ForwardIterator, class _OutputIterator1, class _OutputIterator2>
 void
 __brick_partition_by_mask(_ForwardIterator, _ForwardIterator, _OutputIterator1, _OutputIterator2, bool*,
-                          /*vector=*/std::false_type) noexcept;
+                          /*vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator, class _OutputIterator1, class _OutputIterator2>
 void
 __brick_partition_by_mask(_RandomAccessIterator, _RandomAccessIterator, _OutputIterator1, _OutputIterator2, bool*,
-                          /*vector=*/std::true_type) noexcept;
+                          /*vector=*/::std::true_type) noexcept;
+
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _DifferenceType,
+          class _RandomAccessIterator2, class _IndexPredicate>
+std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
+__parallel_selective_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _DifferenceType,
+                          _RandomAccessIterator2, _DifferenceType, _IndexPredicate);
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator, class _UnaryPredicate>
 _OutputIterator
 __pattern_copy_if(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _OutputIterator,
                   _UnaryPredicate) noexcept;
 
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator,
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
           class _UnaryPredicate>
-_OutputIterator
-__pattern_copy_if(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
-                  _OutputIterator, _UnaryPredicate);
+_RandomAccessIterator2
+__pattern_copy_if(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
+                  _RandomAccessIterator2, _UnaryPredicate);
+
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
+          class _UnaryPredicate>
+std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
+__pattern_bounded_copy_if(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1,
+                          typename std::iterator_traits<_RandomAccessIterator1>::difference_type,
+                          _RandomAccessIterator2,
+                          typename std::iterator_traits<_RandomAccessIterator2>::difference_type, _UnaryPredicate);
 
 //------------------------------------------------------------------------
 // count
 //------------------------------------------------------------------------
 
 template <class _RandomAccessIterator, class _Predicate>
-typename std::iterator_traits<_RandomAccessIterator>::difference_type
+typename ::std::iterator_traits<_RandomAccessIterator>::difference_type
     __brick_count(_RandomAccessIterator, _RandomAccessIterator, _Predicate,
-                  /* is_vector = */ std::true_type) noexcept;
+                  /* is_vector = */ ::std::true_type) noexcept;
 
 template <class _ForwardIterator, class _Predicate>
-typename std::iterator_traits<_ForwardIterator>::difference_type
+typename ::std::iterator_traits<_ForwardIterator>::difference_type
     __brick_count(_ForwardIterator, _ForwardIterator, _Predicate,
-                  /* is_vector = */ std::false_type) noexcept;
+                  /* is_vector = */ ::std::false_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
-typename std::iterator_traits<_ForwardIterator>::difference_type
+typename ::std::iterator_traits<_ForwardIterator>::difference_type
 __pattern_count(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Predicate) noexcept;
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Predicate>
-typename std::iterator_traits<_RandomAccessIterator>::difference_type
+typename ::std::iterator_traits<_RandomAccessIterator>::difference_type
 __pattern_count(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
                 _Predicate);
 
@@ -483,11 +507,11 @@ __pattern_count(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIter
 
 template <class _ForwardIterator, class _BinaryPredicate>
 _ForwardIterator __brick_unique(_ForwardIterator, _ForwardIterator, _BinaryPredicate,
-                                /*is_vector=*/std::false_type) noexcept;
+                                /*is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator, class _BinaryPredicate>
 _RandomAccessIterator __brick_unique(_RandomAccessIterator, _RandomAccessIterator, _BinaryPredicate,
-                                     /*is_vector=*/std::true_type) noexcept;
+                                     /*is_vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _BinaryPredicate>
 _ForwardIterator
@@ -496,7 +520,7 @@ __pattern_unique(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _BinaryPredicate>
 _RandomAccessIterator
 __pattern_unique(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
-                 _BinaryPredicate) noexcept;
+                 _BinaryPredicate);
 
 //------------------------------------------------------------------------
 // unique_copy
@@ -504,32 +528,35 @@ __pattern_unique(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIte
 
 template <class _ForwardIterator, class _OutputIterator, class _BinaryPredicate>
 _OutputIterator __brick_unique_copy(_ForwardIterator, _ForwardIterator, _OutputIterator, _BinaryPredicate,
-                                   /*vector=*/std::false_type) noexcept;
+                                    /*vector=*/std::false_type) noexcept;
 
-template <class _RandomAccessIterator, class _OutputIterator, class _BinaryPredicate>
-_OutputIterator __brick_unique_copy(_RandomAccessIterator, _RandomAccessIterator, _OutputIterator, _BinaryPredicate,
-                                    /*vector=*/std::true_type) noexcept;
+template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate>
+_RandomAccessIterator2 __brick_unique_copy(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2,
+                                           _BinaryPredicate, /*vector=*/std::true_type) noexcept;
+
+template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate>
+std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
+__brick_bounded_unique_copy(
+    _RandomAccessIterator1, typename std::iterator_traits<_RandomAccessIterator1>::difference_type,
+    _RandomAccessIterator2, typename std::iterator_traits<_RandomAccessIterator2>::difference_type,
+    _BinaryPredicate __pred, /*vector=*/std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator, class _BinaryPredicate>
 _OutputIterator
 __pattern_unique_copy(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _OutputIterator,
                       _BinaryPredicate) noexcept;
 
-template <class _ExecutionPolicy, class _DifferenceType, class _RandomAccessIterator, class _BinaryPredicate>
-_DifferenceType
-__brick_calc_mask_2(_RandomAccessIterator, _RandomAccessIterator, bool* __restrict, _BinaryPredicate,
-                    /*vector=*/std::false_type) noexcept;
-
-template <class _DifferenceType, class _RandomAccessIterator, class _BinaryPredicate>
-_DifferenceType
-__brick_calc_mask_2(_RandomAccessIterator, _RandomAccessIterator, bool* __restrict, _BinaryPredicate,
-                    /*vector=*/std::true_type) noexcept;
-
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator,
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
           class _BinaryPredicate>
-_OutputIterator
-__pattern_unique_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
-                      _OutputIterator, _BinaryPredicate);
+_RandomAccessIterator2
+__pattern_unique_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
+                      _RandomAccessIterator2, _BinaryPredicate);
+
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _DifferenceType,
+          class _RandomAccessIterator2, class _BinaryPredicate>
+std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
+__pattern_bounded_unique_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _DifferenceType,
+                              _RandomAccessIterator2, _DifferenceType, _BinaryPredicate);
 
 //------------------------------------------------------------------------
 // reverse
@@ -537,19 +564,19 @@ __pattern_unique_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAcce
 
 template <class _BidirectionalIterator>
 void __brick_reverse(_BidirectionalIterator, _BidirectionalIterator,
-                     /*__is_vector=*/std::false_type) noexcept;
+                     /*__is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator>
 void __brick_reverse(_RandomAccessIterator, _RandomAccessIterator,
-                     /*__is_vector=*/std::true_type) noexcept;
+                     /*__is_vector=*/::std::true_type) noexcept;
 
 template <class _BidirectionalIterator>
 void __brick_reverse(_BidirectionalIterator, _BidirectionalIterator, _BidirectionalIterator,
-                     /*is_vector=*/std::false_type) noexcept;
+                     /*is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator>
 void __brick_reverse(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator,
-                     /*is_vector=*/std::true_type) noexcept;
+                     /*is_vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _BidirectionalIterator>
 void
@@ -565,21 +592,21 @@ __pattern_reverse(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIt
 
 template <class _BidirectionalIterator, class _OutputIterator>
 _OutputIterator __brick_reverse_copy(_BidirectionalIterator, _BidirectionalIterator, _OutputIterator,
-                                     /*is_vector=*/std::false_type) noexcept;
+                                     /*is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator, class _OutputIterator>
 _OutputIterator __brick_reverse_copy(_RandomAccessIterator, _RandomAccessIterator, _OutputIterator,
-                                     /*is_vector=*/std::true_type) noexcept;
+                                     /*is_vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _BidirectionalIterator, class _OutputIterator>
 _OutputIterator
 __pattern_reverse_copy(_Tag, _ExecutionPolicy&&, _BidirectionalIterator, _BidirectionalIterator,
                        _OutputIterator) noexcept;
 
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator>
-_OutputIterator
-__pattern_reverse_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
-                       _OutputIterator);
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2>
+_RandomAccessIterator2
+__pattern_reverse_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
+                       _RandomAccessIterator2);
 
 //------------------------------------------------------------------------
 // rotate
@@ -587,11 +614,11 @@ __pattern_reverse_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAcc
 
 template <class _ForwardIterator>
 _ForwardIterator __brick_rotate(_ForwardIterator, _ForwardIterator, _ForwardIterator,
-                                /*is_vector=*/std::false_type) noexcept;
+                                /*is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator>
 _RandomAccessIterator __brick_rotate(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator,
-                                     /*is_vector=*/std::true_type) noexcept;
+                                     /*is_vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator>
 _ForwardIterator
@@ -606,24 +633,23 @@ __pattern_rotate(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIte
 // rotate_copy
 //------------------------------------------------------------------------
 
-template <class _ForwardIterator, class _OutputIterator>
-_OutputIterator __brick_rotate_copy(_ForwardIterator, _ForwardIterator, _ForwardIterator, _OutputIterator,
-                                    /*__is_vector=*/std::false_type) noexcept;
+template <class _Tag, class _ForwardIterator, class _OutputIterator>
+_OutputIterator __brick_rotate_copy(_Tag, _ForwardIterator, _ForwardIterator, _ForwardIterator,
+                                    _OutputIterator) noexcept;
 
-template <class _RandomAccessIterator, class _OutputIterator>
-_OutputIterator __brick_rotate_copy(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator,
-                                    _OutputIterator,
-                                    /*__is_vector=*/std::true_type) noexcept;
+template <class _IsVector, class _RandomAccessIterator, class _OutputIterator>
+_OutputIterator __brick_rotate_copy(__parallel_tag<_IsVector>, _RandomAccessIterator, _RandomAccessIterator,
+                                    _RandomAccessIterator, _OutputIterator) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator>
 _OutputIterator
 __pattern_rotate_copy(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _ForwardIterator,
                       _OutputIterator) noexcept;
 
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator>
-_OutputIterator
-__pattern_rotate_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
-                      _RandomAccessIterator, _OutputIterator);
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2>
+_RandomAccessIterator2
+__pattern_rotate_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
+                      _RandomAccessIterator1, _RandomAccessIterator2);
 
 //------------------------------------------------------------------------
 // is_partitioned
@@ -631,11 +657,11 @@ __pattern_rotate_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAcce
 
 template <class _ForwardIterator, class _UnaryPredicate>
 bool __brick_is_partitioned(_ForwardIterator, _ForwardIterator, _UnaryPredicate,
-                            /*is_vector=*/std::false_type) noexcept;
+                            /*is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator, class _UnaryPredicate>
 bool __brick_is_partitioned(_RandomAccessIterator, _RandomAccessIterator, _UnaryPredicate,
-                            /*is_vector=*/std::true_type) noexcept;
+                            /*is_vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate>
 bool
@@ -652,11 +678,11 @@ __pattern_is_partitioned(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomA
 
 template <class _ForwardIterator, class _UnaryPredicate>
 _ForwardIterator __brick_partition(_ForwardIterator, _ForwardIterator, _UnaryPredicate,
-                                   /*is_vector=*/std::false_type) noexcept;
+                                   /*is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator, class _UnaryPredicate>
 _RandomAccessIterator __brick_partition(_RandomAccessIterator, _RandomAccessIterator, _UnaryPredicate,
-                                        /*is_vector=*/std::true_type) noexcept;
+                                        /*is_vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate>
 _ForwardIterator
@@ -673,11 +699,11 @@ __pattern_partition(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccess
 
 template <class _BidirectionalIterator, class _UnaryPredicate>
 _BidirectionalIterator __brick_stable_partition(_BidirectionalIterator, _BidirectionalIterator, _UnaryPredicate,
-                                                /*__is_vector=*/std::false_type) noexcept;
+                                                /*__is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator, class _UnaryPredicate>
 _RandomAccessIterator __brick_stable_partition(_RandomAccessIterator, _RandomAccessIterator, _UnaryPredicate,
-                                               /*__is_vector=*/std::true_type) noexcept;
+                                               /*__is_vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _BidirectionalIterator, class _UnaryPredicate>
 _BidirectionalIterator
@@ -687,61 +713,63 @@ __pattern_stable_partition(_Tag, _ExecutionPolicy&&, _BidirectionalIterator, _Bi
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _UnaryPredicate>
 _RandomAccessIterator
 __pattern_stable_partition(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
-                           _UnaryPredicate) noexcept;
+                           _UnaryPredicate);
 
 //------------------------------------------------------------------------
 // partition_copy
 //------------------------------------------------------------------------
 
 template <class _ForwardIterator, class _OutputIterator1, class _OutputIterator2, class _UnaryPredicate>
-std::pair<_OutputIterator1, _OutputIterator2>
+::std::pair<_OutputIterator1, _OutputIterator2>
     __brick_partition_copy(_ForwardIterator, _ForwardIterator, _OutputIterator1, _OutputIterator2, _UnaryPredicate,
-                           /*is_vector=*/std::false_type) noexcept;
+                           /*is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator, class _OutputIterator1, class _OutputIterator2, class _UnaryPredicate>
-std::pair<_OutputIterator1, _OutputIterator2> __brick_partition_copy(_RandomAccessIterator, _RandomAccessIterator,
-                                                                     _OutputIterator1, _OutputIterator2,
-                                                                     _UnaryPredicate,
-                                                                     /*is_vector=*/std::true_type) noexcept;
+::std::pair<_OutputIterator1, _OutputIterator2> __brick_partition_copy(_RandomAccessIterator, _RandomAccessIterator,
+                                                                       _OutputIterator1, _OutputIterator2,
+                                                                       _UnaryPredicate,
+                                                                       /*is_vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator1, class _OutputIterator2,
           class _UnaryPredicate>
-std::pair<_OutputIterator1, _OutputIterator2>
+::std::pair<_OutputIterator1, _OutputIterator2>
 __pattern_partition_copy(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _OutputIterator1,
                          _OutputIterator2, _UnaryPredicate) noexcept;
 
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator1,
-          class _OutputIterator2, class _UnaryPredicate>
-std::pair<_OutputIterator1, _OutputIterator2>
-__pattern_partition_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
-                         _OutputIterator1, _OutputIterator2, _UnaryPredicate);
-
-//------------------------------------------------------------------------
-// sort
-//------------------------------------------------------------------------
-
-template <class _Tag, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare, class _IsMoveConstructible>
-void
-__pattern_sort(_Tag, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare,
-               _IsMoveConstructible) noexcept;
-
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
-void
-__pattern_sort(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare,
-               /*is_move_constructible=*/std::true_type);
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
+          class _RandomAccessIterator3, class _UnaryPredicate>
+::std::pair<_RandomAccessIterator2, _RandomAccessIterator3>
+__pattern_partition_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
+                         _RandomAccessIterator2, _RandomAccessIterator3, _UnaryPredicate);
 
 //------------------------------------------------------------------------
 // stable_sort
 //------------------------------------------------------------------------
 
-template <class _Tag, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
+template <class _Tag, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare, class _LeafSort>
 void
-__pattern_stable_sort(_Tag, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare) noexcept;
+__pattern_sort(_Tag, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare, _LeafSort) noexcept;
 
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare, class _LeafSort>
 void
-__pattern_stable_sort(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
-                      _Compare);
+__pattern_sort(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare,
+               _LeafSort);
+
+//------------------------------------------------------------------------
+// sort_by_key
+//------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _RandomAccessIterator1, typename _RandomAccessIterator2,
+          typename _Compare, typename _LeafSort>
+void
+__pattern_sort_by_key(_Tag, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2,
+                      _Compare, _LeafSort) noexcept;
+
+template <typename _IsVector, typename _ExecutionPolicy, typename _RandomAccessIterator1,
+          typename _RandomAccessIterator2, typename _Compare, typename _LeafSort>
+void
+__pattern_sort_by_key(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
+                      _RandomAccessIterator2, _Compare, _LeafSort);
 
 //------------------------------------------------------------------------
 // partial_sort
@@ -761,11 +789,10 @@ __pattern_partial_sort(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAcc
 // partial_sort_copy
 //------------------------------------------------------------------------
 
-template <class _Tag, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
-          class _Compare>
-_RandomAccessIterator2
-__pattern_partial_sort_copy(_Tag, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
-                            _RandomAccessIterator2, _RandomAccessIterator2, _Compare) noexcept;
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _RandomAccessIterator, class _Compare>
+_RandomAccessIterator
+__pattern_partial_sort_copy(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _RandomAccessIterator,
+                            _RandomAccessIterator, _Compare) noexcept;
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
           class _Compare>
@@ -780,25 +807,27 @@ __pattern_partial_sort_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _Rand
 template <class _RandomAccessIterator, class _BinaryPredicate>
 _RandomAccessIterator
 __brick_adjacent_find(_RandomAccessIterator, _RandomAccessIterator, _BinaryPredicate,
-                      /* IsVector = */ std::true_type, bool) noexcept;
+                      /* IsVector = */ ::std::true_type, bool) noexcept;
 
 template <class _ForwardIterator, class _BinaryPredicate>
 _ForwardIterator
 __brick_adjacent_find(_ForwardIterator, _ForwardIterator, _BinaryPredicate,
-                      /* IsVector = */ std::false_type, bool) noexcept;
+                      /* IsVector = */ ::std::false_type, bool) noexcept;
 
-template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _BinaryPredicate>
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _BinaryPredicate, class _Semantic>
 _ForwardIterator
-__pattern_adjacent_find(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _BinaryPredicate, bool) noexcept;
+__pattern_adjacent_find(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _BinaryPredicate,
+                        _Semantic) noexcept;
 
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _BinaryPredicate>
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _BinaryPredicate, class _Semantic>
 _RandomAccessIterator
 __pattern_adjacent_find(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
-                        _BinaryPredicate, bool);
+                        _BinaryPredicate, _Semantic);
 
 //------------------------------------------------------------------------
 // nth_element
 //------------------------------------------------------------------------
+
 template <class _Tag, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
 void
 __pattern_nth_element(_Tag, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator,
@@ -807,20 +836,13 @@ __pattern_nth_element(_Tag, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAc
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
 void
 __pattern_nth_element(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
-                      _RandomAccessIterator, _Compare) noexcept;
+                      _RandomAccessIterator, _Compare);
 
 //------------------------------------------------------------------------
 // fill, fill_n
 //------------------------------------------------------------------------
-template <class _RandomAccessIterator, class _Tp>
-void
-__brick_fill(_RandomAccessIterator, _RandomAccessIterator, const _Tp&,
-             /* __is_vector = */ std::true_type) noexcept;
-
-template <class _ForwardIterator, class _Tp>
-void
-__brick_fill(_ForwardIterator, _ForwardIterator, const _Tp&,
-             /* __is_vector = */ std::false_type) noexcept;
+template <class _Tag, typename _Tp, typename = void>
+struct __brick_fill;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Tp>
 void
@@ -830,15 +852,8 @@ template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator,
 _RandomAccessIterator
 __pattern_fill(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, const _Tp&);
 
-template <class _RandomAccessIterator, class _Size, class _Tp>
-_RandomAccessIterator
-__brick_fill_n(_RandomAccessIterator, _Size, const _Tp&,
-               /* __is_vector = */ std::true_type) noexcept;
-
-template <class _OutputIterator, class _Size, class _Tp>
-_OutputIterator
-__brick_fill_n(_OutputIterator, _Size, const _Tp&,
-               /* __is_vector = */ std::false_type) noexcept;
+template <class _Tag, typename _Tp, typename = void>
+struct __brick_fill_n;
 
 template <class _Tag, class _ExecutionPolicy, class _OutputIterator, class _Size, class _Tp>
 _OutputIterator
@@ -854,11 +869,11 @@ __pattern_fill_n(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIte
 
 template <class _RandomAccessIterator, class _Generator>
 void __brick_generate(_RandomAccessIterator, _RandomAccessIterator, _Generator,
-                      /* is_vector = */ std::true_type) noexcept;
+                      /* is_vector = */ ::std::true_type) noexcept;
 
 template <class _ForwardIterator, class _Generator>
 void __brick_generate(_ForwardIterator, _ForwardIterator, _Generator,
-                      /* is_vector = */ std::false_type) noexcept;
+                      /* is_vector = */ ::std::false_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Generator>
 void
@@ -869,13 +884,13 @@ _RandomAccessIterator
 __pattern_generate(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
                    _Generator);
 
-template <class _RandomAccessIterator, class _Size, class _Generator>
-_RandomAccessIterator __brick_generate_n(_RandomAccessIterator, _Size, _Generator,
-                                         /* is_vector = */ std::true_type) noexcept;
+template <class _RandomAccessIterator, class Size, class _Generator>
+_RandomAccessIterator __brick_generate_n(_RandomAccessIterator, Size, _Generator,
+                                         /* is_vector = */ ::std::true_type) noexcept;
 
-template <class _OutputIterator, class _Size, class _Generator>
-_OutputIterator __brick_generate_n(_OutputIterator, _Size, _Generator,
-                                  /* is_vector = */ std::false_type) noexcept;
+template <class OutputIterator, class Size, class _Generator>
+OutputIterator __brick_generate_n(OutputIterator, Size, _Generator,
+                                  /* is_vector = */ ::std::false_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _OutputIterator, class _Size, class _Generator>
 _OutputIterator
@@ -890,11 +905,11 @@ __pattern_generate_n(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAcces
 //------------------------------------------------------------------------
 template <class _ForwardIterator, class _UnaryPredicate>
 _ForwardIterator __brick_remove_if(_ForwardIterator, _ForwardIterator, _UnaryPredicate,
-                                   /* __is_vector = */ std::false_type) noexcept;
+                                   /* __is_vector = */ ::std::false_type) noexcept;
 
 template <class _RandomAccessIterator, class _UnaryPredicate>
 _RandomAccessIterator __brick_remove_if(_RandomAccessIterator, _RandomAccessIterator, _UnaryPredicate,
-                                        /* __is_vector = */ std::true_type) noexcept;
+                                        /* __is_vector = */ ::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate>
 _ForwardIterator
@@ -903,7 +918,7 @@ __pattern_remove_if(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _UnaryPredicate>
 _RandomAccessIterator
 __pattern_remove_if(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
-                    _UnaryPredicate) noexcept;
+                    _UnaryPredicate);
 
 //------------------------------------------------------------------------
 // merge
@@ -912,12 +927,12 @@ __pattern_remove_if(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccess
 template <class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator, class _Compare>
 _OutputIterator __brick_merge(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2,
                               _OutputIterator, _Compare,
-                              /* __is_vector = */ std::false_type) noexcept;
+                              /* __is_vector = */ ::std::false_type) noexcept;
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _OutputIterator, class _Compare>
 _OutputIterator __brick_merge(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2,
                               _RandomAccessIterator2, _OutputIterator, _Compare,
-                              /* __is_vector = */ std::true_type) noexcept;
+                              /* __is_vector = */ ::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator,
           class _Compare>
@@ -926,10 +941,10 @@ __pattern_merge(_Tag, _ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1,
                 _OutputIterator, _Compare) noexcept;
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
-          class _OutputIterator, class _Compare>
-_OutputIterator
+          class _RandomAccessIterator3, class _Compare>
+_RandomAccessIterator3
 __pattern_merge(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
-                _RandomAccessIterator2, _RandomAccessIterator2, _OutputIterator, _Compare);
+                _RandomAccessIterator2, _RandomAccessIterator2, _RandomAccessIterator3, _Compare);
 
 //------------------------------------------------------------------------
 // inplace_merge
@@ -937,11 +952,11 @@ __pattern_merge(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIter
 
 template <class _BidirectionalIterator, class _Compare>
 void __brick_inplace_merge(_BidirectionalIterator, _BidirectionalIterator, _BidirectionalIterator, _Compare,
-                           /* __is_vector = */ std::false_type) noexcept;
+                           /* __is_vector = */ ::std::false_type) noexcept;
 
 template <class _RandomAccessIterator, class _Compare>
 void __brick_inplace_merge(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare,
-                           /* __is_vector = */ std::true_type) noexcept;
+                           /* __is_vector = */ ::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _BidirectionalIterator, class _Compare>
 void
@@ -975,12 +990,12 @@ __pattern_includes(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessI
 template <class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator, class _Compare>
 _OutputIterator __brick_set_union(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2,
                                   _OutputIterator, _Compare,
-                                  /*__is_vector=*/std::false_type) noexcept;
+                                  /*__is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _OutputIterator, class _Compare>
 _OutputIterator __brick_set_union(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2,
                                   _RandomAccessIterator2, _OutputIterator, _Compare,
-                                  /*__is_vector=*/std::true_type) noexcept;
+                                  /*__is_vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator,
           class _Compare>
@@ -1001,12 +1016,12 @@ __pattern_set_union(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccess
 template <class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator, class _Compare>
 _OutputIterator __brick_set_intersection(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2,
                                          _OutputIterator, _Compare,
-                                         /*__is_vector=*/std::false_type) noexcept;
+                                         /*__is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _OutputIterator, class _Compare>
 _OutputIterator __brick_set_intersection(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2,
                                          _RandomAccessIterator2, _OutputIterator, _Compare,
-                                         /*__is_vector=*/std::true_type) noexcept;
+                                         /*__is_vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator,
           class _Compare>
@@ -1015,11 +1030,11 @@ __pattern_set_intersection(_Tag, _ExecutionPolicy&&, _ForwardIterator1, _Forward
                            _ForwardIterator2, _OutputIterator, _Compare) noexcept;
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
-          class _OutputIterator, class _Compare>
-_OutputIterator
+          class _RandomAccessIterator3, class _Compare>
+_RandomAccessIterator3
 __pattern_set_intersection(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1,
-                           _RandomAccessIterator1, _RandomAccessIterator2, _RandomAccessIterator2, _OutputIterator,
-                           _Compare);
+                           _RandomAccessIterator1, _RandomAccessIterator2, _RandomAccessIterator2,
+                           _RandomAccessIterator3, _Compare);
 
 //------------------------------------------------------------------------
 // set_difference
@@ -1028,12 +1043,12 @@ __pattern_set_intersection(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _Rando
 template <class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator, class _Compare>
 _OutputIterator __brick_set_difference(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2,
                                        _OutputIterator, _Compare,
-                                       /*__is_vector=*/std::false_type) noexcept;
+                                       /*__is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _OutputIterator, class _Compare>
 _OutputIterator __brick_set_difference(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2,
                                        _RandomAccessIterator2, _OutputIterator, _Compare,
-                                       /*__is_vector=*/std::true_type) noexcept;
+                                       /*__is_vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator,
           class _Compare>
@@ -1042,10 +1057,10 @@ __pattern_set_difference(_Tag, _ExecutionPolicy&&, _ForwardIterator1, _ForwardIt
                          _ForwardIterator2, _OutputIterator, _Compare) noexcept;
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
-          class _OutputIterator, class _Compare>
-_OutputIterator
+          class _RandomAccessIterator3, class _Compare>
+_RandomAccessIterator3
 __pattern_set_difference(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
-                         _RandomAccessIterator2, _RandomAccessIterator2, _OutputIterator, _Compare);
+                         _RandomAccessIterator2, _RandomAccessIterator2, _RandomAccessIterator3, _Compare);
 
 //------------------------------------------------------------------------
 // set_symmetric_difference
@@ -1054,12 +1069,12 @@ __pattern_set_difference(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomA
 template <class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator, class _Compare>
 _OutputIterator __brick_set_symmetric_difference(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2,
                                                  _ForwardIterator2, _OutputIterator, _Compare,
-                                                 /*__is_vector=*/std::false_type) noexcept;
+                                                 /*__is_vector=*/::std::false_type) noexcept;
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _OutputIterator, class _Compare>
 _OutputIterator __brick_set_symmetric_difference(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2,
                                                  _RandomAccessIterator2, _OutputIterator, _Compare,
-                                                 /*__is_vector=*/std::true_type) noexcept;
+                                                 /*__is_vector=*/::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator,
           class _Compare>
@@ -1068,11 +1083,11 @@ __pattern_set_symmetric_difference(_Tag, _ExecutionPolicy&&, _ForwardIterator1,
                                    _ForwardIterator2, _OutputIterator, _Compare) noexcept;
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
-          class _OutputIterator, class _Compare>
-_OutputIterator
+          class _RandomAccessIterator3, class _Compare>
+_RandomAccessIterator3
 __pattern_set_symmetric_difference(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1,
                                    _RandomAccessIterator1, _RandomAccessIterator2, _RandomAccessIterator2,
-                                   _OutputIterator, _Compare);
+                                   _RandomAccessIterator3, _Compare);
 
 //------------------------------------------------------------------------
 // is_heap_until
@@ -1080,11 +1095,11 @@ __pattern_set_symmetric_difference(__parallel_tag<_IsVector>, _ExecutionPolicy&&
 
 template <class _RandomAccessIterator, class _Compare>
 _RandomAccessIterator __brick_is_heap_until(_RandomAccessIterator, _RandomAccessIterator, _Compare,
-                                            /* __is_vector = */ std::false_type) noexcept;
+                                            /* __is_vector = */ ::std::false_type) noexcept;
 
 template <class _RandomAccessIterator, class _Compare>
 _RandomAccessIterator __brick_is_heap_until(_RandomAccessIterator, _RandomAccessIterator, _Compare,
-                                            /* __is_vector = */ std::true_type) noexcept;
+                                            /* __is_vector = */ ::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
 _RandomAccessIterator
@@ -1093,7 +1108,28 @@ __pattern_is_heap_until(_Tag, _ExecutionPolicy&&, _RandomAccessIterator, _Random
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
 _RandomAccessIterator
 __pattern_is_heap_until(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
-                        _Compare) noexcept;
+                        _Compare);
+
+//------------------------------------------------------------------------
+// is_heap
+//------------------------------------------------------------------------
+
+template <class _RandomAccessIterator, class _Compare>
+bool __brick_is_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare,
+                     /* __is_vector = */ ::std::false_type) noexcept;
+
+template <class _RandomAccessIterator, class _Compare>
+bool __brick_is_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare,
+                     /* __is_vector = */ ::std::true_type) noexcept;
+
+template <class _Tag, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
+bool
+__pattern_is_heap(_Tag, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator, _Compare) noexcept;
+
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
+bool
+__pattern_is_heap(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
+                  _Compare);
 
 //------------------------------------------------------------------------
 // min_element
@@ -1101,13 +1137,13 @@ __pattern_is_heap_until(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAc
 
 template <typename _ForwardIterator, typename _Compare>
 _ForwardIterator __brick_min_element(_ForwardIterator, _ForwardIterator, _Compare,
-                                     /* __is_vector = */ std::false_type) noexcept;
+                                     /* __is_vector = */ ::std::false_type) noexcept;
 
 template <typename _RandomAccessIterator, typename _Compare>
 _RandomAccessIterator __brick_min_element(_RandomAccessIterator, _RandomAccessIterator, _Compare,
-                                          /* __is_vector = */ std::true_type) noexcept;
+                                          /* __is_vector = */ ::std::true_type) noexcept;
 
-template <typename _Tag, typename _ExecutionPolicy, typename _ForwardIterator, typename _Compare>
+template <class _Tag, typename _ExecutionPolicy, typename _ForwardIterator, typename _Compare>
 _ForwardIterator
 __pattern_min_element(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Compare) noexcept;
 
@@ -1121,20 +1157,20 @@ __pattern_min_element(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAcce
 //------------------------------------------------------------------------
 
 template <typename _ForwardIterator, typename _Compare>
-std::pair<_ForwardIterator, _ForwardIterator> __brick_minmax_element(_ForwardIterator, _ForwardIterator, _Compare,
-                                                                     /* __is_vector = */ std::false_type) noexcept;
+::std::pair<_ForwardIterator, _ForwardIterator> __brick_minmax_element(_ForwardIterator, _ForwardIterator, _Compare,
+                                                                       /* __is_vector = */ ::std::false_type) noexcept;
 
 template <typename _RandomAccessIterator, typename _Compare>
-std::pair<_RandomAccessIterator, _RandomAccessIterator>
+::std::pair<_RandomAccessIterator, _RandomAccessIterator>
     __brick_minmax_element(_RandomAccessIterator, _RandomAccessIterator, _Compare,
-                           /* __is_vector = */ std::true_type) noexcept;
+                           /* __is_vector = */ ::std::true_type) noexcept;
 
-template <typename _Tag, typename _ExecutionPolicy, typename _ForwardIterator, typename _Compare>
-std::pair<_ForwardIterator, _ForwardIterator>
+template <class _Tag, typename _ExecutionPolicy, typename _ForwardIterator, typename _Compare>
+::std::pair<_ForwardIterator, _ForwardIterator>
 __pattern_minmax_element(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Compare) noexcept;
 
 template <typename _IsVector, typename _ExecutionPolicy, typename _RandomAccessIterator, typename _Compare>
-std::pair<_RandomAccessIterator, _RandomAccessIterator>
+::std::pair<_RandomAccessIterator, _RandomAccessIterator>
 __pattern_minmax_element(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
                          _Compare);
 
@@ -1143,26 +1179,26 @@ __pattern_minmax_element(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomA
 //------------------------------------------------------------------------
 
 template <class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
-std::pair<_ForwardIterator1, _ForwardIterator2> __brick_mismatch(_ForwardIterator1, _ForwardIterator1,
-                                                                 _ForwardIterator2, _ForwardIterator2, _Predicate,
-                                                                 /* __is_vector = */ std::false_type) noexcept;
+::std::pair<_ForwardIterator1, _ForwardIterator2> __brick_mismatch(_ForwardIterator1, _ForwardIterator1,
+                                                                   _ForwardIterator2, _ForwardIterator2, _Predicate,
+                                                                   /* __is_vector = */ ::std::false_type) noexcept;
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _Predicate>
-std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
+::std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
     __brick_mismatch(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2, _RandomAccessIterator2,
                      _Predicate,
-                     /* __is_vector = */ std::true_type) noexcept;
+                     /* __is_vector = */ ::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
-std::pair<_ForwardIterator1, _ForwardIterator2>
+::std::pair<_ForwardIterator1, _ForwardIterator2>
 __pattern_mismatch(_Tag, _ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2,
                    _Predicate) noexcept;
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
           class _Predicate>
-std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
+::std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
 __pattern_mismatch(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1, _RandomAccessIterator1,
-                   _RandomAccessIterator2, _RandomAccessIterator2, _Predicate) noexcept;
+                   _RandomAccessIterator2, _RandomAccessIterator2, _Predicate);
 
 //------------------------------------------------------------------------
 // lexicographical_compare
@@ -1171,12 +1207,12 @@ __pattern_mismatch(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessI
 template <class _ForwardIterator1, class _ForwardIterator2, class _Compare>
 bool __brick_lexicographical_compare(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2,
                                      _Compare,
-                                     /* __is_vector = */ std::false_type) noexcept;
+                                     /* __is_vector = */ ::std::false_type) noexcept;
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _Compare>
 bool __brick_lexicographical_compare(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2,
                                      _RandomAccessIterator2, _Compare,
-                                     /* __is_vector = */ std::true_type) noexcept;
+                                     /* __is_vector = */ ::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Compare>
 bool
@@ -1190,6 +1226,44 @@ __pattern_lexicographical_compare(__parallel_tag<_IsVector>, _ExecutionPolicy&&,
                                   _RandomAccessIterator1, _RandomAccessIterator2, _RandomAccessIterator2,
                                   _Compare) noexcept;
 
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
+_ForwardIterator2
+__pattern_swap(_Tag, _ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2);
+
+//------------------------------------------------------------------------
+// shift_left
+//------------------------------------------------------------------------
+
+template <class _ForwardIterator>
+_ForwardIterator __brick_shift_left(_ForwardIterator, _ForwardIterator,
+                                    typename ::std::iterator_traits<_ForwardIterator>::difference_type,
+                                    /*__is_vector=*/::std::false_type) noexcept;
+
+template <class _ForwardIterator>
+_ForwardIterator __brick_shift_left(_ForwardIterator, _ForwardIterator,
+                                    typename ::std::iterator_traits<_ForwardIterator>::difference_type,
+                                    /*__is_vector=*/::std::true_type) noexcept;
+
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator>
+_ForwardIterator
+__pattern_shift_left(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator,
+                     typename ::std::iterator_traits<_ForwardIterator>::difference_type) noexcept;
+
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator>
+_RandomAccessIterator
+__pattern_shift_left(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
+                     typename ::std::iterator_traits<_RandomAccessIterator>::difference_type);
+
+//------------------------------------------------------------------------
+// shift_right
+//------------------------------------------------------------------------
+
+template <class _Tag, class _ExecutionPolicy, class _BidirectionalIterator>
+_BidirectionalIterator
+__pattern_shift_right(_Tag, _ExecutionPolicy&&, _BidirectionalIterator, _BidirectionalIterator,
+                      typename ::std::iterator_traits<_BidirectionalIterator>::difference_type);
+
 } // namespace __internal
-} // namespace __pstl
-#endif /* _PSTL_ALGORITHM_FWD_H */
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_ALGORITHM_FWD_H
diff --git a/libstdc++-v3/include/pstl/algorithm_impl.h b/libstdc++-v3/include/pstl/algorithm_impl.h
index 2080e82f8b49..4a3d62df90e8 100644
--- a/libstdc++-v3/include/pstl/algorithm_impl.h
+++ b/libstdc++-v3/include/pstl/algorithm_impl.h
@@ -1,30 +1,46 @@
 // -*- C++ -*-
-//===-- algorithm_impl.h --------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_ALGORITHM_IMPL_H
-#define _PSTL_ALGORITHM_IMPL_H
+#ifndef _ONEDPL_ALGORITHM_IMPL_H
+#define _ONEDPL_ALGORITHM_IMPL_H
 
 #include <iterator>
 #include <type_traits>
-#include <utility>
 #include <functional>
 #include <algorithm>
+#include <cassert>
+#include <cmath>
+#include <tuple>
+
+#include "algorithm_fwd.h"
 
 #include "execution_impl.h"
 #include "memory_impl.h"
 #include "parallel_backend_utils.h"
-#include "parallel_backend.h"
-#include "parallel_impl.h"
 #include "unseq_backend_simd.h"
 
+#include "parallel_backend.h"
+#include "parallel_impl.h"
+#include "iterator_impl.h"
+#include "functional_impl.h" // for __onedpl::identity, std::invoke
 
-namespace __pstl
+#if _ONEDPL_HETERO_BACKEND
+#    include "hetero/algorithm_impl_hetero.h" // for __pattern_fill_n, __pattern_generate_n
+#endif
+
+namespace std::__onedpl
 {
 namespace __internal
 {
@@ -36,23 +52,25 @@ namespace __internal
 template <class _ForwardIterator, class _Pred>
 bool
 __brick_any_of(const _ForwardIterator __first, const _ForwardIterator __last, _Pred __pred,
-               /*__is_vector=*/std::false_type) noexcept
+               /*__is_vector=*/::std::false_type) noexcept
 {
-    return std::any_of(__first, __last, __pred);
-};
+    return ::std::any_of(__first, __last, __pred);
+}
 
 template <class _RandomAccessIterator, class _Pred>
 bool
 __brick_any_of(const _RandomAccessIterator __first, const _RandomAccessIterator __last, _Pred __pred,
-               /*__is_vector=*/std::true_type) noexcept
+               /*__is_vector=*/::std::true_type) noexcept
 {
     return __unseq_backend::__simd_or(__first, __last - __first, __pred);
-};
+}
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Pred>
 bool
 __pattern_any_of(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_any_of(__first, __last, __pred, typename _Tag::__is_vector{});
 }
 
@@ -61,15 +79,12 @@ bool
 __pattern_any_of(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                  _RandomAccessIterator __last, _Pred __pred)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
-
-    return __internal::__except_handler(
-        [&]()
-        {
-            return __internal::__parallel_or(__backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                             [__pred](_RandomAccessIterator __i, _RandomAccessIterator __j)
-                                             { return __internal::__brick_any_of(__i, __j, __pred, _IsVector{}); });
-        });
+    return __internal::__except_handler([&]() {
+        return __internal::__parallel_or(__tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                         [__pred](_RandomAccessIterator __i, _RandomAccessIterator __j) {
+                                             return __internal::__brick_any_of(__i, __j, __pred, _IsVector{});
+                                         });
+    });
 }
 
 // [alg.foreach]
@@ -79,7 +94,7 @@ template <class _ForwardIterator, class _Size, class _Function>
 _ForwardIterator
 __for_each_n_it_serial(_ForwardIterator __first, _Size __n, _Function __f)
 {
-    for (; __n > 0; ++__first, (void) --__n)
+    for (; __n > 0; ++__first, (void)--__n)
         __f(__first);
     return __first;
 }
@@ -91,64 +106,74 @@ __for_each_n_it_serial(_ForwardIterator __first, _Size __n, _Function __f)
 //------------------------------------------------------------------------
 template <class _ForwardIterator, class _Function>
 void
-__brick_walk1(_ForwardIterator __first, _ForwardIterator __last, _Function __f, /*vector=*/std::false_type) noexcept
+__brick_walk1(_ForwardIterator __first, _ForwardIterator __last, _Function __f, /*vector=*/::std::false_type)
 {
-    std::for_each(__first, __last, __f);
+    ::std::for_each(__first, __last, __f);
 }
 
 template <class _RandomAccessIterator, class _Function>
 void
 __brick_walk1(_RandomAccessIterator __first, _RandomAccessIterator __last, _Function __f,
-              /*vector=*/std::true_type) noexcept
+              /*vector=*/::std::true_type)
 {
-    __unseq_backend::__simd_walk_1(__first, __last - __first, __f);
+    __unseq_backend::__simd_walk_n(__last - __first, __f, __first);
+}
+
+template <class _DifferenceType, class _Function>
+void
+__brick_walk1(_DifferenceType __n, _Function __f, ::std::false_type) noexcept
+{
+    for (_DifferenceType __i = 0; __i < __n; ++__i)
+        __f(__i);
+}
+
+template <class _DifferenceType, class _Function>
+void
+__brick_walk1(_DifferenceType __n, _Function __f, ::std::true_type) noexcept
+{
+    // TODO: when using this overload the correctness of the vectorization depends on that functor is provided.
+    // To avoid possible bugs we need to add a restriction on the functor so only the ones which would be
+    // correctly vectorizes are used passed here. But for now, just re-direct to serial version.
+    __onedpl::__internal::__brick_walk1(__n, __f, ::std::false_type{});
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Function>
 void
-__pattern_walk1(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, _Function __f) noexcept
+__pattern_walk1(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, _Function __f)
 {
+    static_assert(__is_serial_tag_v<_Tag>);
+
     __internal::__brick_walk1(__first, __last, __f, typename _Tag::__is_vector{});
 }
 
+template <class _ExecutionPolicy, class _ForwardIterator, class _Function>
+void
+__pattern_walk1(__parallel_forward_tag, _ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
+                _Function __f)
+{
+    using __backend_tag = typename __parallel_forward_tag::__backend_tag;
+
+    using _ReferenceType = typename std::iterator_traits<_ForwardIterator>::reference;
+    auto __func = [&__f](_ReferenceType arg) { __f(arg); };
+    __internal::__except_handler([&]() {
+        __par_backend::__parallel_for_each(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                           __func);
+    });
+}
+
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Function>
 void
-__pattern_walk1(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+__pattern_walk1(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                 _RandomAccessIterator __last, _Function __f)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    __internal::__except_handler(
-        [&]()
-        {
-            __par_backend::__parallel_for(__backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                          [__f](_RandomAccessIterator __i, _RandomAccessIterator __j)
-                                          { __internal::__brick_walk1(__i, __j, __f, _IsVector{}); });
-        });
-}
-
-template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Brick>
-void
-__pattern_walk_brick(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last,
-                     _Brick __brick) noexcept
-{
-    __brick(__first, __last);
-}
-
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Brick>
-void
-__pattern_walk_brick(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
-                     _RandomAccessIterator __last, _Brick __brick)
-{
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
-
-    __internal::__except_handler(
-        [&]()
-        {
-            __par_backend::__parallel_for(__backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                          [__brick](_RandomAccessIterator __i, _RandomAccessIterator __j)
-                                          { __brick(__i, __j); });
-        });
+    __internal::__except_handler([&]() {
+        __par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                      [__f](_RandomAccessIterator __i, _RandomAccessIterator __j) {
+                                          __internal::__brick_walk1(__i, __j, __f, _IsVector{});
+                                      });
+    });
 }
 
 //------------------------------------------------------------------------
@@ -156,7 +181,7 @@ __pattern_walk_brick(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec,
 //------------------------------------------------------------------------
 template <class _ForwardIterator, class _Size, class _Function>
 _ForwardIterator
-__brick_walk1_n(_ForwardIterator __first, _Size __n, _Function __f, /*_IsVectorTag=*/std::false_type)
+__brick_walk1_n(_ForwardIterator __first, _Size __n, _Function __f, /*_IsVectorTag=*/::std::false_type)
 {
     return __internal::__for_each_n_it_serial(__first, __n,
                                               [&__f](_ForwardIterator __it) { __f(*__it); }); // calling serial version
@@ -165,15 +190,17 @@ __brick_walk1_n(_ForwardIterator __first, _Size __n, _Function __f, /*_IsVectorT
 template <class _RandomAccessIterator, class _DifferenceType, class _Function>
 _RandomAccessIterator
 __brick_walk1_n(_RandomAccessIterator __first, _DifferenceType __n, _Function __f,
-                /*vectorTag=*/std::true_type) noexcept
+                /*vectorTag=*/::std::true_type)
 {
-    return __unseq_backend::__simd_walk_1(__first, __n, __f);
+    return __unseq_backend::__simd_walk_n(__n, __f, __first);
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Function>
 _ForwardIterator
-__pattern_walk1_n(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _Size __n, _Function __f) noexcept
+__pattern_walk1_n(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _Size __n, _Function __f)
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_walk1_n(__first, __n, __f, typename _Tag::__is_vector{});
 }
 
@@ -182,35 +209,11 @@ _RandomAccessIterator
 __pattern_walk1_n(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first, _Size __n,
                   _Function __f)
 {
-    __internal::__pattern_walk1(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __first + __n, __f);
-
+    __onedpl::__internal::__pattern_walk1(__tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __first + __n,
+                                             __f);
     return __first + __n;
 }
 
-template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Brick>
-_ForwardIterator
-__pattern_walk_brick_n(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _Size __n, _Brick __brick) noexcept
-{
-    return __brick(__first, __n);
-}
-
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Size, class _Brick>
-_RandomAccessIterator
-__pattern_walk_brick_n(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
-                       _Size __n, _Brick __brick)
-{
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
-
-    return __internal::__except_handler(
-        [&]()
-        {
-            __par_backend::__parallel_for(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __first + __n,
-                [__brick](_RandomAccessIterator __i, _RandomAccessIterator __j) { __brick(__i, __j - __i); });
-            return __first + __n;
-        });
-}
-
 //------------------------------------------------------------------------
 // walk2 (pseudo)
 //
@@ -219,9 +222,9 @@ __pattern_walk_brick_n(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exe
 template <class _ForwardIterator1, class _ForwardIterator2, class _Function>
 _ForwardIterator2
 __brick_walk2(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _Function __f,
-              /*vector=*/std::false_type) noexcept
+              /*vector=*/::std::false_type) noexcept
 {
-    for (; __first1 != __last1; ++__first1, (void) ++__first2)
+    for (; __first1 != __last1; ++__first1, (void)++__first2)
         __f(*__first1, *__first2);
     return __first2;
 }
@@ -230,17 +233,17 @@ template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _Fun
 _RandomAccessIterator2
 __brick_walk2(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
               _Function __f,
-              /*vector=*/std::true_type) noexcept
+              /*vector=*/::std::true_type) noexcept
 {
-    return __unseq_backend::__simd_walk_2(__first1, __last1 - __first1, __first2, __f);
+    return __unseq_backend::__simd_walk_n(__last1 - __first1, __f, __first1, __first2);
 }
 
 template <class _ForwardIterator1, class _Size, class _ForwardIterator2, class _Function>
 _ForwardIterator2
 __brick_walk2_n(_ForwardIterator1 __first1, _Size __n, _ForwardIterator2 __first2, _Function __f,
-                /*vector=*/std::false_type) noexcept
+                /*vector=*/::std::false_type) noexcept
 {
-    for (; __n > 0; --__n, (void) ++__first1, ++__first2)
+    for (; __n > 0; --__n, (void)++__first1, ++__first2)
         __f(*__first1, *__first2);
     return __first2;
 }
@@ -248,9 +251,9 @@ __brick_walk2_n(_ForwardIterator1 __first1, _Size __n, _ForwardIterator2 __first
 template <class _RandomAccessIterator1, class _Size, class _RandomAccessIterator2, class _Function>
 _RandomAccessIterator2
 __brick_walk2_n(_RandomAccessIterator1 __first1, _Size __n, _RandomAccessIterator2 __first2, _Function __f,
-                /*vector=*/std::true_type) noexcept
+                /*vector=*/::std::true_type) noexcept
 {
-    return __unseq_backend::__simd_walk_2(__first1, __n, __first2, __f);
+    return __unseq_backend::__simd_walk_n(__n, __f, __first1, __first2);
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Function>
@@ -258,26 +261,55 @@ _ForwardIterator2
 __pattern_walk2(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                 _ForwardIterator2 __first2, _Function __f) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag>);
+
     return __internal::__brick_walk2(__first1, __last1, __first2, __f, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
           class _Function>
 _RandomAccessIterator2
-__pattern_walk2(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
+__pattern_walk2(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
                 _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _Function __f)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    return __internal::__except_handler(
-        [&]()
-        {
-            __par_backend::__parallel_for(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
-                [__f, __first1, __first2](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j)
-                { __internal::__brick_walk2(__i, __j, __first2 + (__i - __first1), __f, _IsVector{}); });
-            return __first2 + (__last1 - __first1);
-        });
+    return __internal::__except_handler([&]() {
+        __par_backend::__parallel_for(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
+            [__f, __first1, __first2](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
+                __internal::__brick_walk2(__i, __j, __first2 + (__i - __first1), __f, _IsVector{});
+            });
+        return __first2 + (__last1 - __first1);
+    });
+}
+
+template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Function>
+_ForwardIterator2
+__pattern_walk2(__parallel_forward_tag, _ExecutionPolicy&& __exec, _ForwardIterator1 __first1,
+                _ForwardIterator1 __last1, _ForwardIterator2 __first2, _Function __f)
+{
+    using __backend_tag = typename __parallel_forward_tag::__backend_tag;
+
+    return __internal::__except_handler([&]() {
+        using _iterator_tuple = zip_forward_iterator<_ForwardIterator1, _ForwardIterator2>;
+        auto __begin = _iterator_tuple(__first1, __first2);
+        auto __end = _iterator_tuple(__last1, /*dummy parameter*/ _ForwardIterator2());
+
+        using _ReferenceType1 = typename std::iterator_traits<_ForwardIterator1>::reference;
+        using _ReferenceType2 = typename std::iterator_traits<_ForwardIterator2>::reference;
+
+        __par_backend::__parallel_for_each(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __begin, __end,
+                                           [&__f](::std::tuple<_ReferenceType1, _ReferenceType2> __val) {
+                                               __f(::std::get<0>(__val), ::std::get<1>(__val));
+                                           });
+
+        //TODO: parallel_for_each does not allow to return correct iterator value according to the ::std::transform
+        // implementation. Therefore, iterator value is calculated separately.
+        for (; __begin != __end; ++__begin)
+            ;
+        return ::std::get<1>(__begin.base());
+    });
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _Size, class _ForwardIterator2,
@@ -286,6 +318,8 @@ _ForwardIterator2
 __pattern_walk2_n(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1, _Size __n, _ForwardIterator2 __first2,
                   _Function __f) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_walk2_n(__first1, __n, __first2, __f, typename _Tag::__is_vector{});
 }
 
@@ -295,7 +329,7 @@ _RandomAccessIterator2
 __pattern_walk2_n(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
                   _Size __n, _RandomAccessIterator2 __first2, _Function __f)
 {
-    return __internal::__pattern_walk2(__tag, std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + __n,
+    return __internal::__pattern_walk2(__tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + __n,
                                        __first2, __f);
 }
 
@@ -304,54 +338,86 @@ _ForwardIterator2
 __pattern_walk2_brick(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                       _ForwardIterator2 __first2, _Brick __brick) noexcept
 {
-    return __brick(__first1, __last1, __first2);
+    static_assert(__is_serial_tag_v<_Tag>);
+
+    return __brick(__first1, __last1, __first2, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
           class _Brick>
 _RandomAccessIterator2
-__pattern_walk2_brick(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
+__pattern_walk2_brick(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
                       _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _Brick __brick)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    return __internal::__except_handler(
-        [&]()
-        {
-            __par_backend::__parallel_for(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
-                [__first1, __first2, __brick](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j)
-                { __brick(__i, __j, __first2 + (__i - __first1)); });
-            return __first2 + (__last1 - __first1);
-        });
+    return __except_handler([&]() {
+        __par_backend::__parallel_for(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
+            [__first1, __first2, __brick](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
+                __brick(__i, __j, __first2 + (__i - __first1), _IsVector{});
+            });
+        return __first2 + (__last1 - __first1);
+    });
 }
 
-template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _Size, class _ForwardIterator2,
-          class _Brick>
+//TODO: it postponed till adding more or less effective parallel implementation
+template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Brick>
 _ForwardIterator2
-__pattern_walk2_brick_n(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1, _Size __n, _ForwardIterator2 __first2,
-                        _Brick __brick) noexcept
+__pattern_walk2_brick(__parallel_forward_tag, _ExecutionPolicy&& __exec, _ForwardIterator1 __first1,
+                      _ForwardIterator1 __last1, _ForwardIterator2 __first2, _Brick __brick)
 {
-    return __brick(__first1, __n, __first2);
+    using __backend_tag = typename __parallel_forward_tag::__backend_tag;
+
+    using _iterator_tuple = zip_forward_iterator<_ForwardIterator1, _ForwardIterator2>;
+    auto __begin = _iterator_tuple(__first1, __first2);
+    auto __end = _iterator_tuple(__last1, /*dummy parameter*/ _ForwardIterator2());
+
+    using _ReferenceType1 = typename std::iterator_traits<_ForwardIterator1>::reference;
+    using _ReferenceType2 = typename std::iterator_traits<_ForwardIterator2>::reference;
+
+    return __except_handler([&]() {
+        __par_backend::__parallel_for_each(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __begin, __end,
+                                           [__brick](::std::tuple<_ReferenceType1, _ReferenceType2> __val) {
+                                               __brick(::std::get<0>(__val),
+                                                       ::std::forward<_ReferenceType2>(::std::get<1>(__val)));
+                                           });
+
+        //TODO: parallel_for_each does not allow to return correct iterator value according to the ::std::transform
+        // implementation. Therefore, iterator value is calculated separately.
+        for (; __begin != __end; ++__begin)
+            ;
+        return ::std::get<1>(__begin.base());
+    });
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _Size,
           class _RandomAccessIterator2, class _Brick>
 _RandomAccessIterator2
-__pattern_walk2_brick_n(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
+__pattern_walk2_brick_n(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
                         _Size __n, _RandomAccessIterator2 __first2, _Brick __brick)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    return __internal::__except_handler(
-        [&]()
-        {
-            __par_backend::__parallel_for(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + __n,
-                [__first1, __first2, __brick](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j)
-                { __brick(__i, __j - __i, __first2 + (__i - __first1)); });
-            return __first2 + __n;
-        });
+    return __except_handler([&]() {
+        __par_backend::__parallel_for(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + __n,
+            [__first1, __first2, __brick](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
+                __brick(__i, __j - __i, __first2 + (__i - __first1), _IsVector{});
+            });
+        return __first2 + __n;
+    });
+}
+
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _Size, class _ForwardIterator2,
+          class _Brick>
+_ForwardIterator2
+__pattern_walk2_brick_n(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1, _Size __n,
+                        _ForwardIterator2 __first2, _Brick __brick) noexcept
+{
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
+    return __brick(__first1, __n, __first2, typename _Tag::__is_vector{});
 }
 
 //------------------------------------------------------------------------
@@ -362,9 +428,9 @@ __pattern_walk2_brick_n(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __ex
 template <class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator3, class _Function>
 _ForwardIterator3
 __brick_walk3(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
-              _ForwardIterator3 __first3, _Function __f, /*vector=*/std::false_type) noexcept
+              _ForwardIterator3 __first3, _Function __f, /*vector=*/::std::false_type) noexcept
 {
-    for (; __first1 != __last1; ++__first1, (void) ++__first2, ++__first3)
+    for (; __first1 != __last1; ++__first1, (void)++__first2, ++__first3)
         __f(*__first1, *__first2, *__first3);
     return __first3;
 }
@@ -372,9 +438,9 @@ __brick_walk3(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIte
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _RandomAccessIterator3, class _Function>
 _RandomAccessIterator3
 __brick_walk3(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
-              _RandomAccessIterator3 __first3, _Function __f, /*vector=*/std::true_type) noexcept
+              _RandomAccessIterator3 __first3, _Function __f, /*vector=*/::std::true_type) noexcept
 {
-    return __unseq_backend::__simd_walk_3(__first1, __last1 - __first1, __first2, __first3, __f);
+    return __unseq_backend::__simd_walk_n(__last1 - __first1, __f, __first1, __first2, __first3);
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator3,
@@ -383,29 +449,88 @@ _ForwardIterator3
 __pattern_walk3(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                 _ForwardIterator2 __first2, _ForwardIterator3 __first3, _Function __f) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag>);
+
     return __internal::__brick_walk3(__first1, __last1, __first2, __first3, __f, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
           class _RandomAccessIterator3, class _Function>
 _RandomAccessIterator3
-__pattern_walk3(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
+__pattern_walk3(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
                 _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator3 __first3,
                 _Function __f)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    return __internal::__except_handler(
-        [&]()
-        {
-            __par_backend::__parallel_for(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
-                [__f, __first1, __first2, __first3](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
-                    __internal::__brick_walk3(__i, __j, __first2 + (__i - __first1), __first3 + (__i - __first1), __f,
-                                              _IsVector{});
-                });
-            return __first3 + (__last1 - __first1);
-        });
+    return __internal::__except_handler([&]() {
+        __par_backend::__parallel_for(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
+            [__f, __first1, __first2, __first3](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
+                __internal::__brick_walk3(__i, __j, __first2 + (__i - __first1), __first3 + (__i - __first1), __f,
+                                          _IsVector{});
+            });
+        return __first3 + (__last1 - __first1);
+    });
+}
+
+template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator3,
+          class _Function>
+_ForwardIterator3
+__pattern_walk3(__parallel_forward_tag, _ExecutionPolicy&& __exec, _ForwardIterator1 __first1,
+                _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator3 __first3, _Function __f)
+{
+    using __backend_tag = typename __parallel_forward_tag::__backend_tag;
+
+    return __internal::__except_handler([&]() {
+        using _iterator_tuple = zip_forward_iterator<_ForwardIterator1, _ForwardIterator2, _ForwardIterator3>;
+        auto __begin = _iterator_tuple(__first1, __first2, __first3);
+        auto __end = _iterator_tuple(__last1, /*dummy parameter*/ _ForwardIterator2(),
+                                     /*dummy parameter*/ _ForwardIterator3());
+
+        using _ReferenceType1 = typename std::iterator_traits<_ForwardIterator1>::reference;
+        using _ReferenceType2 = typename std::iterator_traits<_ForwardIterator2>::reference;
+        using _ReferenceType3 = typename std::iterator_traits<_ForwardIterator3>::reference;
+
+        __par_backend::__parallel_for_each(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __begin, __end,
+                                           [&](::std::tuple<_ReferenceType1, _ReferenceType2, _ReferenceType3> __val) {
+                                               __f(::std::get<0>(__val), ::std::get<1>(__val), ::std::get<2>(__val));
+                                           });
+
+        //TODO: parallel_for_each does not allow to return correct iterator value according to the ::std::transform
+        // implementation. Therefore, iterator value is calculated separately.
+        for (; __begin != __end; ++__begin)
+            ;
+        return ::std::get<2>(__begin.base());
+    });
+}
+
+//------------------------------------------------------------------------
+// transform_if
+//------------------------------------------------------------------------
+
+template <class _Tag, typename _ExecutionPolicy, typename _ForwardIterator1, typename _ForwardIterator2,
+          typename _Function>
+_ForwardIterator2
+__pattern_walk2_transform_if(_Tag __tag, _ExecutionPolicy&& __exec, _ForwardIterator1 __first1,
+                             _ForwardIterator1 __last1, _ForwardIterator2 __first2, _Function __func) noexcept
+{
+    static_assert(__is_host_dispatch_tag_v<_Tag>);
+
+    return __pattern_walk2(__tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __func);
+}
+
+template <class _Tag, typename _ExecutionPolicy, typename _ForwardIterator1, typename _ForwardIterator2,
+          typename _ForwardIterator3, typename _Function>
+_ForwardIterator3
+__pattern_walk3_transform_if(_Tag __tag, _ExecutionPolicy&& __exec, _ForwardIterator1 __first1,
+                             _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator3 __first3,
+                             _Function __func) noexcept
+{
+    static_assert(__is_host_dispatch_tag_v<_Tag>);
+
+    return __pattern_walk3(__tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __first3,
+                           __func);
 }
 
 //------------------------------------------------------------------------
@@ -415,20 +540,21 @@ __pattern_walk3(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _Ran
 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
 bool
 __brick_equal(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
-              _ForwardIterator2 __last2, _BinaryPredicate __p, /* IsVector = */ std::false_type) noexcept
+              _ForwardIterator2 __last2, _BinaryPredicate __p, /* IsVector = */ ::std::false_type) noexcept
 {
-    return std::equal(__first1, __last1, __first2, __last2, __p);
+    return ::std::equal(__first1, __last1, __first2, __last2, __p);
 }
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate>
 bool
 __brick_equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
-              _RandomAccessIterator2 __last2, _BinaryPredicate __p, /* is_vector = */ std::true_type) noexcept
+              _RandomAccessIterator2 __last2, _BinaryPredicate __p, /* is_vector = */ ::std::true_type) noexcept
 {
     if (__last1 - __first1 != __last2 - __first2)
         return false;
 
-    return __unseq_backend::__simd_first(__first1, __last1 - __first1, __first2, std::not_fn(__p)).first == __last1;
+    return __unseq_backend::__simd_first(__first1, __last1 - __first1, __first2, __not_pred<_BinaryPredicate&>(__p))
+               .first == __last1;
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
@@ -436,6 +562,8 @@ bool
 __pattern_equal(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                 _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __p) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_equal(__first1, __last1, __first2, __last2, __p, typename _Tag::__is_vector{});
 }
 
@@ -446,22 +574,20 @@ __pattern_equal(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _Ran
                 _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2,
                 _BinaryPredicate __p)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
-
     if (__last1 - __first1 != __last2 - __first2)
         return false;
 
-    return __internal::__except_handler(
-        [&]()
-        {
-            return !__internal::__parallel_or(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
-                [__first1, __first2, __p](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j)
-                {
-                    return !__internal::__brick_equal(__i, __j, __first2 + (__i - __first1),
-                                                      __first2 + (__j - __first1), __p, _IsVector{});
-                });
-        });
+    if (__last1 - __first1 == 0)
+        return true;
+
+    return __internal::__except_handler([&]() {
+        return !__internal::__parallel_or(
+            __tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
+            [__first1, __first2, __p](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
+                return !__internal::__brick_equal(__i, __j, __first2 + (__i - __first1), __first2 + (__j - __first1),
+                                                  __p, _IsVector{});
+            });
+    });
 }
 
 //------------------------------------------------------------------------
@@ -471,17 +597,18 @@ __pattern_equal(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _Ran
 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
 bool
 __brick_equal(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _BinaryPredicate __p,
-              /* IsVector = */ std::false_type) noexcept
+              /* IsVector = */ ::std::false_type) noexcept
 {
-    return std::equal(__first1, __last1, __first2, __p);
+    return ::std::equal(__first1, __last1, __first2, __p);
 }
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate>
 bool
 __brick_equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
-              _BinaryPredicate __p, /* is_vector = */ std::true_type) noexcept
+              _BinaryPredicate __p, /* is_vector = */ ::std::true_type) noexcept
 {
-    return __unseq_backend::__simd_first(__first1, __last1 - __first1, __first2, std::not_fn(__p)).first == __last1;
+    return __unseq_backend::__simd_first(__first1, __last1 - __first1, __first2, __not_pred<_BinaryPredicate&>(__p))
+               .first == __last1;
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
@@ -489,6 +616,8 @@ bool
 __pattern_equal(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                 _ForwardIterator2 __first2, _BinaryPredicate __p) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_equal(__first1, __last1, __first2, __p, typename _Tag::__is_vector{});
 }
 
@@ -498,16 +627,13 @@ bool
 __pattern_equal(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
                 _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _BinaryPredicate __p)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
-
-    return __internal::__except_handler(
-        [&]()
-        {
-            return !__internal::__parallel_or(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
-                [__first1, __first2, __p](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j)
-                { return !__internal::__brick_equal(__i, __j, __first2 + (__i - __first1), __p, _IsVector{}); });
-        });
+    return __internal::__except_handler([&]() {
+        return !__internal::__parallel_or(
+            __tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
+            [__first1, __first2, __p](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
+                return !__internal::__brick_equal(__i, __j, __first2 + (__i - __first1), __p, _IsVector{});
+            });
+    });
 }
 
 //------------------------------------------------------------------------
@@ -516,27 +642,27 @@ __pattern_equal(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _Ran
 template <class _ForwardIterator, class _Predicate>
 _ForwardIterator
 __brick_find_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred,
-                /*is_vector=*/std::false_type) noexcept
+                /*is_vector=*/::std::false_type) noexcept
 {
-    return std::find_if(__first, __last, __pred);
+    return ::std::find_if(__first, __last, __pred);
 }
 
 template <class _RandomAccessIterator, class _Predicate>
 _RandomAccessIterator
 __brick_find_if(_RandomAccessIterator __first, _RandomAccessIterator __last, _Predicate __pred,
-                /*is_vector=*/std::true_type) noexcept
+                /*is_vector=*/::std::true_type) noexcept
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type _SizeType;
-    return __unseq_backend::__simd_first(
-        __first, _SizeType(0), __last - __first,
-        [&__pred](_RandomAccessIterator __it, _SizeType __i) { return __pred(__it[__i]); });
+    using _SizeType = typename std::iterator_traits<_RandomAccessIterator>::difference_type;
+    return __unseq_backend::__simd_first(__first, _SizeType(0), __last - __first, __internal::__pred_at_index{__pred});
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
 _ForwardIterator
-__pattern_find_if(_Tag __tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last,
+__pattern_find_if(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last,
                   _Predicate __pred) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_find_if(__first, __last, __pred, typename _Tag::__is_vector{});
 }
 
@@ -545,18 +671,14 @@ _RandomAccessIterator
 __pattern_find_if(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                   _RandomAccessIterator __last, _Predicate __pred)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
-
-    return __internal::__except_handler(
-        [&]()
-        {
-            return __internal::__parallel_find(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                [__pred](_RandomAccessIterator __i, _RandomAccessIterator __j)
-                { return __internal::__brick_find_if(__i, __j, __pred, _IsVector{}); },
-                std::less<typename std::iterator_traits<_RandomAccessIterator>::difference_type>(),
-                /*is_first=*/true);
-        });
+    return __except_handler([&]() {
+        return __parallel_find(
+            __tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+            [__pred](_RandomAccessIterator __i, _RandomAccessIterator __j) {
+                return __brick_find_if(__i, __j, __pred, _IsVector{});
+            },
+            ::std::true_type{});
+    });
 }
 
 //------------------------------------------------------------------------
@@ -572,7 +694,6 @@ __find_subrange(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _
                 _RandomAccessIterator2 __s_first, _RandomAccessIterator2 __s_last, _BinaryPredicate __pred,
                 bool __b_first, _IsVector __is_vector) noexcept
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator2>::value_type _ValueType;
     auto __n2 = __s_last - __s_first;
     if (__n2 < 1)
     {
@@ -589,14 +710,16 @@ __find_subrange(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _
     while (__first != __last && (__global_last - __first >= __n2))
     {
         // find position of *s_first in [first, last) (it can be start of subsequence)
-        __first = __internal::__brick_find_if(
-            __first, __last, __equal_value_by_pred<_ValueType, _BinaryPredicate>(*__s_first, __pred), __is_vector);
+        auto __u_pred =
+            [__pred, __s_first](auto&& __val) mutable { return __pred(std::forward<decltype(__val)>(__val), *__s_first); };
+        __first = __internal::__brick_find_if(__first, __last, __u_pred, __is_vector);
 
         // if position that was found previously is the start of subsequence
         // then we can exit the loop (b_first == true) or keep the position
         // (b_first == false)
         if (__first != __last && (__global_last - __first >= __n2) &&
-            __internal::__brick_equal(__s_first + 1, __s_last, __first + 1, __pred, __is_vector))
+            __internal::__brick_equal(__s_first + 1, __s_last, __first + 1,
+                                      __onedpl::__internal::__reorder_pred(__pred), __is_vector))
         {
             if (__b_first)
             {
@@ -627,19 +750,26 @@ _RandomAccessIterator
 __find_subrange(_RandomAccessIterator __first, _RandomAccessIterator __last, _RandomAccessIterator __global_last,
                 _Size __count, const _Tp& __value, _BinaryPredicate __pred, _IsVector __is_vector) noexcept
 {
-    if (static_cast<_Size>(__global_last - __first) < __count || __count < 1)
+    if (__count < 1)
     {
-        return __last; // According to the standard last shall be returned when count < 1
+        return __first; // According to the standard std::search_n shall return first when count < 1
     }
 
-    auto __unary_pred = __equal_value_by_pred<_Tp, _BinaryPredicate>(__value, __pred);
+    if (static_cast<_Size>(__global_last - __first) < __count)
+    {
+        return __last;
+    }
+
+    auto __unary_pred =
+        [__pred, &__value](auto&& __val) mutable { return __pred(std::forward<decltype(__val)>(__val), __value); };
     while (__first != __last && (static_cast<_Size>(__global_last - __first) >= __count))
     {
         __first = __internal::__brick_find_if(__first, __last, __unary_pred, __is_vector);
 
         // check that all of elements in [first+1, first+count) equal to value
-        if (__first != __last && (static_cast<_Size>(__global_last - __first) >= __count) &&
-            !__internal::__brick_any_of(__first + 1, __first + __count, std::not_fn(__unary_pred), __is_vector))
+        if (__first != __last && (__global_last - __first >= __count) &&
+            !__internal::__brick_any_of(__first + 1, __first + __count,
+                                        __not_pred<decltype(__unary_pred)&>(__unary_pred), __is_vector))
         {
             return __first;
         }
@@ -658,17 +788,17 @@ __find_subrange(_RandomAccessIterator __first, _RandomAccessIterator __last, _Ra
 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
 _ForwardIterator1
 __brick_find_end(_ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
-                 _ForwardIterator2 __s_last, _BinaryPredicate __pred, /*__is_vector=*/std::false_type) noexcept
+                 _ForwardIterator2 __s_last, _BinaryPredicate __pred, /*__is_vector=*/::std::false_type) noexcept
 {
-    return std::find_end(__first, __last, __s_first, __s_last, __pred);
+    return ::std::find_end(__first, __last, __s_first, __s_last, __pred);
 }
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate>
 _RandomAccessIterator1
 __brick_find_end(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __s_first,
-                 _RandomAccessIterator2 __s_last, _BinaryPredicate __pred, /*__is_vector=*/std::true_type) noexcept
+                 _RandomAccessIterator2 __s_last, _BinaryPredicate __pred, /*__is_vector=*/::std::true_type) noexcept
 {
-    return __find_subrange(__first, __last, __last, __s_first, __s_last, __pred, false, std::true_type());
+    return __find_subrange(__first, __last, __last, __s_first, __s_last, __pred, false, ::std::true_type());
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
@@ -676,6 +806,8 @@ _ForwardIterator1
 __pattern_find_end(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first, _ForwardIterator1 __last,
                    _ForwardIterator2 __s_first, _ForwardIterator2 __s_last, _BinaryPredicate __pred) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_find_end(__first, __last, __s_first, __s_last, __pred, typename _Tag::__is_vector{});
 }
 
@@ -684,30 +816,25 @@ template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1,
 _RandomAccessIterator1
 __pattern_find_end(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first,
                    _RandomAccessIterator1 __last, _RandomAccessIterator2 __s_first, _RandomAccessIterator2 __s_last,
-                   _BinaryPredicate __pred) noexcept
+                   _BinaryPredicate __pred)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
-
     if (__last - __first == __s_last - __s_first)
     {
-        const bool __res = __internal::__pattern_equal(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
+        const bool __res = __internal::__pattern_equal(__tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
                                                        __s_first, __pred);
         return __res ? __first : __last;
     }
     else
     {
-        return __internal::__except_handler(
-            [&]()
-            {
-                return __internal::__parallel_find(
-                    __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                    [__last, __s_first, __s_last, __pred](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
-                        return __internal::__find_subrange(__i, __j, __last, __s_first, __s_last, __pred, false,
-                                                           _IsVector{});
-                    },
-                    std::greater<typename std::iterator_traits<_RandomAccessIterator1>::difference_type>(),
-                    /*is_first=*/false);
-            });
+        return __internal::__except_handler([&]() {
+            return __internal::__parallel_find(
+                __tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                [__last, __s_first, __s_last, __pred](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
+                    return __internal::__find_subrange(__i, __j, __last, __s_first, __s_last, __pred, false,
+                                                       _IsVector{});
+                },
+                ::std::false_type{});
+        });
     }
 }
 
@@ -717,15 +844,15 @@ __pattern_find_end(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _
 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
 _ForwardIterator1
 __brick_find_first_of(_ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
-                      _ForwardIterator2 __s_last, _BinaryPredicate __pred, /*__is_vector=*/std::false_type) noexcept
+                      _ForwardIterator2 __s_last, _BinaryPredicate __pred, /*__is_vector=*/::std::false_type) noexcept
 {
-    return std::find_first_of(__first, __last, __s_first, __s_last, __pred);
+    return ::std::find_first_of(__first, __last, __s_first, __s_last, __pred);
 }
 
-template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate>
-_RandomAccessIterator1
-__brick_find_first_of(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __s_first,
-                      _RandomAccessIterator2 __s_last, _BinaryPredicate __pred, /*__is_vector=*/std::true_type) noexcept
+template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
+_ForwardIterator1
+__brick_find_first_of(_ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
+                      _ForwardIterator2 __s_last, _BinaryPredicate __pred, /*__is_vector=*/::std::true_type) noexcept
 {
     return __unseq_backend::__simd_find_first_of(__first, __last, __s_first, __s_last, __pred);
 }
@@ -735,6 +862,8 @@ _ForwardIterator1
 __pattern_find_first_of(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first, _ForwardIterator1 __last,
                         _ForwardIterator2 __s_first, _ForwardIterator2 __s_last, _BinaryPredicate __pred) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_find_first_of(__first, __last, __s_first, __s_last, __pred,
                                              typename _Tag::__is_vector{});
 }
@@ -744,38 +873,35 @@ template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1,
 _RandomAccessIterator1
 __pattern_find_first_of(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first,
                         _RandomAccessIterator1 __last, _RandomAccessIterator2 __s_first,
-                        _RandomAccessIterator2 __s_last, _BinaryPredicate __pred) noexcept
+                        _RandomAccessIterator2 __s_last, _BinaryPredicate __pred)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
-
-    return __internal::__except_handler(
-        [&]()
-        {
-            return __internal::__parallel_find(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                [__s_first, __s_last, __pred](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j)
-                { return __internal::__brick_find_first_of(__i, __j, __s_first, __s_last, __pred, _IsVector{}); },
-                std::less<typename std::iterator_traits<_RandomAccessIterator1>::difference_type>(), /*is_first=*/true);
-        });
+    return __internal::__except_handler([&]() {
+        return __internal::__parallel_find(
+            __tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+            [__s_first, __s_last, &__pred](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
+                return __internal::__brick_find_first_of(__i, __j, __s_first, __s_last, __pred, _IsVector{});
+            },
+            ::std::true_type{});
+    });
 }
 
 //------------------------------------------------------------------------
 // search
 //------------------------------------------------------------------------
-template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate>
-_RandomAccessIterator1
-__brick_search(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __s_first,
-               _RandomAccessIterator2 __s_last, _BinaryPredicate __pred, /*vector=*/std::false_type) noexcept
+template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
+_ForwardIterator1
+__brick_search(_ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
+               _ForwardIterator2 __s_last, _BinaryPredicate __pred, /*vector=*/::std::false_type) noexcept
 {
-    return std::search(__first, __last, __s_first, __s_last, __pred);
+    return ::std::search(__first, __last, __s_first, __s_last, __pred);
 }
 
-template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate>
-_RandomAccessIterator1
-__brick_search(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __s_first,
-               _RandomAccessIterator2 __s_last, _BinaryPredicate __pred, /*vector=*/std::true_type) noexcept
+template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
+_ForwardIterator1
+__brick_search(_ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
+               _ForwardIterator2 __s_last, _BinaryPredicate __pred, /*vector=*/::std::true_type) noexcept
 {
-    return __internal::__find_subrange(__first, __last, __last, __s_first, __s_last, __pred, true, std::true_type());
+    return __internal::__find_subrange(__first, __last, __last, __s_first, __s_last, __pred, true, ::std::true_type());
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
@@ -783,6 +909,8 @@ _ForwardIterator1
 __pattern_search(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first, _ForwardIterator1 __last,
                  _ForwardIterator2 __s_first, _ForwardIterator2 __s_last, _BinaryPredicate __pred) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_search(__first, __last, __s_first, __s_last, __pred, typename _Tag::__is_vector{});
 }
 
@@ -791,30 +919,25 @@ template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1,
 _RandomAccessIterator1
 __pattern_search(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first,
                  _RandomAccessIterator1 __last, _RandomAccessIterator2 __s_first, _RandomAccessIterator2 __s_last,
-                 _BinaryPredicate __pred) noexcept
+                 _BinaryPredicate __pred)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
-
     if (__last - __first == __s_last - __s_first)
     {
-        const bool __res = __internal::__pattern_equal(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
+        const bool __res = __internal::__pattern_equal(__tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
                                                        __s_first, __pred);
         return __res ? __first : __last;
     }
     else
     {
-        return __internal::__except_handler(
-            [&]()
-            {
-                return __internal::__parallel_find(
-                    __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                    [__last, __s_first, __s_last, __pred](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
-                        return __internal::__find_subrange(__i, __j, __last, __s_first, __s_last, __pred, true,
-                                                           _IsVector{});
-                    },
-                    std::less<typename std::iterator_traits<_RandomAccessIterator1>::difference_type>(),
-                    /*is_first=*/true);
-            });
+        return __internal::__except_handler([&]() {
+            return __internal::__parallel_find(
+                __tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                [__last, __s_first, __s_last, __pred](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
+                    return __internal::__find_subrange(__i, __j, __last, __s_first, __s_last, __pred, true,
+                                                       _IsVector{});
+                },
+                /*_IsFirst=*/::std::true_type{});
+        });
     }
 }
 
@@ -824,17 +947,17 @@ __pattern_search(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _Ra
 template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
 _ForwardIterator
 __brick_search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value,
-                 _BinaryPredicate __pred, /*vector=*/std::false_type) noexcept
+                 _BinaryPredicate __pred, /*vector=*/::std::false_type) noexcept
 {
-    return std::search_n(__first, __last, __count, __value, __pred);
+    return ::std::search_n(__first, __last, __count, __value, __pred);
 }
 
 template <class _RandomAccessIterator, class _Size, class _Tp, class _BinaryPredicate>
 _RandomAccessIterator
 __brick_search_n(_RandomAccessIterator __first, _RandomAccessIterator __last, _Size __count, const _Tp& __value,
-                 _BinaryPredicate __pred, /*vector=*/std::true_type) noexcept
+                 _BinaryPredicate __pred, /*vector=*/::std::true_type) noexcept
 {
-    return __internal::__find_subrange(__first, __last, __last, __count, __value, __pred, std::true_type());
+    return __internal::__find_subrange(__first, __last, __last, __count, __value, __pred, ::std::true_type());
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
@@ -842,6 +965,8 @@ _ForwardIterator
 __pattern_search_n(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, _Size __count,
                    const _Tp& __value, _BinaryPredicate __pred) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_search_n(__first, __last, __count, __value, __pred, typename _Tag::__is_vector{});
 }
 
@@ -849,121 +974,146 @@ template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator,
           class _BinaryPredicate>
 _RandomAccessIterator
 __pattern_search_n(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
-                   _RandomAccessIterator __last, _Size __count, const _Tp& __value, _BinaryPredicate __pred) noexcept
+                   _RandomAccessIterator __last, _Size __count, const _Tp& __value, _BinaryPredicate __pred)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
-
     if (static_cast<_Size>(__last - __first) == __count)
     {
-        const bool __result =
-            !__internal::__pattern_any_of(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                          [&__value, &__pred](const _Tp& __val) { return !__pred(__val, __value); });
+        const bool __result = !__internal::__pattern_any_of(__tag, std::forward<_ExecutionPolicy>(__exec), __first,
+            __last, [&__value, __pred](auto&& __val) mutable { return !__pred(std::forward<decltype(__val)>(__val),
+            __value); });
         return __result ? __first : __last;
     }
     else
     {
-        return __internal::__except_handler(
-            [&__exec, __first, __last, __count, &__value, __pred]()
-            {
-                return __internal::__parallel_find(
-                    __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                    [__last, __count, &__value, __pred](_RandomAccessIterator __i, _RandomAccessIterator __j)
-                    { return __internal::__find_subrange(__i, __j, __last, __count, __value, __pred, _IsVector{}); },
-                    std::less<typename std::iterator_traits<_RandomAccessIterator>::difference_type>(),
-                    /*is_first=*/true);
-            });
+        return __internal::__except_handler([__tag, &__exec, __first, __last, __count, &__value, __pred]() {
+            return __internal::__parallel_find(
+                __tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                [__last, __count, &__value, __pred](_RandomAccessIterator __i, _RandomAccessIterator __j) {
+                    return __internal::__find_subrange(__i, __j, __last, __count, __value, __pred, _IsVector{});
+                },
+                ::std::true_type{});
+        });
     }
 }
 
 //------------------------------------------------------------------------
 // copy_n
 //------------------------------------------------------------------------
+// It might be possible to share more between copy and copy_n, but it's not
+// clear that doing so is worth the trouble and extra layers of call chain.
+// Sometimes a little duplication for sake of regularity is better than the alternative.
 
-template <class _ForwardIterator, class _Size, class _OutputIterator>
-_OutputIterator
-__brick_copy_n(_ForwardIterator __first, _Size __n, _OutputIterator __result, /*vector=*/std::false_type) noexcept
+template <class _Tag>
+struct __brick_copy_n<_Tag, std::enable_if_t<__onedpl::__internal::__is_host_dispatch_tag_v<_Tag>>>
 {
-    return std::copy_n(__first, __n, __result);
-}
+    template <typename _RandomAccessIterator1, typename _Size, typename _RandomAccessIterator2>
+    _RandomAccessIterator2
+    operator()(_RandomAccessIterator1 __first, _Size __n, _RandomAccessIterator2 __result,
+               /*vec*/ ::std::true_type) const
+    {
+        return __unseq_backend::__simd_assign(
+            __first, __n, __result,
+            [](_RandomAccessIterator1 __first, _RandomAccessIterator2 __result) { *__result = *__first; });
+    }
 
-template <class _RandomAccessIterator1, class _Size, class _RandomAccessIterator2>
-_RandomAccessIterator2
-__brick_copy_n(_RandomAccessIterator1 __first, _Size __n, _RandomAccessIterator2 __result,
-               /*vector=*/std::true_type) noexcept
-{
-    return __unseq_backend::__simd_assign(
-        __first, __n, __result,
-        [](_RandomAccessIterator1 __first, _RandomAccessIterator2 __result) { *__result = *__first; });
-}
+    template <typename _Iterator, typename _Size, typename _OutputIterator>
+    _OutputIterator
+    operator()(_Iterator __first, _Size __n, _OutputIterator __result, /*vec*/ ::std::false_type) const
+    {
+        return ::std::copy_n(__first, __n, __result);
+    }
+};
 
 //------------------------------------------------------------------------
 // copy
 //------------------------------------------------------------------------
-template <class _ForwardIterator, class _OutputIterator>
-_OutputIterator
-__brick_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result,
-             /*vector=*/std::false_type) noexcept
-{
-    return std::copy(__first, __last, __result);
-}
 
-template <class _RandomAccessIterator1, class _RandomAccessIterator2>
-_RandomAccessIterator2
-__brick_copy(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __result,
-             /*vector=*/std::true_type) noexcept
+template <class _Tag>
+struct __brick_copy<_Tag, std::enable_if_t<__is_host_dispatch_tag_v<_Tag>>>
 {
-    return __unseq_backend::__simd_assign(
-        __first, __last - __first, __result,
-        [](_RandomAccessIterator1 __first, _RandomAccessIterator2 __result) { *__result = *__first; });
-}
+    template <typename _RandomAccessIterator1, typename _RandomAccessIterator2>
+    _RandomAccessIterator2
+    operator()(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __result,
+               /*vec*/ ::std::true_type) const
+    {
+        return __unseq_backend::__simd_assign(
+            __first, __last - __first, __result,
+            [](_RandomAccessIterator1 __first, _RandomAccessIterator2 __result) { *__result = *__first; });
+    }
+
+    template <typename _Iterator, typename _OutputIterator>
+    _OutputIterator
+    operator()(_Iterator __first, _Iterator __last, _OutputIterator __result, /*vec*/ ::std::false_type) const
+    {
+        return ::std::copy(__first, __last, __result);
+    }
+
+    template <typename _ReferenceType1, typename _ReferenceType2>
+    void
+    operator()(_ReferenceType1 __val, _ReferenceType2&& __result) const
+    {
+        __result = __val;
+    }
+};
 
 //------------------------------------------------------------------------
 // move
 //------------------------------------------------------------------------
-template <class _ForwardIterator, class _OutputIterator>
-_OutputIterator
-__brick_move(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result,
-             /*vector=*/std::false_type) noexcept
-{
-    return std::move(__first, __last, __result);
-}
 
-template <class _RandomAccessIterator1, class _RandomAccessIterator2>
-_RandomAccessIterator2
-__brick_move(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __result,
-             /*vector=*/std::true_type) noexcept
+template <class _Tag>
+struct __brick_move<_Tag, std::enable_if_t<__is_host_dispatch_tag_v<_Tag>>>
 {
-    return __unseq_backend::__simd_assign(
-        __first, __last - __first, __result,
-        [](_RandomAccessIterator1 __first, _RandomAccessIterator2 __result) { *__result = std::move(*__first); });
-}
+    template <typename _RandomAccessIterator1, typename _RandomAccessIterator2>
+    _RandomAccessIterator2
+    operator()(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __result,
+               /*vec*/ ::std::true_type) const
+    {
+        return __unseq_backend::__simd_assign(
+            __first, __last - __first, __result,
+            [](_RandomAccessIterator1 __first, _RandomAccessIterator2 __result) { *__result = ::std::move(*__first); });
+    }
 
+    template <typename _Iterator, typename _OutputIterator>
+    _OutputIterator
+    operator()(_Iterator __first, _Iterator __last, _OutputIterator __result, /*vec*/ ::std::false_type) const
+    {
+        return ::std::move(__first, __last, __result);
+    }
+
+    template <typename _ReferenceType1, typename _ReferenceType2>
+    void
+    operator()(_ReferenceType1&& __val, _ReferenceType2&& __result) const
+    {
+        __result = ::std::move(__val);
+    }
+};
+
+template <class _Tag, typename = std::enable_if_t<__is_host_dispatch_tag_v<_Tag>>>
 struct __brick_move_destroy
 {
     template <typename _RandomAccessIterator1, typename _RandomAccessIterator2>
     _RandomAccessIterator2
     operator()(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __result,
-               /*vec*/ std::true_type) const
+               /*vec*/ ::std::true_type) const
     {
-        using _IteratorValueType = typename std::iterator_traits<_RandomAccessIterator1>::value_type;
+        using _IteratorValueType = typename ::std::iterator_traits<_RandomAccessIterator1>::value_type;
 
         return __unseq_backend::__simd_assign(__first, __last - __first, __result,
                                               [](_RandomAccessIterator1 __first, _RandomAccessIterator2 __result) {
-                                                  *__result = std::move(*__first);
+                                                  *__result = ::std::move(*__first);
                                                   (*__first).~_IteratorValueType();
                                               });
     }
 
-    template <typename _RandomAccessIterator1, typename _RandomAccessIterator2>
-    _RandomAccessIterator2
-    operator()(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __result,
-               /*vec*/ std::false_type) const
+    template <typename _Iterator, typename _OutputIterator>
+    _OutputIterator
+    operator()(_Iterator __first, _Iterator __last, _OutputIterator __result, /*vec*/ ::std::false_type) const
     {
-        using _IteratorValueType = typename std::iterator_traits<_RandomAccessIterator1>::value_type;
+        using _IteratorValueType = typename ::std::iterator_traits<_Iterator>::value_type;
 
-        for (; __first != __last; ++__first, (void) ++__result)
+        for (; __first != __last; ++__first, (void)++__result)
         {
-            *__result = std::move(*__first);
+            *__result = ::std::move(*__first);
             (*__first).~_IteratorValueType();
         }
         return __result;
@@ -976,17 +1126,17 @@ struct __brick_move_destroy
 template <class _ForwardIterator, class _OutputIterator>
 _OutputIterator
 __brick_swap_ranges(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result,
-                    /*vector=*/std::false_type) noexcept
+                    /*vector=*/::std::false_type) noexcept
 {
-    return std::swap_ranges(__first, __last, __result);
+    return ::std::swap_ranges(__first, __last, __result);
 }
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2>
 _RandomAccessIterator2
 __brick_swap_ranges(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __result,
-                    /*vector=*/std::true_type) noexcept
+                    /*vector=*/::std::true_type) noexcept
 {
-    using std::iter_swap;
+    using ::std::iter_swap;
     return __unseq_backend::__simd_assign(__first, __last - __first, __result,
                                           iter_swap<_RandomAccessIterator1, _RandomAccessIterator2>);
 }
@@ -1005,81 +1155,85 @@ __brick_copy_if(_ForwardIterator __first, _ForwardIterator __last, _OutputIterat
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _UnaryPredicate>
 _RandomAccessIterator2
 __brick_copy_if(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __result,
-                _UnaryPredicate __pred,
-                /*vector=*/std::true_type) noexcept
+                _UnaryPredicate __pred, /*vector=*/std::true_type) noexcept
 {
-#if defined(_PSTL_MONOTONIC_PRESENT)
-    return __unseq_backend::__simd_copy_if(__first, __last - __first, __result, __pred);
-#else
-    return std::copy_if(__first, __last, __result, __pred);
-#endif
+    using _DifferenceType = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
+    _DifferenceType __n = __last - __first;
+    return __result + __unseq_backend::__simd_selective_copy</*bounded =*/ false>(
+                          __first, __n, __result, __n, __internal::__pred_at_index{__pred}).second;
 }
 
-// TODO: Try to use transform_reduce for combining __brick_copy_if_phase1 on IsVector.
-template <class _DifferenceType, class _ForwardIterator, class _UnaryPredicate>
-std::pair<_DifferenceType, _DifferenceType>
-__brick_calc_mask_1(_ForwardIterator __first, _ForwardIterator __last, bool* __restrict __mask, _UnaryPredicate __pred,
-                    /*vector=*/std::false_type) noexcept
+template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _UnaryPredicate>
+std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
+__brick_bounded_copy_if(_RandomAccessIterator1 __first,
+                        typename std::iterator_traits<_RandomAccessIterator1>::difference_type __n,
+                        _RandomAccessIterator2 __result,
+                        typename std::iterator_traits<_RandomAccessIterator2>::difference_type __n_out,
+                        _UnaryPredicate __pred, /*vector=*/std::true_type) noexcept
 {
-    auto __count_true = _DifferenceType(0);
-    auto __size = __last - __first;
+    using _DifferenceType = std::common_type_t<decltype(__n), decltype(__n_out)>;
+    auto [__stop_in, __stop_out] = __unseq_backend::__simd_selective_copy</*bounded =*/ true>(
+        __first, _DifferenceType(__n), __result, _DifferenceType(__n_out), __internal::__pred_at_index{__pred});
+    return {__first + __stop_in, __result + __stop_out};
+}
 
-    static_assert(__are_random_access_iterators<_ForwardIterator>::value,
-                  "Pattern-brick error. Should be a random access iterator.");
-
-    for (; __first != __last; ++__first, (void) ++__mask)
+template <class _RandomAccessIterator, class _DifferenceType, class _IndexPredicate>
+std::pair<_DifferenceType, _DifferenceType>
+__brick_compute_mask(_RandomAccessIterator __first, _DifferenceType __len, _IndexPredicate __pred, bool* __mask,
+                     /*vector=*/std::false_type) noexcept
+{
+    _DifferenceType __count_true = 0;
+    for (_DifferenceType __i = 0; __i < __len; ++__i)
     {
-        *__mask = __pred(*__first);
-        if (*__mask)
+        __mask[__i] = __pred(__first, __i);
+        __count_true += __mask[__i];
+    }
+    return std::make_pair(__count_true, __len - __count_true);
+}
+
+template <class _RandomAccessIterator, class _DifferenceType, class _IndexPredicate>
+std::pair<_DifferenceType, _DifferenceType>
+__brick_compute_mask(_RandomAccessIterator __first, _DifferenceType __len, _IndexPredicate __pred, bool* __mask,
+                     /*vector=*/std::true_type) noexcept
+{
+    auto __count_true = __unseq_backend::__simd_compute_mask(__first, __len, __pred, __mask);
+    return std::make_pair(__count_true, __len - __count_true);
+}
+
+template <bool __Bounded, class _RandomAccessIterator1, class _RandomAccessIterator2, class _Bound, class _Assigner>
+_Bound
+__brick_copy_by_mask(_RandomAccessIterator1 __first, _Bound __in_len, _RandomAccessIterator2 __result, _Bound __out_len,
+                     bool* __mask, _Assigner __assigner, /*vector=*/std::false_type) noexcept
+{
+    _Bound __i = 0, __j = 0;
+    for (; __i < __in_len; ++__i)
+    {
+        if (__mask[__i])
         {
-            ++__count_true;
+            if constexpr (__Bounded)
+                if (__j == __out_len)
+                    break;
+            __assigner(__first + __i, __result + __j);
+            ++__j;
         }
     }
-    return std::make_pair(__count_true, __size - __count_true);
+    return __i;
 }
 
-template <class _DifferenceType, class _RandomAccessIterator, class _UnaryPredicate>
-std::pair<_DifferenceType, _DifferenceType>
-__brick_calc_mask_1(_RandomAccessIterator __first, _RandomAccessIterator __last, bool* __mask, _UnaryPredicate __pred,
-                    /*vector=*/std::true_type) noexcept
+template <bool __Bounded, class _RandomAccessIterator1, class _RandomAccessIterator2, class _Bound, class _Assigner>
+_Bound
+__brick_copy_by_mask(_RandomAccessIterator1 __first, _Bound __in_len, _RandomAccessIterator2 __result, _Bound __out_len,
+                     bool* __mask, _Assigner __assigner, /*vector=*/std::true_type) noexcept
 {
-    auto __result = __unseq_backend::__simd_calc_mask_1(__first, __last - __first, __mask, __pred);
-    return std::make_pair(__result, (__last - __first) - __result);
-}
-
-template <class _ForwardIterator, class _OutputIterator, class _Assigner>
-void
-__brick_copy_by_mask(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result, bool* __mask,
-                     _Assigner __assigner, /*vector=*/std::false_type) noexcept
-{
-    for (; __first != __last; ++__first, (void) ++__mask)
-    {
-        if (*__mask)
-        {
-            __assigner(__first, __result);
-            ++__result;
-        }
-    }
-}
-
-template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _Assigner>
-void
-__brick_copy_by_mask(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __result,
-                     bool* __restrict __mask, _Assigner __assigner, /*vector=*/std::true_type) noexcept
-{
-#if defined(_PSTL_MONOTONIC_PRESENT)
-    __unseq_backend::__simd_copy_by_mask(__first, __last - __first, __result, __mask, __assigner);
-#else
-    __internal::__brick_copy_by_mask(__first, __last, __result, __mask, __assigner, std::false_type());
-#endif
+    return __unseq_backend::__simd_copy_by_mask<__Bounded>(__first, __in_len, __result, __out_len, __mask, __assigner);
 }
 
 template <class _ForwardIterator, class _OutputIterator1, class _OutputIterator2>
 void
 __brick_partition_by_mask(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator1 __out_true,
-                          _OutputIterator2 __out_false, bool* __mask, /*vector=*/std::false_type) noexcept
+                          _OutputIterator2 __out_false, bool* __mask, /*vector=*/::std::false_type) noexcept
 {
-    for (; __first != __last; ++__first, (void) ++__mask)
+    for (; __first != __last; ++__first, (void)++__mask)
     {
         if (*__mask)
         {
@@ -1098,20 +1252,67 @@ template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _Ran
 void
 __brick_partition_by_mask(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last,
                           _RandomAccessIterator2 __out_true, _RandomAccessIterator3 __out_false, bool* __mask,
-                          /*vector=*/std::true_type) noexcept
+                          /*vector=*/::std::true_type) noexcept
 {
-#if defined(_PSTL_MONOTONIC_PRESENT)
+#if (_PSTL_MONOTONIC_PRESENT || _ONEDPL_MONOTONIC_PRESENT)
     __unseq_backend::__simd_partition_by_mask(__first, __last - __first, __out_true, __out_false, __mask);
 #else
-    __internal::__brick_partition_by_mask(__first, __last, __out_true, __out_false, __mask, std::false_type());
+    __internal::__brick_partition_by_mask(__first, __last, __out_true, __out_false, __mask, ::std::false_type());
 #endif
 }
 
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _DifferenceType,
+          class _RandomAccessIterator2, class _IndexPredicate>
+std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
+__parallel_selective_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first,
+                          _DifferenceType __n, _RandomAccessIterator2 __result, _DifferenceType __n_out,
+                          _IndexPredicate __pred)
+{
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
+    __par_backend::__buffer<bool> __mask_buf(__n);
+    bool* __mask = __mask_buf.get();
+
+    return __internal::__except_handler([&__exec, __n, __first, __result, __pred, __mask, __n_out]() {
+        _DifferenceType __stop_in{__n}, __stop_out{__n_out};
+        __par_backend::__parallel_strict_scan(
+            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __n, _DifferenceType(0),
+            [=](_DifferenceType __i, _DifferenceType __len) { // Reduce
+                return __internal::__brick_compute_mask(__first + __i, __len, __pred, __mask + __i, _IsVector{}).first;
+            },
+            std::plus<_DifferenceType>(), // Combine
+            [=, &__stop_in](_DifferenceType __i, _DifferenceType __len, _DifferenceType __initial) { // Scan
+                if (__initial > __n_out) // The chunk has neither elements to write nor the stop position
+                    return;
+                auto __assign = [](_RandomAccessIterator1 __x, _RandomAccessIterator2 __z) { *__z = *__x; };
+                _DifferenceType __space = __n_out - __initial;
+                if (__space >= __len)
+                {
+                    __internal::__brick_copy_by_mask</*bounded =*/ false>(
+                        __first + __i, __len, __result + __initial, __space, __mask + __i, __assign, _IsVector{});
+                }
+                else
+                {
+                    _DifferenceType __stop = __internal::__brick_copy_by_mask</*bounded =*/ true>(
+                        __first + __i, __len, __result + __initial, __space, __mask + __i, __assign, _IsVector{});
+                    if (__stop != __len)          // Found the position of the first element that cannot be copied
+                        __stop_in = __i + __stop; // Since there is only one such position, there is no data race
+                }
+            },
+            [&__stop_out](_DifferenceType __total) { // Apex
+                if (__total < __stop_out) // Output size is bigger than needed
+                    __stop_out = __total;
+            });
+        return std::make_pair(__first + __stop_in, __result + __stop_out);
+    });
+}
+
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator, class _UnaryPredicate>
 _OutputIterator
 __pattern_copy_if(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result,
                   _UnaryPredicate __pred) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_copy_if(__first, __last, __result, __pred, typename _Tag::__is_vector{});
 }
 
@@ -1121,103 +1322,101 @@ _RandomAccessIterator2
 __pattern_copy_if(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first,
                   _RandomAccessIterator1 __last, _RandomAccessIterator2 __result, _UnaryPredicate __pred)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
-
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type _DifferenceType;
+    using _DifferenceType = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
     const _DifferenceType __n = __last - __first;
     if (_DifferenceType(1) < __n)
     {
-        __par_backend::__buffer<bool> __mask_buf(__n);
-        return __internal::__except_handler(
-            [&__exec, __n, __first, __result, __pred, &__mask_buf]()
-            {
-                bool* __mask = __mask_buf.get();
-                _DifferenceType __m{};
-                __par_backend::__parallel_strict_scan(
-                    __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __n, _DifferenceType(0),
-                    [=](_DifferenceType __i, _DifferenceType __len) { // Reduce
-                        return __internal::__brick_calc_mask_1<_DifferenceType>(__first + __i, __first + (__i + __len),
-                                                                                __mask + __i, __pred, _IsVector{})
-                            .first;
-                    },
-                    std::plus<_DifferenceType>(),                                                // Combine
-                    [=](_DifferenceType __i, _DifferenceType __len, _DifferenceType __initial) { // Scan
-                        __internal::__brick_copy_by_mask(
-                            __first + __i, __first + (__i + __len), __result + __initial, __mask + __i,
-                            [](_RandomAccessIterator1 __x, _RandomAccessIterator2 __z) { *__z = *__x; }, _IsVector{});
-                    },
-                    [&__m](_DifferenceType __total) { __m = __total; });
-                return __result + __m;
-            });
+        return __parallel_selective_copy(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __n, __result, __n,
+                                         __internal::__pred_at_index{__pred}).second;
     }
     // trivial sequence - use serial algorithm
     return __internal::__brick_copy_if(__first, __last, __result, __pred, _IsVector{});
 }
 
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
+          class _UnaryPredicate>
+std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
+__pattern_bounded_copy_if(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first,
+                          typename std::iterator_traits<_RandomAccessIterator1>::difference_type __n,
+                          _RandomAccessIterator2 __result,
+                          typename std::iterator_traits<_RandomAccessIterator2>::difference_type __n_out,
+                          _UnaryPredicate __pred)
+{
+    using _DifferenceType = std::common_type_t<decltype(__n), decltype(__n_out)>;
+    return __parallel_selective_copy(__tag, std::forward<_ExecutionPolicy>(__exec), __first, _DifferenceType(__n),
+                                     __result, _DifferenceType(__n_out), __internal::__pred_at_index{__pred});
+}
+
 //------------------------------------------------------------------------
 // count
 //------------------------------------------------------------------------
 template <class _RandomAccessIterator, class _Predicate>
-typename std::iterator_traits<_RandomAccessIterator>::difference_type
+typename ::std::iterator_traits<_RandomAccessIterator>::difference_type
 __brick_count(_RandomAccessIterator __first, _RandomAccessIterator __last, _Predicate __pred,
-              /* is_vector = */ std::true_type) noexcept
+              /* is_vector = */ ::std::true_type) noexcept
 {
     return __unseq_backend::__simd_count(__first, __last - __first, __pred);
 }
 
 template <class _ForwardIterator, class _Predicate>
-typename std::iterator_traits<_ForwardIterator>::difference_type
+typename ::std::iterator_traits<_ForwardIterator>::difference_type
 __brick_count(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred,
-              /* is_vector = */ std::false_type) noexcept
+              /* is_vector = */ ::std::false_type) noexcept
 {
-    return std::count_if(__first, __last, __pred);
+    return ::std::count_if(__first, __last, __pred);
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
-typename std::iterator_traits<_ForwardIterator>::difference_type
+typename ::std::iterator_traits<_ForwardIterator>::difference_type
 __pattern_count(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_count(__first, __last, __pred, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Predicate>
-typename std::iterator_traits<_RandomAccessIterator>::difference_type
-__pattern_count(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+typename ::std::iterator_traits<_RandomAccessIterator>::difference_type
+__pattern_count(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                 _RandomAccessIterator __last, _Predicate __pred)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type _SizeType;
-    return __internal::__except_handler(
-        [&]()
-        {
-            return __par_backend::__parallel_reduce(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last, _SizeType(0),
-                [__pred](_RandomAccessIterator __begin, _RandomAccessIterator __end, _SizeType __value) -> _SizeType
-                { return __value + __internal::__brick_count(__begin, __end, __pred, _IsVector{}); },
-                std::plus<_SizeType>());
-        });
+    using _SizeType = typename std::iterator_traits<_RandomAccessIterator>::difference_type;
+
+    //trivial pre-checks
+    if (__first == __last)
+        return _SizeType(0);
+
+    return __internal::__except_handler([&]() {
+        return __par_backend::__parallel_reduce(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last, _SizeType(0),
+            [__pred](_RandomAccessIterator __begin, _RandomAccessIterator __end, _SizeType __value) -> _SizeType {
+                return __value + __internal::__brick_count(__begin, __end, __pred, _IsVector{});
+            },
+            ::std::plus<_SizeType>());
+    });
 }
 
 //------------------------------------------------------------------------
 // unique
 //------------------------------------------------------------------------
 
-template <class _RandomAccessIterator, class _BinaryPredicate>
-_RandomAccessIterator
-__brick_unique(_RandomAccessIterator __first, _RandomAccessIterator __last, _BinaryPredicate __pred,
-               /*is_vector=*/std::false_type) noexcept
+template <class _ForwardIterator, class _BinaryPredicate>
+_ForwardIterator
+__brick_unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred,
+               /*is_vector=*/::std::false_type) noexcept
 {
-    return std::unique(__first, __last, __pred);
+    return ::std::unique(__first, __last, __pred);
 }
 
 template <class _RandomAccessIterator, class _BinaryPredicate>
 _RandomAccessIterator
 __brick_unique(_RandomAccessIterator __first, _RandomAccessIterator __last, _BinaryPredicate __pred,
-               /*is_vector=*/std::true_type) noexcept
+               /*is_vector=*/::std::true_type) noexcept
 {
     _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
-    return std::unique(__first, __last, __pred);
+    return ::std::unique(__first, __last, __pred);
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _BinaryPredicate>
@@ -1225,30 +1424,31 @@ _ForwardIterator
 __pattern_unique(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last,
                  _BinaryPredicate __pred) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_unique(__first, __last, __pred, typename _Tag::__is_vector{});
 }
 
 // That function is shared between two algorithms - remove_if (__pattern_remove_if) and unique (pattern unique). But a mask calculation is different.
 // So, a caller passes _CalcMask brick into remove_elements.
-template <class _IsVector, class _ExecutionPolicy, class _ForwardIterator, class _CalcMask>
-_ForwardIterator
-__remove_elements(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _ForwardIterator __first,
-                  _ForwardIterator __last, _CalcMask __calc_mask)
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _CalcMask>
+_RandomAccessIterator
+__remove_elements(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+                  _RandomAccessIterator __last, _CalcMask __calc_mask)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    typedef typename std::iterator_traits<_ForwardIterator>::difference_type _DifferenceType;
-    typedef typename std::iterator_traits<_ForwardIterator>::value_type _Tp;
+    using _DifferenceType = typename std::iterator_traits<_RandomAccessIterator>::difference_type;
+    using _Tp = typename std::iterator_traits<_RandomAccessIterator>::value_type;
     _DifferenceType __n = __last - __first;
     __par_backend::__buffer<bool> __mask_buf(__n);
     // 1. find a first iterator that should be removed
     return __internal::__except_handler([&]() {
         bool* __mask = __mask_buf.get();
         _DifferenceType __min = __par_backend::__parallel_reduce(
-            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), _DifferenceType(0), __n, __n,
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), _DifferenceType(0), __n, __n,
             [__first, __mask, &__calc_mask](_DifferenceType __i, _DifferenceType __j,
-                                            _DifferenceType __local_min) -> _DifferenceType
-            {
+                                            _DifferenceType __local_min) -> _DifferenceType {
                 // Create mask
                 __calc_mask(__mask + __i, __mask + __j, __first + __i);
 
@@ -1264,10 +1464,11 @@ __remove_elements(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _F
                 {
                     return __local_min;
                 }
-                return std::min(__local_min, _DifferenceType(__result - __mask));
+                return ::std::min(__local_min, _DifferenceType(__result - __mask));
             },
-            [](_DifferenceType __local_min1, _DifferenceType __local_min2) -> _DifferenceType
-            { return std::min(__local_min1, __local_min2); });
+            [](_DifferenceType __local_min1, _DifferenceType __local_min2) -> _DifferenceType {
+                return ::std::min(__local_min1, __local_min2);
+            });
 
         // No elements to remove - exit
         if (__min == __n)
@@ -1284,37 +1485,25 @@ __remove_elements(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _F
         // 2. Elements that doesn't satisfy pred are moved to result
         __par_backend::__parallel_strict_scan(
             __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __n, _DifferenceType(0),
-            [__mask](_DifferenceType __i, _DifferenceType __len)
-            {
+            [__mask](_DifferenceType __i, _DifferenceType __len) {
                 return __internal::__brick_count(
                     __mask + __i, __mask + __i + __len, [](bool __val) { return __val; }, _IsVector{});
             },
-            std::plus<_DifferenceType>(),
-            [=](_DifferenceType __i, _DifferenceType __len, _DifferenceType __initial)
-            {
-                __internal::__brick_copy_by_mask(
-                    __first + __i, __first + __i + __len, __result + __initial, __mask + __i,
-                    [](_ForwardIterator __x, _Tp* __z)
-                    {
-                        __internal::__invoke_if_else(
-                            std::conjunction<std::is_trivially_copyable<_Tp>, std::is_trivially_default_constructible<_Tp>>(),
-                            [&]() { *__z = std::move(*__x); },
-                            [&]() { ::new (std::addressof(*__z)) _Tp(std::move(*__x)); });
-                    },
+            ::std::plus<_DifferenceType>(),
+            [=](_DifferenceType __i, _DifferenceType __len, _DifferenceType __initial) {
+                __internal::__brick_copy_by_mask</*bounded*/ false>(
+                    __first + __i, __len, __result + __initial, __len, __mask + __i,
+                    [](_RandomAccessIterator __x, _Tp* __z) { ::new (std::addressof(*__z)) _Tp(std::move(*__x)); },
                     _IsVector{});
             },
             [&__m](_DifferenceType __total) { __m = __total; });
 
         // 3. Elements from result are moved to [first, last)
-        __par_backend::__parallel_for(
-            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __result, __result + __m,
-            [__result, __first](_Tp* __i, _Tp* __j)
-            {
-                __invoke_if_else(
-                    std::conjunction<std::is_trivially_copyable<_Tp>, std::is_trivially_default_constructible<_Tp>>(),
-                    [&]() { __brick_move(__i, __j, __first + (__i - __result), _IsVector{}); },
-                    [&]() { __brick_move_destroy()(__i, __j, __first + (__i - __result), _IsVector{}); });
-            });
+        __par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __result,
+                                      __result + __m, [__result, __first](_Tp* __i, _Tp* __j) {
+                                          __brick_move_destroy<__parallel_tag<_IsVector>>{}(
+                                              __i, __j, __first + (__i - __result), _IsVector{});
+                                      });
         return __first + __m;
     });
 }
@@ -1322,9 +1511,9 @@ __remove_elements(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _F
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _BinaryPredicate>
 _RandomAccessIterator
 __pattern_unique(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
-                 _RandomAccessIterator __last, _BinaryPredicate __pred) noexcept
+                 _RandomAccessIterator __last, _BinaryPredicate __pred)
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator>::reference _ReferenceType;
+    using _ReferenceType = typename std::iterator_traits<_RandomAccessIterator>::reference;
 
     if (__first == __last)
     {
@@ -1336,9 +1525,8 @@ __pattern_unique(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _Ra
         return __internal::__brick_unique(__first, __last, __pred, _IsVector{});
     }
     return __internal::__remove_elements(
-        __tag, std::forward<_ExecutionPolicy>(__exec), ++__first, __last,
-        [&__pred](bool* __b, bool* __e, _RandomAccessIterator __it)
-        {
+        __tag, ::std::forward<_ExecutionPolicy>(__exec), ++__first, __last,
+        [&__pred](bool* __b, bool* __e, _RandomAccessIterator __it) {
             __internal::__brick_walk3(
                 __b, __e, __it - 1, __it,
                 [&__pred](bool& __x, _ReferenceType __y, _ReferenceType __z) { __x = !__pred(__y, __z); }, _IsVector{});
@@ -1351,8 +1539,8 @@ __pattern_unique(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _Ra
 
 template <class _ForwardIterator, class _OutputIterator, class _BinaryPredicate>
 _OutputIterator
-__brick_unique_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result, _BinaryPredicate __pred,
-                    /*vector=*/std::false_type) noexcept
+__brick_unique_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result,
+                    _BinaryPredicate __pred, /*vector=*/std::false_type) noexcept
 {
     return std::unique_copy(__first, __last, __result, __pred);
 }
@@ -1362,11 +1550,37 @@ _RandomAccessIterator2
 __brick_unique_copy(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __result,
                     _BinaryPredicate __pred, /*vector=*/std::true_type) noexcept
 {
-#if defined(_PSTL_MONOTONIC_PRESENT)
-    return __unseq_backend::__simd_unique_copy(__first, __last - __first, __result, __pred);
-#else
-    return std::unique_copy(__first, __last, __result, __pred);
-#endif
+    // Ensure the arguments to *_selective_copy are of signed type, to avoid wraparound in the predicate
+    // when the index equals to zero
+    using _DifferenceType = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
+    _DifferenceType __n = __last - __first;
+    if (__n == 0)
+        return __result;
+
+    *__result++ = *__first++; // Always copy the first element
+    --__n;
+    __result += __unseq_backend::__simd_selective_copy</*bounded =*/ false>(__first, __n, __result, __n,
+                    __internal::__unique_at_index{__pred}).second;
+    return __result;
+}
+
+template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate>
+std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
+__brick_bounded_unique_copy(_RandomAccessIterator1 __first,
+                            typename std::iterator_traits<_RandomAccessIterator1>::difference_type __n,
+                            _RandomAccessIterator2 __result,
+                            typename std::iterator_traits<_RandomAccessIterator2>::difference_type __n_out,
+                            _BinaryPredicate __pred, /*vector=*/std::true_type) noexcept
+{
+    using _DifferenceType = std::common_type_t<decltype(__n), decltype(__n_out)>;
+    if (__n == 0 || __n_out == 0)
+        return {__first, __result};
+
+    *__result++ = *__first++; // Always copy the first element
+    --__n; --__n_out;
+    auto [__stop_in, __stop_out] = __unseq_backend::__simd_selective_copy</*bounded =*/ true>(
+        __first, _DifferenceType(__n), __result, _DifferenceType(__n_out), __internal::__unique_at_index{__pred});
+    return {__first + __stop_in, __result + __stop_out};
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator, class _BinaryPredicate>
@@ -1374,119 +1588,83 @@ _OutputIterator
 __pattern_unique_copy(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last,
                       _OutputIterator __result, _BinaryPredicate __pred) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_unique_copy(__first, __last, __result, __pred, typename _Tag::__is_vector{});
 }
 
-template <class _DifferenceType, class _RandomAccessIterator, class _BinaryPredicate>
-_DifferenceType
-__brick_calc_mask_2(_RandomAccessIterator __first, _RandomAccessIterator __last, bool* __restrict __mask,
-                    _BinaryPredicate __pred, /*vector=*/std::false_type) noexcept
-{
-    _DifferenceType __count = 0;
-    for (; __first != __last; ++__first, (void) ++__mask)
-    {
-        *__mask = !__pred(*__first, *(__first - 1));
-        __count += *__mask;
-    }
-    return __count;
-}
-
-template <class _DifferenceType, class _RandomAccessIterator, class _BinaryPredicate>
-_DifferenceType
-__brick_calc_mask_2(_RandomAccessIterator __first, _RandomAccessIterator __last, bool* __restrict __mask,
-                    _BinaryPredicate __pred, /*vector=*/std::true_type) noexcept
-{
-    return __unseq_backend::__simd_calc_mask_2(__first, __last - __first, __mask, __pred);
-}
-
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
           class _BinaryPredicate>
 _RandomAccessIterator2
 __pattern_unique_copy(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first,
                       _RandomAccessIterator1 __last, _RandomAccessIterator2 __result, _BinaryPredicate __pred)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
-
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type _DifferenceType;
-    const _DifferenceType __n = __last - __first;
+    using _DifferenceType = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
+    _DifferenceType __n = __last - __first;
     if (_DifferenceType(2) < __n)
     {
-        __par_backend::__buffer<bool> __mask_buf(__n);
-        if (_DifferenceType(2) < __n)
-        {
-            return __internal::__except_handler(
-                [&__exec, __n, __first, __result, __pred, &__mask_buf]()
-                {
-                    bool* __mask = __mask_buf.get();
-                    _DifferenceType __m{};
-                    __par_backend::__parallel_strict_scan(
-                        __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __n, _DifferenceType(0),
-                        [=](_DifferenceType __i, _DifferenceType __len) -> _DifferenceType { // Reduce
-                            _DifferenceType __extra = 0;
-                            if (__i == 0)
-                            {
-                                // Special boundary case
-                                __mask[__i] = true;
-                                if (--__len == 0)
-                                    return 1;
-                                ++__i;
-                                ++__extra;
-                            }
-                            return __internal::__brick_calc_mask_2<_DifferenceType>(
-                                       __first + __i, __first + (__i + __len), __mask + __i, __pred, _IsVector{}) +
-                                   __extra;
-                        },
-                        std::plus<_DifferenceType>(),                                                // Combine
-                        [=](_DifferenceType __i, _DifferenceType __len, _DifferenceType __initial) { // Scan
-                            // Phase 2 is same as for __pattern_copy_if
-                            __internal::__brick_copy_by_mask(
-                                __first + __i, __first + (__i + __len), __result + __initial, __mask + __i,
-                                [](_RandomAccessIterator1 __x, _RandomAccessIterator2 __z) { *__z = *__x; },
-                                _IsVector{});
-                        },
-                        [&__m](_DifferenceType __total) { __m = __total; });
-                    return __result + __m;
-                });
-        }
+        *__result++ = *__first++; // Always copy the first element
+        --__n;
+        return __parallel_selective_copy(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __n, __result, __n,
+                                         __internal::__unique_at_index{__pred}).second;
     }
     // trivial sequence - use serial algorithm
     return __internal::__brick_unique_copy(__first, __last, __result, __pred, _IsVector{});
 }
 
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _DifferenceType,
+          class _RandomAccessIterator2, class _BinaryPredicate>
+std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
+__pattern_bounded_unique_copy(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec,
+                              _RandomAccessIterator1 __first, _DifferenceType __n, _RandomAccessIterator2 __result,
+                              _DifferenceType __n_out, _BinaryPredicate __pred)
+{
+    if (__n == 0 || __n_out == 0)
+        return {__first, __result};
+
+    *__result++ = *__first++; // Always copy the first element
+    --__n; --__n_out;
+    return __parallel_selective_copy(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __n, __result, __n_out,
+                                     __internal::__unique_at_index{__pred});
+}
+
 //------------------------------------------------------------------------
 // reverse
 //------------------------------------------------------------------------
 template <class _BidirectionalIterator>
 void
-__brick_reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, /*__is_vector=*/std::false_type) noexcept
+__brick_reverse(_BidirectionalIterator __first, _BidirectionalIterator __last,
+                /*__is_vector=*/::std::false_type) noexcept
 {
-    std::reverse(__first, __last);
+    ::std::reverse(__first, __last);
 }
 
 template <class _RandomAccessIterator>
 void
-__brick_reverse(_RandomAccessIterator __first, _RandomAccessIterator __last, /*__is_vector=*/std::true_type) noexcept
+__brick_reverse(_RandomAccessIterator __first, _RandomAccessIterator __last,
+                /*__is_vector=*/::std::true_type) noexcept
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator>::reference _ReferenceType;
+    using _ReferenceType = typename std::iterator_traits<_RandomAccessIterator>::reference;
 
     const auto __n = (__last - __first) / 2;
-    __unseq_backend::__simd_walk_2(__first, __n, std::reverse_iterator<_RandomAccessIterator>(__last),
+    __unseq_backend::__simd_walk_n(__n,
                                    [](_ReferenceType __x, _ReferenceType __y) {
-                                       using std::swap;
+                                       using ::std::swap;
                                        swap(__x, __y);
-                                   });
+                                   },
+                                   __first, std::reverse_iterator<_RandomAccessIterator>(__last));
 }
 
 // this brick is called in parallel version, so we can use iterator arithmetic
 template <class _BidirectionalIterator>
 void
 __brick_reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, _BidirectionalIterator __d_last,
-                /*is_vector=*/std::false_type) noexcept
+                /*is_vector=*/::std::false_type) noexcept
 {
-    for (--__d_last; __first != __last; ++__first, (void) --__d_last)
+    for (; __first != __last; ++__first)
     {
-        using std::iter_swap;
-        iter_swap(__first, __d_last);
+        using ::std::iter_swap;
+        iter_swap(__first, --__d_last);
     }
 }
 
@@ -1494,35 +1672,45 @@ __brick_reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, _
 template <class _RandomAccessIterator>
 void
 __brick_reverse(_RandomAccessIterator __first, _RandomAccessIterator __last, _RandomAccessIterator __d_last,
-                /*is_vector=*/std::true_type) noexcept
+                /*is_vector=*/::std::true_type) noexcept
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator>::reference _ReferenceType;
+    using _ReferenceType = typename std::iterator_traits<_RandomAccessIterator>::reference;
 
-    __unseq_backend::__simd_walk_2(__first, __last - __first, std::reverse_iterator<_RandomAccessIterator>(__d_last),
+    __unseq_backend::__simd_walk_n(__last - __first,
                                    [](_ReferenceType __x, _ReferenceType __y) {
-                                       using std::swap;
+                                       using ::std::swap;
                                        swap(__x, __y);
-                                   });
+                                   },
+                                   __first, std::reverse_iterator<_RandomAccessIterator>(__d_last));
 }
 
 template <class _Tag, class _ExecutionPolicy, class _BidirectionalIterator>
 void
 __pattern_reverse(_Tag, _ExecutionPolicy&&, _BidirectionalIterator __first, _BidirectionalIterator __last) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     __internal::__brick_reverse(__first, __last, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator>
 void
-__pattern_reverse(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+__pattern_reverse(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                   _RandomAccessIterator __last)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    __par_backend::__parallel_for(
-        __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __first + (__last - __first) / 2,
-        [__first, __last](_RandomAccessIterator __inner_first, _RandomAccessIterator __inner_last)
-        { __internal::__brick_reverse(__inner_first, __inner_last, __last - (__inner_first - __first), _IsVector{}); });
+    if (__first == __last)
+        return;
+
+    __internal::__except_handler([&]() {
+        __par_backend::__parallel_for(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __first + (__last - __first) / 2,
+            [__first, __last](_RandomAccessIterator __inner_first, _RandomAccessIterator __inner_last) {
+                __internal::__brick_reverse(__inner_first, __inner_last, __last - (__inner_first - __first),
+                                            _IsVector{});
+            });
+    });
 }
 
 //------------------------------------------------------------------------
@@ -1532,21 +1720,22 @@ __pattern_reverse(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _R
 template <class _BidirectionalIterator, class _OutputIterator>
 _OutputIterator
 __brick_reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __d_first,
-                     /*is_vector=*/std::false_type) noexcept
+                     /*is_vector=*/::std::false_type) noexcept
 {
-    return std::reverse_copy(__first, __last, __d_first);
+    return ::std::reverse_copy(__first, __last, __d_first);
 }
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2>
 _RandomAccessIterator2
 __brick_reverse_copy(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __d_first,
-                     /*is_vector=*/std::true_type) noexcept
+                     /*is_vector=*/::std::true_type) noexcept
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::reference _ReferenceType1;
-    typedef typename std::iterator_traits<_RandomAccessIterator2>::reference _ReferenceType2;
+    using _ReferenceType1 = typename std::iterator_traits<_RandomAccessIterator1>::reference;
+    using _ReferenceType2 = typename std::iterator_traits<_RandomAccessIterator2>::reference;
 
-    return __unseq_backend::__simd_walk_2(std::reverse_iterator<_RandomAccessIterator1>(__last), __last - __first,
-                                          __d_first, [](_ReferenceType1 __x, _ReferenceType2 __y) { __y = __x; });
+    return __unseq_backend::__simd_walk_n(__last - __first,
+        [](_ReferenceType1 __x, _ReferenceType2 __y) { __y = __x; },
+        std::reverse_iterator<_RandomAccessIterator1>(__last), __d_first);
 }
 
 template <class _Tag, class _ExecutionPolicy, class _BidirectionalIterator, class _OutputIterator>
@@ -1554,25 +1743,32 @@ _OutputIterator
 __pattern_reverse_copy(_Tag, _ExecutionPolicy&&, _BidirectionalIterator __first, _BidirectionalIterator __last,
                        _OutputIterator __d_first) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_reverse_copy(__first, __last, __d_first, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2>
 _RandomAccessIterator2
-__pattern_reverse_copy(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first,
+__pattern_reverse_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first,
                        _RandomAccessIterator1 __last, _RandomAccessIterator2 __d_first)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
     auto __len = __last - __first;
-    __par_backend::__parallel_for(
-        __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-        [__first, __len, __d_first](_RandomAccessIterator1 __inner_first, _RandomAccessIterator1 __inner_last)
-        {
-            __internal::__brick_reverse_copy(__inner_first, __inner_last,
-                                             __d_first + (__len - (__inner_last - __first)), _IsVector{});
-        });
-    return __d_first + __len;
+
+    if (__len == 0)
+        return __d_first;
+
+    return __internal::__except_handler([&]() {
+        __par_backend::__parallel_for(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+            [__first, __len, __d_first](_RandomAccessIterator1 __inner_first, _RandomAccessIterator1 __inner_last) {
+                __internal::__brick_reverse_copy(__inner_first, __inner_last,
+                                                 __d_first + (__len - (__inner_last - __first)), _IsVector{});
+            });
+        return __d_first + __len;
+    });
 }
 
 //------------------------------------------------------------------------
@@ -1581,20 +1777,15 @@ __pattern_reverse_copy(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exe
 template <class _ForwardIterator>
 _ForwardIterator
 __brick_rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last,
-               /*is_vector=*/std::false_type) noexcept
+               /*is_vector=*/::std::false_type) noexcept
 {
-#if defined(_PSTL_CPP11_STD_ROTATE_BROKEN)
-    std::rotate(__first, __middle, __last);
-    return std::next(__first, std::distance(__middle, __last));
-#else
-    return std::rotate(__first, __middle, __last);
-#endif
+    return ::std::rotate(__first, __middle, __last);
 }
 
 template <class _RandomAccessIterator>
 _RandomAccessIterator
 __brick_rotate(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
-               /*is_vector=*/std::true_type) noexcept
+               /*is_vector=*/::std::true_type) noexcept
 {
     auto __n = __last - __first;
     auto __m = __middle - __first;
@@ -1606,7 +1797,7 @@ __brick_rotate(_RandomAccessIterator __first, _RandomAccessIterator __middle, _R
 
     while (__n > 1 && __m > 0)
     {
-        using std::iter_swap;
+        using ::std::iter_swap;
         const auto __m_2 = __m * 2;
         if (__is_left)
         {
@@ -1637,68 +1828,72 @@ _ForwardIterator
 __pattern_rotate(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __middle,
                  _ForwardIterator __last) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_rotate(__first, __middle, __last, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator>
 _RandomAccessIterator
-__pattern_rotate(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+__pattern_rotate(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                  _RandomAccessIterator __middle, _RandomAccessIterator __last)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    typedef typename std::iterator_traits<_RandomAccessIterator>::value_type _Tp;
+    using _Tp = typename std::iterator_traits<_RandomAccessIterator>::value_type;
     auto __n = __last - __first;
     auto __m = __middle - __first;
     if (__m <= __n / 2)
     {
         __par_backend::__buffer<_Tp> __buf(__n - __m);
-        return __internal::__except_handler(
-            [&__exec, __n, __m, __first, __middle, __last, &__buf]()
-            {
-                _Tp* __result = __buf.get();
-                __par_backend::__parallel_for(
-                    __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __middle, __last,
-                    [__middle, __result](_RandomAccessIterator __b, _RandomAccessIterator __e)
-                    { __internal::__brick_uninitialized_move(__b, __e, __result + (__b - __middle), _IsVector{}); });
+        return __internal::__except_handler([&__exec, __n, __m, __first, __middle, __last, &__buf]() {
+            _Tp* __result = __buf.get();
+            __par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __middle, __last,
+                                          [__middle, __result](_RandomAccessIterator __b, _RandomAccessIterator __e) {
+                                              __internal::__brick_uninitialized_move(
+                                                  __b, __e, __result + (__b - __middle), _IsVector{});
+                                          });
 
-                __par_backend::__parallel_for(
-                    __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __middle,
-                    [__last, __middle](_RandomAccessIterator __b, _RandomAccessIterator __e)
-                    { __internal::__brick_move(__b, __e, __b + (__last - __middle), _IsVector{}); });
+            __par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __middle,
+                                          [__last, __middle](_RandomAccessIterator __b, _RandomAccessIterator __e) {
+                                              __internal::__brick_move<__parallel_tag<_IsVector>>{}(
+                                                  __b, __e, __b + (__last - __middle), _IsVector{});
+                                          });
 
-                __par_backend::__parallel_for(
-                    __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __result, __result + (__n - __m),
-                    [__first, __result](_Tp* __b, _Tp* __e)
-                    { __brick_move_destroy()(__b, __e, __first + (__b - __result), _IsVector{}); });
+            __par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __result,
+                                          __result + (__n - __m), [__first, __result](_Tp* __b, _Tp* __e) {
+                                              __brick_move_destroy<__parallel_tag<_IsVector>>{}(
+                                                  __b, __e, __first + (__b - __result), _IsVector{});
+                                          });
 
-                return __first + (__last - __middle);
-            });
+            return __first + (__last - __middle);
+        });
     }
     else
     {
         __par_backend::__buffer<_Tp> __buf(__m);
-        return __internal::__except_handler(
-            [&__exec, __n, __m, __first, __middle, __last, &__buf]()
-            {
-                _Tp* __result = __buf.get();
-                __par_backend::__parallel_for(
-                    __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __middle,
-                    [__first, __result](_RandomAccessIterator __b, _RandomAccessIterator __e)
-                    { __internal::__brick_uninitialized_move(__b, __e, __result + (__b - __first), _IsVector{}); });
+        return __internal::__except_handler([&__exec, __n, __m, __first, __middle, __last, &__buf]() {
+            _Tp* __result = __buf.get();
+            __par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __middle,
+                                          [__first, __result](_RandomAccessIterator __b, _RandomAccessIterator __e) {
+                                              __internal::__brick_uninitialized_move(
+                                                  __b, __e, __result + (__b - __first), _IsVector{});
+                                          });
 
-                __par_backend::__parallel_for(
-                    __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __middle, __last,
-                    [__first, __middle](_RandomAccessIterator __b, _RandomAccessIterator __e)
-                    { __internal::__brick_move(__b, __e, __first + (__b - __middle), _IsVector{}); });
+            __par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __middle, __last,
+                                          [__first, __middle](_RandomAccessIterator __b, _RandomAccessIterator __e) {
+                                              __internal::__brick_move<__parallel_tag<_IsVector>>{}(
+                                                  __b, __e, __first + (__b - __middle), _IsVector{});
+                                          });
 
-                __par_backend::__parallel_for(
-                    __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __result, __result + __m,
-                    [__n, __m, __first, __result](_Tp* __b, _Tp* __e)
-                    { __brick_move_destroy()(__b, __e, __first + ((__n - __m) + (__b - __result)), _IsVector{}); });
+            __par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __result,
+                                          __result + __m, [__n, __m, __first, __result](_Tp* __b, _Tp* __e) {
+                                              __brick_move_destroy<__parallel_tag<_IsVector>>{}(
+                                                  __b, __e, __first + ((__n - __m) + (__b - __result)), _IsVector{});
+                                          });
 
-                return __first + (__last - __middle);
-            });
+            return __first + (__last - __middle);
+        });
     }
 }
 
@@ -1706,61 +1901,69 @@ __pattern_rotate(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _Ra
 // rotate_copy
 //------------------------------------------------------------------------
 
-template <class _ForwardIterator, class _OutputIterator>
-_OutputIterator
-__brick_rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last,
-                    _OutputIterator __result, /*__is_vector=*/std::false_type) noexcept
-{
-    return std::rotate_copy(__first, __middle, __last, __result);
-}
-
-template <class _RandomAccessIterator1, class _RandomAccessIterator2>
-_RandomAccessIterator2
-__brick_rotate_copy(_RandomAccessIterator1 __first, _RandomAccessIterator1 __middle, _RandomAccessIterator1 __last,
-                    _RandomAccessIterator2 __result, /*__is_vector=*/std::true_type) noexcept
-{
-    _RandomAccessIterator2 __res = __internal::__brick_copy(__middle, __last, __result, std::true_type());
-    return __internal::__brick_copy(__first, __middle, __res, std::true_type());
-}
-
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator>
 _OutputIterator
-__pattern_rotate_copy(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __middle,
-                      _ForwardIterator __last, _OutputIterator __result) noexcept
+__brick_rotate_copy(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __middle,
+                    _ForwardIterator __last, _OutputIterator __result) noexcept
 {
-    return __internal::__brick_rotate_copy(__first, __middle, __last, __result, typename _Tag::__is_vector{});
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
+    return ::std::rotate_copy(__first, __middle, __last, __result);
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2>
 _RandomAccessIterator2
-__pattern_rotate_copy(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first,
+__brick_rotate_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1 __first,
+                    _RandomAccessIterator1 __middle, _RandomAccessIterator1 __last,
+                    _RandomAccessIterator2 __result) noexcept
+{
+    _RandomAccessIterator2 __res = __brick_copy<__parallel_tag<_IsVector>>{}(__middle, __last, __result);
+    return __internal::__brick_copy<__parallel_tag<_IsVector>>{}(__first, __middle, __res);
+}
+
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator>
+_OutputIterator
+__pattern_rotate_copy(_Tag __tag, _ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __middle,
+                      _ForwardIterator __last, _OutputIterator __result) noexcept
+{
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
+    return __internal::__brick_rotate_copy(__tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __middle, __last,
+                                           __result);
+}
+
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2>
+_RandomAccessIterator2
+__pattern_rotate_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first,
                       _RandomAccessIterator1 __middle, _RandomAccessIterator1 __last, _RandomAccessIterator2 __result)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    __par_backend::__parallel_for(
-        __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-        [__first, __last, __middle, __result](_RandomAccessIterator1 __b, _RandomAccessIterator1 __e)
-        {
-            if (__b > __middle)
-            {
-                __internal::__brick_copy(__b, __e, __result + (__b - __middle), _IsVector{});
-            }
-            else
-            {
-                _RandomAccessIterator2 __new_result = __result + ((__last - __middle) + (__b - __first));
-                if (__e < __middle)
+    return __internal::__except_handler([&]() {
+        __par_backend::__parallel_for(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+            [__first, __last, __middle, __result](_RandomAccessIterator1 __b, _RandomAccessIterator1 __e) {
+                __internal::__brick_copy<__parallel_tag<_IsVector>> __copy{};
+                if (__b > __middle)
                 {
-                    __internal::__brick_copy(__b, __e, __new_result, _IsVector{});
+                    __copy(__b, __e, __result + (__b - __middle), _IsVector{});
                 }
                 else
                 {
-                    __internal::__brick_copy(__b, __middle, __new_result, _IsVector{});
-                    __internal::__brick_copy(__middle, __e, __result, _IsVector{});
+                    _RandomAccessIterator2 __new_result = __result + ((__last - __middle) + (__b - __first));
+                    if (__e < __middle)
+                    {
+                        __copy(__b, __e, __new_result, _IsVector{});
+                    }
+                    else
+                    {
+                        __copy(__b, __middle, __new_result, _IsVector{});
+                        __copy(__middle, __e, __result, _IsVector{});
+                    }
                 }
-            }
-        });
-    return __result + (__last - __first);
+            });
+        return __result + (__last - __first);
+    });
 }
 
 //------------------------------------------------------------------------
@@ -1770,17 +1973,17 @@ __pattern_rotate_copy(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec
 template <class _ForwardIterator, class _UnaryPredicate>
 bool
 __brick_is_partitioned(_ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred,
-                       /*is_vector=*/std::false_type) noexcept
+                       /*is_vector=*/::std::false_type) noexcept
 {
-    return std::is_partitioned(__first, __last, __pred);
+    return ::std::is_partitioned(__first, __last, __pred);
 }
 
 template <class _RandomAccessIterator, class _UnaryPredicate>
 bool
 __brick_is_partitioned(_RandomAccessIterator __first, _RandomAccessIterator __last, _UnaryPredicate __pred,
-                       /*is_vector=*/std::true_type) noexcept
+                       /*is_vector=*/::std::true_type) noexcept
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type _SizeType;
+    using _SizeType = typename std::iterator_traits<_RandomAccessIterator>::difference_type;
     if (__first == __last)
     {
         return true;
@@ -1807,108 +2010,108 @@ bool
 __pattern_is_partitioned(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last,
                          _UnaryPredicate __pred) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_is_partitioned(__first, __last, __pred, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _UnaryPredicate>
 bool
-__pattern_is_partitioned(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+__pattern_is_partitioned(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                          _RandomAccessIterator __last, _UnaryPredicate __pred)
 {
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
+
+    //trivial pre-checks
     if (__first == __last)
-    {
         return true;
-    }
-    else
-    {
-        using __backend_tag = typename decltype(__tag)::__backend_tag;
 
-        return __internal::__except_handler([&]() {
-            // State of current range:
-            // broken     - current range is not partitioned by pred
-            // all_true   - all elements in current range satisfy pred
-            // all_false  - all elements in current range don't satisfy pred
-            // true_false - elements satisfy pred are placed before elements that don't satisfy pred
-            enum _ReduceType
-            {
-                __not_init = -1,
-                __broken,
-                __all_true,
-                __all_false,
-                __true_false
-            };
-            _ReduceType __init = __not_init;
+    return __internal::__except_handler([&]() {
+        // State of current range:
+        // broken     - current range is not partitioned by pred
+        // all_true   - all elements in current range satisfy pred
+        // all_false  - all elements in current range don't satisfy pred
+        // true_false - elements satisfy pred are placed before elements that don't satisfy pred
+        enum _ReduceRes
+        {
+            __not_init = -1,
+            __broken,
+            __all_true,
+            __all_false,
+            __true_false
+        };
+        // Array with states that we'll have when state from the left branch is merged with state from the right branch.
+        // State is calculated by formula: new_state = table[left_state * 4 + right_state]
+        const _ReduceRes __table[] = {__broken,     __broken,     __broken,     __broken, __broken,    __all_true,
+                                      __true_false, __true_false, __broken,     __broken, __all_false, __broken,
+                                      __broken,     __broken,     __true_false, __broken};
+        struct _ReduceType
+        {
+            _ReduceRes __val;
+            _RandomAccessIterator __pos;
+        };
+        //a commutative combiner
+        auto __combine = [&__table](_ReduceType __x, _ReduceType __y) {
+            return __x.__pos > __y.__pos ? _ReduceType{__table[__y.__val * 4 + __x.__val], __y.__pos}
+                                         : _ReduceType{__table[__x.__val * 4 + __y.__val], __x.__pos};
+        };
 
-            // Array with states that we'll have when state from the left branch is merged with state from the right branch.
-            // State is calculated by formula: new_state = table[left_state * 4 + right_state]
-            _ReduceType __table[] = {__broken,     __broken,     __broken,     __broken, __broken,    __all_true,
-                                     __true_false, __true_false, __broken,     __broken, __all_false, __broken,
-                                     __broken,     __broken,     __true_false, __broken};
+        const _ReduceType __identity{__not_init, __last};
 
-            __init = __par_backend::__parallel_reduce(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last, __init,
-                [&__pred, &__table](_RandomAccessIterator __i, _RandomAccessIterator __j,
-                                    _ReduceType __value) -> _ReduceType
+        _ReduceType __result = __par_backend::__parallel_reduce(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last, __identity,
+            [&__pred, __combine](_RandomAccessIterator __i, _RandomAccessIterator __j,
+                                 _ReduceType __value) -> _ReduceType {
+                if (__value.__val == __broken)
+                    return _ReduceType{__broken, __i};
+
+                _ReduceType __res{__not_init, __i};
+                // if first element satisfy pred
+                if (__pred(*__i))
                 {
-                    if (__value == __broken)
+                    // find first element that don't satisfy pred
+                    _RandomAccessIterator __x =
+                        __internal::__brick_find_if(__i + 1, __j, __not_pred<_UnaryPredicate&>(__pred), _IsVector{});
+                    if (__x != __j)
                     {
-                        return __broken;
-                    }
-                    _ReduceType __res = __not_init;
-                    // if first element satisfy pred
-                    if (__pred(*__i))
-                    {
-                        // find first element that don't satisfy pred
-                        _RandomAccessIterator __x =
-                            __internal::__brick_find_if(__i + 1, __j, std::not_fn(__pred), _IsVector{});
-                        if (__x != __j)
-                        {
-                            // find first element after "x" that satisfy pred
-                            _RandomAccessIterator __y = __internal::__brick_find_if(__x + 1, __j, __pred, _IsVector{});
-                            // if it was found then range isn't partitioned by pred
-                            if (__y != __j)
-                            {
-                                return __broken;
-                            }
-                            else
-                            {
-                                __res = __true_false;
-                            }
-                        }
-                        else
-                        {
-                            __res = __all_true;
-                        }
+                        // find first element after "x" that satisfy pred
+                        _RandomAccessIterator __y = __internal::__brick_find_if(__x + 1, __j, __pred, _IsVector{});
+                        // if it was found then range isn't partitioned by pred
+                        if (__y != __j)
+                            return _ReduceType{__broken, __i};
+
+                        __res = _ReduceType{__true_false, __i};
                     }
                     else
-                    { // if first element doesn't satisfy pred
-                        // then we should find the first element that satisfy pred.
-                        // If we found it then range isn't partitioned by pred
-                        if (__internal::__brick_find_if(__i + 1, __j, __pred, _IsVector{}) != __j)
-                        {
-                            return __broken;
-                        }
-                        else
-                        {
-                            __res = __all_false;
-                        }
-                    }
-                    // if we have value from left range then we should calculate the result
-                    return (__value == -1) ? __res : __table[__value * 4 + __res];
-                },
+                        __res = _ReduceType{__all_true, __i};
+                }
+                else
+                { // if first element doesn't satisfy pred
+                    // then we should find the first element that satisfy pred.
+                    // If we found it then range isn't partitioned by pred
+                    if (__internal::__brick_find_if(__i + 1, __j, __pred, _IsVector{}) != __j)
+                        return _ReduceType{__broken, __i};
 
-                [&__table](_ReduceType __val1, _ReduceType __val2) -> _ReduceType
-                {
-                    if (__val1 == __broken || __val2 == __broken)
-                    {
-                        return __broken;
-                    }
-                    // calculate the result for new big range
-                    return __table[__val1 * 4 + __val2];
-                });
-            return __init != __broken;
-        });
-    }
+                    __res = _ReduceType{__all_false, __i};
+                }
+                // if we have value from left range then we should calculate the result
+                return (__value.__val == __not_init) ? __res : __combine(__value, __res);
+            },
+
+            [__combine](_ReduceType __val1, _ReduceType __val2) -> _ReduceType {
+                if (__val1.__val == __not_init)
+                    return __val2;
+                if (__val2.__val == __not_init)
+                    return __val1;
+                assert(__val1.__val != __not_init && __val2.__val != __not_init);
+
+                if (__val1.__val == __broken || __val2.__val == __broken)
+                    return _ReduceType{__broken, __val1.__pos};
+                // calculate the result for new big range
+                return __combine(__val1, __val2);
+            });
+        return __result.__val != __broken;
+    });
 }
 
 //------------------------------------------------------------------------
@@ -1918,18 +2121,18 @@ __pattern_is_partitioned(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __e
 template <class _ForwardIterator, class _UnaryPredicate>
 _ForwardIterator
 __brick_partition(_ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred,
-                  /*is_vector=*/std::false_type) noexcept
+                  /*is_vector=*/::std::false_type) noexcept
 {
-    return std::partition(__first, __last, __pred);
+    return ::std::partition(__first, __last, __pred);
 }
 
 template <class _RandomAccessIterator, class _UnaryPredicate>
 _RandomAccessIterator
 __brick_partition(_RandomAccessIterator __first, _RandomAccessIterator __last, _UnaryPredicate __pred,
-                  /*is_vector=*/std::true_type) noexcept
+                  /*is_vector=*/::std::true_type) noexcept
 {
     _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
-    return std::partition(__first, __last, __pred);
+    return ::std::partition(__first, __last, __pred);
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate>
@@ -1937,15 +2140,17 @@ _ForwardIterator
 __pattern_partition(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last,
                     _UnaryPredicate __pred) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_partition(__first, __last, __pred, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _UnaryPredicate>
 _RandomAccessIterator
-__pattern_partition(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+__pattern_partition(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                     _RandomAccessIterator __last, _UnaryPredicate __pred)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
     // partitioned range: elements before pivot satisfy pred (true part),
     //                    elements after pivot don't satisfy pred (false part)
@@ -1960,8 +2165,7 @@ __pattern_partition(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec,
         _PartitionRange __init{__last, __last, __last};
 
         // lambda for merging two partitioned ranges to one partitioned range
-        auto __reductor = [&__exec](_PartitionRange __val1, _PartitionRange __val2) -> _PartitionRange
-        {
+        auto __reductor = [&__exec](_PartitionRange __val1, _PartitionRange __val2) -> _PartitionRange {
             auto __size1 = __val1.__end - __val1.__pivot;
             auto __size2 = __val2.__pivot - __val2.__begin;
             auto __new_begin = __val2.__begin - (__val1.__end - __val1.__begin);
@@ -1976,7 +2180,7 @@ __pattern_partition(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec,
             else if (__size2 > __size1)
             {
                 __par_backend::__parallel_for(
-                    __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __val1.__pivot, __val1.__pivot + __size1,
+                    __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __val1.__pivot, __val1.__pivot + __size1,
                     [__val1, __val2, __size1](_RandomAccessIterator __i, _RandomAccessIterator __j) {
                         __internal::__brick_swap_ranges(__i, __j, (__val2.__pivot - __size1) + (__i - __val1.__pivot),
                                                         _IsVector{});
@@ -1987,7 +2191,7 @@ __pattern_partition(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec,
             else
             {
                 __par_backend::__parallel_for(
-                    __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __val1.__pivot, __val1.__pivot + __size2,
+                    __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __val1.__pivot, __val1.__pivot + __size2,
                     [__val1, __val2](_RandomAccessIterator __i, _RandomAccessIterator __j) {
                         __internal::__brick_swap_ranges(__i, __j, __val2.__begin + (__i - __val1.__pivot), _IsVector{});
                     });
@@ -1996,10 +2200,9 @@ __pattern_partition(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec,
         };
 
         _PartitionRange __result = __par_backend::__parallel_reduce(
-            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last, __init,
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last, __init,
             [__pred, __reductor](_RandomAccessIterator __i, _RandomAccessIterator __j,
-                                 _PartitionRange __value) -> _PartitionRange
-            {
+                                 _PartitionRange __value) -> _PartitionRange {
                 //1. serial partition
                 _RandomAccessIterator __pivot = __internal::__brick_partition(__i, __j, __pred, _IsVector{});
 
@@ -2018,18 +2221,18 @@ __pattern_partition(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec,
 template <class _BidirectionalIterator, class _UnaryPredicate>
 _BidirectionalIterator
 __brick_stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _UnaryPredicate __pred,
-                         /*__is_vector=*/std::false_type) noexcept
+                         /*__is_vector=*/::std::false_type) noexcept
 {
-    return std::stable_partition(__first, __last, __pred);
+    return ::std::stable_partition(__first, __last, __pred);
 }
 
 template <class _RandomAccessIterator, class _UnaryPredicate>
 _RandomAccessIterator
 __brick_stable_partition(_RandomAccessIterator __first, _RandomAccessIterator __last, _UnaryPredicate __pred,
-                         /*__is_vector=*/std::true_type) noexcept
+                         /*__is_vector=*/::std::true_type) noexcept
 {
     _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
-    return std::stable_partition(__first, __last, __pred);
+    return ::std::stable_partition(__first, __last, __pred);
 }
 
 template <class _Tag, class _ExecutionPolicy, class _BidirectionalIterator, class _UnaryPredicate>
@@ -2037,15 +2240,17 @@ _BidirectionalIterator
 __pattern_stable_partition(_Tag, _ExecutionPolicy&&, _BidirectionalIterator __first, _BidirectionalIterator __last,
                            _UnaryPredicate __pred) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_stable_partition(__first, __last, __pred, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _UnaryPredicate>
 _RandomAccessIterator
-__pattern_stable_partition(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
-                           _RandomAccessIterator __last, _UnaryPredicate __pred) noexcept
+__pattern_stable_partition(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+                           _RandomAccessIterator __last, _UnaryPredicate __pred)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
     // partitioned range: elements before pivot satisfy pred (true part),
     //                    elements after pivot don't satisfy pred (false part)
@@ -2060,8 +2265,7 @@ __pattern_stable_partition(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& _
         _PartitionRange __init{__last, __last, __last};
 
         // lambda for merging two partitioned ranges to one partitioned range
-        auto __reductor = [](_PartitionRange __val1, _PartitionRange __val2) -> _PartitionRange
-        {
+        auto __reductor = [](_PartitionRange __val1, _PartitionRange __val2) -> _PartitionRange {
             auto __size1 = __val1.__end - __val1.__pivot;
             auto __new_begin = __val2.__begin - (__val1.__end - __val1.__begin);
 
@@ -2080,10 +2284,9 @@ __pattern_stable_partition(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& _
         };
 
         _PartitionRange __result = __par_backend::__parallel_reduce(
-            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last, __init,
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last, __init,
             [&__pred, __reductor](_RandomAccessIterator __i, _RandomAccessIterator __j,
-                                  _PartitionRange __value) -> _PartitionRange
-            {
+                                  _PartitionRange __value) -> _PartitionRange {
                 //1. serial stable_partition
                 _RandomAccessIterator __pivot = __internal::__brick_stable_partition(__i, __j, __pred, _IsVector{});
 
@@ -2100,74 +2303,75 @@ __pattern_stable_partition(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& _
 //------------------------------------------------------------------------
 
 template <class _ForwardIterator, class _OutputIterator1, class _OutputIterator2, class _UnaryPredicate>
-std::pair<_OutputIterator1, _OutputIterator2>
+::std::pair<_OutputIterator1, _OutputIterator2>
 __brick_partition_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator1 __out_true,
-                       _OutputIterator2 __out_false, _UnaryPredicate __pred, /*is_vector=*/std::false_type) noexcept
+                       _OutputIterator2 __out_false, _UnaryPredicate __pred, /*is_vector=*/::std::false_type) noexcept
 {
-    return std::partition_copy(__first, __last, __out_true, __out_false, __pred);
+    return ::std::partition_copy(__first, __last, __out_true, __out_false, __pred);
 }
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _RandomAccessIterator3,
           class _UnaryPredicate>
-std::pair<_RandomAccessIterator2, _RandomAccessIterator3>
+::std::pair<_RandomAccessIterator2, _RandomAccessIterator3>
 __brick_partition_copy(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _RandomAccessIterator2 __out_true,
                        _RandomAccessIterator3 __out_false, _UnaryPredicate __pred,
-                       /*is_vector=*/std::true_type) noexcept
+                       /*is_vector=*/::std::true_type) noexcept
 {
-#if defined(_PSTL_MONOTONIC_PRESENT)
+#if (_PSTL_MONOTONIC_PRESENT || _ONEDPL_MONOTONIC_PRESENT)
     return __unseq_backend::__simd_partition_copy(__first, __last - __first, __out_true, __out_false, __pred);
 #else
-    return std::partition_copy(__first, __last, __out_true, __out_false, __pred);
+    return ::std::partition_copy(__first, __last, __out_true, __out_false, __pred);
 #endif
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator1, class _OutputIterator2,
           class _UnaryPredicate>
-std::pair<_OutputIterator1, _OutputIterator2>
+::std::pair<_OutputIterator1, _OutputIterator2>
 __pattern_partition_copy(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last,
                          _OutputIterator1 __out_true, _OutputIterator2 __out_false, _UnaryPredicate __pred) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_partition_copy(__first, __last, __out_true, __out_false, __pred,
                                               typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
           class _RandomAccessIterator3, class _UnaryPredicate>
-std::pair<_RandomAccessIterator2, _RandomAccessIterator3>
-__pattern_partition_copy(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first,
+::std::pair<_RandomAccessIterator2, _RandomAccessIterator3>
+__pattern_partition_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first,
                          _RandomAccessIterator1 __last, _RandomAccessIterator2 __out_true,
                          _RandomAccessIterator3 __out_false, _UnaryPredicate __pred)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type _DifferenceType;
-    typedef std::pair<_DifferenceType, _DifferenceType> _ReturnType;
+    using _DifferenceType = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
+    using _ReturnType = std::pair<_DifferenceType, _DifferenceType>;
     const _DifferenceType __n = __last - __first;
     if (_DifferenceType(1) < __n)
     {
         __par_backend::__buffer<bool> __mask_buf(__n);
-        return __internal::__except_handler(
-            [&__exec, __n, __first, __out_true, __out_false, __pred, &__mask_buf]()
-            {
-                bool* __mask = __mask_buf.get();
-                _ReturnType __m{};
-                __par_backend::__parallel_strict_scan(
-                    __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __n,
-                    std::make_pair(_DifferenceType(0), _DifferenceType(0)),
-                    [=](_DifferenceType __i, _DifferenceType __len) { // Reduce
-                        return __internal::__brick_calc_mask_1<_DifferenceType>(__first + __i, __first + (__i + __len),
-                                                                                __mask + __i, __pred, _IsVector{});
-                    },
-                    [](const _ReturnType& __x, const _ReturnType& __y) -> _ReturnType
-                    { return std::make_pair(__x.first + __y.first, __x.second + __y.second); }, // Combine
-                    [=](_DifferenceType __i, _DifferenceType __len, _ReturnType __initial) {    // Scan
-                        __internal::__brick_partition_by_mask(
-                            __first + __i, __first + (__i + __len), __out_true + __initial.first,
-                            __out_false + __initial.second, __mask + __i, _IsVector{});
-                    },
-                    [&__m](_ReturnType __total) { __m = __total; });
-                return std::make_pair(__out_true + __m.first, __out_false + __m.second);
-            });
+        return __internal::__except_handler([&__exec, __n, __first, __out_true, __out_false, &__pred, &__mask_buf]() {
+            bool* __mask = __mask_buf.get();
+            _ReturnType __m{};
+            __par_backend::__parallel_strict_scan(
+                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __n,
+                std::make_pair(_DifferenceType(0), _DifferenceType(0)),
+                [=, &__pred](_DifferenceType __i, _DifferenceType __len) { // Reduce
+                    return __internal::__brick_compute_mask(__first + __i, __len, __internal::__pred_at_index{__pred},
+                                                            __mask + __i, _IsVector{});
+                },
+                [](const _ReturnType& __x, const _ReturnType& __y) -> _ReturnType {
+                    return ::std::make_pair(__x.first + __y.first, __x.second + __y.second);
+                },                                                                       // Combine
+                [=](_DifferenceType __i, _DifferenceType __len, _ReturnType __initial) { // Scan
+                    __internal::__brick_partition_by_mask(__first + __i, __first + (__i + __len),
+                                                          __out_true + __initial.first, __out_false + __initial.second,
+                                                          __mask + __i, _IsVector{});
+                },
+                [&__m](_ReturnType __total) { __m = __total; });
+            return ::std::make_pair(__out_true + __m.first, __out_false + __m.second);
+        });
     }
     // trivial sequence - use serial algorithm
     return __internal::__brick_partition_copy(__first, __last, __out_true, __out_false, __pred, _IsVector{});
@@ -2177,58 +2381,76 @@ __pattern_partition_copy(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __e
 // sort
 //------------------------------------------------------------------------
 
-template <class _Tag, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare, class _IsMoveConstructible>
+template <class _Tag, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare, class _LeafSort>
 void
 __pattern_sort(_Tag, _ExecutionPolicy&&, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
-               _IsMoveConstructible) noexcept
+               _LeafSort __leaf_sort) noexcept
 {
-    std::sort(__first, __last, __comp);
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
+    __leaf_sort(__first, __last, __comp);
 }
 
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare, class _LeafSort>
 void
-__pattern_sort(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
-               _RandomAccessIterator __last, _Compare __comp, /*is_move_constructible=*/std::true_type)
+__pattern_sort(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+               _RandomAccessIterator __last, _Compare __comp, _LeafSort __leaf_sort)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    __internal::__except_handler(
-        [&]()
-        {
-            __par_backend::__parallel_stable_sort(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last, __comp,
-                [](_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
-                { std::sort(__first, __last, __comp); });
-        });
+    __internal::__except_handler([&]() {
+        __par_backend::__parallel_stable_sort(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last, __comp,
+            [__leaf_sort](_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
+                __leaf_sort(__first, __last, __comp);
+            },
+            __last - __first);
+    });
 }
 
 //------------------------------------------------------------------------
-// stable_sort
+// sort_by_key
 //------------------------------------------------------------------------
 
-template <class _Tag, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
+template <typename _Tag, typename _ExecutionPolicy, typename _RandomAccessIterator1, typename _RandomAccessIterator2,
+          typename _Compare, typename _LeafSort>
 void
-__pattern_stable_sort(_Tag, _ExecutionPolicy&&, _RandomAccessIterator __first, _RandomAccessIterator __last,
-                      _Compare __comp) noexcept
+__pattern_sort_by_key(_Tag, _ExecutionPolicy&&, _RandomAccessIterator1 __keys_first,
+                      _RandomAccessIterator1 __keys_last, _RandomAccessIterator2 __values_first, _Compare __comp,
+                      _LeafSort __leaf_sort) noexcept
 {
-    std::stable_sort(__first, __last, __comp);
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
+    auto __beg = __onedpl::make_zip_iterator(__keys_first, __values_first);
+    auto __end = __beg + (__keys_last - __keys_first);
+    auto __cmp_f = [__comp](const auto& __a, const auto& __b) {
+        return std::invoke(__comp, std::get<0>(__a), std::get<0>(__b));
+    };
+
+    __leaf_sort(__beg, __end, __cmp_f);
 }
 
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
+template <typename _IsVector, typename _ExecutionPolicy, typename _RandomAccessIterator1,
+          typename _RandomAccessIterator2, typename _Compare, typename _LeafSort>
 void
-__pattern_stable_sort(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
-                      _RandomAccessIterator __last, _Compare __comp)
+__pattern_sort_by_key(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __keys_first,
+                      _RandomAccessIterator1 __keys_last, _RandomAccessIterator2 __values_first, _Compare __comp,
+                      _LeafSort __leaf_sort)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    auto __beg = __onedpl::make_zip_iterator(__keys_first, __values_first);
+    auto __end = __beg + (__keys_last - __keys_first);
+    auto __cmp_f = [__comp](const auto& __a, const auto& __b) {
+        return std::invoke(__comp, std::get<0>(__a), std::get<0>(__b));
+    };
 
-    __internal::__except_handler(
-        [&]()
-        {
-            __par_backend::__parallel_stable_sort(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last, __comp,
-                [](_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
-                { std::stable_sort(__first, __last, __comp); });
-        });
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
+
+    __internal::__except_handler([&]() {
+        __par_backend::__parallel_stable_sort(
+            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __beg, __end, __cmp_f,
+            [__leaf_sort](auto __first, auto __last, auto __cmp) { __leaf_sort(__first, __last, __cmp); },
+            __end - __beg);
+    });
 }
 
 //------------------------------------------------------------------------
@@ -2240,34 +2462,33 @@ void
 __pattern_partial_sort(_Tag, _ExecutionPolicy&&, _RandomAccessIterator __first, _RandomAccessIterator __middle,
                        _RandomAccessIterator __last, _Compare __comp) noexcept
 {
-    std::partial_sort(__first, __middle, __last, __comp);
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
+    ::std::partial_sort(__first, __middle, __last, __comp);
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
 void
-__pattern_partial_sort(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+__pattern_partial_sort(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                        _RandomAccessIterator __middle, _RandomAccessIterator __last, _Compare __comp)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
     const auto __n = __middle - __first;
     if (__n == 0)
         return;
 
-    __internal::__except_handler(
-        [&]()
-        {
-            __par_backend::__parallel_stable_sort(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last, __comp,
-                [__n](_RandomAccessIterator __begin, _RandomAccessIterator __end, _Compare __comp)
-                {
-                    if (__n < __end - __begin)
-                        std::partial_sort(__begin, __begin + __n, __end, __comp);
-                    else
-                        std::sort(__begin, __end, __comp);
-                },
-                __n);
-        });
+    __except_handler([&]() {
+        __par_backend::__parallel_stable_sort(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last, __comp,
+            [__n](_RandomAccessIterator __begin, _RandomAccessIterator __end, _Compare __comp) {
+                if (__n < __end - __begin)
+                    ::std::partial_sort(__begin, __begin + __n, __end, __comp);
+                else
+                    ::std::sort(__begin, __end, __comp);
+            },
+            __n);
+    });
 }
 
 //------------------------------------------------------------------------
@@ -2279,17 +2500,19 @@ _RandomAccessIterator
 __pattern_partial_sort_copy(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last,
                             _RandomAccessIterator __d_first, _RandomAccessIterator __d_last, _Compare __comp) noexcept
 {
-    return std::partial_sort_copy(__first, __last, __d_first, __d_last, __comp);
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
+    return ::std::partial_sort_copy(__first, __last, __d_first, __d_last, __comp);
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
           class _Compare>
 _RandomAccessIterator2
-__pattern_partial_sort_copy(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first,
+__pattern_partial_sort_copy(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first,
                             _RandomAccessIterator1 __last, _RandomAccessIterator2 __d_first,
                             _RandomAccessIterator2 __d_last, _Compare __comp)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
     if (__last == __first || __d_last == __d_first)
     {
@@ -2301,58 +2524,56 @@ __pattern_partial_sort_copy(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&&
         if (__n2 >= __n1)
         {
             __par_backend::__parallel_stable_sort(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __d_first, __d_first + __n1, __comp,
-                [__first, __d_first](_RandomAccessIterator2 __i, _RandomAccessIterator2 __j, _Compare __comp)
-                {
+                __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __d_first, __d_first + __n1, __comp,
+                [__first, __d_first](_RandomAccessIterator2 __i, _RandomAccessIterator2 __j, _Compare __comp) {
                     _RandomAccessIterator1 __i1 = __first + (__i - __d_first);
                     _RandomAccessIterator1 __j1 = __first + (__j - __d_first);
 
-                // 1. Copy elements from input to output
-#if !defined(_PSTL_ICC_18_OMP_SIMD_BROKEN)
-                    __internal::__brick_copy(__i1, __j1, __i, _IsVector{});
-#else
-                    std::copy(__i1, __j1, __i);
-#endif
+                    // 1. Copy elements from input to output
+                    __brick_copy<__parallel_tag<_IsVector>>{}(__i1, __j1, __i, _IsVector{});
                     // 2. Sort elements in output sequence
-                    std::sort(__i, __j, __comp);
+                    ::std::sort(__i, __j, __comp);
                 },
                 __n1);
             return __d_first + __n1;
         }
         else
         {
-            typedef typename std::iterator_traits<_RandomAccessIterator1>::value_type _T1;
-            typedef typename std::iterator_traits<_RandomAccessIterator2>::value_type _T2;
+            using _T1 = typename std::iterator_traits<_RandomAccessIterator1>::value_type;
+            using _T2 = typename std::iterator_traits<_RandomAccessIterator2>::value_type;
             __par_backend::__buffer<_T1> __buf(__n1);
             _T1* __r = __buf.get();
 
             __par_backend::__parallel_stable_sort(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __r, __r + __n1, __comp,
-                [__n2, __first, __r](_T1* __i, _T1* __j, _Compare __comp)
-                {
+                __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __r, __r + __n1, __comp,
+                [__n2, __first, __r](_T1* __i, _T1* __j, _Compare __comp) {
                     _RandomAccessIterator1 __it = __first + (__i - __r);
 
                     // 1. Copy elements from input to raw memory
-                    for (_T1* __k = __i; __k != __j; ++__k, (void) ++__it)
+                    for (_T1* __k = __i; __k != __j; ++__k, (void)++__it)
                     {
                         ::new (__k) _T2(*__it);
                     }
 
-                    // 2. Sort elements in temporary __buffer
+                    // 2. Sort elements in temporary buffer
                     if (__n2 < __j - __i)
-                        std::partial_sort(__i, __i + __n2, __j, __comp);
+                        ::std::partial_sort(__i, __i + __n2, __j, __comp);
                     else
-                        std::sort(__i, __j, __comp);
+                        ::std::sort(__i, __j, __comp);
                 },
                 __n2);
 
-            // 3. Move elements from temporary __buffer to output
-            __par_backend::__parallel_for(__backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __r, __r + __n2,
-                                          [__r, __d_first](_T1* __i, _T1* __j)
-                                          { __brick_move_destroy()(__i, __j, __d_first + (__i - __r), _IsVector{}); });
-            __par_backend::__parallel_for(__backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __r + __n2,
-                                          __r + __n1,
-                                          [](_T1* __i, _T1* __j) { __brick_destroy(__i, __j, _IsVector{}); });
+            // 3. Move elements from temporary buffer to output
+            __par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __r, __r + __n2,
+                                          [__r, __d_first](_T1* __i, _T1* __j) {
+                                              __brick_move_destroy<__parallel_tag<_IsVector>>{}(
+                                                  __i, __j, __d_first + (__i - __r), _IsVector{});
+                                          });
+
+            if constexpr (!::std::is_trivially_destructible_v<_T1>)
+                __par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __r + __n2,
+                                              __r + __n1,
+                                              [](_T1* __i, _T1* __j) { __brick_destroy(__i, __j, _IsVector{}); });
 
             return __d_first + __n2;
         }
@@ -2365,7 +2586,7 @@ __pattern_partial_sort_copy(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&&
 template <class _RandomAccessIterator, class _BinaryPredicate>
 _RandomAccessIterator
 __brick_adjacent_find(_RandomAccessIterator __first, _RandomAccessIterator __last, _BinaryPredicate __pred,
-                      /* IsVector = */ std::true_type, bool __or_semantic) noexcept
+                      /* IsVector = */ ::std::true_type, bool __or_semantic) noexcept
 {
     return __unseq_backend::__simd_adjacent_find(__first, __last, __pred, __or_semantic);
 }
@@ -2373,66 +2594,65 @@ __brick_adjacent_find(_RandomAccessIterator __first, _RandomAccessIterator __las
 template <class _ForwardIterator, class _BinaryPredicate>
 _ForwardIterator
 __brick_adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred,
-                      /* IsVector = */ std::false_type, bool) noexcept
+                      /* IsVector = */ ::std::false_type, bool /* __or_semantic */) noexcept
 {
-    return std::adjacent_find(__first, __last, __pred);
+    return ::std::adjacent_find(__first, __last, __pred);
 }
 
-template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _BinaryPredicate>
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _BinaryPredicate, class _Semantic>
 _ForwardIterator
 __pattern_adjacent_find(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last,
-                        _BinaryPredicate __pred, bool __or_semantic) noexcept
+                        _BinaryPredicate __pred, _Semantic) noexcept
 {
-    return __internal::__brick_adjacent_find(__first, __last, __pred, typename _Tag::__is_vector{}, __or_semantic);
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
+    return __internal::__brick_adjacent_find(__first, __last, __pred, typename _Tag::__is_vector{}, _Semantic::value);
 }
 
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _BinaryPredicate>
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _BinaryPredicate, class _Semantic>
 _RandomAccessIterator
-__pattern_adjacent_find(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
-                        _RandomAccessIterator __last, _BinaryPredicate __pred, bool __or_semantic)
+__pattern_adjacent_find(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+                        _RandomAccessIterator __last, _BinaryPredicate __pred, _Semantic __or_semantic)
 {
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
+
     if (__last - __first < 2)
         return __last;
 
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
-
-    return __internal::__except_handler(
-        [&]()
-        {
-            return __par_backend::__parallel_reduce(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last, __last,
-                [__last, __pred, __or_semantic](_RandomAccessIterator __begin, _RandomAccessIterator __end,
-                                                _RandomAccessIterator __value) -> _RandomAccessIterator
-                {
-                    // TODO: investigate performance benefits from the use of shared variable for the result,
-                    // checking (compare_and_swap idiom) its __value at __first.
-                    if (__or_semantic && __value < __last)
-                    { //found
-                        __par_backend::__cancel_execution();
-                        return __value;
-                    }
-
-                    if (__value > __begin)
-                    {
-                        // modify __end to check the predicate on the boundary __values;
-                        // TODO: to use a custom range with boundaries overlapping
-                        // TODO: investigate what if we remove "if" below and run algorithm on range [__first, __last-1)
-                        // then check the pair [__last-1, __last)
-                        if (__end != __last)
-                            ++__end;
-
-                        //correct the global result iterator if the "brick" returns a local "__last"
-                        const _RandomAccessIterator __res =
-                            __internal::__brick_adjacent_find(__begin, __end, __pred, _IsVector{}, __or_semantic);
-                        if (__res < __end)
-                            __value = __res;
-                    }
+    return __internal::__except_handler([&]() {
+        return __par_backend::__parallel_reduce(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last, __last,
+            [__last, __pred, __or_semantic](_RandomAccessIterator __begin, _RandomAccessIterator __end,
+                                            _RandomAccessIterator __value) -> _RandomAccessIterator {
+                // TODO: investigate performance benefits from the use of shared variable for the result,
+                // checking (compare_and_swap idiom) its __value at __first.
+                if (__or_semantic && __value < __last)
+                { //found
                     return __value;
-                },
-                [](_RandomAccessIterator __x, _RandomAccessIterator __y) -> _RandomAccessIterator
-                { return __x < __y ? __x : __y; } //reduce a __value
-            );
-        });
+                }
+
+                if (__value > __begin)
+                {
+                    // modify __end to check the predicate on the boundary __values;
+                    // TODO: to use a custom range with boundaries overlapping
+                    // TODO: investigate what if we remove "if" below and run algorithm on range [__first, __last-1)
+                    // then check the pair [__last-1, __last)
+                    if (__end != __last)
+                        ++__end;
+
+                    //correct the global result iterator if the "brick" returns a local "__last"
+                    const _RandomAccessIterator __res =
+                        __internal::__brick_adjacent_find(__begin, __end, __pred, _IsVector{}, __or_semantic);
+                    if (__res < __end)
+                        __value = __res;
+                }
+                return __value;
+            },
+            [](_RandomAccessIterator __x, _RandomAccessIterator __y) -> _RandomAccessIterator {
+                return __x < __y ? __x : __y;
+            } //reduce a __value
+        );
+    });
 }
 
 //------------------------------------------------------------------------
@@ -2444,26 +2664,29 @@ void
 __pattern_nth_element(_Tag, _ExecutionPolicy&&, _RandomAccessIterator __first, _RandomAccessIterator __nth,
                       _RandomAccessIterator __last, _Compare __comp) noexcept
 {
-    std::nth_element(__first, __nth, __last, __comp);
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
+    ::std::nth_element(__first, __nth, __last, __comp);
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
 void
 __pattern_nth_element(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
-                      _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) noexcept
+                      _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
 {
     if (__first == __last || __nth == __last)
     {
         return;
     }
 
-    using std::iter_swap;
-    typedef typename std::iterator_traits<_RandomAccessIterator>::value_type _Tp;
+    using ::std::iter_swap;
+    using _Tp = typename std::iterator_traits<_RandomAccessIterator>::value_type;
     _RandomAccessIterator __x;
     do
     {
-        __x = __internal::__pattern_partition(__tag, std::forward<_ExecutionPolicy>(__exec), __first + 1, __last,
-                                              [&__comp, __first](const _Tp& __x) { return __comp(__x, *__first); });
+        __x = __internal::__pattern_partition(
+            __tag, std::forward<_ExecutionPolicy>(__exec), __first + 1, __last,
+            [&__comp, __first](const _Tp& __x) { return std::invoke(__comp, __x, *__first); });
         --__x;
         if (__x != __first)
         {
@@ -2477,15 +2700,12 @@ __pattern_nth_element(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec
         // if x < nth then our new range for partition is [x, last)
         else if (__x - __nth < 0)
         {
-            // if *x == *nth then we can start new partition with x+1
-            if (!__comp(*__nth, *__x) && !__comp(*__x, *__nth))
+            // if *x == *nth then we start the new partition at the next index where *x != *nth
+            while (!std::invoke(__comp, *__nth, *__x) && !std::invoke(__comp, *__x, *__nth) && __x - __nth < 0)
             {
                 ++__x;
             }
-            else
-            {
-                iter_swap(__nth, __x);
-            }
+            iter_swap(__nth, __x);
             __first = __x;
         }
     } while (__x != __nth);
@@ -2494,66 +2714,83 @@ __pattern_nth_element(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec
 //------------------------------------------------------------------------
 // fill, fill_n
 //------------------------------------------------------------------------
-template <class _RandomAccessIterator, class _Tp>
-void
-__brick_fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value,
-             /* __is_vector = */ std::true_type) noexcept
+template <class _Tag, typename _Tp>
+struct __brick_fill<_Tag, _Tp, std::enable_if_t<__is_host_dispatch_tag_v<_Tag>>>
 {
-    __unseq_backend::__simd_fill_n(__first, __last - __first, __value);
-}
+    const _Tp& __value;
 
-template <class _ForwardIterator, class _Tp>
-void
-__brick_fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value,
-             /* __is_vector = */ std::false_type) noexcept
-{
-    std::fill(__first, __last, __value);
-}
+    template <typename _RandomAccessIterator>
+    void
+    operator()(_RandomAccessIterator __first, _RandomAccessIterator __last,
+               /* __is_vector = */ ::std::true_type) const noexcept
+    {
+        __unseq_backend::__simd_fill_n(__first, __last - __first, __value);
+    }
+
+    template <typename _ForwardIterator>
+    void
+    operator()(_ForwardIterator __first, _ForwardIterator __last,
+               /* __is_vector = */ ::std::false_type) const noexcept
+    {
+        ::std::fill(__first, __last, __value);
+    }
+};
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Tp>
 void
 __pattern_fill(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) noexcept
 {
-    __internal::__brick_fill(__first, __last, __value, typename _Tag::__is_vector{});
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
+    __internal::__brick_fill<_Tag, _Tp>{__value}(__first, __last, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Tp>
 _RandomAccessIterator
-__pattern_fill(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+__pattern_fill(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                _RandomAccessIterator __last, const _Tp& __value)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    return __internal::__except_handler(
-        [&__exec, __first, __last, &__value]()
-        {
-            __par_backend::__parallel_for(__backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                          [&__value](_RandomAccessIterator __begin, _RandomAccessIterator __end)
-                                          { __internal::__brick_fill(__begin, __end, __value, _IsVector{}); });
-            return __last;
-        });
+    return __internal::__except_handler([&__exec, __first, __last, &__value]() {
+        __par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                      [&__value](_RandomAccessIterator __begin, _RandomAccessIterator __end) {
+                                          __internal::__brick_fill<__parallel_tag<_IsVector>, _Tp>{__value}(
+                                              __begin, __end, _IsVector{});
+                                      });
+        return __last;
+    });
 }
 
-template <class _RandomAccessIterator, class _Size, class _Tp>
-_RandomAccessIterator
-__brick_fill_n(_RandomAccessIterator __first, _Size __count, const _Tp& __value,
-               /* __is_vector = */ std::true_type) noexcept
+template <class _Tag, typename _Tp>
+struct __brick_fill_n<_Tag, _Tp, std::enable_if_t<__is_host_dispatch_tag_v<_Tag>>>
 {
-    return __unseq_backend::__simd_fill_n(__first, __count, __value);
-}
+    const _Tp& __value;
 
-template <class _OutputIterator, class _Size, class _Tp>
-_OutputIterator
-__brick_fill_n(_OutputIterator __first, _Size __count, const _Tp& __value, /* __is_vector = */ std::false_type) noexcept
-{
-    return std::fill_n(__first, __count, __value);
-}
+    template <typename _RandomAccessIterator, typename _Size>
+    _RandomAccessIterator
+    operator()(_RandomAccessIterator __first, _Size __count,
+               /* __is_vector = */ ::std::true_type) const noexcept
+    {
+        return __unseq_backend::__simd_fill_n(__first, __count, __value);
+    }
+
+    template <typename _OutputIterator, typename _Size>
+    _OutputIterator
+    operator()(_OutputIterator __first, _Size __count,
+               /* __is_vector = */ ::std::false_type) const noexcept
+    {
+        return ::std::fill_n(__first, __count, __value);
+    }
+};
 
 template <class _Tag, class _ExecutionPolicy, class _OutputIterator, class _Size, class _Tp>
 _OutputIterator
 __pattern_fill_n(_Tag, _ExecutionPolicy&&, _OutputIterator __first, _Size __count, const _Tp& __value) noexcept
 {
-    return __internal::__brick_fill_n(__first, __count, __value, typename _Tag::__is_vector{});
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
+    return __internal::__brick_fill_n<_Tag, _Tp>{__value}(__first, __count, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Size, class _Tp>
@@ -2561,7 +2798,7 @@ _RandomAccessIterator
 __pattern_fill_n(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                  _Size __count, const _Tp& __value)
 {
-    return __internal::__pattern_fill(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __first + __count,
+    return __internal::__pattern_fill(__tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __first + __count,
                                       __value);
 }
 
@@ -2571,7 +2808,7 @@ __pattern_fill_n(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _Ra
 template <class _RandomAccessIterator, class _Generator>
 void
 __brick_generate(_RandomAccessIterator __first, _RandomAccessIterator __last, _Generator __g,
-                 /* is_vector = */ std::true_type) noexcept
+                 /* is_vector = */ ::std::true_type) noexcept
 {
     __unseq_backend::__simd_generate_n(__first, __last - __first, __g);
 }
@@ -2579,54 +2816,57 @@ __brick_generate(_RandomAccessIterator __first, _RandomAccessIterator __last, _G
 template <class _ForwardIterator, class _Generator>
 void
 __brick_generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __g,
-                 /* is_vector = */ std::false_type) noexcept
+                 /* is_vector = */ ::std::false_type) noexcept
 {
-    std::generate(__first, __last, __g);
+    ::std::generate(__first, __last, __g);
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Generator>
 void
 __pattern_generate(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, _Generator __g) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     __internal::__brick_generate(__first, __last, __g, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Generator>
 _RandomAccessIterator
-__pattern_generate(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+__pattern_generate(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                    _RandomAccessIterator __last, _Generator __g)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    return __internal::__except_handler(
-        [&]()
-        {
-            __par_backend::__parallel_for(__backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                          [__g](_RandomAccessIterator __begin, _RandomAccessIterator __end)
-                                          { __internal::__brick_generate(__begin, __end, __g, _IsVector{}); });
-            return __last;
-        });
+    return __internal::__except_handler([&]() {
+        __par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                      [__g](_RandomAccessIterator __begin, _RandomAccessIterator __end) {
+                                          __internal::__brick_generate(__begin, __end, __g, _IsVector{});
+                                      });
+        return __last;
+    });
 }
 
-template <class _RandomAccessIterator, class _Size, class _Generator>
+template <class _RandomAccessIterator, class Size, class _Generator>
 _RandomAccessIterator
-__brick_generate_n(_RandomAccessIterator __first, _Size __count, _Generator __g,
-                   /* is_vector = */ std::true_type) noexcept
+__brick_generate_n(_RandomAccessIterator __first, Size __count, _Generator __g,
+                   /* is_vector = */ ::std::true_type) noexcept
 {
     return __unseq_backend::__simd_generate_n(__first, __count, __g);
 }
 
-template <class _OutputIterator, class _Size, class _Generator>
-_OutputIterator
-__brick_generate_n(_OutputIterator __first, _Size __count, _Generator __g, /* is_vector = */ std::false_type) noexcept
+template <class OutputIterator, class Size, class _Generator>
+OutputIterator
+__brick_generate_n(OutputIterator __first, Size __count, _Generator __g, /* is_vector = */ ::std::false_type) noexcept
 {
-    return std::generate_n(__first, __count, __g);
+    return ::std::generate_n(__first, __count, __g);
 }
 
 template <class _Tag, class _ExecutionPolicy, class _OutputIterator, class _Size, class _Generator>
 _OutputIterator
 __pattern_generate_n(_Tag, _ExecutionPolicy&&, _OutputIterator __first, _Size __count, _Generator __g) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_generate_n(__first, __count, __g, typename _Tag::__is_vector{});
 }
 
@@ -2635,9 +2875,9 @@ _RandomAccessIterator
 __pattern_generate_n(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                      _Size __count, _Generator __g)
 {
-    static_assert(__are_random_access_iterators<_RandomAccessIterator>::value,
+    static_assert(__is_random_access_iterator_v<_RandomAccessIterator>,
                   "Pattern-brick error. Should be a random access iterator.");
-    return __internal::__pattern_generate(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __first + __count,
+    return __internal::__pattern_generate(__tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __first + __count,
                                           __g);
 }
 
@@ -2648,20 +2888,20 @@ __pattern_generate_n(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec,
 template <class _ForwardIterator, class _UnaryPredicate>
 _ForwardIterator
 __brick_remove_if(_ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred,
-                  /* __is_vector = */ std::false_type) noexcept
+                  /* __is_vector = */ ::std::false_type) noexcept
 {
-    return std::remove_if(__first, __last, __pred);
+    return ::std::remove_if(__first, __last, __pred);
 }
 
 template <class _RandomAccessIterator, class _UnaryPredicate>
 _RandomAccessIterator
 __brick_remove_if(_RandomAccessIterator __first, _RandomAccessIterator __last, _UnaryPredicate __pred,
-                  /* __is_vector = */ std::true_type) noexcept
+                  /* __is_vector = */ ::std::true_type) noexcept
 {
-#if defined(_PSTL_MONOTONIC_PRESENT)
+#if (_PSTL_MONOTONIC_PRESENT || _ONEDPL_MONOTONIC_PRESENT)
     return __unseq_backend::__simd_remove_if(__first, __last - __first, __pred);
 #else
-    return std::remove_if(__first, __last, __pred);
+    return ::std::remove_if(__first, __last, __pred);
 #endif
 }
 
@@ -2670,15 +2910,17 @@ _ForwardIterator
 __pattern_remove_if(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last,
                     _UnaryPredicate __pred) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_remove_if(__first, __last, __pred, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _UnaryPredicate>
 _RandomAccessIterator
 __pattern_remove_if(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
-                    _RandomAccessIterator __last, _UnaryPredicate __pred) noexcept
+                    _RandomAccessIterator __last, _UnaryPredicate __pred)
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator>::reference _ReferenceType;
+    using _ReferenceType = typename std::iterator_traits<_RandomAccessIterator>::reference;
 
     if (__first == __last || __first + 1 == __last)
     {
@@ -2687,9 +2929,8 @@ __pattern_remove_if(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec,
     }
 
     return __internal::__remove_elements(
-        __tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-        [&__pred](bool* __b, bool* __e, _RandomAccessIterator __it)
-        {
+        __tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+        [&__pred](bool* __b, bool* __e, _RandomAccessIterator __it) {
             __internal::__brick_walk2(
                 __b, __e, __it, [&__pred](bool& __x, _ReferenceType __y) { __x = !__pred(__y); }, _IsVector{});
         });
@@ -2698,24 +2939,54 @@ __pattern_remove_if(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec,
 //------------------------------------------------------------------------
 // merge
 //------------------------------------------------------------------------
+template <typename _ForwardIterator1, typename _ForwardIterator2, typename _OutputIterator, typename _Comp,
+          typename _Proj1, typename _Proj2>
+std::tuple<_ForwardIterator1, _ForwardIterator2, _OutputIterator>
+__serial_merge_out_lim(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
+                       _ForwardIterator2 __last2, _OutputIterator __first3, _OutputIterator __last3, _Comp __comp,
+                       _Proj1 __proj1, _Proj2 __proj2)
+{
+    while (__first3 != __last3)
+    {
+        if (__first1 == __last1)
+        {
+            assert(__first2 != __last2);
+            *__first3++ = *__first2++;
+        }
+        else if (__first2 == __last2)
+        {
+            assert(__first1 != __last1);
+            *__first3++ = *__first1++;
+        }
+        else
+        {
+            if (std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1)))
+                *__first3++ = *__first2++;
+            else
+                *__first3++ = *__first1++;
+        }
+    }
+
+    return {__first1, __first2, __first3};
+}
 
 template <class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator, class _Compare>
 _OutputIterator
 __brick_merge(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
               _ForwardIterator2 __last2, _OutputIterator __d_first, _Compare __comp,
-              /* __is_vector = */ std::false_type) noexcept
+              /* __is_vector = */ ::std::false_type) noexcept
 {
-    return std::merge(__first1, __last1, __first2, __last2, __d_first, __comp);
+    return ::std::merge(__first1, __last1, __first2, __last2, __d_first, __comp);
 }
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _RandomAccessIterator3, class _Compare>
 _RandomAccessIterator3
 __brick_merge(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
               _RandomAccessIterator2 __last2, _RandomAccessIterator3 __d_first, _Compare __comp,
-              /* __is_vector = */ std::true_type) noexcept
+              /* __is_vector = */ ::std::true_type) noexcept
 {
     _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
-    return std::merge(__first1, __last1, __first2, __last2, __d_first, __comp);
+    return ::std::merge(__first1, __last1, __first2, __last2, __d_first, __comp);
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator,
@@ -2725,26 +2996,139 @@ __pattern_merge(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1, _ForwardIt
                 _ForwardIterator2 __first2, _ForwardIterator2 __last2, _OutputIterator __d_first,
                 _Compare __comp) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_merge(__first1, __last1, __first2, __last2, __d_first, __comp,
                                      typename _Tag::__is_vector{});
 }
 
+template <typename _ForwardIterator1, typename _ForwardIterator2, typename _OutputIterator>
+using _merge_path_out_lim_return_t = std::tuple<_ForwardIterator1, _ForwardIterator2, _OutputIterator>;
+
+template <typename _Tag, typename _ExecutionPolicy, typename _ForwardIterator1, typename _ForwardIterator2,
+          typename _ForwardIterator3, typename _Comp, typename _Proj1, typename _Proj2>
+_merge_path_out_lim_return_t<_ForwardIterator1, _ForwardIterator2, _ForwardIterator3>
+__merge_path_out_lim(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
+                     _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator3 __first3,
+                     _ForwardIterator3 __last3, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2)
+{
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
+    return __serial_merge_out_lim(__first1, __last1, __first2, __last2, __first3, __last3, __comp, __proj1, __proj2);
+}
+
+inline constexpr std::size_t __merge_path_cut_off = 2000;
+
+template <typename _IsVector, typename _ExecutionPolicy, typename _RandomAccessIterator1,
+          typename _RandomAccessIterator2, typename _RandomAccessIterator3, typename _Comp, typename _Proj1,
+          typename _Proj2>
+std::enable_if_t<__is_random_access_iterator_v<_RandomAccessIterator1> &&
+                     __is_random_access_iterator_v<_RandomAccessIterator2> &&
+                     __is_random_access_iterator_v<_RandomAccessIterator3>,
+                 _merge_path_out_lim_return_t<_RandomAccessIterator1, _RandomAccessIterator2, _RandomAccessIterator3>>
+__merge_path_out_lim(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
+                     _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2,
+                     _RandomAccessIterator3 __first3, _RandomAccessIterator3 __last3, _Comp __comp, _Proj1 __proj1,
+                     _Proj2 __proj2)
+{
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
+
+    using _Index1 = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
+    using _Index2 = typename std::iterator_traits<_RandomAccessIterator2>::difference_type;
+    using _Index3 = typename std::iterator_traits<_RandomAccessIterator3>::difference_type;
+    using _IndexCommon = std::common_type_t<_Index1, _Index2, _Index3>;
+    static_assert(std::is_signed_v<_IndexCommon>);
+
+    using _counting_iterator_t = __onedpl::counting_iterator<_IndexCommon>;
+
+    const _IndexCommon __n_1 = __last1 - __first1;
+    const _IndexCommon __n_2 = __last2 - __first2;
+    const _IndexCommon __n_out = __last3 - __first3;
+
+    assert(__n_1 > 0);
+    assert(__n_2 > 0);
+    assert(__n_out > 0);
+
+    _merge_path_out_lim_return_t<_RandomAccessIterator1, _RandomAccessIterator2, _RandomAccessIterator3> __result{
+        __first1, __first2, __first3};
+
+    __internal::__except_handler([&]() {
+        __par_backend::__parallel_for(
+            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), _IndexCommon{0}, __n_out,
+            [=, &__result](_IndexCommon __i, _IndexCommon __j) {
+                //a start merging point on the merge path; for each thread
+                _IndexCommon __r = 0; //row index
+                _IndexCommon __c = 0; //column index
+
+                if (__i > 0)
+                {
+                    //calc merge path intersection:
+                    const _IndexCommon __d_size =
+                        std::abs(std::max(_IndexCommon{0}, __i - __n_2) - (std::min(__i, __n_1) - 1)) + 1;
+
+                    auto __get_row = [__i, __n_1](_IndexCommon __d) -> _IndexCommon {
+                        return std::min(__i, __n_1) - __d - 1;
+                    };
+                    auto __get_column = [__i, __n_1](_IndexCommon __d) -> _IndexCommon {
+                        return std::max(_IndexCommon{0}, __i - __n_1) + __d;
+                    };
+
+                    const _counting_iterator_t __it_d(0);
+
+                    _counting_iterator_t __found =
+                        std::lower_bound(__it_d, __it_d + __d_size, 1, [&](_IndexCommon __d, auto __val) {
+                            const _IndexCommon __r_tmp = __get_row(__d);
+                            const _IndexCommon __c_tmp = __get_column(__d);
+
+                            assert(0 <= __r_tmp && __r_tmp < __n_1);
+                            assert(0 <= __c_tmp && __c_tmp < __n_2);
+
+                            const auto __res = std::invoke(__comp, std::invoke(__proj2, __first2[__c_tmp]),
+                                                           std::invoke(__proj1, __first1[__r_tmp])) ? 0 : 1;
+                            return __res < __val;
+                        });
+                    const _IndexCommon __res_d = *__found; // __found == end -> __d_size, which is intentional
+
+                    //intersection point
+                    __r = __get_row(__res_d);
+                    __c = __get_column(__res_d);
+
+                    ++__r; //to get a merge matrix ceil, lying on the current diagonal
+                }
+
+                //serial merge n elements, starting from input x and y, to [i, j) output range
+                const auto __merge_out_lim_res =
+                    __serial_merge_out_lim(__first1 + __r, __first1 + __n_1, __first2 + __c, __first2 + __n_2,
+                                           __first3 + __i, __first3 + __j, __comp, __proj1, __proj2);
+
+                if (__j == __n_out)
+                    __result = __merge_out_lim_res;
+            },
+            __merge_path_cut_off); //grainsize
+    });
+
+    return __result;
+}
+
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
           class _RandomAccessIterator3, class _Compare>
 _RandomAccessIterator3
-__pattern_merge(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
+__pattern_merge(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
                 _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2,
                 _RandomAccessIterator3 __d_first, _Compare __comp)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    __par_backend::__parallel_merge(
-        __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __d_first,
-        __comp,
-        [](_RandomAccessIterator1 __f1, _RandomAccessIterator1 __l1, _RandomAccessIterator2 __f2,
-           _RandomAccessIterator2 __l2, _RandomAccessIterator3 __f3, _Compare __comp)
-        { return __internal::__brick_merge(__f1, __l1, __f2, __l2, __f3, __comp, _IsVector{}); });
-    return __d_first + (__last1 - __first1) + (__last2 - __first2);
+    return __internal::__except_handler([&]() {
+        __par_backend::__parallel_merge(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __d_first,
+            __comp,
+            [](_RandomAccessIterator1 __f1, _RandomAccessIterator1 __l1, _RandomAccessIterator2 __f2,
+               _RandomAccessIterator2 __l2, _RandomAccessIterator3 __f3, _Compare __comp) {
+                return __internal::__brick_merge(__f1, __l1, __f2, __l2, __f3, __comp, _IsVector{});
+            });
+        return __d_first + (__last1 - __first1) + (__last2 - __first2);
+    });
 }
 
 //------------------------------------------------------------------------
@@ -2753,18 +3137,18 @@ __pattern_merge(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _Ran
 template <class _BidirectionalIterator, class _Compare>
 void
 __brick_inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
-                      _Compare __comp, /* __is_vector = */ std::false_type) noexcept
+                      _Compare __comp, /* __is_vector = */ ::std::false_type) noexcept
 {
-    std::inplace_merge(__first, __middle, __last, __comp);
+    ::std::inplace_merge(__first, __middle, __last, __comp);
 }
 
 template <class _RandomAccessIterator, class _Compare>
 void
 __brick_inplace_merge(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
-                      _Compare __comp, /* __is_vector = */ std::true_type) noexcept
+                      _Compare __comp, /* __is_vector = */ ::std::true_type) noexcept
 {
     _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial")
-    std::inplace_merge(__first, __middle, __last, __comp);
+    ::std::inplace_merge(__first, __middle, __last, __comp);
 }
 
 template <class _Tag, class _ExecutionPolicy, class _BidirectionalIterator, class _Compare>
@@ -2772,53 +3156,51 @@ void
 __pattern_inplace_merge(_Tag, _ExecutionPolicy&&, _BidirectionalIterator __first, _BidirectionalIterator __middle,
                         _BidirectionalIterator __last, _Compare __comp) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     __internal::__brick_inplace_merge(__first, __middle, __last, __comp, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
 void
-__pattern_inplace_merge(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+__pattern_inplace_merge(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                         _RandomAccessIterator __middle, _RandomAccessIterator __last, _Compare __comp)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
     if (__first == __last || __first == __middle || __middle == __last)
     {
         return;
     }
-    typedef typename std::iterator_traits<_RandomAccessIterator>::value_type _Tp;
+
+    using _Tp = typename std::iterator_traits<_RandomAccessIterator>::value_type;
     auto __n = __last - __first;
     __par_backend::__buffer<_Tp> __buf(__n);
     _Tp* __r = __buf.get();
-    __internal::__except_handler(
-        [&]()
-        {
-            auto __move_values = [](_RandomAccessIterator __x, _Tp* __z)
-            {
-                __internal::__invoke_if_else(
-                    std::conjunction<std::is_trivially_copyable<_Tp>, std::is_trivially_default_constructible<_Tp>>(),
-                    [&]() { *__z = std::move(*__x); },
-                    [&]() { ::new (std::addressof(*__z)) _Tp(std::move(*__x)); });
-            };
+    __internal::__except_handler([&]() {
+        auto __move_values = [](_RandomAccessIterator __x, _Tp* __z) {
+            ::new (std::addressof(*__z)) _Tp(std::move(*__x));
+        };
 
-            auto __move_sequences = [](_RandomAccessIterator __first1, _RandomAccessIterator __last1, _Tp* __first2)
-            { return __internal::__brick_uninitialized_move(__first1, __last1, __first2, _IsVector()); };
+        auto __move_sequences = [](_RandomAccessIterator __first1, _RandomAccessIterator __last1, _Tp* __first2) {
+            return __internal::__brick_uninitialized_move(__first1, __last1, __first2, _IsVector{});
+        };
 
-            __par_backend::__parallel_merge(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __middle, __middle, __last, __r,
-                __comp,
-                [__n, __move_values, __move_sequences](_RandomAccessIterator __f1, _RandomAccessIterator __l1,
-                                                       _RandomAccessIterator __f2, _RandomAccessIterator __l2,
-                                                       _Tp* __f3, _Compare __comp)
-                {
-                    (__utils::__serial_move_merge(__n))(__f1, __l1, __f2, __l2, __f3, __comp, __move_values,
-                                                        __move_values, __move_sequences, __move_sequences);
-                    return __f3 + (__l1 - __f1) + (__l2 - __f2);
-                });
-            __par_backend::__parallel_for(__backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __r, __r + __n,
-                                          [__r, __first](_Tp* __i, _Tp* __j)
-                                          { __brick_move_destroy()(__i, __j, __first + (__i - __r), _IsVector{}); });
-        });
+        __par_backend::__parallel_merge(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __middle, __middle, __last, __r, __comp,
+            [__n, __move_values, __move_sequences](_RandomAccessIterator __f1, _RandomAccessIterator __l1,
+                                                   _RandomAccessIterator __f2, _RandomAccessIterator __l2, _Tp* __f3,
+                                                   _Compare __comp) {
+                (__utils::__serial_move_merge(__n))(__f1, __l1, __f2, __l2, __f3, __comp, __move_values, __move_values,
+                                                    __move_sequences, __move_sequences);
+                return __f3 + (__l1 - __f1) + (__l2 - __f2);
+            });
+        __par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __r, __r + __n,
+                                      [__r, __first](_Tp* __i, _Tp* __j) {
+                                          __brick_move_destroy<__parallel_tag<_IsVector>>{}(
+                                              __i, __j, __first + (__i - __r), _IsVector{});
+                                      });
+    });
 }
 
 //------------------------------------------------------------------------
@@ -2830,7 +3212,9 @@ bool
 __pattern_includes(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                    _ForwardIterator2 __first2, _ForwardIterator2 __last2, _Compare __comp) noexcept
 {
-    return std::includes(__first1, __last1, __first2, __last2, __comp);
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
+    return ::std::includes(__first1, __last1, __first2, __last2, __comp);
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
@@ -2840,72 +3224,77 @@ __pattern_includes(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _
                    _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2,
                    _Compare __comp)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
-
-    if (__first2 >= __last2)
+    if (__first2 == __last2)
         return true;
 
-    if (__first1 >= __last1 || __comp(*__first2, *__first1) || __comp(*(__last1 - 1), *(__last2 - 1)))
+    //optimization; {1} - the first sequence, {2} - the second sequence
+    //{1} is empty or size_of{2} > size_of{1}
+    if (__first1 == __last1 || __last2 - __first2 > __last1 - __first1 ||
+        // {1}:     [**********]     or   [**********]
+        // {2}: [***********]                   [***********]
+        std::invoke(__comp, *__first2, *__first1) || std::invoke(__comp, *(__last1 - 1), *(__last2 - 1)))
         return false;
 
-    __first1 = std::lower_bound(__first1, __last1, *__first2, __comp);
+    __first1 = ::std::lower_bound(__first1, __last1, *__first2, __comp);
     if (__first1 == __last1)
         return false;
 
     if (__last2 - __first2 == 1)
-        return !__comp(*__first1, *__first2) && !__comp(*__first2, *__first1);
+        return !std::invoke(__comp, *__first1, *__first2) && !std::invoke(__comp, *__first2, *__first1);
 
-    return __internal::__except_handler(
-        [&]()
-        {
-            return !__internal::__parallel_or(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first2, __last2,
-                [__first1, __last1, __first2, __last2, &__comp](_RandomAccessIterator2 __i, _RandomAccessIterator2 __j)
+    return __internal::__except_handler([&]() {
+        return !__internal::__parallel_or(
+            __tag, ::std::forward<_ExecutionPolicy>(__exec), __first2, __last2,
+            [__first1, __last1, __first2, __last2, &__comp](_RandomAccessIterator2 __i, _RandomAccessIterator2 __j) {
+                assert(__j > __i);
+                //assert(__j - __i > 1);
+
+                //1. moving boundaries to "consume" subsequence of equal elements
+                auto __is_equal_sorted = [&__comp](_RandomAccessIterator2 __a, _RandomAccessIterator2 __b) -> bool {
+                    //enough one call of __comp due to compared couple belongs to one sorted sequence
+                    return !std::invoke(__comp, *__a, *__b);
+                };
+
+                //1.1 left bound, case "aaa[aaaxyz...]" - searching "x"
+                if (__i > __first2 && __is_equal_sorted(__i - 1, __i))
                 {
-                    _PSTL_ASSERT(__j > __i);
-                    //_PSTL_ASSERT(__j - __i > 1);
+                    //whole subrange continues to have equal elements - return "no op"
+                    if (__is_equal_sorted(__i, __j - 1))
+                        return false;
 
-                    //1. moving boundaries to "consume" subsequence of equal elements
-                    auto __is_equal = [&__comp](_RandomAccessIterator2 __a, _RandomAccessIterator2 __b) -> bool
-                    { return !__comp(*__a, *__b) && !__comp(*__b, *__a); };
+                    __i = ::std::upper_bound(__i, __last2, *__i, __comp);
+                }
 
-                    //1.1 left bound, case "aaa[aaaxyz...]" - searching "x"
-                    if (__i > __first2 && __is_equal(__i, __i - 1))
-                    {
-                        //whole subrange continues to content equal elements - return "no op"
-                        if (__is_equal(__i, __j - 1))
-                            return false;
+                //1.2 right bound, case "[...aaa]aaaxyz" - searching "x"
+                if (__j < __last2 && __is_equal_sorted(__j - 1, __j))
+                    __j = ::std::upper_bound(__j, __last2, *__j, __comp);
 
-                        __i = std::upper_bound(__i, __last2, *__i, __comp);
-                    }
+                //2. testing is __a subsequence of the second range included into the first range
+                auto __b = ::std::lower_bound(__first1, __last1, *__i, __comp);
 
-                    //1.2 right bound, case "[...aaa]aaaxyz" - searching "x"
-                    if (__j < __last2 && __is_equal(__j - 1, __j))
-                        __j = std::upper_bound(__j, __last2, *__j, __comp);
-
-                    //2. testing is __a subsequence of the second range included into the first range
-                    auto __b = std::lower_bound(__first1, __last1, *__i, __comp);
-
-                    _PSTL_ASSERT(!__comp(*(__last1 - 1), *__b));
-                    _PSTL_ASSERT(!__comp(*(__j - 1), *__i));
-                    return !std::includes(__b, __last1, __i, __j, __comp);
-                });
-        });
+                assert(!std::invoke(__comp, *(__last1 - 1), *__b));
+                assert(!std::invoke(__comp, *(__j - 1), *__i));
+                return !::std::includes(__b, __last1, __i, __j, __comp);
+            });
+    });
 }
 
 inline constexpr auto __set_algo_cut_off = 1000;
 
-template <class _IsVector, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2,
-          class _OutputIterator, class _Compare, class _SizeFunction, class _SetOP>
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
+          class _OutputIterator, class _SizeFunction, class _SetOP, class _Compare, class _Proj1, class _Proj2>
 _OutputIterator
-__parallel_set_op(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _ForwardIterator1 __first1,
-                  _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2,
-                  _OutputIterator __result, _Compare __comp, _SizeFunction __size_func, _SetOP __set_op)
+__parallel_set_op(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
+                  _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2,
+                  _OutputIterator __result, _SizeFunction __size_func, _SetOP __set_op, _Compare __comp, _Proj1 __proj1,
+                  _Proj2 __proj2)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    typedef typename std::iterator_traits<_ForwardIterator1>::difference_type _DifferenceType;
-    typedef typename std::iterator_traits<_OutputIterator>::value_type _Tp;
+    using _DifferenceType1 = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
+    using _DifferenceType2 = typename std::iterator_traits<_RandomAccessIterator2>::difference_type;
+    using _DifferenceType = std::common_type_t<_DifferenceType1, _DifferenceType2>;
+    using _T = typename std::iterator_traits<_OutputIterator>::value_type;
 
     struct _SetRange
     {
@@ -2917,144 +3306,144 @@ __parallel_set_op(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _F
         }
     };
 
-    const _DifferenceType __n1 = __last1 - __first1;
-    const _DifferenceType __n2 = __last2 - __first2;
+    const _DifferenceType1 __n1 = __last1 - __first1;
+    const _DifferenceType2 __n2 = __last2 - __first2;
 
-    __par_backend::__buffer<_Tp> __buf(__size_func(__n1, __n2));
+    __par_backend::__buffer<_T> __buf(__size_func(__n1, __n2));
 
-    return __internal::__except_handler(
-        [&__exec, __n1, __first1, __last1, __first2, __last2, __result, __comp, __size_func, __set_op, &__buf]()
-        {
-            auto __buffer = __buf.get();
-            _DifferenceType __m{};
-            auto __scan = [=](_DifferenceType, _DifferenceType, const _SetRange& __s) { // Scan
-                if (!__s.empty())
-                    __brick_move_destroy()(__buffer + __s.__buf_pos, __buffer + (__s.__buf_pos + __s.__len),
-                                           __result + __s.__pos, _IsVector{});
-            };
-            __par_backend::__parallel_strict_scan(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __n1, _SetRange{0, 0, 0}, //-1, 0},
-                [=](_DifferenceType __i, _DifferenceType __len) {                                  // Reduce
-                    //[__b; __e) - a subrange of the first sequence, to reduce
-                    _ForwardIterator1 __b = __first1 + __i, __e = __first1 + (__i + __len);
+    return __internal::__except_handler([&__exec, __n1, __first1, __last1, __first2, __last2, __result, __size_func,
+                                         __set_op, &__buf, __comp, __proj1, __proj2]() {
+        auto __tmp_memory = __buf.get();
+        _DifferenceType1 __m{};
+        auto __scan = [=](_DifferenceType1, _DifferenceType1, const _SetRange& __s) { // Scan
+            if (!__s.empty())
+                __brick_move_destroy<__parallel_tag<_IsVector>>{}(__tmp_memory + __s.__buf_pos,
+                                                                  __tmp_memory + (__s.__buf_pos + __s.__len),
+                                                                  __result + __s.__pos, _IsVector{});
+        };
+        __par_backend::__parallel_strict_scan(
+            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __n1, _SetRange{0, 0, 0},
+            [=](_DifferenceType1 __i, _DifferenceType1 __len) { // Reduce
+                //[__b; __e) - a subrange of the first sequence, to reduce
+                _RandomAccessIterator1 __b = __first1 + __i;
+                _RandomAccessIterator1 __e = __first1 + (__i + __len);
 
-                    //try searching for the first element which not equal to *__b
-                    if (__b != __first1)
-                        __b = std::upper_bound(__b, __last1, *__b, __comp);
+                //try searching for the first element which not equal to *__b
+                if (__b != __first1)
+                    __b += __internal::__pstl_upper_bound(__b, _DifferenceType1{0}, __last1 - __b, __b, __comp, __proj1, __proj1);
 
-                    //try searching for the first element which not equal to *__e
-                    if (__e != __last1)
-                        __e = std::upper_bound(__e, __last1, *__e, __comp);
+                //try searching for the first element which not equal to *__e
+                if (__e != __last1)
+                    __e += __internal::__pstl_upper_bound(__e, _DifferenceType1{0}, __last1 - __e, __e, __comp, __proj1, __proj1);
 
-                    //check is [__b; __e) empty
-                    if (__e - __b < 1)
-                    {
-                        _ForwardIterator2 __bb = __last2;
-                        if (__b != __last1)
-                            __bb = std::lower_bound(__first2, __last2, *__b, __comp);
-
-                        const _DifferenceType __buf_pos = __size_func((__b - __first1), (__bb - __first2));
-                        return _SetRange{0, 0, __buf_pos};
-                    }
-
-                    //try searching for "corresponding" subrange [__bb; __ee) in the second sequence
-                    _ForwardIterator2 __bb = __first2;
-                    if (__b != __first1)
-                        __bb = std::lower_bound(__first2, __last2, *__b, __comp);
-
-                    _ForwardIterator2 __ee = __last2;
-                    if (__e != __last1)
-                        __ee = std::lower_bound(__bb, __last2, *__e, __comp);
+                //check is [__b; __e) empty
+                if (__e - __b < 1)
+                {
+                    _RandomAccessIterator2 __bb = __last2;
+                    if (__b != __last1)
+                        __bb = __first2 + __internal::__pstl_lower_bound(__first2, _DifferenceType2{0}, __last2 - __first2,
+                                                                      __b, __comp, __proj2, __proj1);
 
                     const _DifferenceType __buf_pos = __size_func((__b - __first1), (__bb - __first2));
-                    auto __buffer_b = __buffer + __buf_pos;
-                    auto __res = __set_op(__b, __e, __bb, __ee, __buffer_b, __comp);
+                    return _SetRange{0, 0, __buf_pos};
+                }
 
-                    return _SetRange{0, __res - __buffer_b, __buf_pos};
-                },
-                [](const _SetRange& __a, const _SetRange& __b) { // Combine
-                    if (__b.__buf_pos > __a.__buf_pos || ((__b.__buf_pos == __a.__buf_pos) && !__b.empty()))
-                        return _SetRange{__a.__pos + __a.__len + __b.__pos, __b.__len, __b.__buf_pos};
-                    return _SetRange{__b.__pos + __b.__len + __a.__pos, __a.__len, __a.__buf_pos};
-                },
-                __scan,                                     // Scan
-                [&__m, &__scan](const _SetRange& __total) { // Apex
-                    //final scan
-                    __scan(0, 0, __total);
-                    __m = __total.__pos + __total.__len;
-                });
-            return __result + __m;
-        });
+                //try searching for "corresponding" subrange [__bb; __ee) in the second sequence
+                _RandomAccessIterator2 __bb = __first2;
+                if (__b != __first1)
+                    __bb = __first2 + __internal::__pstl_lower_bound(__first2, _DifferenceType2{0}, __last2 - __first2,
+                                                                     __b, __comp, __proj2, __proj1);
+
+                _RandomAccessIterator2 __ee = __last2;
+                if (__e != __last1)
+                    __ee = __bb + __internal::__pstl_lower_bound(__bb, _DifferenceType2{0}, __last2 - __bb, __e, __comp,
+                                                                 __proj2, __proj1);
+
+                const _DifferenceType __buf_pos = __size_func((__b - __first1), (__bb - __first2));
+                auto __buffer_b = __tmp_memory + __buf_pos;
+                auto __res = __set_op(__b, __e, __bb, __ee, __buffer_b, __comp, __proj1, __proj2);
+
+                return _SetRange{0, __res - __buffer_b, __buf_pos};
+            },
+            [](const _SetRange& __a, const _SetRange& __b) { // Combine
+                if (__b.__buf_pos > __a.__buf_pos || ((__b.__buf_pos == __a.__buf_pos) && !__b.empty()))
+                    return _SetRange{__a.__pos + __a.__len + __b.__pos, __b.__len, __b.__buf_pos};
+                return _SetRange{__b.__pos + __b.__len + __a.__pos, __a.__len, __a.__buf_pos};
+            },
+            __scan,                                     // Scan
+            [&__m, &__scan](const _SetRange& __total) { // Apex
+                //final scan
+                __scan(0, 0, __total);
+                __m = __total.__pos + __total.__len;
+            });
+        return __result + __m;
+    });
 }
 
 //a shared parallel pattern for '__pattern_set_union' and '__pattern_set_symmetric_difference'
-template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator,
-          class _Compare, class _SetUnionOp>
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
+          class _OutputIterator, class _SetUnionOp, class _Compare, class _Proj1, class _Proj2>
 _OutputIterator
-__parallel_set_union_op(_Tag __tag, _ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
-                        _ForwardIterator2 __first2, _ForwardIterator2 __last2, _OutputIterator __result,
-                        _Compare __comp, _SetUnionOp __set_union_op)
+__parallel_set_union_op(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
+                        _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2,
+                        _OutputIterator __result, _SetUnionOp __set_union_op, _Compare __comp, _Proj1 __proj1,
+                        _Proj2 __proj2)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    typedef typename std::iterator_traits<_ForwardIterator1>::difference_type _DifferenceType;
+    using _DifferenceType1 = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
+    using _DifferenceType2 = typename std::iterator_traits<_RandomAccessIterator2>::difference_type;
+    using _DifferenceType = std::common_type_t<_DifferenceType1, _DifferenceType2>;
 
     const auto __n1 = __last1 - __first1;
     const auto __n2 = __last2 - __first2;
 
-    auto copy_range1 = [](_ForwardIterator1 __begin, _ForwardIterator1 __end, _OutputIterator __res)
-    { return __internal::__brick_copy(__begin, __end, __res, typename _Tag::__is_vector{}); };
-    auto copy_range2 = [](_ForwardIterator2 __begin, _ForwardIterator2 __end, _OutputIterator __res)
-    { return __internal::__brick_copy(__begin, __end, __res, typename _Tag::__is_vector{}); };
+    __brick_copy<__parallel_tag<_IsVector>> __copy_range{};
 
     // {1} {}: parallel copying just first sequence
     if (__n2 == 0)
-        return __internal::__pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
-                                                 __result, copy_range1);
+        return __internal::__pattern_walk2_brick(__tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
+                                                 __result, __copy_range);
 
-    // {} {2}: parallel copying justmake  second sequence
+    // {} {2}: parallel copying just second sequence
     if (__n1 == 0)
-        return __internal::__pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first2, __last2,
-                                                 __result, copy_range2);
+        return __internal::__pattern_walk2_brick(__tag, ::std::forward<_ExecutionPolicy>(__exec), __first2, __last2,
+                                                 __result, __copy_range);
 
     // testing  whether the sequences are intersected
-    _ForwardIterator1 __left_bound_seq_1 = std::lower_bound(__first1, __last1, *__first2, __comp);
+    _RandomAccessIterator1 __left_bound_seq_1 =
+        __first1 + __internal::__pstl_lower_bound(__first1, _DifferenceType1{0}, __last1 - __first1, __first2, __comp,
+                                                  __proj1, __proj2);
 
     if (__left_bound_seq_1 == __last1)
     {
         //{1} < {2}: seq2 is wholly greater than seq1, so, do parallel copying seq1 and seq2
         __par_backend::__parallel_invoke(
-            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec),
-            [=]
-            {
-                __internal::__pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
-                                                  __result, copy_range1);
+            __backend_tag{}, __exec,
+            [=, &__exec] {
+                __internal::__pattern_walk2_brick(__tag, __exec, __first1, __last1, __result, __copy_range);
             },
-            [=]
-            {
-                __internal::__pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first2, __last2,
-                                                  __result + __n1, copy_range2);
+            [=, &__exec] {
+                __internal::__pattern_walk2_brick(__tag, __exec, __first2, __last2, __result + __n1, __copy_range);
             });
         return __result + __n1 + __n2;
     }
 
     // testing  whether the sequences are intersected
-    _ForwardIterator2 __left_bound_seq_2 = std::lower_bound(__first2, __last2, *__first1, __comp);
+    _RandomAccessIterator2 __left_bound_seq_2 =
+        __first2 + __internal::__pstl_lower_bound(__first2, _DifferenceType2{0}, __last2 - __first2, __first1, __comp,
+                                                  __proj2, __proj1);
 
     if (__left_bound_seq_2 == __last2)
     {
         //{2} < {1}: seq2 is wholly greater than seq1, so, do parallel copying seq1 and seq2
         __par_backend::__parallel_invoke(
-            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec),
-            [=]
-            {
-                __internal::__pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first2, __last2,
-                                                  __result, copy_range2);
+            __backend_tag{}, __exec,
+            [=, &__exec] {
+                __internal::__pattern_walk2_brick(__tag, __exec, __first2, __last2, __result, __copy_range);
             },
-            [=]
-            {
-                __internal::__pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
-                                                  __result + __n2, copy_range1);
+            [=, &__exec] {
+                __internal::__pattern_walk2_brick(__tag, __exec, __first1, __last1, __result + __n2, __copy_range);
             });
         return __result + __n1 + __n2;
     }
@@ -3065,50 +3454,44 @@ __parallel_set_union_op(_Tag __tag, _ExecutionPolicy&& __exec, _ForwardIterator1
         auto __res_or = __result;
         __result += __m1; //we know proper offset due to [first1; left_bound_seq_1) < [first2; last2)
         __par_backend::__parallel_invoke(
-            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec),
+            __backend_tag{}, __exec,
             //do parallel copying of [first1; left_bound_seq_1)
-            [=]
-            {
-                __internal::__pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first1,
-                                                  __left_bound_seq_1, __res_or, copy_range1);
+            [=, &__exec] {
+                __internal::__pattern_walk2_brick(__tag, __exec, __first1, __left_bound_seq_1, __res_or, __copy_range);
             },
-            [=, &__result]
-            {
+            [=, &__exec, &__result] {
                 __result = __internal::__parallel_set_op(
-                    __tag, std::forward<_ExecutionPolicy>(__exec), __left_bound_seq_1, __last1, __first2, __last2,
-                    __result, __comp, [](_DifferenceType __n, _DifferenceType __m) { return __n + __m; },
-                    __set_union_op);
+                    __tag, __exec, __left_bound_seq_1, __last1, __first2, __last2, __result,
+                    [](_DifferenceType __n, _DifferenceType __m) { return __n + __m; }, __set_union_op, __comp, __proj1,
+                    __proj2);
             });
         return __result;
     }
 
     const auto __m2 = __left_bound_seq_2 - __first2;
-    _PSTL_ASSERT(__m1 == 0 || __m2 == 0);
+    assert(__m1 == 0 || __m2 == 0);
     if (__m2 > __set_algo_cut_off)
     {
         auto __res_or = __result;
         __result += __m2; //we know proper offset due to [first2; left_bound_seq_2) < [first1; last1)
         __par_backend::__parallel_invoke(
-            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec),
+            __backend_tag{}, __exec,
             //do parallel copying of [first2; left_bound_seq_2)
-            [=]
-            {
-                __internal::__pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first2,
-                                                  __left_bound_seq_2, __res_or, copy_range2);
+            [=, &__exec] {
+                __internal::__pattern_walk2_brick(__tag, __exec, __first2, __left_bound_seq_2, __res_or, __copy_range);
             },
-            [=, &__result]
-            {
+            [=, &__exec, &__result] {
                 __result = __internal::__parallel_set_op(
-                    __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __left_bound_seq_2, __last2,
-                    __result, __comp, [](_DifferenceType __n, _DifferenceType __m) { return __n + __m; },
-                    __set_union_op);
+                    __tag, __exec, __first1, __last1, __left_bound_seq_2, __last2, __result,
+                    [](_DifferenceType __n, _DifferenceType __m) { return __n + __m; }, __set_union_op, __comp, __proj1,
+                    __proj2);
             });
         return __result;
     }
 
     return __internal::__parallel_set_op(
-        __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result, __comp,
-        [](_DifferenceType __n, _DifferenceType __m) { return __n + __m; }, __set_union_op);
+        __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
+        [](_DifferenceType __n, _DifferenceType __m) { return __n + __m; }, __set_union_op, __comp, __proj1, __proj2);
 }
 
 //------------------------------------------------------------------------
@@ -3119,7 +3502,7 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _OutputIterato
 _OutputIterator
 __brick_set_union(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
                   _ForwardIterator2 __last2, _OutputIterator __result, _Compare __comp,
-                  /*__is_vector=*/std::false_type) noexcept
+                  /*__is_vector=*/::std::false_type) noexcept
 {
     return std::set_union(__first1, __last1, __first2, __last2, __result, __comp);
 }
@@ -3139,7 +3522,7 @@ template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _Out
 _OutputIterator
 __brick_set_union(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
                   _RandomAccessIterator2 __last2, _OutputIterator __result, _Compare __comp,
-                  /*__is_vector=*/std::true_type) noexcept
+                  /*__is_vector=*/::std::true_type) noexcept
 {
     _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
     return std::set_union(__first1, __last1, __first2, __last2, __result, __comp);
@@ -3152,6 +3535,8 @@ __pattern_set_union(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1, _Forwa
                     _ForwardIterator2 __first2, _ForwardIterator2 __last2, _OutputIterator __result,
                     _Compare __comp) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_set_union(__first1, __last1, __first2, __last2, __result, __comp,
                                          typename _Tag::__is_vector{});
 }
@@ -3163,7 +3548,6 @@ __pattern_set_union(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec,
                     _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2,
                     _OutputIterator __result, _Compare __comp)
 {
-
     const auto __n1 = __last1 - __first1;
     const auto __n2 = __last2 - __first2;
 
@@ -3171,15 +3555,17 @@ __pattern_set_union(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec,
     if (__n1 + __n2 <= __set_algo_cut_off)
         return std::set_union(__first1, __last1, __first2, __last2, __result, __comp);
 
-    typedef typename std::iterator_traits<_OutputIterator>::value_type _Tp;
+    using _Tp = typename std::iterator_traits<_OutputIterator>::value_type;
     return __parallel_set_union_op(
-        __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result, __comp,
+        __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
         [](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
-           _RandomAccessIterator2 __last2, _Tp* __result, _Compare __comp)
-        {
-            return __pstl::__utils::__set_union_construct(__first1, __last1, __first2, __last2, __result, __comp,
-                                                          __BrickCopyConstruct<_IsVector>());
-        });
+           _RandomAccessIterator2 __last2, _Tp* __result, _Compare __comp, __onedpl::identity,
+           __onedpl::identity) {
+            return __onedpl::__utils::__set_union_construct(__first1, __last1, __first2, __last2, __result,
+                                                               __BrickCopyConstruct<_IsVector>(), __comp,
+                                                               __onedpl::identity{}, __onedpl::identity{});
+        },
+        __comp, __onedpl::identity{}, __onedpl::identity{});
 }
 
 //------------------------------------------------------------------------
@@ -3190,7 +3576,7 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _OutputIterato
 _OutputIterator
 __brick_set_intersection(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
                          _ForwardIterator2 __last2, _OutputIterator __result, _Compare __comp,
-                         /*__is_vector=*/std::false_type) noexcept
+                         /*__is_vector=*/::std::false_type) noexcept
 {
     return std::set_intersection(__first1, __last1, __first2, __last2, __result, __comp);
 }
@@ -3200,7 +3586,7 @@ _RandomAccessIterator3
 __brick_set_intersection(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
                          _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2,
                          _RandomAccessIterator3 __result, _Compare __comp,
-                         /*__is_vector=*/std::true_type) noexcept
+                         /*__is_vector=*/::std::true_type) noexcept
 {
     _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
     return std::set_intersection(__first1, __last1, __first2, __last2, __result, __comp);
@@ -3213,6 +3599,8 @@ __pattern_set_intersection(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1,
                            _ForwardIterator2 __first2, _ForwardIterator2 __last2, _OutputIterator __result,
                            _Compare __comp) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_set_intersection(__first1, __last1, __first2, __last2, __result, __comp,
                                                 typename _Tag::__is_vector{});
 }
@@ -3224,8 +3612,11 @@ __pattern_set_intersection(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& _
                            _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
                            _RandomAccessIterator2 __last2, _RandomAccessIterator3 __result, _Compare __comp)
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator3>::value_type _Tp;
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type _DifferenceType;
+    using _T = typename std::iterator_traits<_RandomAccessIterator3>::value_type;
+
+    using _DifferenceType1 = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
+    using _DifferenceType2 = typename std::iterator_traits<_RandomAccessIterator2>::difference_type;
+    using _DifferenceType = std::common_type_t<_DifferenceType1, _DifferenceType2>;
 
     const auto __n1 = __last1 - __first1;
     const auto __n2 = __last2 - __first2;
@@ -3250,29 +3641,41 @@ __pattern_set_intersection(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& _
     if (__m1 > __set_algo_cut_off)
     {
         //we know proper offset due to [first1; left_bound_seq_1) < [first2; last2)
-        return __internal::__parallel_set_op(
-            __tag, std::forward<_ExecutionPolicy>(__exec), __left_bound_seq_1, __last1, __first2, __last2, __result,
-            __comp, [](_DifferenceType __n, _DifferenceType __m) { return std::min(__n, __m); },
-            [](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
-               _RandomAccessIterator2 __last2, _Tp* __result, _Compare __comp) {
-                return __pstl::__utils::__set_intersection_construct(__first1, __last1, __first2, __last2, __result,
-                                                                     __comp);
-            });
+        return __internal::__except_handler([&]() {
+            return __internal::__parallel_set_op(
+                __tag, std::forward<_ExecutionPolicy>(__exec), __left_bound_seq_1, __last1, __first2, __last2, __result,
+                [](_DifferenceType __n, _DifferenceType __m) { return std::min(__n, __m); },
+                [](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
+                   _RandomAccessIterator2 __last2, _T* __result, _Compare __comp, __onedpl::identity,
+                   __onedpl::identity) {
+                    return __onedpl::__utils::__set_intersection_construct(
+                        __first1, __last1, __first2, __last2, __result,
+                        __onedpl::__internal::__op_uninitialized_copy<_ExecutionPolicy>{}, __comp,
+                        __onedpl::identity{}, __onedpl::identity{});
+                },
+                __comp, __onedpl::identity{}, __onedpl::identity{});
+        });
     }
 
     const auto __m2 = __last2 - __left_bound_seq_2 + __n1;
     if (__m2 > __set_algo_cut_off)
     {
         //we know proper offset due to [first2; left_bound_seq_2) < [first1; last1)
-        __result = __internal::__parallel_set_op(
-            __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __left_bound_seq_2, __last2, __result,
-            __comp, [](_DifferenceType __n, _DifferenceType __m) { return std::min(__n, __m); },
-            [](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
-               _RandomAccessIterator2 __last2, _Tp* __result, _Compare __comp) {
-                return __pstl::__utils::__set_intersection_construct(__first2, __last2, __first1, __last1, __result,
-                                                                     __comp);
-            });
-        return __result;
+        return __internal::__except_handler([&]() {
+            __result = __internal::__parallel_set_op(
+                __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __left_bound_seq_2, __last2, __result,
+                [](_DifferenceType __n, _DifferenceType __m) { return std::min(__n, __m); },
+                [](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
+                   _RandomAccessIterator2 __last2, _T* __result, _Compare __comp, __onedpl::identity,
+                   __onedpl::identity) {
+                    return __onedpl::__utils::__set_intersection_construct(
+                        __first1, __last1, __first2, __last2, __result,
+                        __onedpl::__internal::__op_uninitialized_copy<_ExecutionPolicy>{}, __comp,
+                        __onedpl::identity{}, __onedpl::identity{});
+                },
+                __comp, __onedpl::identity{}, __onedpl::identity{});
+            return __result;
+        });
     }
 
     // [left_bound_seq_1; last1) and [left_bound_seq_2; last2) - use serial algorithm
@@ -3287,7 +3690,7 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _OutputIterato
 _OutputIterator
 __brick_set_difference(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
                        _ForwardIterator2 __last2, _OutputIterator __result, _Compare __comp,
-                       /*__is_vector=*/std::false_type) noexcept
+                       /*__is_vector=*/::std::false_type) noexcept
 {
     return std::set_difference(__first1, __last1, __first2, __last2, __result, __comp);
 }
@@ -3296,7 +3699,7 @@ template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _Ran
 _RandomAccessIterator3
 __brick_set_difference(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
                        _RandomAccessIterator2 __last2, _RandomAccessIterator3 __result, _Compare __comp,
-                       /*__is_vector=*/std::true_type) noexcept
+                       /*__is_vector=*/::std::true_type) noexcept
 {
     _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
     return std::set_difference(__first1, __last1, __first2, __last2, __result, __comp);
@@ -3309,6 +3712,8 @@ __pattern_set_difference(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1, _
                          _ForwardIterator2 __first2, _ForwardIterator2 __last2, _OutputIterator __result,
                          _Compare __comp) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_set_difference(__first1, __last1, __first2, __last2, __result, __comp,
                                               typename _Tag::__is_vector{});
 }
@@ -3320,8 +3725,8 @@ __pattern_set_difference(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __e
                          _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
                          _RandomAccessIterator2 __last2, _RandomAccessIterator3 __result, _Compare __comp)
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator3>::value_type _Tp;
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type _DifferenceType;
+    using _T = typename std::iterator_traits<_RandomAccessIterator3>::value_type;
+    using _DifferenceType = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
 
     const auto __n1 = __last1 - __first1;
     const auto __n2 = __last2 - __first2;
@@ -3332,39 +3737,35 @@ __pattern_set_difference(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __e
 
     // {1} \ {}: parallel copying just first sequence
     if (__n2 == 0)
-        return __internal::__pattern_walk2_brick(
-            __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __result,
-            [](_RandomAccessIterator1 __begin, _RandomAccessIterator1 __end, _RandomAccessIterator3 __res)
-            { return __internal::__brick_copy(__begin, __end, __res, _IsVector{}); });
+        return __pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __result,
+                                     __internal::__brick_copy<__parallel_tag<_IsVector>>{});
 
     // testing  whether the sequences are intersected
     _RandomAccessIterator1 __left_bound_seq_1 = std::lower_bound(__first1, __last1, *__first2, __comp);
     //{1} < {2}: seq 2 is wholly greater than seq 1, so, parallel copying just first sequence
     if (__left_bound_seq_1 == __last1)
-        return __internal::__pattern_walk2_brick(
-            __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __result,
-            [](_RandomAccessIterator1 __begin, _RandomAccessIterator1 __end, _RandomAccessIterator3 __res)
-            { return __internal::__brick_copy(__begin, __end, __res, _IsVector{}); });
+        return __pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __result,
+                                     __internal::__brick_copy<__parallel_tag<_IsVector>>{});
 
     // testing  whether the sequences are intersected
     _RandomAccessIterator2 __left_bound_seq_2 = std::lower_bound(__first2, __last2, *__first1, __comp);
     //{2} < {1}: seq 1 is wholly greater than seq 2, so, parallel copying just first sequence
     if (__left_bound_seq_2 == __last2)
-        return __internal::__pattern_walk2_brick(
-            __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __result,
-            [](_RandomAccessIterator1 __begin, _RandomAccessIterator1 __end, _RandomAccessIterator3 __res)
-            { return __internal::__brick_copy(__begin, __end, __res, _IsVector{}); });
+        return __internal::__pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
+                                                 __result, __brick_copy<__parallel_tag<_IsVector>>{});
 
     if (__n1 + __n2 > __set_algo_cut_off)
         return __parallel_set_op(
-            __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result, __comp,
+            __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
             [](_DifferenceType __n, _DifferenceType) { return __n; },
             [](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
-               _RandomAccessIterator2 __last2, _Tp* __result, _Compare __comp)
-            {
-                return __pstl::__utils::__set_difference_construct(__first1, __last1, __first2, __last2, __result,
-                                                                   __comp, __BrickCopyConstruct<_IsVector>());
-            });
+               _RandomAccessIterator2 __last2, _T* __result, _Compare __comp, __onedpl::identity,
+               __onedpl::identity) {
+                return __onedpl::__utils::__set_difference_construct(
+                    __first1, __last1, __first2, __last2, __result, __BrickCopyConstruct<_IsVector>(), __comp,
+                    __onedpl::identity{}, __onedpl::identity{});
+            },
+            __comp, __onedpl::identity{}, __onedpl::identity{});
 
     // use serial algorithm
     return std::set_difference(__first1, __last1, __first2, __last2, __result, __comp);
@@ -3378,7 +3779,7 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _OutputIterato
 _OutputIterator
 __brick_set_symmetric_difference(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
                                  _ForwardIterator2 __last2, _OutputIterator __result, _Compare __comp,
-                                 /*__is_vector=*/std::false_type) noexcept
+                                 /*__is_vector=*/::std::false_type) noexcept
 {
     return std::set_symmetric_difference(__first1, __last1, __first2, __last2, __result, __comp);
 }
@@ -3388,7 +3789,7 @@ _RandomAccessIterator3
 __brick_set_symmetric_difference(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
                                  _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2,
                                  _RandomAccessIterator3 __result, _Compare __comp,
-                                 /*__is_vector=*/std::true_type) noexcept
+                                 /*__is_vector=*/::std::true_type) noexcept
 {
     _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
     return std::set_symmetric_difference(__first1, __last1, __first2, __last2, __result, __comp);
@@ -3401,6 +3802,8 @@ __pattern_set_symmetric_difference(_Tag, _ExecutionPolicy&&, _ForwardIterator1 _
                                    _ForwardIterator2 __first2, _ForwardIterator2 __last2, _OutputIterator __result,
                                    _Compare __comp) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_set_symmetric_difference(__first1, __last1, __first2, __last2, __result, __comp,
                                                         typename _Tag::__is_vector{});
 }
@@ -3413,7 +3816,6 @@ __pattern_set_symmetric_difference(__parallel_tag<_IsVector> __tag, _ExecutionPo
                                    _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2,
                                    _RandomAccessIterator3 __result, _Compare __comp)
 {
-
     const auto __n1 = __last1 - __first1;
     const auto __n2 = __last2 - __first2;
 
@@ -3421,15 +3823,19 @@ __pattern_set_symmetric_difference(__parallel_tag<_IsVector> __tag, _ExecutionPo
     if (__n1 + __n2 <= __set_algo_cut_off)
         return std::set_symmetric_difference(__first1, __last1, __first2, __last2, __result, __comp);
 
-    typedef typename std::iterator_traits<_RandomAccessIterator3>::value_type _Tp;
-    return __internal::__parallel_set_union_op(
-        __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result, __comp,
-        [](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
-           _RandomAccessIterator2 __last2, _Tp* __result, _Compare __comp)
-        {
-            return __pstl::__utils::__set_symmetric_difference_construct(__first1, __last1, __first2, __last2, __result,
-                                                                         __comp, __BrickCopyConstruct<_IsVector>());
-        });
+    using _T = typename std::iterator_traits<_RandomAccessIterator3>::value_type;
+    return __internal::__except_handler([&]() {
+        return __internal::__parallel_set_union_op(
+            __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
+            [](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
+               _RandomAccessIterator2 __last2, _T* __result, _Compare __comp, __onedpl::identity,
+               __onedpl::identity) {
+                return __onedpl::__utils::__set_symmetric_difference_construct(
+                    __first1, __last1, __first2, __last2, __result, __BrickCopyConstruct<_IsVector>(), __comp,
+                    __onedpl::identity{}, __onedpl::identity{});
+            },
+            __comp, __onedpl::identity{}, __onedpl::identity{});
+    });
 }
 
 //------------------------------------------------------------------------
@@ -3439,22 +3845,21 @@ __pattern_set_symmetric_difference(__parallel_tag<_IsVector> __tag, _ExecutionPo
 template <class _RandomAccessIterator, class _Compare>
 _RandomAccessIterator
 __brick_is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
-                      /* __is_vector = */ std::false_type) noexcept
+                      /* __is_vector = */ ::std::false_type) noexcept
 {
-    return std::is_heap_until(__first, __last, __comp);
+    return ::std::is_heap_until(__first, __last, __comp);
 }
 
 template <class _RandomAccessIterator, class _Compare>
 _RandomAccessIterator
 __brick_is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
-                      /* __is_vector = */ std::true_type) noexcept
+                      /* __is_vector = */ ::std::true_type) noexcept
 {
-    if (__last - __first < 2)
-        return __last;
-    typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type _SizeType;
-    return __unseq_backend::__simd_first(
-        __first, _SizeType(0), __last - __first,
-        [&__comp](_RandomAccessIterator __it, _SizeType __i) { return __comp(__it[(__i - 1) / 2], __it[__i]); });
+    using _SizeType = typename std::iterator_traits<_RandomAccessIterator>::difference_type;
+    return __unseq_backend::__simd_first(__first, _SizeType(0), __last - __first,
+                                         [&__comp](_RandomAccessIterator __it, _SizeType __i) {
+                                             return std::invoke(__comp, __it[(__i - 1) / 2], __it[__i]);
+                                         });
 }
 
 template <class _Tag, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
@@ -3462,58 +3867,114 @@ _RandomAccessIterator
 __pattern_is_heap_until(_Tag, _ExecutionPolicy&&, _RandomAccessIterator __first, _RandomAccessIterator __last,
                         _Compare __comp) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_is_heap_until(__first, __last, __comp, typename _Tag::__is_vector{});
 }
 
 template <class _RandomAccessIterator, class _DifferenceType, class _Compare>
 _RandomAccessIterator
 __is_heap_until_local(_RandomAccessIterator __first, _DifferenceType __begin, _DifferenceType __end, _Compare __comp,
-                      /* __is_vector = */ std::false_type) noexcept
+                      /* __is_vector = */ ::std::false_type) noexcept
 {
     _DifferenceType __i = __begin;
     for (; __i < __end; ++__i)
-    {
-        if (__comp(__first[(__i - 1) / 2], __first[__i]))
-        {
+        if (std::invoke(__comp, __first[(__i - 1) / 2], __first[__i]))
             break;
-        }
-    }
     return __first + __i;
 }
 
 template <class _RandomAccessIterator, class _DifferenceType, class _Compare>
 _RandomAccessIterator
 __is_heap_until_local(_RandomAccessIterator __first, _DifferenceType __begin, _DifferenceType __end, _Compare __comp,
-                      /* __is_vector = */ std::true_type) noexcept
+                      /* __is_vector = */ ::std::true_type) noexcept
 {
-    return __unseq_backend::__simd_first(
-        __first, __begin, __end,
-        [&__comp](_RandomAccessIterator __it, _DifferenceType __i) { return __comp(__it[(__i - 1) / 2], __it[__i]); });
+    return __unseq_backend::__simd_first(__first, __begin, __end,
+                                         [&__comp](_RandomAccessIterator __it, _DifferenceType __i) {
+                                             return std::invoke(__comp, __it[(__i - 1) / 2], __it[__i]);
+                                         });
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
 _RandomAccessIterator
 __pattern_is_heap_until(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
-                        _RandomAccessIterator __last, _Compare __comp) noexcept
+                        _RandomAccessIterator __last, _Compare __comp)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    return __internal::__except_handler([&]() {
+        return __parallel_find(
+            __tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+            [__first, __comp](_RandomAccessIterator __i, _RandomAccessIterator __j) {
+                return __internal::__is_heap_until_local(__first, __i - __first, __j - __first, __comp, _IsVector{});
+            },
+            ::std::true_type{});
+    });
+}
 
-    if (__last - __first < 2)
-        return __last;
+//------------------------------------------------------------------------
+// is_heap
+//------------------------------------------------------------------------
 
-    return __internal::__except_handler(
-        [&]()
-        {
-            return __parallel_find(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                [__first, __comp](_RandomAccessIterator __i, _RandomAccessIterator __j) {
-                    return __internal::__is_heap_until_local(__first, __i - __first, __j - __first, __comp,
-                                                             _IsVector{});
-                },
-                std::less<typename std::iterator_traits<_RandomAccessIterator>::difference_type>(), /*is_first=*/true);
+template <class _RandomAccessIterator, class _Compare>
+bool
+__brick_is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
+                /* __is_vector = */ ::std::false_type) noexcept
+{
+    return ::std::is_heap(__first, __last, __comp);
+}
+
+template <class _RandomAccessIterator, class _Compare>
+bool
+__brick_is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
+                /* __is_vector = */ ::std::true_type) noexcept
+{
+    return !__unseq_backend::__simd_or_iter(__first, __last - __first, [__first, &__comp](_RandomAccessIterator __it) {
+        return std::invoke(__comp, *(__first + (__it - __first - 1) / 2), *__it);
+    });
+}
+
+template <class _RandomAccessIterator, class _DifferenceType, class _Compare>
+bool
+__is_heap_local(_RandomAccessIterator __first, _DifferenceType __begin, _DifferenceType __end, _Compare __comp,
+                /* __is_vector = */ ::std::false_type) noexcept
+{
+    return __internal::__is_heap_until_local(__first, __begin, __end, __comp, ::std::false_type{}) == __first + __end;
+}
+
+template <class _RandomAccessIterator, class _DifferenceType, class _Compare>
+bool
+__is_heap_local(_RandomAccessIterator __first, _DifferenceType __begin, _DifferenceType __end, _Compare __comp,
+                /* __is_vector = */ ::std::true_type) noexcept
+{
+    return !__unseq_backend::__simd_or_iter(
+        __first + __begin, __end - __begin, [__first, &__comp](_RandomAccessIterator __it) {
+            return std::invoke(__comp, *(__first + (__it - __first - 1) / 2), *__it);
         });
 }
 
+template <class _Tag, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
+bool
+__pattern_is_heap(_Tag, _ExecutionPolicy&&, _RandomAccessIterator __first, _RandomAccessIterator __last,
+                  _Compare __comp) noexcept
+{
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
+    return __internal::__brick_is_heap(__first, __last, __comp, typename _Tag::__is_vector{});
+}
+
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
+bool
+__pattern_is_heap(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+                  _RandomAccessIterator __last, _Compare __comp)
+{
+    return __internal::__except_handler([&]() {
+        return !__parallel_or(__tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                              [__first, __comp](_RandomAccessIterator __i, _RandomAccessIterator __j) {
+                                  return !__internal::__is_heap_local(__first, __i - __first, __j - __first, __comp,
+                                                                      _IsVector{});
+                              });
+    });
+}
+
 //------------------------------------------------------------------------
 // min_element
 //------------------------------------------------------------------------
@@ -3521,56 +3982,64 @@ __pattern_is_heap_until(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __ex
 template <typename _ForwardIterator, typename _Compare>
 _ForwardIterator
 __brick_min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp,
-                    /* __is_vector = */ std::false_type) noexcept
+                    /* __is_vector = */ ::std::false_type) noexcept
 {
-    return std::min_element(__first, __last, __comp);
+    return ::std::min_element(__first, __last, __comp);
 }
 
 template <typename _RandomAccessIterator, typename _Compare>
 _RandomAccessIterator
 __brick_min_element(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
-                    /* __is_vector = */ std::true_type) noexcept
+                    /* __is_vector = */ ::std::true_type) noexcept
 {
-#if defined(_PSTL_UDR_PRESENT)
+#if _ONEDPL_UDR_PRESENT // _PSTL_UDR_PRESENT
     return __unseq_backend::__simd_min_element(__first, __last - __first, __comp);
 #else
-    return std::min_element(__first, __last, __comp);
+    return ::std::min_element(__first, __last, __comp);
 #endif
 }
 
-template <typename _Tag, typename _ExecutionPolicy, typename _ForwardIterator, typename _Compare>
+template <class _Tag, typename _ExecutionPolicy, typename _ForwardIterator, typename _Compare>
 _ForwardIterator
 __pattern_min_element(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last,
                       _Compare __comp) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_min_element(__first, __last, __comp, typename _Tag::__is_vector{});
 }
 
 template <typename _IsVector, typename _ExecutionPolicy, typename _RandomAccessIterator, typename _Compare>
 _RandomAccessIterator
-__pattern_min_element(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+__pattern_min_element(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                       _RandomAccessIterator __last, _Compare __comp)
 {
-    if (__first == __last)
-        return __last;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    // a trivial case pre-check
+    if (__last - __first < 2)
+        return __first;
 
-    return __internal::__except_handler(
-        [&]()
-        {
-            return __par_backend::__parallel_reduce(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first + 1, __last, __first,
-                [=](_RandomAccessIterator __begin, _RandomAccessIterator __end,
-                    _RandomAccessIterator __init) -> _RandomAccessIterator
-                {
-                    const _RandomAccessIterator subresult =
-                        __internal::__brick_min_element(__begin, __end, __comp, _IsVector{});
-                    return __internal::__cmp_iterators_by_values(__init, subresult, __comp);
-                },
-                [=](_RandomAccessIterator __it1, _RandomAccessIterator __it2) -> _RandomAccessIterator
-                { return __internal::__cmp_iterators_by_values(__it1, __it2, __comp); });
-        });
+    return __internal::__except_handler([&]() {
+        return __par_backend::__parallel_reduce(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last, /*identity*/ __last,
+            [=](_RandomAccessIterator __begin, _RandomAccessIterator __end,
+                _RandomAccessIterator __init) -> _RandomAccessIterator {
+                const _RandomAccessIterator __subresult =
+                    __internal::__brick_min_element(__begin, __end, __comp, _IsVector{});
+                return __init == __last ? __subresult
+                                        : __internal::__cmp_iterators_by_values(__init, __subresult, __comp,
+                                                                                __onedpl::__internal::__pstl_less());
+            },
+            [=](_RandomAccessIterator __it1, _RandomAccessIterator __it2) -> _RandomAccessIterator {
+                if (__it1 == __last)
+                    return __it2;
+                if (__it2 == __last)
+                    return __it1;
+                return __internal::__cmp_iterators_by_values(__it1, __it2, __comp,
+                                                             __onedpl::__internal::__pstl_less());
+            });
+    });
 }
 
 //------------------------------------------------------------------------
@@ -3578,61 +4047,74 @@ __pattern_min_element(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec
 //------------------------------------------------------------------------
 
 template <typename _ForwardIterator, typename _Compare>
-std::pair<_ForwardIterator, _ForwardIterator>
+::std::pair<_ForwardIterator, _ForwardIterator>
 __brick_minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp,
-                       /* __is_vector = */ std::false_type) noexcept
+                       /* __is_vector = */ ::std::false_type) noexcept
 {
-    return std::minmax_element(__first, __last, __comp);
+    return ::std::minmax_element(__first, __last, __comp);
 }
 
 template <typename _RandomAccessIterator, typename _Compare>
-std::pair<_RandomAccessIterator, _RandomAccessIterator>
+::std::pair<_RandomAccessIterator, _RandomAccessIterator>
 __brick_minmax_element(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
-                       /* __is_vector = */ std::true_type) noexcept
+                       /* __is_vector = */ ::std::true_type) noexcept
 {
-#if defined(_PSTL_UDR_PRESENT)
+#if _ONEDPL_UDR_PRESENT // _PSTL_UDR_PRESENT
     return __unseq_backend::__simd_minmax_element(__first, __last - __first, __comp);
 #else
-    return std::minmax_element(__first, __last, __comp);
+    return ::std::minmax_element(__first, __last, __comp);
 #endif
 }
 
-template <typename _Tag, typename _ExecutionPolicy, typename _ForwardIterator, typename _Compare>
-std::pair<_ForwardIterator, _ForwardIterator>
+template <class _Tag, typename _ExecutionPolicy, typename _ForwardIterator, typename _Compare>
+::std::pair<_ForwardIterator, _ForwardIterator>
 __pattern_minmax_element(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last,
                          _Compare __comp) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_minmax_element(__first, __last, __comp, typename _Tag::__is_vector{});
 }
 
 template <typename _IsVector, typename _ExecutionPolicy, typename _RandomAccessIterator, typename _Compare>
-std::pair<_RandomAccessIterator, _RandomAccessIterator>
-__pattern_minmax_element(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+::std::pair<_RandomAccessIterator, _RandomAccessIterator>
+__pattern_minmax_element(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                          _RandomAccessIterator __last, _Compare __comp)
 {
-    if (__first == __last)
-        return std::make_pair(__first, __first);
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    // a trivial case pre-check
+    if (__last - __first < 2)
+        return ::std::make_pair(__first, __first);
 
     return __internal::__except_handler([&]() {
-        typedef std::pair<_RandomAccessIterator, _RandomAccessIterator> _Result;
+        using _Result = std::pair<_RandomAccessIterator, _RandomAccessIterator>;
 
         return __par_backend::__parallel_reduce(
-            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first + 1, __last,
-            std::make_pair(__first, __first),
-            [=](_RandomAccessIterator __begin, _RandomAccessIterator __end, _Result __init) -> _Result
-            {
+            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last,
+            /*identity*/ std::make_pair(__last, __last),
+            [=, &__comp](_RandomAccessIterator __begin, _RandomAccessIterator __end, _Result __init) -> _Result {
                 const _Result __subresult = __internal::__brick_minmax_element(__begin, __end, __comp, _IsVector{});
-                return std::make_pair(
-                    __internal::__cmp_iterators_by_values(__subresult.first, __init.first, __comp),
-                    __internal::__cmp_iterators_by_values(__init.second, __subresult.second, std::not_fn(__comp)));
+                if (__init.first == __last) // = identity
+                    return __subresult;
+                return ::std::make_pair(
+                    __internal::__cmp_iterators_by_values(__init.first, __subresult.first, __comp,
+                                                          __onedpl::__internal::__pstl_less()),
+                    __internal::__cmp_iterators_by_values(__init.second, __subresult.second,
+                                                          __onedpl::__internal::__reorder_pred<_Compare>(__comp),
+                                                          __onedpl::__internal::__pstl_greater()));
             },
-            [=](_Result __p1, _Result __p2) -> _Result
-            {
-                return std::make_pair(
-                    __internal::__cmp_iterators_by_values(__p1.first, __p2.first, __comp),
-                    __internal::__cmp_iterators_by_values(__p2.second, __p1.second, std::not_fn(__comp)));
+            [=, &__comp](_Result __p1, _Result __p2) -> _Result {
+                if (__p1.first == __last)
+                    return __p2;
+                if (__p2.first == __last)
+                    return __p1;
+                return ::std::make_pair(
+                    __internal::__cmp_iterators_by_values(__p1.first, __p2.first, __comp,
+                                                          __onedpl::__internal::__pstl_less()),
+                    __internal::__cmp_iterators_by_values(__p1.second, __p2.second,
+                                                          __onedpl::__internal::__reorder_pred<_Compare>(__comp),
+                                                          __onedpl::__internal::__pstl_greater()));
             });
     });
 }
@@ -3641,66 +4123,61 @@ __pattern_minmax_element(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __e
 // mismatch
 //------------------------------------------------------------------------
 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-std::pair<_ForwardIterator1, _ForwardIterator2>
+::std::pair<_ForwardIterator1, _ForwardIterator2>
 __mismatch_serial(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
                   _ForwardIterator2 __last2, _BinaryPredicate __pred)
 {
-#if defined(_PSTL_CPP14_2RANGE_MISMATCH_EQUAL_PRESENT)
-    return std::mismatch(__first1, __last1, __first2, __last2, __pred);
-#else
-    for (; __first1 != __last1 && __first2 != __last2 && __pred(*__first1, *__first2); ++__first1, (void) ++__first2)
-    {
-    }
-    return std::make_pair(__first1, __first2);
-#endif
+    return ::std::mismatch(__first1, __last1, __first2, __last2, __pred);
 }
 
 template <class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
-std::pair<_ForwardIterator1, _ForwardIterator2>
+::std::pair<_ForwardIterator1, _ForwardIterator2>
 __brick_mismatch(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
-                 _ForwardIterator2 __last2, _Predicate __pred, /* __is_vector = */ std::false_type) noexcept
+                 _ForwardIterator2 __last2, _Predicate __pred, /* __is_vector = */ ::std::false_type) noexcept
 {
     return __mismatch_serial(__first1, __last1, __first2, __last2, __pred);
 }
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _Predicate>
-std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
+::std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
 __brick_mismatch(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
-                 _RandomAccessIterator2 __last2, _Predicate __pred, /* __is_vector = */ std::true_type) noexcept
+                 _RandomAccessIterator2 __last2, _Predicate __pred, /* __is_vector = */ ::std::true_type) noexcept
 {
-    auto __n = std::min(__last1 - __first1, __last2 - __first2);
-    return __unseq_backend::__simd_first(__first1, __n, __first2, std::not_fn(__pred));
+    auto __n = ::std::min(__last1 - __first1, __last2 - __first2);
+    return __unseq_backend::__simd_first(__first1, __n, __first2, __not_pred<_Predicate&>(__pred));
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
-std::pair<_ForwardIterator1, _ForwardIterator2>
+::std::pair<_ForwardIterator1, _ForwardIterator2>
 __pattern_mismatch(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                    _ForwardIterator2 __first2, _ForwardIterator2 __last2, _Predicate __pred) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_mismatch(__first1, __last1, __first2, __last2, __pred, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
           class _Predicate>
-std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
+::std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
 __pattern_mismatch(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
                    _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2,
-                   _Predicate __pred) noexcept
+                   _Predicate __pred)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    if (__last1 - __first1 == 0 || __last2 - __first2 == 0)
+        return {__first1, __first2};
 
     return __internal::__except_handler([&]() {
-        auto __n = std::min(__last1 - __first1, __last2 - __first2);
+        auto __n = ::std::min(__last1 - __first1, __last2 - __first2);
         auto __result = __internal::__parallel_find(
-            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + __n,
-            [__first1, __first2, __pred](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j)
-            {
+            __tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + __n,
+            [__first1, __first2, __pred](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
                 return __internal::__brick_mismatch(__i, __j, __first2 + (__i - __first1), __first2 + (__j - __first1),
                                                     __pred, _IsVector{})
                     .first;
             },
-            std::less<typename std::iterator_traits<_RandomAccessIterator1>::difference_type>(), /*is_first=*/true);
-        return std::make_pair(__result, __first2 + (__result - __first1));
+            ::std::true_type{});
+        return ::std::make_pair(__result, __first2 + (__result - __first1));
     });
 }
 
@@ -3712,16 +4189,16 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _Compare>
 bool
 __brick_lexicographical_compare(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
                                 _ForwardIterator2 __last2, _Compare __comp,
-                                /* __is_vector = */ std::false_type) noexcept
+                                /* __is_vector = */ ::std::false_type) noexcept
 {
-    return std::lexicographical_compare(__first1, __last1, __first2, __last2, __comp);
+    return ::std::lexicographical_compare(__first1, __last1, __first2, __last2, __comp);
 }
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _Compare>
 bool
 __brick_lexicographical_compare(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
                                 _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _Compare __comp,
-                                /* __is_vector = */ std::true_type) noexcept
+                                /* __is_vector = */ ::std::true_type) noexcept
 {
     if (__first2 == __last2)
     { // if second sequence is empty
@@ -3733,23 +4210,23 @@ __brick_lexicographical_compare(_RandomAccessIterator1 __first1, _RandomAccessIt
     }
     else
     {
-        typedef typename std::iterator_traits<_RandomAccessIterator1>::reference ref_type1;
-        typedef typename std::iterator_traits<_RandomAccessIterator2>::reference ref_type2;
+        using ref_type1 = typename std::iterator_traits<_RandomAccessIterator1>::reference;
+        using ref_type2 = typename std::iterator_traits<_RandomAccessIterator2>::reference;
         --__last1;
         --__last2;
-        auto __n = std::min(__last1 - __first1, __last2 - __first2);
-        std::pair<_RandomAccessIterator1, _RandomAccessIterator2> __result = __unseq_backend::__simd_first(
+        auto __n = ::std::min(__last1 - __first1, __last2 - __first2);
+        ::std::pair<_RandomAccessIterator1, _RandomAccessIterator2> __result = __unseq_backend::__simd_first(
             __first1, __n, __first2, [__comp](const ref_type1 __x, const ref_type2 __y) mutable {
-                return __comp(__x, __y) || __comp(__y, __x);
+                return std::invoke(__comp, __x, __y) || std::invoke(__comp, __y, __x);
             });
 
         if (__result.first == __last1 && __result.second != __last2)
         { // if first sequence shorter than second
-            return !__comp(*__result.second, *__result.first);
+            return !std::invoke(__comp, *__result.second, *__result.first);
         }
         else
         { // if second sequence shorter than first or both have the same number of elements
-            return __comp(*__result.first, *__result.second);
+            return std::invoke(__comp, *__result.first, *__result.second);
         }
     }
 }
@@ -3759,6 +4236,8 @@ bool
 __pattern_lexicographical_compare(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                                   _ForwardIterator2 __first2, _ForwardIterator2 __last2, _Compare __comp) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_lexicographical_compare(__first1, __last1, __first2, __last2, __comp,
                                                        typename _Tag::__is_vector{});
 }
@@ -3771,8 +4250,6 @@ __pattern_lexicographical_compare(__parallel_tag<_IsVector> __tag, _ExecutionPol
                                   _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2,
                                   _Compare __comp) noexcept
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
-
     if (__first2 == __last2)
     { // if second sequence is empty
         return false;
@@ -3783,36 +4260,198 @@ __pattern_lexicographical_compare(__parallel_tag<_IsVector> __tag, _ExecutionPol
     }
     else
     {
-        typedef typename std::iterator_traits<_RandomAccessIterator1>::reference _RefType1;
-        typedef typename std::iterator_traits<_RandomAccessIterator2>::reference _RefType2;
-        --__last1;
-        --__last2;
-        auto __n = std::min(__last1 - __first1, __last2 - __first2);
-        auto __result = __internal::__parallel_find(
-            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + __n,
-            [__first1, __first2, &__comp](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j)
-            {
-                return __internal::__brick_mismatch(
-                           __i, __j, __first2 + (__i - __first1), __first2 + (__j - __first1),
-                           [&__comp](const _RefType1 __x, const _RefType2 __y)
-                           { return !__comp(__x, __y) && !__comp(__y, __x); },
-                           _IsVector{})
-                    .first;
-            },
-            std::less<typename std::iterator_traits<_RandomAccessIterator1>::difference_type>(), /*is_first=*/true);
+        using _RefType1 = typename std::iterator_traits<_RandomAccessIterator1>::reference;
+        using _RefType2 = typename std::iterator_traits<_RandomAccessIterator2>::reference;
 
-        if (__result == __last1 && __first2 + (__result - __first1) != __last2)
-        { // if first sequence shorter than second
-            return !__comp(*(__first2 + (__result - __first1)), *__result);
-        }
-        else
-        { // if second sequence shorter than first or both have the same number of elements
-            return __comp(*__result, *(__first2 + (__result - __first1)));
-        }
+        return __internal::__except_handler([&]() {
+            --__last1;
+            --__last2;
+            auto __n = ::std::min(__last1 - __first1, __last2 - __first2);
+            auto __result = __internal::__parallel_find(
+                __tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + __n,
+                [__first1, __first2, &__comp](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
+                    return __internal::__brick_mismatch(
+                               __i, __j, __first2 + (__i - __first1), __first2 + (__j - __first1),
+                               [&__comp](const _RefType1 __x, const _RefType2 __y) {
+                                   return !std::invoke(__comp, __x, __y) && !std::invoke(__comp, __y, __x);
+                               },
+                               _IsVector{})
+                        .first;
+                },
+                ::std::true_type{});
+
+            if (__result == __last1 && __first2 + (__result - __first1) != __last2)
+            { // if first sequence shorter than second
+                return !std::invoke(__comp, *(__first2 + (__result - __first1)), *__result);
+            }
+            else
+            { // if second sequence shorter than first or both have the same number of elements
+                return std::invoke(__comp, *__result, *(__first2 + (__result - __first1)));
+            }
+        });
     }
 }
 
-} // namespace __internal
-} // namespace __pstl
+//------------------------------------------------------------------------
+// swap
+//------------------------------------------------------------------------
 
-#endif /* _PSTL_ALGORITHM_IMPL_H */
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
+_ForwardIterator2
+__pattern_swap(_Tag __tag, _ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
+               _ForwardIterator2 __first2)
+{
+    static_assert(__is_host_dispatch_tag_v<_Tag>);
+
+    return __pattern_walk2(__tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2,
+                           __onedpl::__internal::__swap_fn{});
+}
+
+//------------------------------------------------------------------------
+// shift_left
+//------------------------------------------------------------------------
+
+template <class _ForwardIterator>
+_ForwardIterator
+__brick_shift_left(_ForwardIterator __first, _ForwardIterator __last,
+                   typename ::std::iterator_traits<_ForwardIterator>::difference_type __n,
+                   /*is_vector=*/::std::false_type) noexcept
+{
+#if _ONEDPL_CPP20_SHIFT_LEFT_RIGHT_PRESENT
+    return ::std::shift_left(__first, __last, __n);
+#else
+    //If (n > 0 && n < m), returns first + (m - n). Otherwise, if n  > 0, returns first. Otherwise, returns last.
+    if (__n <= 0)
+        return __last;
+
+    //seek for (first + n)
+    auto __it = __onedpl::__internal::__next_to_last()(__first, __last, __n);
+    if (__it == __last) // n >= last - first;
+        return __first;
+
+    //Moving the rest elements from a position number n to the begin of the sequence.
+    for (; __it != __last; ++__it, (void)++__first)
+        *__first = ::std::move(*__it);
+
+    return __first;
+#endif
+}
+
+template <class _ForwardIterator>
+_ForwardIterator
+__brick_shift_left(_ForwardIterator __first, _ForwardIterator __last,
+                   typename ::std::iterator_traits<_ForwardIterator>::difference_type __n,
+                   /*is_vector=*/::std::true_type) noexcept
+{
+    //If (n > 0 && n < m), returns first + (m - n). Otherwise, if n  > 0, returns first. Otherwise, returns last.
+    if (__n <= 0)
+        return __last;
+    auto __size = __last - __first;
+    if (__n >= __size)
+        return __first;
+
+    using _DiffType = typename ::std::iterator_traits<_ForwardIterator>::difference_type;
+    using _ReferenceType = typename ::std::iterator_traits<_ForwardIterator>::reference;
+
+    _DiffType __mid = __size / 2 + __size % 2;
+    _DiffType __size_res = __size - __n;
+
+    //1. n >= size/2; there is enough memory to 'total' parallel (SIMD) copying
+    if (__n >= __mid)
+    {
+        __unseq_backend::__simd_walk_n(__size_res,
+                                       [](_ReferenceType __x, _ReferenceType __y) { __y = ::std::move(__x); },
+                                       __first + __n, __first);
+    }
+    else //2. n < size/2; there is not enough memory to parallel (SIMD) copying; doing SIMD copying by n elements
+    {
+        for (auto __k = __n; __k < __size; __k += __n)
+        {
+            auto __end = ::std::min(__k + __n, __size);
+            __unseq_backend::__simd_walk_n(__end - __k,
+                                           [](_ReferenceType __x, _ReferenceType __y) { __y = ::std::move(__x); },
+                                           __first + __k, __first + __k - __n);
+        }
+    }
+
+    return __first + __size_res;
+}
+
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator>
+_ForwardIterator
+__pattern_shift_left(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last,
+                     typename ::std::iterator_traits<_ForwardIterator>::difference_type __n) noexcept
+{
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
+    return __brick_shift_left(__first, __last, __n, typename _Tag::__is_vector{});
+}
+
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator>
+_RandomAccessIterator
+__pattern_shift_left(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+                     _RandomAccessIterator __last,
+                     typename ::std::iterator_traits<_RandomAccessIterator>::difference_type __n)
+{
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
+
+    //If (n > 0 && n < m), returns first + (m - n). Otherwise, if n  > 0, returns first. Otherwise, returns last.
+    if (__n <= 0)
+        return __last;
+    auto __size = __last - __first;
+    if (__n >= __size)
+        return __first;
+
+    using _DiffType = typename ::std::iterator_traits<_RandomAccessIterator>::difference_type;
+
+    _DiffType __mid = __size / 2 + __size % 2;
+    _DiffType __size_res = __size - __n;
+
+    return __internal::__except_handler([&]() {
+        //1. n >= size/2; there is enough memory to 'total' parallel copying
+        if (__n >= __mid)
+        {
+            __par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __n, __size,
+                                          [__first, __n](_DiffType __i, _DiffType __j) {
+                                              __brick_move<__parallel_tag<_IsVector>>{}(
+                                                  __first + __i, __first + __j, __first + __i - __n, _IsVector{});
+                                          });
+        }
+        else //2. n < size/2; there is not enough memory to parallel copying; doing parallel copying by n elements
+        {
+            //TODO: to consider parallel processing by the 'internal' loop (but we may probably get cache locality issues)
+            for (auto __k = __n; __k < __size; __k += __n)
+            {
+                auto __end = ::std::min(__k + __n, __size);
+                __par_backend::__parallel_for(__backend_tag{}, __exec, __k, __end,
+                                              [__first, __n](_DiffType __i, _DiffType __j) {
+                                                  __brick_move<__parallel_tag<_IsVector>>{}(
+                                                      __first + __i, __first + __j, __first + __i - __n, _IsVector{});
+                                              });
+            }
+        }
+
+        return __first + __size_res;
+    });
+}
+
+template <class _Tag, class _ExecutionPolicy, class _BidirectionalIterator>
+_BidirectionalIterator
+__pattern_shift_right(_Tag __tag, _ExecutionPolicy&& __exec, _BidirectionalIterator __first,
+                      _BidirectionalIterator __last,
+                      typename ::std::iterator_traits<_BidirectionalIterator>::difference_type __n)
+{
+    static_assert(__is_host_dispatch_tag_v<_Tag>);
+
+    using _ReverseIterator = typename ::std::reverse_iterator<_BidirectionalIterator>;
+
+    auto __res = __onedpl::__internal::__pattern_shift_left(
+        __tag, ::std::forward<_ExecutionPolicy>(__exec), _ReverseIterator(__last), _ReverseIterator(__first), __n);
+
+    return __res.base();
+}
+
+} // namespace __internal
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_ALGORITHM_IMPL_H
diff --git a/libstdc++-v3/include/pstl/algorithm_ranges_impl.h b/libstdc++-v3/include/pstl/algorithm_ranges_impl.h
new file mode 100644
index 000000000000..6c2c227edf84
--- /dev/null
+++ b/libstdc++-v3/include/pstl/algorithm_ranges_impl.h
@@ -0,0 +1,1429 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_ALGORITHM_RANGES_IMPL_H
+#define _ONEDPL_ALGORITHM_RANGES_IMPL_H
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+
+#    include <ranges>
+#    include <utility>
+#    include <cassert>
+#    include <functional>
+#    include <type_traits>
+
+#    include "execution_impl.h"
+#    include "algorithm_impl.h"
+
+namespace std::__onedpl
+{
+namespace __internal
+{
+namespace __ranges
+{
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_for_each
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _Fun, typename _Proj>
+void
+__pattern_for_each(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, _Fun __f, _Proj __proj)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    __onedpl::__internal::__pattern_walk1(__tag, std::forward<_ExecutionPolicy>(__exec), std::ranges::begin(__r),
+                                             std::ranges::begin(__r) + std::ranges::size(__r),
+                                             __onedpl::__internal::__unary_op<_Fun, _Proj>{__f, __proj});
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _Fun, typename _Proj>
+void
+__pattern_for_each(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r, _Fun __f, _Proj __proj)
+{
+    std::ranges::for_each(std::forward<_R>(__r), __f, __proj);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_transform
+//---------------------------------------------------------------------------------------------------------------------
+
+template<typename _Tag, typename _ExecutionPolicy, typename _InRange, typename _OutRange, typename _F, typename _Proj>
+void
+__pattern_transform(_Tag __tag, _ExecutionPolicy&& __exec, _InRange&& __in_r, _OutRange&& __out_r, _F __op,
+                    _Proj __proj)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+    assert(std::ranges::size(__in_r) <= std::ranges::size(__out_r)); // for debug purposes only
+
+    __onedpl::__internal::__transform_functor<__onedpl::__internal::__unary_op<_F, _Proj>> __f{{__op, __proj}};
+
+    __onedpl::__internal::__pattern_walk2(__tag, std::forward<_ExecutionPolicy>(__exec), std::ranges::begin(__in_r),
+                                             std::ranges::begin(__in_r) + std::ranges::size(__in_r),
+                                             std::ranges::begin(__out_r), __f);
+}
+
+template<typename _ExecutionPolicy, typename _InRange, typename _OutRange, typename _F, typename _Proj>
+void
+__pattern_transform(__serial_tag</*IsVector*/std::false_type>, _ExecutionPolicy&&, _InRange&& __in_r, _OutRange&& __out_r,
+                    _F __op, _Proj __proj)
+{
+    std::ranges::transform(std::forward<_InRange>(__in_r), std::ranges::begin(__out_r), __op, __proj);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_transform (binary vesrion)
+//---------------------------------------------------------------------------------------------------------------------
+
+template<typename _Tag, typename _ExecutionPolicy, typename _InRange1, typename _InRange2, typename _OutRange,
+         typename _F, typename _Proj1, typename _Proj2>
+void
+__pattern_transform(_Tag __tag, _ExecutionPolicy&& __exec, _InRange1&& __in_r1, _InRange2&& __in_r2,
+                    _OutRange&& __out_r, _F __binary_op, _Proj1 __proj1,_Proj2 __proj2)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    __onedpl::__internal::__transform_functor<__onedpl::__internal::__binary_op<_F, _Proj1, _Proj2>>
+        __f{{__binary_op, __proj1, __proj2}};
+
+    __onedpl::__internal::__pattern_walk3(__tag, std::forward<_ExecutionPolicy>(__exec), std::ranges::begin(__in_r1),
+                                             std::ranges::begin(__in_r1) + std::ranges::size(__in_r1),
+                                             std::ranges::begin(__in_r2), std::ranges::begin(__out_r), __f);
+}
+
+template<typename _ExecutionPolicy, typename _InRange1, typename _InRange2, typename _OutRange, typename _F,
+         typename _Proj1, typename _Proj2>
+void
+__pattern_transform(__serial_tag</*IsVector*/std::false_type>, _ExecutionPolicy&&, _InRange1&& __in_r1, _InRange2&& __in_r2, _OutRange&& __out_r,
+                    _F __binary_op, _Proj1 __proj1, _Proj2 __proj2)
+{
+    std::ranges::transform(std::forward<_InRange1>(__in_r1), std::forward<_InRange2>(__in_r2),
+                           std::ranges::begin(__out_r), __binary_op, __proj1, __proj2);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_find_if
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _Proj, typename _Pred>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_find_if(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, _Pred __pred, _Proj __proj)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    return __onedpl::__internal::__pattern_find_if(
+        __tag, std::forward<_ExecutionPolicy>(__exec), std::ranges::begin(__r),
+        std::ranges::begin(__r) + std::ranges::size(__r),
+        __onedpl::__internal::__unary_op<_Pred, _Proj>{__pred, __proj});
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _Proj, typename _Pred>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_find_if(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r, _Pred __pred, _Proj __proj)
+{
+    return std::ranges::find_if(std::forward<_R>(__r), __pred, __proj);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// __pattern_find_first_of
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R1, typename _R2, typename _Pred, typename _Proj1,
+          typename _Proj2>
+std::ranges::borrowed_iterator_t<_R1>
+__pattern_find_first_of(_Tag __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _Pred __pred, _Proj1 __proj1,
+                        _Proj2 __proj2)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    return __onedpl::__internal::__pattern_find_first_of(
+        __tag, std::forward<_ExecutionPolicy>(__exec), std::ranges::begin(__r1),
+        std::ranges::begin(__r1) + std::ranges::size(__r1), std::ranges::begin(__r2),
+        std::ranges::begin(__r2) + std::ranges::size(__r2),
+        __onedpl::__internal::__binary_op<_Pred, _Proj1, _Proj2>{__pred, __proj1, __proj2});
+}
+
+template <typename _ExecutionPolicy, typename _R1, typename _R2, typename _Pred, typename _Proj1, typename _Proj2>
+std::ranges::borrowed_iterator_t<_R1>
+__pattern_find_first_of(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R1&& __r1, _R2&& __r2,
+                        _Pred __pred, _Proj1 __proj1, _Proj2 __proj2)
+{
+    return std::ranges::find_first_of(std::forward<_R1>(__r1), std::forward<_R2>(__r2), __pred, __proj1, __proj2);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// __pattern_find_end
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R1, typename _R2, typename _Pred, typename _Proj1,
+          typename _Proj2>
+std::ranges::borrowed_subrange_t<_R1>
+__pattern_find_end(_Tag __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _Pred __pred, _Proj1 __proj1,
+                   _Proj2 __proj2)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    auto __first1 = std::ranges::begin(__r1);
+    auto __last1 = __first1 + std::ranges::size(__r1);
+    if (std::ranges::empty(__r2))
+        return {__last1, __last1};
+
+    const auto __n2 = std::ranges::size(__r2);
+    auto __first2 = std::ranges::begin(__r2);
+    auto __last2 = __first2 + __n2;
+
+    auto __it = __onedpl::__internal::__pattern_find_end(
+        __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
+        __onedpl::__internal::__binary_op<_Pred, _Proj1, _Proj2>{__pred, __proj1, __proj2});
+
+    return {__it, __it + (__it == __last1 ? 0 : __n2)};
+}
+
+template <typename _ExecutionPolicy, typename _R1, typename _R2, typename _Pred, typename _Proj1, typename _Proj2>
+std::ranges::borrowed_subrange_t<_R1>
+__pattern_find_end(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R1&& __r1, _R2&& __r2, _Pred __pred,
+                   _Proj1 __proj1, _Proj2 __proj2)
+{
+    return std::ranges::find_end(std::forward<_R1>(__r1), std::forward<_R2>(__r2), __pred, __proj1, __proj2);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_any_of
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _Proj, typename _Pred>
+bool
+__pattern_any_of(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, _Pred __pred, _Proj __proj)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    return __onedpl::__internal::__pattern_any_of(__tag, std::forward<_ExecutionPolicy>(__exec),
+                                                     std::ranges::begin(__r),
+                                                     std::ranges::begin(__r) + std::ranges::size(__r),
+                                                     __onedpl::__internal::__unary_op<_Pred, _Proj>{__pred, __proj});
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _Proj, typename _Pred>
+bool
+__pattern_any_of(__serial_tag</*IsVector*/std::false_type>, _ExecutionPolicy&&, _R&& __r, _Pred __pred, _Proj __proj)
+{
+    return std::ranges::any_of(std::forward<_R>(__r), __pred, __proj);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_adjacent_find
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _Proj, typename _Pred>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_adjacent_find_ranges(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, _Pred __pred, _Proj __proj)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    return __onedpl::__internal::__pattern_adjacent_find(
+        __tag, std::forward<_ExecutionPolicy>(__exec), std::ranges::begin(__r),
+        std::ranges::begin(__r) + std::ranges::size(__r),
+        __onedpl::__internal::__binary_op<_Pred, _Proj, _Proj>{__pred, __proj, __proj},
+        __onedpl::__internal::__first_semantic());
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _Proj, typename _Pred>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_adjacent_find_ranges(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r, _Pred __pred,
+                               _Proj __proj)
+{
+    return std::ranges::adjacent_find(std::forward<_R>(__r), __pred, __proj);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_search
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R1, typename _R2, typename _Pred, typename _Proj1,
+          typename _Proj2>
+std::ranges::borrowed_subrange_t<_R1>
+__pattern_search(_Tag __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _Pred __pred, _Proj1 __proj1,
+                 _Proj2 __proj2)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    auto __first1 = std::ranges::begin(__r1);
+    auto __last1 = __first1 + std::ranges::size(__r1);
+
+    const auto __n2 = std::ranges::size(__r2);
+    auto __first2 = std::ranges::begin(__r2);
+    auto __last2 = __first2 + __n2;
+
+    auto __res = __onedpl::__internal::__pattern_search(
+        __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
+        __onedpl::__internal::__binary_op<_Pred, _Proj1, _Proj2>{__pred, __proj1, __proj2});
+
+    return {__res, __res == __last1 ? __res : __res + __n2};
+}
+
+template <typename _ExecutionPolicy, typename _R1, typename _R2, typename _Pred, typename _Proj1, typename _Proj2>
+std::ranges::borrowed_subrange_t<_R1>
+__pattern_search(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R1&& __r1, _R2&& __r2, _Pred __pred,
+                 _Proj1 __proj1, _Proj2 __proj2)
+{
+    return std::ranges::search(std::forward<_R1>(__r1), std::forward<_R2>(__r2), __pred, __proj1, __proj2);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_search_n
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _T, typename _Pred, typename _Proj>
+std::ranges::borrowed_subrange_t<_R>
+__pattern_search_n(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, std::ranges::range_difference_t<_R> __count,
+                   const _T& __value, _Pred __pred, _Proj __proj)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    auto __res = __onedpl::__internal::__pattern_search_n(
+        __tag, std::forward<_ExecutionPolicy>(__exec), std::ranges::begin(__r),
+        std::ranges::begin(__r) + std::ranges::size(__r), __count, __value,
+        __onedpl::__internal::__binary_op<_Pred, _Proj, __onedpl::identity>{__pred, __proj});
+
+    return {__res, __res == std::ranges::end(__r) ? __res : __res + __count};
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _T, typename _Pred, typename _Proj>
+std::ranges::borrowed_subrange_t<_R>
+__pattern_search_n(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r,
+                   std::ranges::range_difference_t<_R> __count, const _T& __value, _Pred __pred, _Proj __proj)
+{
+    return std::ranges::search_n(std::forward<_R>(__r), __count, __value, __pred, __proj);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_count_if
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _Proj, typename _Pred>
+std::ranges::range_difference_t<_R>
+__pattern_count_if(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, _Pred __pred, _Proj __proj)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    return __onedpl::__internal::__pattern_count(__tag, std::forward<_ExecutionPolicy>(__exec),
+                                                    std::ranges::begin(__r),
+                                                    std::ranges::begin(__r) + std::ranges::size(__r),
+                                                    __onedpl::__internal::__unary_op<_Pred, _Proj>{__pred, __proj});
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _Proj, typename _Pred>
+std::ranges::range_difference_t<_R>
+__pattern_count_if(__serial_tag</*IsVector*/std::false_type>, _ExecutionPolicy&&, _R&& __r, _Pred __pred, _Proj __proj)
+{
+    return std::ranges::count_if(std::forward<_R>(__r), __pred, __proj);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_count
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _T, typename _Proj>
+std::ranges::range_difference_t<_R>
+__pattern_count(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, const _T& __value, _Proj __proj)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    return __onedpl::__internal::__pattern_count(
+        __tag, std::forward<_ExecutionPolicy>(__exec), std::ranges::begin(__r),
+        std::ranges::begin(__r) + std::ranges::size(__r),
+        __onedpl::__internal::__count_fn_pred<_T, _Proj>{__value, __proj});
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _T, typename _Proj>
+std::ranges::range_difference_t<_R>
+__pattern_count(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r, const _T& __value,
+                _Proj __proj)
+{
+    return std::ranges::count(std::forward<_R>(__r), __value, __proj);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_equal
+//---------------------------------------------------------------------------------------------------------------------
+template<typename _Tag, typename _ExecutionPolicy, typename _R1, typename _R2, typename _Pred, typename _Proj1,
+         typename _Proj2>
+bool
+__pattern_equal(_Tag __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _Pred __pred,
+                _Proj1 __proj1, _Proj2 __proj2)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    return __onedpl::__internal::__pattern_equal(
+        __tag, std::forward<_ExecutionPolicy>(__exec), std::ranges::begin(__r1),
+        std::ranges::begin(__r1) + std::ranges::size(__r1), std::ranges::begin(__r2),
+        std::ranges::begin(__r2) + std::ranges::size(__r2),
+        __onedpl::__internal::__binary_op<_Pred, _Proj1, _Proj2>{__pred, __proj1, __proj2});
+}
+
+template<typename _ExecutionPolicy, typename _R1, typename _R2, typename _Pred, typename _Proj1,
+         typename _Proj2>
+bool
+__pattern_equal(__serial_tag</*IsVector*/std::false_type>, _ExecutionPolicy&&, _R1&& __r1, _R2&& __r2, _Pred __pred, _Proj1 __proj1, _Proj2 __proj2)
+{
+    return std::ranges::equal(std::forward<_R1>(__r1), std::forward<_R2>(__r2), __pred, __proj1, __proj2);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_is_sorted
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _Proj, typename _Comp>
+bool
+__pattern_is_sorted(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, _Comp __comp, _Proj __proj)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    return __onedpl::__internal::__pattern_adjacent_find(
+               __tag, std::forward<_ExecutionPolicy>(__exec), std::ranges::begin(__r),
+               std::ranges::begin(__r) + std::ranges::size(__r),
+               __onedpl::__internal::__reorder_pred(
+                   __onedpl::__internal::__binary_op<_Comp, _Proj, _Proj>{__comp, __proj, __proj}),
+               __onedpl::__internal::__or_semantic()) == __r.end();
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _Proj, typename _Comp>
+bool
+__pattern_is_sorted(__serial_tag</*IsVector*/std::false_type>, _ExecutionPolicy&&, _R&& __r, _Comp __comp, _Proj __proj)
+{
+    return std::ranges::is_sorted(std::forward<_R>(__r), __comp, __proj);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_sort_ranges
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _Proj, typename _Comp, typename _LeafSort>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_sort_ranges(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, _Comp __comp, _Proj __proj,
+                      _LeafSort __leaf_sort)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    auto __first = std::ranges::begin(__r);
+    auto __last = __first + std::ranges::size(__r);
+
+    __onedpl::__internal::__pattern_sort(
+        __tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
+        __onedpl::__internal::__binary_op<_Comp, _Proj, _Proj>{__comp, __proj, __proj}, __leaf_sort);
+
+    return __last;
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _Proj, typename _Comp, typename _LeafSort>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_sort_ranges(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r, _Comp __comp,
+                      _Proj __proj, _LeafSort __leaf_sort)
+{
+    return __leaf_sort(std::forward<_R>(__r), __comp, __proj);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_min_element
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _Proj, typename _Comp>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_min_element(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, _Comp __comp, _Proj __proj)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    return __onedpl::__internal::__pattern_min_element(
+        __tag, std::forward<_ExecutionPolicy>(__exec), std::ranges::begin(__r),
+        std::ranges::begin(__r) + std::ranges::size(__r),
+        __onedpl::__internal::__binary_op<_Comp, _Proj, _Proj>{__comp, __proj, __proj});
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _Proj, typename _Comp>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_min_element(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r, _Comp __comp,
+                      _Proj __proj)
+{
+    return std::ranges::min_element(std::forward<_R>(__r), __comp, __proj);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_min
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _Proj, typename _Comp>
+std::ranges::range_value_t<_R>
+__pattern_min(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, _Comp __comp, _Proj __proj)
+{
+    return *__pattern_min_element(__tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __comp, __proj);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_minmax_element
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _Proj, typename _Comp>
+auto
+__pattern_minmax_element(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, _Comp __comp, _Proj __proj)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    return __onedpl::__internal::__pattern_minmax_element(
+        __tag, std::forward<_ExecutionPolicy>(__exec), std::ranges::begin(__r),
+        std::ranges::begin(__r) + std::ranges::size(__r),
+        __onedpl::__internal::__binary_op<_Comp, _Proj, _Proj>{__comp, __proj, __proj});
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _Proj, typename _Comp>
+auto
+__pattern_minmax_element(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r, _Comp __comp,
+                         _Proj __proj)
+{
+    return std::ranges::minmax_element(std::forward<_R>(__r), __comp, __proj);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// __pattern_minmax
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _Proj, typename _Comp>
+std::pair<std::ranges::range_value_t<_R>, std::ranges::range_value_t<_R>>
+__pattern_minmax(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, _Comp __comp, _Proj __proj)
+{
+    auto [__it_min, __it_max] =
+        __pattern_minmax_element(__tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __comp, __proj);
+
+    return {*__it_min, *__it_max};
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_copy
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _InRange, typename _OutRange>
+void
+__pattern_copy(_Tag __tag, _ExecutionPolicy&& __exec, _InRange&& __in_r, _OutRange&& __out_r)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    assert(std::ranges::size(__in_r) <= std::ranges::size(__out_r)); // for debug purposes only
+
+    __onedpl::__internal::__pattern_walk2_brick(
+        __tag, std::forward<_ExecutionPolicy>(__exec), std::ranges::begin(__in_r),
+        std::ranges::begin(__in_r) + std::ranges::size(__in_r), std::ranges::begin(__out_r),
+        __onedpl::__internal::__brick_copy<decltype(__tag)>{});
+}
+
+template<typename _ExecutionPolicy, typename _InRange, typename _OutRange>
+void
+__pattern_copy(__serial_tag</*IsVector*/std::false_type>, _ExecutionPolicy&&, _InRange&& __in_r, _OutRange&& __out_r)
+{
+    std::ranges::copy(std::forward<_InRange>(__in_r), std::ranges::begin(__out_r));
+}
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_copy_if
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _IsVector, typename _ExecutionPolicy, typename _InRange, typename _OutRange, typename _Pred,
+          typename _Proj>
+std::ranges::copy_if_result<std::ranges::borrowed_iterator_t<_InRange>, std::ranges::borrowed_iterator_t<_OutRange>>
+__pattern_copy_if_ranges(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _InRange&& __in_r,
+                         _OutRange&& __out_r, _Pred __pred, _Proj __proj)
+{
+    using _Size = __onedpl::__ranges::__common_size_t<_InRange, _OutRange>;
+    auto __first_in = std::ranges::begin(__in_r);
+    auto __first_out = std::ranges::begin(__out_r);
+    _Size __sz_in = std::ranges::size(__in_r);
+    _Size __sz_out = std::ranges::size(__out_r);
+
+    // TODO: test if redirecting to "regular" copy_if for sufficient output performs better
+    if (__sz_in > 0 && __sz_out > 0)
+    {
+        auto /*std::pair*/ __res = __onedpl::__internal::__pattern_bounded_copy_if(
+            __tag, std::forward<_ExecutionPolicy>(__exec), __first_in, __sz_in, __first_out, __sz_out,
+            __onedpl::__internal::__unary_op<_Pred, _Proj>{__pred, __proj});
+
+        return {__res.first, __res.second};
+    }
+    else if (__sz_in > 0)
+    {
+        __first_in = __pattern_find_if(__tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_InRange>(__in_r),
+                                       __pred, __proj);
+    }
+    return {__first_in, __first_out};
+}
+
+template <typename _ExecutionPolicy, typename _InRange, typename _OutRange, typename _Pred, typename _Proj>
+std::ranges::copy_if_result<std::ranges::borrowed_iterator_t<_InRange>, std::ranges::borrowed_iterator_t<_OutRange>>
+__pattern_copy_if_ranges(__serial_tag</*IsVector*/ std::true_type>, _ExecutionPolicy&&, _InRange&& __in_r,
+                         _OutRange&& __out_r, _Pred __pred, _Proj __proj)
+{
+    auto /*std::pair*/ __res = __onedpl::__internal::__brick_bounded_copy_if(
+        std::ranges::begin(__in_r), std::ranges::size(__in_r), std::ranges::begin(__out_r), std::ranges::size(__out_r),
+        __onedpl::__internal::__unary_op<_Pred, _Proj>{__pred, __proj}, /*vector=*/std::true_type{});
+
+    return {__res.first, __res.second};
+}
+
+template <typename _ExecutionPolicy, typename _InRange, typename _OutRange, typename _Pred, typename _Proj>
+std::ranges::copy_if_result<std::ranges::borrowed_iterator_t<_InRange>, std::ranges::borrowed_iterator_t<_OutRange>>
+__pattern_copy_if_ranges(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _InRange&& __in_r,
+                         _OutRange&& __out_r, _Pred __pred, _Proj __proj)
+{
+    auto __it_in = std::ranges::begin(__in_r);
+    auto __it_out = std::ranges::begin(__out_r);
+    auto __end_in = std::ranges::end(__in_r);
+    auto __end_out = std::ranges::end(__out_r);
+    for (; __it_in != __end_in; ++__it_in)
+    {
+        if (std::invoke(__pred, std::invoke(__proj, *__it_in)))
+        {
+            if (__it_out != __end_out)
+            {
+                *__it_out = *__it_in;
+                ++__it_out;
+            }
+            else
+                break;
+        }
+    }
+    return {__it_in, __it_out};
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// __pattern_fill
+//---------------------------------------------------------------------------------------------------------------------
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _T>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_fill(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, const _T& __value)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    const auto __first = std::ranges::begin(__r);
+    const auto __last = __first + std::ranges::size(__r);
+    __onedpl::__internal::__pattern_fill(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __value);
+
+    return __last;
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _T>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_fill(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r, const _T& __value)
+{
+    return std::ranges::fill(std::forward<_R>(__r), __value);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_merge_ranges
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R1, typename _R2, typename _OutRange, typename _Comp,
+          typename _Proj1, typename _Proj2>
+std::ranges::merge_result<std::ranges::borrowed_iterator_t<_R1>, std::ranges::borrowed_iterator_t<_R2>,
+                          std::ranges::borrowed_iterator_t<_OutRange>>
+__pattern_merge_ranges(_Tag __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _Comp __comp,
+                       _Proj1 __proj1, _Proj2 __proj2)
+{
+    using _IndexCommon = __onedpl::__ranges::__common_size_t<_R1, _R2, _OutRange>;
+
+    auto __first1 = std::ranges::begin(__r1);
+    auto __first2 = std::ranges::begin(__r2);
+    auto __first3 = std::ranges::begin(__out_r);
+
+    const _IndexCommon __n1 = std::ranges::size(__r1);
+    const _IndexCommon __n2 = std::ranges::size(__r2);
+    const _IndexCommon __n3 = std::ranges::size(__out_r);
+
+    //{3} is empty
+    if (__n3 == 0)
+        return {__first1, __first2, __first3};
+
+    //{1} is empty
+    if (__n1 == 0)
+    {
+        __internal::__brick_copy<_Tag> __copy_range{};
+
+        auto __last2_tmp = __first2 + std::min(__n3, __n2);
+
+        auto __last_out_res = __internal::__pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first2,
+                                                                __last2_tmp, __first3, __copy_range);
+        return {__first1, __last2_tmp, __last_out_res};
+    }
+
+    //{2} is empty
+    if (__n2 == 0)
+    {
+        __internal::__brick_copy<_Tag> __copy_range{};
+
+        auto __last1_tmp = __first1 + std::min(__n3, __n1);
+
+        auto __last_out_res = __internal::__pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first1,
+                                                                __last1_tmp, __first3, __copy_range);
+        return {__last1_tmp, __first2, __last_out_res};
+    }
+
+    auto [__it1, __it2, __it3] = __merge_path_out_lim(
+        __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + __n1, __first2, __first2 + __n2, __first3,
+        __first3 + std::min<_IndexCommon>(__n1 + __n2, __n3), __comp, __proj1, __proj2);
+
+    return {__it1, __it2, __it3};
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// includes
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _R1, typename _R2, typename _Comp, typename _Proj1, typename _Proj2>
+bool
+__brick_includes(_R1&& __r1, _R2&& __r2, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2,
+                 /*__is_vector=*/std::false_type) noexcept
+{
+    return std::ranges::includes(std::forward<_R1>(__r1), std::forward<_R2>(__r2), __comp, __proj1, __proj2);
+}
+
+template <typename _R1, typename _R2, typename _Comp, typename _Proj1, typename _Proj2>
+bool
+__brick_includes(_R1&& __r1, _R2&& __r2, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2,
+                 /*__is_vector=*/std::true_type) noexcept
+{
+    _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
+    return std::ranges::includes(std::forward<_R1>(__r1), std::forward<_R2>(__r2), __comp, __proj1, __proj2);
+}
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R1, typename _R2, typename _Comp, typename _Proj1,
+          typename _Proj2>
+bool
+__pattern_includes(_Tag __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _Comp __comp, _Proj1 __proj1,
+                   _Proj2 __proj2)
+{
+    static_assert(__is_serial_tag_v<_Tag>);
+
+    return __brick_includes(std::forward<_R1>(__r1), std::forward<_R2>(__r2), __comp, __proj1, __proj2,
+                            typename _Tag::__is_vector{});
+}
+
+template <class _IsVector, typename _ExecutionPolicy, typename _R1, typename _R2, typename _Comp, typename _Proj1,
+          typename _Proj2>
+bool
+__pattern_includes(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _Comp __comp,
+                   _Proj1 __proj1, _Proj2 __proj2)
+{
+    using _RandomAccessIterator2 = std::ranges::iterator_t<_R2>;
+
+    const auto __n1 = std::ranges::size(__r1);
+    const auto __n2 = std::ranges::size(__r2);
+
+    // use serial algorithm
+    if (__n1 + __n2 <= __onedpl::__internal::__set_algo_cut_off)
+        return std::ranges::includes(std::forward<_R1>(__r1), std::forward<_R2>(__r2), __comp, __proj1, __proj2);
+
+    auto __first1 = std::ranges::begin(__r1);
+    auto __last1 = __first1 + __n1;
+    auto __first2 = std::ranges::begin(__r2);
+    auto __last2 = __first2 + __n2;
+
+    using _DifferenceType1 = typename std::iterator_traits<decltype(__first1)>::difference_type;
+    using _DifferenceType2 = typename std::iterator_traits<decltype(__first2)>::difference_type;
+
+    if (__first2 == __last2)
+        return true;
+
+    //optimization; {1} - the first sequence, {2} - the second sequence
+    //{1} is empty or size_of{2} > size_of{1}
+    if (__first1 == __last1 || __last2 - __first2 > __last1 - __first1 ||
+        // {1}:     [**********]     or   [**********]
+        // {2}: [***********]                   [***********]
+        std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1)) ||
+        std::invoke(__comp, std::invoke(__proj1, *(__last1 - 1)), std::invoke(__proj2, *(__last2 - 1))))
+        return false;
+
+    __first1 += __onedpl::__internal::__pstl_lower_bound(__first1, _DifferenceType1{0}, __last1 - __first1, __first2,
+                                                            __comp, __proj1, __proj2);
+    if (__first1 == __last1)
+        return false;
+
+    if (__last2 - __first2 == 1)
+        return !std::invoke(__comp, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__first2)) &&
+               !std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1));
+
+    return !__internal::__parallel_or(
+        __tag, std::forward<_ExecutionPolicy>(__exec), __first2, __last2,
+        [__first1, __last1, __first2, __last2, __comp, __proj1, __proj2](_RandomAccessIterator2 __i,
+                                                                         _RandomAccessIterator2 __j) {
+            assert(__j > __i);
+
+            //1. moving boundaries to "consume" subsequence of equal elements
+            auto __is_equal_sorted = [&__comp, __proj2](_RandomAccessIterator2 __a,
+                                                        _RandomAccessIterator2 __b) -> bool {
+                //enough one call of __comp due to compared couple belongs to one sorted sequence
+                return !std::invoke(__comp, std::invoke(__proj2, *__a), std::invoke(__proj2, *__b));
+            };
+
+            //1.1 left bound, case "aaa[aaaxyz...]" - searching "x"
+            if (__i > __first2 && __is_equal_sorted(__i - 1, __i))
+            {
+                //whole subrange continues to have equal elements - return "no op"
+                if (__is_equal_sorted(__i, __j - 1))
+                    return false;
+
+                __i += __onedpl::__internal::__pstl_upper_bound(__i, _DifferenceType2{0}, __last2 - __i, __i, __comp,
+                                                                   __proj2, __proj2);
+            }
+
+            //1.2 right bound, case "[...aaa]aaaxyz" - searching "x"
+            if (__j < __last2 && __is_equal_sorted(__j - 1, __j))
+                __j += __onedpl::__internal::__pstl_upper_bound(__j, _DifferenceType2{0}, __last2 - __j, __j, __comp,
+                                                                   __proj2, __proj2);
+
+            //2. testing is __a subsequence of the second range included into the first range
+            auto __b = __first1 + __onedpl::__internal::__pstl_lower_bound(
+                                      __first1, _DifferenceType1{0}, __last1 - __first1, __i, __comp, __proj1, __proj2);
+
+            return !std::ranges::includes(__b, __last1, __i, __j, __comp, __proj1, __proj2);
+        });
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// set_union
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _R1, typename _R2, typename _OutRange>
+using __set_union_return_t =
+    std::ranges::set_union_result<std::ranges::borrowed_iterator_t<_R1>, std::ranges::borrowed_iterator_t<_R2>,
+                                  std::ranges::borrowed_iterator_t<_OutRange>>;
+
+template <typename _R1, typename _R2, typename _OutRange, typename _Comp, typename _Proj1, typename _Proj2>
+__set_union_return_t<_R1, _R2, _OutRange>
+__brick_set_union(_R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2,
+                  /*__is_vector=*/std::false_type) noexcept
+{
+    return std::ranges::set_union(std::forward<_R1>(__r1), std::forward<_R2>(__r2), std::ranges::begin(__out_r), __comp,
+                                  __proj1, __proj2);
+}
+
+template <typename _R1, typename _R2, typename _OutRange, typename _Comp, typename _Proj1, typename _Proj2>
+__set_union_return_t<_R1, _R2, _OutRange>
+__brick_set_union(_R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2,
+                  /*__is_vector=*/std::true_type) noexcept
+{
+    _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
+    return std::ranges::set_union(std::forward<_R1>(__r1), std::forward<_R2>(__r2), std::ranges::begin(__out_r), __comp,
+                                  __proj1, __proj2);
+}
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R1, typename _R2, typename _OutRange, typename _Comp,
+          typename _Proj1, typename _Proj2>
+__set_union_return_t<_R1, _R2, _OutRange>
+__pattern_set_union(_Tag __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _Comp __comp,
+                    _Proj1 __proj1, _Proj2 __proj2)
+{
+    static_assert(__is_serial_tag_v<_Tag>);
+
+    return __brick_set_union(std::forward<_R1>(__r1), std::forward<_R2>(__r2), std::forward<_OutRange>(__out_r), __comp,
+                             __proj1, __proj2, typename _Tag::__is_vector{});
+}
+
+template <class _IsVector, typename _ExecutionPolicy, typename _R1, typename _R2, typename _OutRange, typename _Comp,
+          typename _Proj1, typename _Proj2>
+__set_union_return_t<_R1, _R2, _OutRange>
+__pattern_set_union(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2,
+                    _OutRange&& __out_r, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2)
+{
+    using _RandomAccessIterator1 = std::ranges::iterator_t<_R1>;
+    using _RandomAccessIterator2 = std::ranges::iterator_t<_R2>;
+    using _Tp = std::ranges::range_value_t<_OutRange>;
+
+    const auto __n1 = std::ranges::size(__r1);
+    const auto __n2 = std::ranges::size(__r2);
+
+    // use serial algorithm
+    if (__n1 + __n2 <= __onedpl::__internal::__set_algo_cut_off)
+        return std::ranges::set_union(__r1, __r2, std::begin(__out_r), __comp, __proj1, __proj2);
+
+    auto __first1 = std::ranges::begin(__r1);
+    auto __last1 = __first1 + __n1;
+    auto __first2 = std::ranges::begin(__r2);
+    auto __last2 = __first2 + __n2;
+    auto __result = std::ranges::begin(__out_r);
+
+    auto __out_last = __onedpl::__internal::__parallel_set_union_op(
+        __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
+        [](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
+           _RandomAccessIterator2 __last2, _Tp* __result, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2) {
+            return __onedpl::__utils::__set_union_construct(
+                __first1, __last1, __first2, __last2, __result,
+                __onedpl::__internal::__BrickCopyConstruct<_IsVector>(), __comp, __proj1, __proj2);
+        },
+        __comp, __proj1, __proj2);
+
+    return {__first1 + __n1, __first2 + __n2, __result + (__out_last - __result)};
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// set_intersection
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _R1, typename _R2, typename _OutRange>
+using __set_intersection_return_t =
+    std::ranges::set_intersection_result<std::ranges::borrowed_iterator_t<_R1>, std::ranges::borrowed_iterator_t<_R2>,
+                                         std::ranges::borrowed_iterator_t<_OutRange>>;
+
+template <typename _R1, typename _R2, typename _OutRange, typename _Comp, typename _Proj1, typename _Proj2>
+__set_intersection_return_t<_R1, _R2, _OutRange>
+__brick_set_intersection(_R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2,
+                         /*__is_vector=*/std::false_type) noexcept
+{
+    return std::ranges::set_intersection(std::forward<_R1>(__r1), std::forward<_R2>(__r2), std::ranges::begin(__out_r),
+                                         __comp, __proj1, __proj2);
+}
+
+template <typename _R1, typename _R2, typename _OutRange, typename _Comp, typename _Proj1, typename _Proj2>
+__set_intersection_return_t<_R1, _R2, _OutRange>
+__brick_set_intersection(_R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2,
+                         /*__is_vector=*/std::true_type) noexcept
+{
+    _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
+    return std::ranges::set_intersection(std::forward<_R1>(__r1), std::forward<_R2>(__r2), std::ranges::begin(__out_r),
+                                         __comp, __proj1, __proj2);
+}
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R1, typename _R2, typename _OutRange, typename _Comp,
+          typename _Proj1, typename _Proj2>
+__set_intersection_return_t<_R1, _R2, _OutRange>
+__pattern_set_intersection(_Tag __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _OutRange&& __out_r,
+                           _Comp __comp, _Proj1 __proj1, _Proj2 __proj2)
+{
+    static_assert(__is_serial_tag_v<_Tag>);
+
+    return __brick_set_intersection(std::forward<_R1>(__r1), std::forward<_R2>(__r2), std::forward<_OutRange>(__out_r),
+                                    __comp, __proj1, __proj2, typename _Tag::__is_vector{});
+}
+
+template <class _IsVector, typename _ExecutionPolicy, typename _R1, typename _R2, typename _OutRange, typename _Comp,
+          typename _Proj1, typename _Proj2>
+__set_intersection_return_t<_R1, _R2, _OutRange>
+__pattern_set_intersection(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2,
+                           _OutRange&& __out_r, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2)
+{
+    using _RandomAccessIterator1 = std::ranges::iterator_t<_R1>;
+    using _RandomAccessIterator2 = std::ranges::iterator_t<_R2>;
+    using _T = std::ranges::range_value_t<_OutRange>;
+
+    using _DifferenceType1 = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
+    using _DifferenceType2 = typename std::iterator_traits<_RandomAccessIterator2>::difference_type;
+    using _DifferenceType = std::common_type_t<_DifferenceType1, _DifferenceType2>;
+
+    const auto __n1 = std::ranges::size(__r1);
+    const auto __n2 = std::ranges::size(__r2);
+
+    auto __first1 = std::ranges::begin(__r1);
+    auto __last1 = __first1 + __n1;
+    auto __first2 = std::ranges::begin(__r2);
+    auto __last2 = __first2 + __n2;
+    auto __result = std::ranges::begin(__out_r);
+
+    // intersection is empty
+    if (__n1 == 0 || __n2 == 0)
+        return {__last1, __last2, __result};
+
+    // testing  whether the sequences are intersected
+    auto __left_bound_seq_1 =
+        __first1 + __onedpl::__internal::__pstl_lower_bound(__first1, _DifferenceType1{0}, __last1 - __first1,
+                                                               __first2, __comp, __proj1, __proj2);
+    //{1} < {2}: seq 2 is wholly greater than seq 1, so, the intersection is empty
+    if (__left_bound_seq_1 == __last1)
+        return {__last1, __last2, __result};
+
+    // testing  whether the sequences are intersected
+    auto __left_bound_seq_2 =
+        __first2 + __onedpl::__internal::__pstl_lower_bound(__first2, _DifferenceType2{0}, __last2 - __first2,
+                                                               __first1, __comp, __proj2, __proj1);
+    //{2} < {1}: seq 1 is wholly greater than seq 2, so, the intersection is empty
+    if (__left_bound_seq_2 == __last2)
+        return {__last1, __last2, __result};
+
+    const auto __m1 = __last1 - __left_bound_seq_1 + __n2;
+    if (__m1 > __onedpl::__internal::__set_algo_cut_off)
+    {
+        //we know proper offset due to [first1; left_bound_seq_1) < [first2; last2)
+        return __internal::__except_handler([&]() {
+            auto __out_last = __internal::__parallel_set_op(
+                __tag, std::forward<_ExecutionPolicy>(__exec), __left_bound_seq_1, __last1, __first2, __last2, __result,
+                [](_DifferenceType __n, _DifferenceType __m) { return std::min(__n, __m); },
+                [](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
+                   _RandomAccessIterator2 __last2, _T* __result, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2) {
+                    return __onedpl::__utils::__set_intersection_construct(
+                        __first1, __last1, __first2, __last2, __result,
+                        __onedpl::__internal::__op_uninitialized_copy<_ExecutionPolicy>{}, __comp, __proj1, __proj2);
+                },
+                __comp, __proj1, __proj2);
+            return __set_intersection_return_t<_R1, _R2, _OutRange>{__last1, __last2, __out_last};
+        });
+    }
+
+    const auto __m2 = __last2 - __left_bound_seq_2 + __n1;
+    if (__m2 > __onedpl::__internal::__set_algo_cut_off)
+    {
+        //we know proper offset due to [first2; left_bound_seq_2) < [first1; last1)
+        return __internal::__except_handler([&]() {
+            auto __out_last = __internal::__parallel_set_op(
+                __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __left_bound_seq_2, __last2, __result,
+                [](_DifferenceType __n, _DifferenceType __m) { return std::min(__n, __m); },
+                [](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
+                   _RandomAccessIterator2 __last2, _T* __result, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2) {
+                    return __onedpl::__utils::__set_intersection_construct(
+                        __first1, __last1, __first2, __last2, __result,
+                        __onedpl::__internal::__op_uninitialized_copy<_ExecutionPolicy>{}, __comp, __proj1, __proj2);
+                },
+                __comp, __proj1, __proj2);
+            return __set_intersection_return_t<_R1, _R2, _OutRange>{__last1, __last2, __out_last};
+        });
+    }
+
+    // [left_bound_seq_1; last1) and [left_bound_seq_2; last2) - use serial algorithm
+    return std::ranges::set_intersection(__left_bound_seq_1, __last1, __left_bound_seq_2, __last2,
+                                         std::ranges::begin(__out_r), __comp, __proj1, __proj2);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// set_difference
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _R1, typename _OutRange>
+using __set_difference_return_t = std::ranges::set_difference_result<std::ranges::borrowed_iterator_t<_R1>,
+                                                                     std::ranges::borrowed_iterator_t<_OutRange>>;
+
+template <typename _R1, typename _R2, typename _OutRange, typename _Comp, typename _Proj1, typename _Proj2>
+__set_difference_return_t<_R1, _OutRange>
+__brick_set_difference(_R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2,
+                       /*__is_vector=*/std::false_type) noexcept
+{
+    return std::ranges::set_difference(std::forward<_R1>(__r1), std::forward<_R2>(__r2), std::ranges::begin(__out_r),
+                                       __comp, __proj1, __proj2);
+}
+
+template <typename _R1, typename _R2, typename _OutRange, typename _Comp, typename _Proj1, typename _Proj2>
+__set_difference_return_t<_R1, _OutRange>
+__brick_set_difference(_R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2,
+                       /*__is_vector=*/std::true_type) noexcept
+{
+    _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
+    return std::ranges::set_difference(std::forward<_R1>(__r1), std::forward<_R2>(__r2), std::ranges::begin(__out_r),
+                                       __comp, __proj1, __proj2);
+}
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R1, typename _R2, typename _OutRange, typename _Comp,
+          typename _Proj1, typename _Proj2>
+__set_difference_return_t<_R1, _OutRange>
+__pattern_set_difference(_Tag __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _OutRange&& __out_r,
+                         _Comp __comp, _Proj1 __proj1, _Proj2 __proj2)
+{
+    static_assert(__is_serial_tag_v<_Tag>);
+
+    return __brick_set_difference(std::forward<_R1>(__r1), std::forward<_R2>(__r2), std::forward<_OutRange>(__out_r),
+                                  __comp, __proj1, __proj2, typename _Tag::__is_vector{});
+}
+
+template <class _IsVector, typename _ExecutionPolicy, typename _R1, typename _R2, typename _OutRange, typename _Comp,
+          typename _Proj1, typename _Proj2>
+__set_difference_return_t<_R1, _OutRange>
+__pattern_set_difference(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2,
+                         _OutRange&& __out_r, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2)
+{
+    using _RandomAccessIterator1 = std::ranges::iterator_t<_R1>;
+    using _RandomAccessIterator2 = std::ranges::iterator_t<_R2>;
+    using _T = std::ranges::range_value_t<_OutRange>;
+
+    using _DifferenceType1 = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
+    using _DifferenceType2 = typename std::iterator_traits<_RandomAccessIterator2>::difference_type;
+    using _DifferenceType = std::common_type_t<_DifferenceType1, _DifferenceType2>;
+
+    const auto __n1 = std::ranges::size(__r1);
+    const auto __n2 = std::ranges::size(__r2);
+
+    auto __first1 = std::ranges::begin(__r1);
+    auto __last1 = __first1 + __n1;
+    auto __first2 = std::ranges::begin(__r2);
+    auto __last2 = __first2 + __n2;
+    auto __result = std::ranges::begin(__out_r);
+
+    // {} \ {2}: the difference is empty
+    if (__n1 == 0)
+        return {__first1, __result};
+
+    // {1} \ {}: parallel copying just first sequence
+    if (__n2 == 0)
+    {
+        auto __out_last = __pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
+                                                __result, __internal::__brick_copy<__parallel_tag<_IsVector>>{});
+        return {__last1, __out_last};
+    }
+
+    // testing  whether the sequences are intersected
+    auto __left_bound_seq_1 =
+        __first1 + __onedpl::__internal::__pstl_lower_bound(__first1, _DifferenceType1{0}, __last1 - __first1,
+                                                               __first2, __comp, __proj1, __proj2);
+    //{1} < {2}: seq 2 is wholly greater than seq 1, so, parallel copying just first sequence
+    if (__left_bound_seq_1 == __last1)
+    {
+        auto __out_last = __pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
+                                                __result, __internal::__brick_copy<__parallel_tag<_IsVector>>{});
+        return {__last1, __out_last};
+    }
+
+    // testing  whether the sequences are intersected
+    auto __left_bound_seq_2 =
+        __first2 + __onedpl::__internal::__pstl_lower_bound(__first2, _DifferenceType2{0}, __last2 - __first2,
+                                                               __first1, __comp, __proj2, __proj1);
+    //{2} < {1}: seq 1 is wholly greater than seq 2, so, parallel copying just first sequence
+    if (__left_bound_seq_2 == __last2)
+    {
+        auto __out_last =
+            __internal::__pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
+                                              __result, __brick_copy<__parallel_tag<_IsVector>>{});
+        return {__last1, __out_last};
+    }
+
+    if (__n1 + __n2 > __set_algo_cut_off)
+    {
+        auto __out_last = __parallel_set_op(
+            __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
+            [](_DifferenceType __n, _DifferenceType) { return __n; },
+            [](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
+               _RandomAccessIterator2 __last2, _T* __result, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2) {
+                return __onedpl::__utils::__set_difference_construct(__first1, __last1, __first2, __last2, __result,
+                                                                        __BrickCopyConstruct<_IsVector>(), __comp,
+                                                                        __proj1, __proj2);
+            },
+            __comp, __proj1, __proj2);
+        return {__last1, __result + (__out_last - __result)};
+    }
+
+    // use serial algorithm
+    return std::ranges::set_difference(std::forward<_R1>(__r1), std::forward<_R2>(__r2), std::ranges::begin(__out_r),
+                                       __comp, __proj1, __proj2);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// set_symmetric_difference
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _R1, typename _R2, typename _OutRange>
+using __set_symmetric_difference_return_t =
+    std::ranges::set_symmetric_difference_result<std::ranges::borrowed_iterator_t<_R1>,
+                                                 std::ranges::borrowed_iterator_t<_R2>,
+                                                 std::ranges::borrowed_iterator_t<_OutRange>>;
+
+template <typename _R1, typename _R2, typename _OutRange, typename _Comp, typename _Proj1, typename _Proj2>
+__set_symmetric_difference_return_t<_R1, _R2, _OutRange>
+__brick_set_symmetric_difference(_R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _Comp __comp, _Proj1 __proj1,
+                                 _Proj2 __proj2,
+                                 /*__is_vector=*/std::false_type) noexcept
+{
+    return std::ranges::set_symmetric_difference(std::forward<_R1>(__r1), std::forward<_R2>(__r2),
+                                                 std::ranges::begin(__out_r), __comp, __proj1, __proj2);
+}
+
+template <typename _R1, typename _R2, typename _OutRange, typename _Comp, typename _Proj1, typename _Proj2>
+__set_symmetric_difference_return_t<_R1, _R2, _OutRange>
+__brick_set_symmetric_difference(_R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _Comp __comp, _Proj1 __proj1,
+                                 _Proj2 __proj2,
+                                 /*__is_vector=*/std::true_type) noexcept
+{
+    _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
+    return std::ranges::set_symmetric_difference(std::forward<_R1>(__r1), std::forward<_R2>(__r2),
+                                                 std::ranges::begin(__out_r), __comp, __proj1, __proj2);
+}
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R1, typename _R2, typename _OutRange, typename _Comp,
+          typename _Proj1, typename _Proj2>
+__set_symmetric_difference_return_t<_R1, _R2, _OutRange>
+__pattern_set_symmetric_difference(_Tag __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _OutRange&& __out_r,
+                                   _Comp __comp, _Proj1 __proj1, _Proj2 __proj2)
+{
+    static_assert(__is_serial_tag_v<_Tag>);
+
+    return __brick_set_symmetric_difference(std::forward<_R1>(__r1), std::forward<_R2>(__r2),
+                                            std::forward<_OutRange>(__out_r), __comp, __proj1, __proj2,
+                                            typename _Tag::__is_vector{});
+}
+
+template <class _IsVector, typename _ExecutionPolicy, typename _R1, typename _R2, typename _OutRange, typename _Comp,
+          typename _Proj1, typename _Proj2>
+__set_symmetric_difference_return_t<_R1, _R2, _OutRange>
+__pattern_set_symmetric_difference(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2,
+                                   _OutRange&& __out_r, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2)
+{
+    using _RandomAccessIterator1 = std::ranges::iterator_t<_R1>;
+    using _RandomAccessIterator2 = std::ranges::iterator_t<_R2>;
+    using _Tp = std::ranges::range_value_t<_OutRange>;
+
+    const auto __n1 = std::ranges::size(__r1);
+    const auto __n2 = std::ranges::size(__r2);
+
+    // use serial algorithm
+    if (__n1 + __n2 <= __onedpl::__internal::__set_algo_cut_off)
+        return std::ranges::set_symmetric_difference(std::forward<_R1>(__r1), std::forward<_R2>(__r2),
+                                                     std::ranges::begin(__out_r), __comp, __proj1, __proj2);
+
+    auto __first1 = std::ranges::begin(__r1);
+    auto __last1 = __first1 + __n1;
+    auto __first2 = std::ranges::begin(__r2);
+    auto __last2 = __first2 + __n2;
+    auto __result = std::ranges::begin(__out_r);
+
+    auto __out_last = __onedpl::__internal::__parallel_set_union_op(
+        __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
+        [](_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2,
+           _RandomAccessIterator2 __last2, _Tp* __result, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2) {
+            return __onedpl::__utils::__set_symmetric_difference_construct(
+                __first1, __last1, __first2, __last2, __result,
+                __onedpl::__internal::__BrickCopyConstruct<_IsVector>(), __comp, __proj1, __proj2);
+        },
+        __comp, __proj1, __proj2);
+
+    return {__last1, __last2, __out_last};
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// __pattern_mismatch
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _R1, typename _R2>
+using __mismatch_return_t =
+    std::ranges::mismatch_result<std::ranges::borrowed_iterator_t<_R1>, std::ranges::borrowed_iterator_t<_R2>>;
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R1, typename _R2, typename _Pred, typename _Proj1,
+          typename _Proj2>
+__mismatch_return_t<_R1, _R2>
+__pattern_mismatch(_Tag __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _Pred __pred, _Proj1 __proj1,
+                   _Proj2 __proj2)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    auto __first1 = std::ranges::begin(__r1);
+    auto __first2 = std::ranges::begin(__r2);
+
+    const auto& [first, second] = __onedpl::__internal::__pattern_mismatch(
+        __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + std::ranges::size(__r1), __first2,
+        __first2 + std::ranges::size(__r2), __onedpl::__internal::__binary_op{__pred, __proj1, __proj2});
+
+    return {first, second};
+}
+
+template <typename _ExecutionPolicy, typename _R1, typename _R2, typename _Pred, typename _Proj1, typename _Proj2>
+__mismatch_return_t<_R1, _R2>
+__pattern_mismatch(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R1&& __r1, _R2&& __r2, _Pred __pred,
+                   _Proj1 __proj1, _Proj2 __proj2)
+{
+    return std::ranges::mismatch(std::forward<_R1>(__r1), std::forward<_R2>(__r2), __pred, __proj1, __proj2);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// __pattern_remove_if
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _Proj, typename _Pred>
+std::ranges::borrowed_subrange_t<_R>
+__pattern_remove_if(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, _Pred __pred, _Proj __proj)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    auto __end = std::ranges::begin(__r) + std::ranges::size(__r);
+
+    auto __it = __onedpl::__internal::__pattern_remove_if(
+        __tag, std::forward<_ExecutionPolicy>(__exec), std::ranges::begin(__r), __end,
+        __onedpl::__internal::__unary_op<_Pred, _Proj>{__pred, __proj});
+
+    return {__it, __end};
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _Proj, typename _Pred>
+std::ranges::borrowed_subrange_t<_R>
+__pattern_remove_if(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r, _Pred __pred,
+                    _Proj __proj)
+{
+    return std::ranges::remove_if(std::forward<_R>(__r), __pred, __proj);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// __pattern_reverse
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R>
+void
+__pattern_reverse(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    auto __first = std::ranges::begin(__r);
+    auto __last = __first + std::ranges::size(__r);
+    __onedpl::__internal::__pattern_reverse(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __last);
+}
+
+template <typename _ExecutionPolicy, typename _R>
+void
+__pattern_reverse(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r)
+{
+    std::ranges::reverse(std::forward<_R>(__r));
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// __pattern_reverse_copy
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _InRange, typename _OutRange>
+void
+__pattern_reverse_copy(_Tag __tag, _ExecutionPolicy&& __exec, _InRange&& __in_r, _OutRange&& __out_r)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    auto __first_in = std::ranges::begin(__in_r);
+    auto __last_in = __first_in + std::ranges::size(__in_r);
+    auto __first_out = std::ranges::begin(__out_r);
+    __onedpl::__internal::__pattern_reverse_copy(__tag, std::forward<_ExecutionPolicy>(__exec), __first_in,
+                                                    __last_in, __first_out);
+}
+
+template <typename _ExecutionPolicy, typename _InRange, typename _OutRange>
+void
+__pattern_reverse_copy(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _InRange&& __in_r,
+                       _OutRange&& __out_r)
+{
+    std::ranges::reverse_copy(std::forward<_InRange>(__in_r), std::ranges::begin(__out_r));
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// __pattern_move
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _InRange, typename _OutRange>
+void
+__pattern_move(_Tag __tag, _ExecutionPolicy&& __exec, _InRange&& __r, _OutRange&& __out_r)
+{
+    auto __end = std::ranges::begin(__r) + std::ranges::size(__r);
+    __onedpl::__internal::__pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec),
+                                                   std::ranges::begin(__r), __end, std::ranges::begin(__out_r),
+                                                   __onedpl::__internal::__brick_move<decltype(__tag)>{});
+}
+
+template <typename _ExecutionPolicy, typename _InRange, typename _OutRange>
+void
+__pattern_move(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _InRange&& __r, _OutRange&& __out_r)
+{
+    std::ranges::move(std::forward<_InRange>(__r), std::ranges::begin(__out_r));
+}
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R1, typename _R2>
+void
+__pattern_swap_ranges(_Tag __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    auto __beg1 = std::ranges::begin(__r1);
+    auto __end1 = __beg1 + std::ranges::size(__r1);
+    auto __beg2 = std::ranges::begin(__r2);
+    __onedpl::__internal::__pattern_swap(__tag, std::forward<_ExecutionPolicy>(__exec), __beg1, __end1, __beg2);
+}
+
+template <typename _ExecutionPolicy, typename _R1, typename _R2>
+void
+__pattern_swap_ranges(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R1&& __r1, _R2&& __r2)
+{
+    std::ranges::swap_ranges(std::forward<_R1>(__r1), std::forward<_R2>(__r2));
+}
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _Comp, typename _Proj>
+std::ranges::borrowed_subrange_t<_R>
+__pattern_unique(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, _Comp __comp, _Proj __proj)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    auto __beg = std::ranges::begin(__r);
+    auto __end = __beg + std::ranges::size(__r);
+    auto __it = __onedpl::__internal::__pattern_unique(
+        __tag, std::forward<_ExecutionPolicy>(__exec), __beg, __end,
+        __onedpl::__internal::__binary_op<_Comp, _Proj, _Proj>{__comp, __proj, __proj});
+
+    return {__it, __end};
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _Comp, typename _Proj>
+std::ranges::borrowed_subrange_t<_R>
+__pattern_unique(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r, _Comp __comp, _Proj __proj)
+{
+    return std::ranges::unique(std::forward<_R>(__r), __comp, __proj);
+}
+
+template <typename _R, typename _OutR>
+using __unique_copy_return_t =
+    std::ranges::unique_copy_result<std::ranges::borrowed_iterator_t<_R>, std::ranges::borrowed_iterator_t<_OutR>>;
+
+template <typename _IsVector, typename _ExecutionPolicy, typename _R, typename _OutR, typename _Comp, typename _Proj>
+__unique_copy_return_t<_R, _OutR>
+__pattern_unique_copy(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _R&& __r, _OutR&& __out_r,
+                      _Comp __comp, _Proj __proj)
+{
+    using _DiffType = std::make_signed_t<__onedpl::__ranges::__common_size_t<_R, _OutR>>;
+    _DiffType __sz_in = std::ranges::ssize(__r);
+    _DiffType __sz_out = std::ranges::ssize(__out_r);
+
+    auto /*std::pair*/ __res = __onedpl::__internal::__pattern_bounded_unique_copy(
+        __tag, std::forward<_ExecutionPolicy>(__exec), std::ranges::begin(__r), __sz_in, std::ranges::begin(__out_r),
+        __sz_out, __onedpl::__internal::__binary_op<_Comp, _Proj, _Proj>{__comp, __proj, __proj});
+
+    return {__res.first, __res.second};
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _OutR, typename _Comp, typename _Proj>
+__unique_copy_return_t<_R, _OutR>
+__pattern_unique_copy(__serial_tag</*IsVector*/ std::true_type>, _ExecutionPolicy&&, _R&& __r, _OutR&& __out_r,
+                      _Comp __comp, _Proj __proj)
+{
+    auto /*std::pair*/ __res = __onedpl::__internal::__brick_bounded_unique_copy(
+        std::ranges::begin(__r), std::ranges::ssize(__r), std::ranges::begin(__out_r), std::ranges::ssize(__out_r),
+        __onedpl::__internal::__binary_op<_Comp, _Proj, _Proj>{__comp, __proj, __proj}, /*vector=*/std::true_type{});
+
+    return {__res.first, __res.second};
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _OutR, typename _Comp, typename _Proj>
+__unique_copy_return_t<_R, _OutR>
+__pattern_unique_copy(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r, _OutR&& __out_r,
+                      _Comp __comp, _Proj __proj)
+{
+    auto __it_in = std::ranges::begin(__r);
+    auto __it_out = std::ranges::begin(__out_r);
+    auto __end_in = std::ranges::end(__r);
+    auto __end_out = std::ranges::end(__out_r);
+    auto __not_comp = std::not_fn(__comp);
+    for (; __it_out != __end_out && __it_in != __end_in; ++__it_out)
+    {
+        *__it_out = *__it_in;
+        // Find an element that is *not* equivalent to the next one
+        __it_in = std::ranges::adjacent_find(__it_in, __end_in, __not_comp, __proj);
+        // That very next one should be read from in the next loop iteration
+        if (__it_in != __end_in)
+            ++__it_in;
+    }
+    return {__it_in, __it_out};
+}
+} // namespace __ranges
+} // namespace __internal
+} // namespace std::__onedpl
+
+#endif //_ONEDPL_CPP20_RANGES_PRESENT
+
+#endif // _ONEDPL_ALGORITHM_RANGES_IMPL_H
diff --git a/libstdc++-v3/include/pstl/execution_defs.h b/libstdc++-v3/include/pstl/execution_defs.h
index 522518c4116b..e8423a746733 100644
--- a/libstdc++-v3/include/pstl/execution_defs.h
+++ b/libstdc++-v3/include/pstl/execution_defs.h
@@ -1,22 +1,29 @@
 // -*- C++ -*-
-//===-- execution_defs.h --------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_EXECUTION_POLICY_DEFS_H
-#define _PSTL_EXECUTION_POLICY_DEFS_H
+#ifndef _ONEDPL_EXECUTION_POLICY_DEFS_H
+#define _ONEDPL_EXECUTION_POLICY_DEFS_H
 
 #include <type_traits>
+#include <iterator>
 
-namespace __pstl
+namespace std::__onedpl
 {
 namespace execution
 {
-inline namespace v1
+inline namespace _V1
 {
 
 // 2.4, Sequential execution policy
@@ -39,62 +46,116 @@ class unsequenced_policy
 };
 
 // 2.8, Execution policy objects
-_GLIBCXX17_INLINE constexpr sequenced_policy seq{};
-_GLIBCXX17_INLINE constexpr parallel_policy par{};
-_GLIBCXX17_INLINE constexpr parallel_unsequenced_policy par_unseq{};
-_GLIBCXX17_INLINE constexpr unsequenced_policy unseq{};
+inline constexpr sequenced_policy seq{};
+inline constexpr parallel_policy par{};
+inline constexpr parallel_unsequenced_policy par_unseq{};
+inline constexpr unsequenced_policy unseq{};
 
 // 2.3, Execution policy type trait
-template <class _Tp>
-struct is_execution_policy : std::false_type
+template <class T>
+struct is_execution_policy : ::std::false_type
 {
 };
 
 template <>
-struct is_execution_policy<__pstl::execution::sequenced_policy> : std::true_type
+struct is_execution_policy<__onedpl::execution::sequenced_policy> : ::std::true_type
 {
 };
 template <>
-struct is_execution_policy<__pstl::execution::parallel_policy> : std::true_type
+struct is_execution_policy<__onedpl::execution::parallel_policy> : ::std::true_type
 {
 };
 template <>
-struct is_execution_policy<__pstl::execution::parallel_unsequenced_policy> : std::true_type
+struct is_execution_policy<__onedpl::execution::parallel_unsequenced_policy> : ::std::true_type
 {
 };
 template <>
-struct is_execution_policy<__pstl::execution::unsequenced_policy> : std::true_type
+struct is_execution_policy<__onedpl::execution::unsequenced_policy> : ::std::true_type
 {
 };
 
-#if defined (_PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT)
-template <class _Tp>
-constexpr bool is_execution_policy_v = __pstl::execution::is_execution_policy<_Tp>::value;
-#endif
+template <class T>
+inline constexpr bool is_execution_policy_v = __onedpl::execution::is_execution_policy<T>::value;
 
-} // namespace v1
+} // namespace _V1
 } // namespace execution
 
+using __onedpl::execution::is_execution_policy;
+using __onedpl::execution::is_execution_policy_v;
+
 namespace __internal
 {
-template <class _ExecPolicy, class _Tp>
-#if _GLIBCXX_RELEASE >= 9
+
+// Extension: host execution policy type trait
+template <class _T>
+struct __is_host_execution_policy : ::std::false_type
+{
+};
+
+template <>
+struct __is_host_execution_policy<__onedpl::execution::sequenced_policy> : ::std::true_type
+{
+};
+template <>
+struct __is_host_execution_policy<__onedpl::execution::parallel_policy> : ::std::true_type
+{
+};
+template <>
+struct __is_host_execution_policy<__onedpl::execution::parallel_unsequenced_policy> : ::std::true_type
+{
+};
+template <>
+struct __is_host_execution_policy<__onedpl::execution::unsequenced_policy> : ::std::true_type
+{
+};
+
+template <class _ExecPolicy, class _T = void>
 using __enable_if_execution_policy =
-    typename std::enable_if<__pstl::execution::is_execution_policy<std::__remove_cvref_t<_ExecPolicy>>::value,
-                            _Tp>::type;
-#else
-using __enable_if_execution_policy =
-    typename std::enable_if<__pstl::execution::is_execution_policy<typename std::decay<_ExecPolicy>::type>::value,
-                            _Tp>::type;
-#endif
+    std::enable_if_t<__onedpl::is_execution_policy_v<std::decay_t<_ExecPolicy>>, _T>;
+
+template <typename _ExecPolicy, typename _T>
+struct __ref_or_copy_impl
+{
+    using type = _T&;
+};
+
+template <typename _ExecPolicy, typename _T>
+using __ref_or_copy = typename __ref_or_copy_impl<::std::decay_t<_ExecPolicy>, _T>::type;
+
+//------------------------------------------------------------------------
+// backend tags
+//------------------------------------------------------------------------
+
+struct __serial_backend_tag
+{
+};
+
+struct __tbb_backend_tag
+{
+};
+
+struct __omp_backend_tag
+{
+};
+
+//------------------------------------------------------------------------
+// dispatch tags
+//------------------------------------------------------------------------
 
 template <class _IsVector>
 struct __serial_tag;
+
 template <class _IsVector>
 struct __parallel_tag;
 
+struct __parallel_forward_tag;
+
 } // namespace __internal
 
-} // namespace __pstl
+} // namespace std::__onedpl
 
-#endif /* _PSTL_EXECUTION_POLICY_DEFS_H */
+#if _ONEDPL_BACKEND_SYCL
+#    include "hetero/dpcpp/execution_sycl_defs.h"
+#endif
+
+#endif // _ONEDPL_EXECUTION_POLICY_DEFS_H
diff --git a/libstdc++-v3/include/pstl/execution_impl.h b/libstdc++-v3/include/pstl/execution_impl.h
index c84061848b97..79c5e95f2e06 100644
--- a/libstdc++-v3/include/pstl/execution_impl.h
+++ b/libstdc++-v3/include/pstl/execution_impl.h
@@ -1,61 +1,45 @@
 // -*- C++ -*-
-//===-- execution_impl.h --------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_EXECUTION_IMPL_H
-#define _PSTL_EXECUTION_IMPL_H
+#ifndef _ONEDPL_EXECUTION_IMPL_H
+#define _ONEDPL_EXECUTION_IMPL_H
 
 #include <iterator>
 #include <type_traits>
 
+#include "parallel_backend.h"
 #include "execution_defs.h"
+#include "iterator_defs.h"
 
-namespace __pstl
+namespace std::__onedpl
 {
 namespace __internal
 {
-#if __glibcxx_concepts
-template<typename _Iter>
-  concept __is_random_access_iter
-    = std::is_base_of_v<std::random_access_iterator_tag,
-			std::__iter_category_t<_Iter>>
-      || std::random_access_iterator<_Iter>;
 
-template <typename... _IteratorTypes>
-  using __are_random_access_iterators
-    = std::bool_constant<(__is_random_access_iter<std::remove_cvref_t<_IteratorTypes>> && ...)>;
-#else
-template <typename... _IteratorTypes>
-using __are_random_access_iterators
-    = std::__and_<
-	std::is_base_of<std::random_access_iterator_tag,
-			std::__iter_category_t<std::__remove_cvref_t<_IteratorTypes>>>...
-      >;
-#endif
+//------------------------------------------------------------------------
+// backend selector with tags
+//------------------------------------------------------------------------
 
-struct __serial_backend_tag
-{
-};
-struct __tbb_backend_tag
-{
-};
-struct __openmp_backend_tag
-{
-};
-
-#if defined(_PSTL_PAR_BACKEND_TBB)
+#if _ONEDPL_PAR_BACKEND_TBB
 using __par_backend_tag = __tbb_backend_tag;
-#elif defined(_PSTL_PAR_BACKEND_OPENMP)
-using __par_backend_tag = __openmp_backend_tag;
-#elif defined(_PSTL_PAR_BACKEND_SERIAL)
+#elif _ONEDPL_PAR_BACKEND_OPENMP
+using __par_backend_tag = __omp_backend_tag;
+#elif _ONEDPL_PAR_BACKEND_SERIAL
 using __par_backend_tag = __serial_backend_tag;
 #else
-#    error "A parallel backend must be specified";
+#    error "Parallel backend was not specified"
 #endif
 
 template <class _IsVector>
@@ -68,44 +52,167 @@ template <class _IsVector>
 struct __parallel_tag
 {
     using __is_vector = _IsVector;
-    // backend tag can be change depending on
-    // TBB availability in the environment
     using __backend_tag = __par_backend_tag;
 };
 
+struct __parallel_forward_tag
+{
+    using __is_vector = ::std::false_type;
+    using __backend_tag = __par_backend_tag;
+};
+
+//----------------------------------------------------------
+// __select_backend (for the host policies)
+//----------------------------------------------------------
+
 template <class _IsVector, class... _IteratorTypes>
-using __tag_type = typename std::conditional<__internal::__are_random_access_iterators<_IteratorTypes...>::value,
-                                             __parallel_tag<_IsVector>, __serial_tag<_IsVector>>::type;
+using __parallel_policy_tag_selector_t = ::std::conditional_t<
+    __internal::__is_random_access_iterator_v<_IteratorTypes...>, __parallel_tag<_IsVector>,
+    ::std::conditional_t<__is_forward_iterator_v<_IteratorTypes...>, __parallel_forward_tag, __serial_tag<_IsVector>>>;
 
 template <class... _IteratorTypes>
-__serial_tag</*_IsVector = */ std::false_type>
-__select_backend(__pstl::execution::sequenced_policy, _IteratorTypes&&...)
+__serial_tag<std::false_type>
+__select_backend(__onedpl::execution::sequenced_policy, _IteratorTypes&&...)
 {
     return {};
 }
 
 template <class... _IteratorTypes>
-__serial_tag<__internal::__are_random_access_iterators<_IteratorTypes...>>
-__select_backend(__pstl::execution::unsequenced_policy, _IteratorTypes&&...)
+__serial_tag<__internal::__is_random_access_iterator<_IteratorTypes...>>
+__select_backend(__onedpl::execution::unsequenced_policy, _IteratorTypes&&...)
 {
     return {};
 }
 
 template <class... _IteratorTypes>
-__tag_type</*_IsVector = */ std::false_type, _IteratorTypes...>
-__select_backend(__pstl::execution::parallel_policy, _IteratorTypes&&...)
+__parallel_policy_tag_selector_t<std::false_type, _IteratorTypes...>
+__select_backend(__onedpl::execution::parallel_policy, _IteratorTypes&&...)
 {
     return {};
 }
 
 template <class... _IteratorTypes>
-__tag_type<__internal::__are_random_access_iterators<_IteratorTypes...>, _IteratorTypes...>
-__select_backend(__pstl::execution::parallel_unsequenced_policy, _IteratorTypes&&...)
+__parallel_policy_tag_selector_t<__internal::__is_random_access_iterator<_IteratorTypes...>, _IteratorTypes...>
+__select_backend(__onedpl::execution::parallel_unsequenced_policy, _IteratorTypes&&...)
 {
     return {};
 }
 
+} //__internal
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+namespace __ranges
+{
+
+inline __internal::__serial_tag<std::false_type>
+__select_backend(__onedpl::execution::sequenced_policy)
+{
+    return {};
+}
+
+inline __internal::__serial_tag<std::true_type> //vectorization allowed
+__select_backend(__onedpl::execution::unsequenced_policy)
+{
+    return {};
+}
+
+inline __internal::__parallel_tag<std::false_type>
+__select_backend(__onedpl::execution::parallel_policy)
+{
+    return {};
+}
+
+inline __internal::__parallel_tag<std::true_type> //vectorization allowed
+__select_backend(__onedpl::execution::parallel_unsequenced_policy)
+{
+    return {};
+}
+
+} //__ranges
+
+#endif //_ONEDPL_CPP20_RANGES_PRESENT
+
+namespace __internal
+{
+//----------------------------------------------------------
+// __is_serial_tag, __is_serial_tag_v
+//----------------------------------------------------------
+
+template <class _Tag>
+struct __is_serial_tag : ::std::false_type
+{
+};
+
+template <class _IsVector>
+struct __is_serial_tag<__serial_tag<_IsVector>> : ::std::true_type
+{
+};
+
+template <class _Tag>
+inline constexpr bool __is_serial_tag_v = __is_serial_tag<_Tag>::value;
+
+//----------------------------------------------------------
+// __is_parallel_forward_tag, __is_parallel_forward_tag_v
+//----------------------------------------------------------
+
+template <class _Tag>
+struct __is_parallel_forward_tag : ::std::false_type
+{
+};
+
+template <>
+struct __is_parallel_forward_tag<__parallel_forward_tag> : ::std::true_type
+{
+};
+
+template <class _Tag>
+inline constexpr bool __is_parallel_forward_tag_v = __is_parallel_forward_tag<_Tag>::value;
+
+//----------------------------------------------------------
+// __is_parallel_tag, __is_parallel_tag_v
+//----------------------------------------------------------
+
+template <class _Tag>
+struct __is_parallel_tag : ::std::false_type
+{
+};
+
+template <class _IsVector>
+struct __is_parallel_tag<__parallel_tag<_IsVector>> : ::std::true_type
+{
+};
+
+template <class _Tag>
+inline constexpr bool __is_parallel_tag_v = __is_parallel_tag<_Tag>::value;
+
+//----------------------------------------------------------
+// __is_host_dispatch_tag_v
+//----------------------------------------------------------
+
+template <class _Tag>
+inline constexpr bool __is_host_dispatch_tag_v =
+    __is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag> || __is_parallel_tag_v<_Tag>;
+
+inline __onedpl::execution::parallel_policy
+__get_unvectorized_policy(const __onedpl::execution::parallel_unsequenced_policy&)
+{
+    return __onedpl::execution::par;
+}
+
+inline __onedpl::execution::sequenced_policy
+__get_unvectorized_policy(const __onedpl::execution::unsequenced_policy&)
+{
+    return __onedpl::execution::seq;
+}
+
+template <typename _ExecutionPolicy>
+_ExecutionPolicy
+__get_unvectorized_policy(const _ExecutionPolicy& __exec)
+{
+    return __exec;
+}
+
 } // namespace __internal
-} // namespace __pstl
+} // namespace std::__onedpl
 
-#endif /* _PSTL_EXECUTION_IMPL_H */
+#endif // _ONEDPL_EXECUTION_IMPL_H
diff --git a/libstdc++-v3/include/pstl/functional_impl.h b/libstdc++-v3/include/pstl/functional_impl.h
new file mode 100644
index 000000000000..377f08a93804
--- /dev/null
+++ b/libstdc++-v3/include/pstl/functional_impl.h
@@ -0,0 +1,61 @@
+// -*- C++ -*-
+//===-- functional_impl.h -------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_FUNCTIONAL_IMPL_H
+#define _ONEDPL_FUNCTIONAL_IMPL_H
+
+#include "onedpl_config.h"
+
+#include <utility>    // for  std::forward
+#include <functional> // for std::greater, std::less
+
+namespace std::__onedpl
+{
+
+struct identity
+{
+    using is_transparent = void;
+
+    template <typename _T>
+    constexpr _T&&
+    operator()(_T&& t) const noexcept
+    {
+        return std::forward<_T>(t);
+    }
+};
+
+template <typename _T>
+struct maximum
+{
+    constexpr const _T&
+    operator()(const _T& a, const _T& b) const
+    {
+        return std::greater<_T>()(a, b) ? a : b;
+    }
+};
+
+template <typename _T>
+struct minimum
+{
+    constexpr const _T&
+    operator()(const _T& a, const _T& b) const
+    {
+        return std::less<_T>()(a, b) ? a : b;
+    }
+};
+
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_FUNCTIONAL_IMPL_H
diff --git a/libstdc++-v3/include/pstl/glue_algorithm_defs.h b/libstdc++-v3/include/pstl/glue_algorithm_defs.h
index d43112f8644a..4d56e8368346 100644
--- a/libstdc++-v3/include/pstl/glue_algorithm_defs.h
+++ b/libstdc++-v3/include/pstl/glue_algorithm_defs.h
@@ -1,442 +1,516 @@
 // -*- C++ -*-
-//===-- glue_algorithm_defs.h ---------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_GLUE_ALGORITHM_DEFS_H
-#define _PSTL_GLUE_ALGORITHM_DEFS_H
+#ifndef _ONEDPL_GLUE_ALGORITHM_DEFS_H
+#define _ONEDPL_GLUE_ALGORITHM_DEFS_H
 
-#include <bits/stl_iterator_base_types.h>
-#include <bits/stl_pair.h>
+#include <functional>
+#include <iterator>
 
 #include "execution_defs.h"
 
-namespace std
+namespace std::__onedpl
 {
 
 // [alg.any_of]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 any_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred);
 
 // [alg.all_of]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 all_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred);
 
 // [alg.none_of]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 none_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred);
 
 // [alg.foreach]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Function>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 for_each(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Function __f);
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Function>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 for_each_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n, _Function __f);
 
 // [alg.find]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 find_if(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred);
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 find_if_not(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred);
 
-template <class _ExecutionPolicy, class _ForwardIterator, class _Tp _GLIBCXX26_ALGO_DEF_VAL_T(_ForwardIterator)>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+template <class _ExecutionPolicy, class _ForwardIterator,
+          class _Tp = typename std::iterator_traits<_ForwardIterator>::value_type>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
 
 // [alg.find.end]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
 find_end(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
          _ForwardIterator2 __s_last, _BinaryPredicate __pred);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
 find_end(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
          _ForwardIterator2 __s_last);
 
 // [alg.find_first_of]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
 find_first_of(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
               _ForwardIterator2 __s_first, _ForwardIterator2 __s_last, _BinaryPredicate __pred);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
 find_first_of(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
               _ForwardIterator2 __s_first, _ForwardIterator2 __s_last);
 
 // [alg.adjacent_find]
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 adjacent_find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 adjacent_find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred);
 
 // [alg.count]
 
-template <class _ExecutionPolicy, class _ForwardIterator, class _Tp _GLIBCXX26_ALGO_DEF_VAL_T(_ForwardIterator)>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
-                                                 typename iterator_traits<_ForwardIterator>::difference_type>
+template <class _ExecutionPolicy, class _ForwardIterator,
+          class _Tp = typename std::iterator_traits<_ForwardIterator>::value_type>
+__onedpl::__internal::__enable_if_execution_policy<
+    _ExecutionPolicy, typename ::std::iterator_traits<_ForwardIterator>::difference_type>
 count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
-                                                 typename iterator_traits<_ForwardIterator>::difference_type>
+__onedpl::__internal::__enable_if_execution_policy<
+    _ExecutionPolicy, typename ::std::iterator_traits<_ForwardIterator>::difference_type>
 count_if(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred);
 
 // [alg.search]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
 search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
        _ForwardIterator2 __s_last, _BinaryPredicate __pred);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
 search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
        _ForwardIterator2 __s_last);
 
-template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Tp _GLIBCXX26_ALGO_DEF_VAL_T(_ForwardIterator), class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+template <class _ExecutionPolicy, class _ForwardIterator, class _Size,
+          class _Tp = typename std::iterator_traits<_ForwardIterator>::value_type, class _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 search_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Size __count,
          const _Tp& __value, _BinaryPredicate __pred);
 
-template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Tp _GLIBCXX26_ALGO_DEF_VAL_T(_ForwardIterator)>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+template <class _ExecutionPolicy, class _ForwardIterator, class _Size,
+          class _Tp = typename std::iterator_traits<_ForwardIterator>::value_type>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 search_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Size __count,
          const _Tp& __value);
 
 // [alg.copy]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _Size, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 copy_n(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _Size __n, _ForwardIterator2 __result);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 copy_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 result,
         _Predicate __pred);
 
 // [alg.swap]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 swap_ranges(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
             _ForwardIterator2 __first2);
 
 // [alg.transform]
-
-template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _UnaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
-transform(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
-          _UnaryOperation __op);
-
+// To workaround the Clang compiler (< 13.0) bug the order of these overload declarations
+// should be in the reversed order comparing with glue_algorithm_impl.h corresponding
+// definitions
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
           class _BinaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 transform(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
           _ForwardIterator __result, _BinaryOperation __op);
 
+template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _UnaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+transform(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
+          _UnaryOperation __op);
+
+// [alg.transform_if]
+
+template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _UnaryOperation,
+          class _UnaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+transform_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
+             _UnaryOperation __op, _UnaryPredicate __pred);
+
+template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator3,
+          class _BinaryOperation, class _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator3>
+transform_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
+             _ForwardIterator2 __first2, _ForwardIterator3 __result, _BinaryOperation __op, _BinaryPredicate __pred);
+
 // [alg.replace]
 
-template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate, class _Tp _GLIBCXX26_ALGO_DEF_VAL_T(_ForwardIterator)>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate,
+          class _Tp = typename std::iterator_traits<_ForwardIterator>::value_type>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 replace_if(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred,
            const _Tp& __new_value);
 
-template <class _ExecutionPolicy, class _ForwardIterator, class _Tp _GLIBCXX26_ALGO_DEF_VAL_T(_ForwardIterator)>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+template <class _ExecutionPolicy, class _ForwardIterator,
+          class _Tp = typename std::iterator_traits<_ForwardIterator>::value_type>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 replace(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value,
         const _Tp& __new_value);
 
-template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _UnaryPredicate, class _Tp _GLIBCXX26_ALGO_DEF_VAL_T(_ForwardIterator2)>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _UnaryPredicate,
+          class _Tp = typename std::iterator_traits<_ForwardIterator2>::value_type>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 replace_copy_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                 _ForwardIterator2 __result, _UnaryPredicate __pred, const _Tp& __new_value);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 replace_copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
              const _Tp& __old_value, const _Tp& __new_value);
 
 // [alg.fill]
 
-template <class _ExecutionPolicy, class _ForwardIterator, class _Tp _GLIBCXX26_ALGO_DEF_VAL_T(_ForwardIterator)>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+template <class _ExecutionPolicy, class _ForwardIterator,
+          class _Tp = typename std::iterator_traits<_ForwardIterator>::value_type>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 fill(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
 
-template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Tp _GLIBCXX26_ALGO_DEF_VAL_T(_ForwardIterator)>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+template <class _ExecutionPolicy, class _ForwardIterator, class _Size,
+          class _Tp = typename std::iterator_traits<_ForwardIterator>::value_type>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 fill_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __count, const _Tp& __value);
 
 // [alg.generate]
 template <class _ExecutionPolicy, class _ForwardIterator, class _Generator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 generate(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Generator __g);
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Generator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
-generate_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __count, _Generator __g);
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+generate_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size count, _Generator __g);
 
 // [alg.remove]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 remove_copy_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                _ForwardIterator2 __result, _Predicate __pred);
 
-template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp _GLIBCXX26_ALGO_DEF_VAL_T(_ForwardIterator1)>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2,
+          class _Tp = typename std::iterator_traits<_ForwardIterator1>::value_type>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 remove_copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
             const _Tp& __value);
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 remove_if(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred);
 
-template <class _ExecutionPolicy, class _ForwardIterator, class _Tp _GLIBCXX26_ALGO_DEF_VAL_T(_ForwardIterator)>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+template <class _ExecutionPolicy, class _ForwardIterator,
+          class _Tp = typename std::iterator_traits<_ForwardIterator>::value_type>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 remove(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
 
 // [alg.unique]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 unique(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred);
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 unique(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 unique_copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
             _BinaryPredicate __pred);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 unique_copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result);
 
 // [alg.reverse]
 
 template <class _ExecutionPolicy, class _BidirectionalIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 reverse(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last);
 
 template <class _ExecutionPolicy, class _BidirectionalIterator, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 reverse_copy(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last,
              _ForwardIterator __d_first);
 
 // [alg.rotate]
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 rotate(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 rotate_copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __middle, _ForwardIterator1 __last,
             _ForwardIterator2 __result);
 
 // [alg.partitions]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 is_partitioned(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred);
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 partition(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred);
 
 template <class _ExecutionPolicy, class _BidirectionalIterator, class _UnaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _BidirectionalIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _BidirectionalIterator>
 stable_partition(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last,
                  _UnaryPredicate __pred);
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _ForwardIterator1, class _ForwardIterator2,
           class _UnaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator1, _ForwardIterator2>>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      ::std::pair<_ForwardIterator1, _ForwardIterator2>>
 partition_copy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
                _ForwardIterator1 __out_true, _ForwardIterator2 __out_false, _UnaryPredicate __pred);
 
 // [alg.sort]
 
 template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
 
 template <class _ExecutionPolicy, class _RandomAccessIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
 
 // [stable.sort]
 
 template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 stable_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
 
 template <class _ExecutionPolicy, class _RandomAccessIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 stable_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
 
+// __onedpl::sort_by_key
+
+template <typename _ExecutionPolicy, typename _RandomAccessIterator1, typename _RandomAccessIterator2,
+          typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+sort_by_key(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __keys_first, _RandomAccessIterator1 __keys_last,
+            _RandomAccessIterator2 __values_first, _Compare __comp);
+
+template <typename _ExecutionPolicy, typename _RandomAccessIterator1, typename _RandomAccessIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+sort_by_key(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __keys_first, _RandomAccessIterator1 __keys_last,
+            _RandomAccessIterator2 __values_first);
+
+// __onedpl::stable_sort_by_key
+
+template <typename _ExecutionPolicy, typename _RandomAccessIterator1, typename _RandomAccessIterator2,
+          typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+stable_sort_by_key(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __keys_first, _RandomAccessIterator1 __keys_last,
+                   _RandomAccessIterator2 __values_first, _Compare __comp);
+
+template <typename _ExecutionPolicy, typename _RandomAccessIterator1, typename _RandomAccessIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+stable_sort_by_key(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __keys_first, _RandomAccessIterator1 __keys_last,
+                   _RandomAccessIterator2 __values_first);
+
 // [mismatch]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator1, _ForwardIterator2>>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      ::std::pair<_ForwardIterator1, _ForwardIterator2>>
 mismatch(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
          _ForwardIterator2 __last2, _BinaryPredicate __pred);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator1, _ForwardIterator2>>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      ::std::pair<_ForwardIterator1, _ForwardIterator2>>
 mismatch(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
          _BinaryPredicate __pred);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator1, _ForwardIterator2>>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      ::std::pair<_ForwardIterator1, _ForwardIterator2>>
 mismatch(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
          _ForwardIterator2 __last2);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator1, _ForwardIterator2>>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      ::std::pair<_ForwardIterator1, _ForwardIterator2>>
 mismatch(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2);
 
 // [alg.equal]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
       _BinaryPredicate __p);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
       _ForwardIterator2 __last2, _BinaryPredicate __p);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
       _ForwardIterator2 __last2);
 
 // [alg.move]
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first);
 
 // [partial.sort]
-
-template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
-partial_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __middle,
-             _RandomAccessIterator __last, _Compare __comp);
+// To workaround the Clang compiler (< 13.0) bug the order of these overload declarations
+// should be in the reversed order comparing with glue_algorithm_impl.h corresponding
+// definitions
 
 template <class _ExecutionPolicy, class _RandomAccessIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 partial_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __middle,
              _RandomAccessIterator __last);
 
-// [partial.sort.copy]
+template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+partial_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __middle,
+             _RandomAccessIterator __last, _Compare __comp);
 
-template <class _ExecutionPolicy, class _ForwardIterator, class _RandomAccessIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
-partial_sort_copy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
-                  _RandomAccessIterator __d_first, _RandomAccessIterator __d_last, _Compare __comp);
+// [partial.sort.copy]
+// To workaround the Clang compiler (< 13.0) bug the order of these overload declarations
+// should be in the reversed order comparing with glue_algorithm_impl.h corresponding
+// definitions
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _RandomAccessIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
 partial_sort_copy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
                   _RandomAccessIterator __d_first, _RandomAccessIterator __d_last);
 
+template <class _ExecutionPolicy, class _ForwardIterator, class _RandomAccessIterator, class _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
+partial_sort_copy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
+                  _RandomAccessIterator __d_first, _RandomAccessIterator __d_last, _Compare __comp);
+
 // [is.sorted]
-template <class _ExecutionPolicy, class _ForwardIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
-is_sorted_until(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp);
+// To workaround the Clang compiler (< 13.0) bug the order of these overload declarations
+// should be in the reversed order comparing with glue_algorithm_impl.h corresponding
+// definitions
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
-is_sorted_until(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+is_sorted(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 is_sorted(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp);
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
-is_sorted(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+is_sorted_until(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
+
+template <class _ExecutionPolicy, class _ForwardIterator, class _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+is_sorted_until(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp);
 
 // [alg.nth.element]
 
 template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 nth_element(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __nth,
             _RandomAccessIterator __last, _Compare __comp);
 
 template <class _ExecutionPolicy, class _RandomAccessIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 nth_element(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __nth,
             _RandomAccessIterator __last);
 
 // [alg.merge]
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
           class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 merge(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
       _ForwardIterator2 __last2, _ForwardIterator __d_first, _Compare __comp);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 merge(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
       _ForwardIterator2 __last2, _ForwardIterator __d_first);
 
 template <class _ExecutionPolicy, class _BidirectionalIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 inplace_merge(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __middle,
               _BidirectionalIterator __last, _Compare __comp);
 
 template <class _ExecutionPolicy, class _BidirectionalIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 inplace_merge(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __middle,
               _BidirectionalIterator __last);
 
 // [includes]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
          _ForwardIterator2 __last2, _Compare __comp);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
          _ForwardIterator2 __last2);
 
@@ -444,12 +518,12 @@ includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
           class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 set_union(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
           _ForwardIterator2 __last2, _ForwardIterator __result, _Compare __comp);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 set_union(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
           _ForwardIterator2 __last2, _ForwardIterator __result);
 
@@ -457,12 +531,12 @@ set_union(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterato
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
           class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 set_intersection(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                  _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result, _Compare __comp);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 set_intersection(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                  _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result);
 
@@ -470,12 +544,12 @@ set_intersection(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _Forward
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
           class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 set_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result, _Compare __comp);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 set_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result);
 
@@ -483,70 +557,84 @@ set_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIt
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
           class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 set_symmetric_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                          _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator result,
                          _Compare __comp);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 set_symmetric_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                          _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result);
 
 // [is.heap]
-template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
-is_heap_until(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
+// To workaround the Clang compiler (< 13.0) bug the order of these overload declarations
+// should be in the reversed order comparing with glue_algorithm_impl.h corresponding
+// definitions
 
 template <class _ExecutionPolicy, class _RandomAccessIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
-is_heap_until(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+is_heap(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
 
 template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 is_heap(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
 
 template <class _ExecutionPolicy, class _RandomAccessIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
-is_heap(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
+is_heap_until(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
+
+template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
+is_heap_until(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp);
 
 // [alg.min.max]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 min_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp);
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 min_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 max_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp);
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 max_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator, _ForwardIterator>>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, ::std::pair<_ForwardIterator, _ForwardIterator>>
 minmax_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp);
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator, _ForwardIterator>>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, ::std::pair<_ForwardIterator, _ForwardIterator>>
 minmax_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
 
 // [alg.lex.comparison]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 lexicographical_compare(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                         _ForwardIterator2 __first2, _ForwardIterator2 __last2, _Compare __comp);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 lexicographical_compare(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                         _ForwardIterator2 __first2, _ForwardIterator2 __last2);
 
-} // namespace std
-#endif /* _PSTL_GLUE_ALGORITHM_DEFS_H */
+template <class _ExecutionPolicy, class _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+shift_left(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
+           typename ::std::iterator_traits<_ForwardIterator>::difference_type __n);
+
+template <class _ExecutionPolicy, class _BidirectionalIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _BidirectionalIterator>
+shift_right(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last,
+            typename ::std::iterator_traits<_BidirectionalIterator>::difference_type __n);
+
+} // namespace std::__onedpl
+#endif // _ONEDPL_GLUE_ALGORITHM_DEFS_H
diff --git a/libstdc++-v3/include/pstl/glue_algorithm_impl.h b/libstdc++-v3/include/pstl/glue_algorithm_impl.h
index 5be45ce57fba..d01c32ad7142 100644
--- a/libstdc++-v3/include/pstl/glue_algorithm_impl.h
+++ b/libstdc++-v3/include/pstl/glue_algorithm_impl.h
@@ -1,1100 +1,1269 @@
 // -*- C++ -*-
-//===-- glue_algorithm_impl.h ---------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_GLUE_ALGORITHM_IMPL_H
-#define _PSTL_GLUE_ALGORITHM_IMPL_H
+#ifndef _ONEDPL_GLUE_ALGORITHM_IMPL_H
+#define _ONEDPL_GLUE_ALGORITHM_IMPL_H
 
 #include <functional>
+#include <algorithm> // std::sort, std::stable_sort
 
 #include "execution_defs.h"
+
 #include "utils.h"
+
+#if _ONEDPL_HETERO_BACKEND
+#    include "hetero/algorithm_impl_hetero.h"
+#    include "hetero/numeric_impl_hetero.h"
+#endif
+
 #include "algorithm_fwd.h"
 #include "numeric_fwd.h" /* count and count_if use __pattern_transform_reduce */
 
-namespace std
+#include "execution_impl.h"
+
+namespace std::__onedpl
 {
 
 // [alg.any_of]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 any_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    return __pstl::__internal::__pattern_any_of(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                                __pred);
+    return __onedpl::__internal::__pattern_any_of(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
+                                                     __last, __pred);
 }
 
 // [alg.all_of]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Pred>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 all_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred)
 {
-    return !std::any_of(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::not_fn(__pred));
+    return !__onedpl::any_of(
+        ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+        __onedpl::__internal::__not_pred<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, _Pred>>(__pred));
 }
 
 // [alg.none_of]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 none_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
 {
-    return !std::any_of(std::forward<_ExecutionPolicy>(__exec), __first, __last, __pred);
+    return !__onedpl::any_of(::std::forward<_ExecutionPolicy>(__exec), __first, __last, __pred);
 }
 
 // [alg.foreach]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Function>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 for_each(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Function __f)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    __pstl::__internal::__pattern_walk1(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __f);
+    __onedpl::__internal::__pattern_walk1(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                             __f);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Function>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 for_each_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n, _Function __f)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    return __pstl::__internal::__pattern_walk1_n(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n,
-                                                 __f);
+    return __onedpl::__internal::__pattern_walk1_n(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
+                                                      __n, __f);
 }
 
 // [alg.find]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 find_if(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    return __pstl::__internal::__pattern_find_if(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                 __last, __pred);
+    return __onedpl::__internal::__pattern_find_if(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
+                                                      __last, __pred);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 find_if_not(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
 {
-    return std::find_if(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::not_fn(__pred));
+    return __onedpl::find_if(
+        ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+        __onedpl::__internal::__not_pred<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, _Predicate>>(
+            __pred));
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
 {
-    return std::find_if(std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                        __pstl::__internal::__equal_value<_Tp>(__value));
+    return __onedpl::find_if(
+        ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+        __onedpl::__internal::__equal_value<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _Tp>>(
+            __value));
 }
 
 // [alg.find.end]
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
 find_end(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
          _ForwardIterator2 __s_last, _BinaryPredicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __s_first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __s_first);
 
-    return __pstl::__internal::__pattern_find_end(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                  __last, __s_first, __s_last, __pred);
+    return __onedpl::__internal::__pattern_find_end(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                       __first, __last, __s_first, __s_last, __pred);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
 find_end(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
          _ForwardIterator2 __s_last)
 {
-    return std::find_end(std::forward<_ExecutionPolicy>(__exec), __first, __last, __s_first, __s_last,
-                         std::equal_to<>());
+    return __onedpl::find_end(::std::forward<_ExecutionPolicy>(__exec), __first, __last, __s_first, __s_last,
+                                 __onedpl::__internal::__pstl_equal());
 }
 
 // [alg.find_first_of]
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
 find_first_of(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
               _ForwardIterator2 __s_first, _ForwardIterator2 __s_last, _BinaryPredicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __s_first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __s_first);
 
-    return __pstl::__internal::__pattern_find_first_of(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                       __last, __s_first, __s_last, __pred);
+    return __onedpl::__internal::__pattern_find_first_of(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                            __first, __last, __s_first, __s_last, __pred);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
 find_first_of(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
               _ForwardIterator2 __s_first, _ForwardIterator2 __s_last)
 {
-    return std::find_first_of(std::forward<_ExecutionPolicy>(__exec), __first, __last, __s_first, __s_last,
-                              std::equal_to<>());
+    return __onedpl::find_first_of(::std::forward<_ExecutionPolicy>(__exec), __first, __last, __s_first, __s_last,
+                                      __onedpl::__internal::__pstl_equal());
 }
 
 // [alg.adjacent_find]
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 adjacent_find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    using _ValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
 
-    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
-    return __pstl::__internal::__pattern_adjacent_find(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                       __last, std::equal_to<_ValueType>(), /*first_semantic*/ false);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
+
+    return __onedpl::__internal::__pattern_adjacent_find(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                            __first, __last, ::std::equal_to<_ValueType>(),
+                                                            __onedpl::__internal::__first_semantic());
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 adjacent_find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
-    return __pstl::__internal::__pattern_adjacent_find(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                       __last, __pred, /*first_semantic*/ false);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
+
+    return __onedpl::__internal::__pattern_adjacent_find(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                            __first, __last, __pred,
+                                                            __onedpl::__internal::__first_semantic());
 }
 
 // [alg.count]
 
-// Implementation note: count and count_if call the pattern directly instead of calling std::transform_reduce
+// Implementation note: count and count_if call the pattern directly instead of calling ::std::transform_reduce
 // so that we do not have to include <numeric>.
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
-                                                 typename iterator_traits<_ForwardIterator>::difference_type>
+__onedpl::__internal::__enable_if_execution_policy<
+    _ExecutionPolicy, typename ::std::iterator_traits<_ForwardIterator>::difference_type>
 count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
-    return __pstl::__internal::__pattern_count(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                               [&__value](const _ValueType& __x) { return __value == __x; });
+    return __onedpl::__internal::__pattern_count(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+        __onedpl::__internal::__equal_value<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _Tp>>(
+            __value));
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
-                                                 typename iterator_traits<_ForwardIterator>::difference_type>
+__onedpl::__internal::__enable_if_execution_policy<
+    _ExecutionPolicy, typename ::std::iterator_traits<_ForwardIterator>::difference_type>
 count_if(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
-    return __pstl::__internal::__pattern_count(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                               __pred);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
+
+    return __onedpl::__internal::__pattern_count(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
+                                                    __last, __pred);
 }
 
 // [alg.search]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
 search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
        _ForwardIterator2 __s_last, _BinaryPredicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __s_first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __s_first);
 
-    return __pstl::__internal::__pattern_search(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                                __s_first, __s_last, __pred);
+    return __onedpl::__internal::__pattern_search(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
+                                                     __last, __s_first, __s_last, __pred);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator1>
 search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
        _ForwardIterator2 __s_last)
 {
-    return std::search(std::forward<_ExecutionPolicy>(__exec), __first, __last, __s_first, __s_last, std::equal_to<>());
+    return __onedpl::search(::std::forward<_ExecutionPolicy>(__exec), __first, __last, __s_first, __s_last,
+                               __onedpl::__internal::__pstl_equal());
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 search_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Size __count,
          const _Tp& __value, _BinaryPredicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    return __pstl::__internal::__pattern_search_n(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                  __last, __count, __value, __pred);
+    return __onedpl::__internal::__pattern_search_n(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                       __first, __last, __count, __value, __pred);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 search_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Size __count,
          const _Tp& __value)
 {
-    return std::search_n(std::forward<_ExecutionPolicy>(__exec), __first, __last, __count, __value,
-                         std::equal_to<typename iterator_traits<_ForwardIterator>::value_type>());
+    return __onedpl::search_n(::std::forward<_ExecutionPolicy>(__exec), __first, __last, __count, __value,
+                                 ::std::equal_to<typename ::std::iterator_traits<_ForwardIterator>::value_type>());
 }
 
 // [alg.copy]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
+    auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __result);
 
-    using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
-
-    return __pstl::__internal::__pattern_walk2_brick(
-        __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
-        [](_ForwardIterator1 __begin, _ForwardIterator1 __end, _ForwardIterator2 __res)
-        { return __pstl::__internal::__brick_copy(__begin, __end, __res, __is_vector{}); });
+    return __onedpl::__internal::__pattern_walk2_brick(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
+        __onedpl::__internal::__brick_copy<decltype(__dispatch_tag)>{});
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _Size, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 copy_n(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _Size __n, _ForwardIterator2 __result)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
+    auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __result);
 
-    using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
-
-    return __pstl::__internal::__pattern_walk2_brick_n(
-        __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
-        [](_ForwardIterator1 __begin, _Size __sz, _ForwardIterator2 __res)
-        { return __pstl::__internal::__brick_copy_n(__begin, __sz, __res, __is_vector{}); });
+    return __onedpl::__internal::__pattern_walk2_brick_n(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
+        __onedpl::__internal::__brick_copy_n<decltype(__dispatch_tag)>{});
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 copy_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
         _Predicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __result);
 
-    return __pstl::__internal::__pattern_copy_if(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                 __last, __result, __pred);
+    return __onedpl::__internal::__pattern_copy_if(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
+                                                      __last, __result, __pred);
 }
 
 // [alg.swap]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 swap_ranges(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
             _ForwardIterator2 __first2)
 {
-    typedef typename iterator_traits<_ForwardIterator1>::reference _ReferenceType1;
-    typedef typename iterator_traits<_ForwardIterator2>::reference _ReferenceType2;
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first1, __first2);
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2);
-
-    return __pstl::__internal::__pattern_walk2(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1,
-                                               __last1, __first2,
-                                               [](_ReferenceType1 __x, _ReferenceType2 __y)
-                                               {
-                                                   using std::swap;
-                                                   swap(__x, __y);
-                                               });
+    return __onedpl::__internal::__pattern_swap(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1,
+                                                   __last1, __first2);
 }
 
 // [alg.transform]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _UnaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 transform(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
           _UnaryOperation __op)
 {
-    typedef typename iterator_traits<_ForwardIterator1>::reference _InputType;
-    typedef typename iterator_traits<_ForwardIterator2>::reference _OutputType;
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __result);
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
-
-    return __pstl::__internal::__pattern_walk2(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                               __result,
-                                               [__op](_InputType __x, _OutputType __y) mutable { __y = __op(__x); });
+    return __onedpl::__internal::__pattern_walk2(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
+        __onedpl::__internal::__transform_functor<_UnaryOperation>{::std::move(__op)});
 }
 
+// we can't use non-const __op here
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
           class _BinaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 transform(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
           _ForwardIterator __result, _BinaryOperation __op)
 {
-    typedef typename iterator_traits<_ForwardIterator1>::reference _Input1Type;
-    typedef typename iterator_traits<_ForwardIterator2>::reference _Input2Type;
-    typedef typename iterator_traits<_ForwardIterator>::reference _OutputType;
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first1, __first2, __result);
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2, __result);
+    return __onedpl::__internal::__pattern_walk3(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __result,
+        __onedpl::__internal::__transform_functor<_BinaryOperation>(::std::move(__op)));
+}
 
-    return __pstl::__internal::__pattern_walk3(
-        __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __result,
-        [__op](_Input1Type __x, _Input2Type __y, _OutputType __z) mutable { __z = __op(__x, __y); });
+// [alg.transform_if]
+
+template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _UnaryOperation,
+          class _UnaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+transform_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
+             _UnaryOperation __op, _UnaryPredicate __pred)
+{
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __result);
+
+    return __onedpl::__internal::__pattern_walk2_transform_if(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
+        __onedpl::__internal::__transform_if_unary_functor<_UnaryOperation, _UnaryPredicate>(::std::move(__op),
+                                                                                                ::std::move(__pred)));
+}
+
+template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator3,
+          class _BinaryOperation, class _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator3>
+transform_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
+             _ForwardIterator2 __first2, _ForwardIterator3 __result, _BinaryOperation __op, _BinaryPredicate __pred)
+{
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first1, __first2, __result);
+
+    return __onedpl::__internal::__pattern_walk3_transform_if(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __result,
+        __onedpl::__internal::__transform_if_binary_functor<_BinaryOperation, _BinaryPredicate>(
+            ::std::move(__op), ::std::move(__pred)));
 }
 
 // [alg.replace]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 replace_if(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred,
            const _Tp& __new_value)
 {
-    typedef typename iterator_traits<_ForwardIterator>::reference _ElementType;
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
-
-    __pstl::__internal::__pattern_walk1(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                        [&__pred, &__new_value](_ElementType __elem)
-                                        {
-                                            if (__pred(__elem))
-                                            {
-                                                __elem = __new_value;
-                                            }
-                                        });
+    __onedpl::__internal::__pattern_walk1(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+        __onedpl::__internal::__replace_functor<
+            __onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _Tp>,
+            __onedpl::__internal::__ref_or_copy<_ExecutionPolicy, _UnaryPredicate>>(__new_value, __pred));
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 replace(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value,
         const _Tp& __new_value)
 {
-    std::replace_if(std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                    __pstl::__internal::__equal_value<_Tp>(__old_value), __new_value);
+    __onedpl::replace_if(
+        ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+        __onedpl::__internal::__equal_value<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _Tp>>(
+            __old_value),
+        __new_value);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _UnaryPredicate, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 replace_copy_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                 _ForwardIterator2 __result, _UnaryPredicate __pred, const _Tp& __new_value)
 {
-    typedef typename iterator_traits<_ForwardIterator1>::reference _InputType;
-    typedef typename iterator_traits<_ForwardIterator2>::reference _OutputType;
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __result);
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
-
-    return __pstl::__internal::__pattern_walk2(
-        __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
-        [__pred, &__new_value](_InputType __x, _OutputType __y) mutable { __y = __pred(__x) ? __new_value : __x; });
+    return __onedpl::__internal::__pattern_walk2(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
+        __onedpl::__internal::__replace_copy_functor<
+            __onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _Tp>,
+            ::std::conditional_t<__onedpl::__internal::__is_const_callable_object_v<_UnaryPredicate>,
+                                 _UnaryPredicate,
+                                 __onedpl::__internal::__ref_or_copy<_ExecutionPolicy, _UnaryPredicate>>>(
+            __new_value, __pred));
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 replace_copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
              const _Tp& __old_value, const _Tp& __new_value)
 {
-    return std::replace_copy_if(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
-                                __pstl::__internal::__equal_value<_Tp>(__old_value), __new_value);
+    return __onedpl::replace_copy_if(
+        ::std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
+        __onedpl::__internal::__equal_value<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _Tp>>(
+            __old_value),
+        __new_value);
 }
 
 // [alg.fill]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 fill(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    __pstl::__internal::__pattern_fill(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                       __value);
+    __onedpl::__internal::__pattern_fill(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                            __value);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 fill_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __count, const _Tp& __value)
 {
     if (__count <= 0)
         return __first;
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    return __pstl::__internal::__pattern_fill_n(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                __count, __value);
+    return __onedpl::__internal::__pattern_fill_n(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
+                                                     __count, __value);
 }
 
 // [alg.generate]
 template <class _ExecutionPolicy, class _ForwardIterator, class _Generator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 generate(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Generator __g)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    __pstl::__internal::__pattern_generate(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                           __g);
+    __onedpl::__internal::__pattern_generate(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
+                                                __last, __g);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Generator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 generate_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __count, _Generator __g)
 {
     if (__count <= 0)
         return __first;
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    return __pstl::__internal::__pattern_generate_n(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                    __count, __g);
+    return __onedpl::__internal::__pattern_generate_n(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                         __first, __count, __g);
 }
 
 // [alg.remove]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Predicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 remove_copy_if(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                _ForwardIterator2 __result, _Predicate __pred)
 {
-    return std::copy_if(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, std::not_fn(__pred));
+    return __onedpl::copy_if(
+        ::std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
+        __onedpl::__internal::__not_pred<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, _Predicate>>(
+            __pred));
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 remove_copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
             const _Tp& __value)
 {
-    return std::copy_if(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
-                        __pstl::__internal::__not_equal_value<_Tp>(__value));
+    return __onedpl::copy_if(
+        ::std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
+        __onedpl::__internal::__not_equal_value<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _Tp>>(
+            __value));
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 remove_if(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    return __pstl::__internal::__pattern_remove_if(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                   __last, __pred);
+    return __onedpl::__internal::__pattern_remove_if(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                        __first, __last, __pred);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 remove(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
 {
-    return std::remove_if(std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                          __pstl::__internal::__equal_value<_Tp>(__value));
+    return __onedpl::remove_if(
+        ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+        __onedpl::__internal::__equal_value<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _Tp>>(
+            __value));
 }
 
 // [alg.unique]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 unique(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    return __pstl::__internal::__pattern_unique(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                                __pred);
+    return __onedpl::__internal::__pattern_unique(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
+                                                     __last, __pred);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 unique(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
 {
-    return std::unique(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::equal_to<>());
+    return __onedpl::unique(::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                               __onedpl::__internal::__pstl_equal());
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 unique_copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result,
             _BinaryPredicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __result);
 
-    return __pstl::__internal::__pattern_unique_copy(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                     __last, __result, __pred);
+    return __onedpl::__internal::__pattern_unique_copy(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                          __first, __last, __result, __pred);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 unique_copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __result)
 {
-    return std::unique_copy(__exec, __first, __last, __result, std::equal_to<>());
+    return __onedpl::unique_copy(::std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
+                                    __onedpl::__internal::__pstl_equal());
 }
 
 // [alg.reverse]
 
 template <class _ExecutionPolicy, class _BidirectionalIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 reverse(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    __pstl::__internal::__pattern_reverse(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last);
+    __onedpl::__internal::__pattern_reverse(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
+                                               __last);
 }
 
 template <class _ExecutionPolicy, class _BidirectionalIterator, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 reverse_copy(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last,
              _ForwardIterator __d_first)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __d_first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __d_first);
 
-    return __pstl::__internal::__pattern_reverse_copy(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                      __last, __d_first);
+    return __onedpl::__internal::__pattern_reverse_copy(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                           __first, __last, __d_first);
 }
 
 // [alg.rotate]
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 rotate(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    return __pstl::__internal::__pattern_rotate(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                __middle, __last);
+    return __onedpl::__internal::__pattern_rotate(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
+                                                     __middle, __last);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 rotate_copy(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __middle, _ForwardIterator1 __last,
             _ForwardIterator2 __result)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __result);
 
-    return __pstl::__internal::__pattern_rotate_copy(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                     __middle, __last, __result);
+    return __onedpl::__internal::__pattern_rotate_copy(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                          __first, __middle, __last, __result);
 }
 
 // [alg.partitions]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 is_partitioned(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
-    return __pstl::__internal::__pattern_is_partitioned(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                        __last, __pred);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
+
+    return __onedpl::__internal::__pattern_is_partitioned(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                             __first, __last, __pred);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 partition(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    return __pstl::__internal::__pattern_partition(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                   __last, __pred);
+    return __onedpl::__internal::__pattern_partition(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                        __first, __last, __pred);
 }
 
 template <class _ExecutionPolicy, class _BidirectionalIterator, class _UnaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _BidirectionalIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _BidirectionalIterator>
 stable_partition(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last,
                  _UnaryPredicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
-    return __pstl::__internal::__pattern_stable_partition(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
-                                                          __first, __last, __pred);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
+
+    return __onedpl::__internal::__pattern_stable_partition(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                               __first, __last, __pred);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _ForwardIterator1, class _ForwardIterator2,
           class _UnaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator1, _ForwardIterator2>>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      ::std::pair<_ForwardIterator1, _ForwardIterator2>>
 partition_copy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
                _ForwardIterator1 __out_true, _ForwardIterator2 __out_false, _UnaryPredicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __out_true, __out_false);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __out_true, __out_false);
 
-    return __pstl::__internal::__pattern_partition_copy(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                        __last, __out_true, __out_false, __pred);
+    return __onedpl::__internal::__pattern_partition_copy(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                             __first, __last, __out_true, __out_false, __pred);
 }
 
+namespace __internal
+{
+struct __sort_fn
+{
+    template <typename... _Arg>
+    void
+    operator()(_Arg... __args) const
+    {
+        std::sort(__args...);
+    }
+};
+} // namespace __internal
+
 // [alg.sort]
 
 template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    typedef typename iterator_traits<_RandomAccessIterator>::value_type _InputType;
-    return __pstl::__internal::__pattern_sort(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                              __comp, typename std::is_move_constructible<_InputType>::type());
+    __onedpl::__internal::__pattern_sort(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                            __comp, __internal::__sort_fn{});
 }
 
 template <class _ExecutionPolicy, class _RandomAccessIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last)
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator>::value_type _InputType;
-    std::sort(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::less<_InputType>());
+    __onedpl::sort(::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                      __onedpl::__internal::__pstl_less());
 }
 
+namespace __internal
+{
+struct __stable_sort_fn
+{
+    template <typename... _Args>
+    void
+    operator()(_Args... __args) const
+    {
+        std::stable_sort(__args...);
+    }
+};
+} // namespace __internal
+
 // [stable.sort]
 
 template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 stable_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    return __pstl::__internal::__pattern_stable_sort(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                     __last, __comp);
+    __onedpl::__internal::__pattern_sort(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                            __comp, __internal::__stable_sort_fn{});
 }
 
 template <class _ExecutionPolicy, class _RandomAccessIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 stable_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last)
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator>::value_type _InputType;
-    std::stable_sort(__exec, __first, __last, std::less<_InputType>());
+    __onedpl::stable_sort(::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                             __onedpl::__internal::__pstl_less());
+}
+
+// __onedpl::sort_by_key
+
+template <typename _ExecutionPolicy, typename _RandomAccessIterator1, typename _RandomAccessIterator2,
+          typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+sort_by_key(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __keys_first, _RandomAccessIterator1 __keys_last,
+            _RandomAccessIterator2 __values_first, _Compare __comp)
+{
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __keys_first, __values_first);
+
+    __onedpl::__internal::__pattern_sort_by_key(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                   __keys_first, __keys_last, __values_first, __comp,
+                                                   __internal::__sort_fn{});
+}
+
+template <typename _ExecutionPolicy, typename _RandomAccessIterator1, typename _RandomAccessIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+sort_by_key(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __keys_first, _RandomAccessIterator1 __keys_last,
+            _RandomAccessIterator2 __values_first)
+{
+    __onedpl::sort_by_key(::std::forward<_ExecutionPolicy>(__exec), __keys_first, __keys_last, __values_first,
+                             __onedpl::__internal::__pstl_less());
+}
+
+// __onedpl::stable_sort_by_key
+
+template <typename _ExecutionPolicy, typename _RandomAccessIterator1, typename _RandomAccessIterator2,
+          typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+stable_sort_by_key(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __keys_first, _RandomAccessIterator1 __keys_last,
+                   _RandomAccessIterator2 __values_first, _Compare __comp)
+{
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __keys_first, __values_first);
+
+    __onedpl::__internal::__pattern_sort_by_key(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                   __keys_first, __keys_last, __values_first, __comp,
+                                                   __internal::__stable_sort_fn{});
+}
+
+template <typename _ExecutionPolicy, typename _RandomAccessIterator1, typename _RandomAccessIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+stable_sort_by_key(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __keys_first, _RandomAccessIterator1 __keys_last,
+                   _RandomAccessIterator2 __values_first)
+{
+    __onedpl::stable_sort_by_key(::std::forward<_ExecutionPolicy>(__exec), __keys_first, __keys_last, __values_first,
+                                    __onedpl::__internal::__pstl_less());
 }
 
 // [mismatch]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator1, _ForwardIterator2>>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      ::std::pair<_ForwardIterator1, _ForwardIterator2>>
 mismatch(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
          _ForwardIterator2 __last2, _BinaryPredicate __pred)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first1, __first2);
 
-    return __pstl::__internal::__pattern_mismatch(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1,
-                                                  __last1, __first2, __last2, __pred);
+    return __onedpl::__internal::__pattern_mismatch(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                       __first1, __last1, __first2, __last2, __pred);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator1, _ForwardIterator2>>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      ::std::pair<_ForwardIterator1, _ForwardIterator2>>
 mismatch(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
          _BinaryPredicate __pred)
 {
-    return std::mismatch(__exec, __first1, __last1, __first2, std::next(__first2, std::distance(__first1, __last1)),
-                         __pred);
+    return __onedpl::mismatch(::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2,
+                                 __onedpl::__internal::__pstl_next(__first2, ::std::distance(__first1, __last1)),
+                                 __pred);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator1, _ForwardIterator2>>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      ::std::pair<_ForwardIterator1, _ForwardIterator2>>
 mismatch(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
          _ForwardIterator2 __last2)
 {
-    return std::mismatch(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
-                         std::equal_to<>());
+    return __onedpl::mismatch(::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
+                                 __onedpl::__internal::__pstl_equal());
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator1, _ForwardIterator2>>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      ::std::pair<_ForwardIterator1, _ForwardIterator2>>
 mismatch(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
 {
     //TODO: to get rid of "distance"
-    return std::mismatch(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2,
-                         std::next(__first2, std::distance(__first1, __last1)));
+    return __onedpl::mismatch(::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2,
+                                 __onedpl::__internal::__pstl_next(__first2, ::std::distance(__first1, __last1)));
 }
 
 // [alg.equal]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
       _BinaryPredicate __p)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first1, __first2);
 
-    return __pstl::__internal::__pattern_equal(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1,
-                                               __last1, __first2, __p);
+    return __onedpl::__internal::__pattern_equal(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first1,
+                                                    __last1, __first2, __p);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
 {
-    return std::equal(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, std::equal_to<>());
+    return __onedpl::equal(::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2,
+                              __onedpl::__internal::__pstl_equal());
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
       _ForwardIterator2 __last2, _BinaryPredicate __p)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first1, __first2);
 
-    return __pstl::__internal::__pattern_equal(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1,
-                                               __last1, __first2, __last2, __p);
+    return __onedpl::__internal::__pattern_equal(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first1,
+                                                    __last1, __first2, __last2, __p);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 equal(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
       _ForwardIterator2 __last2)
 {
-    return equal(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, std::equal_to<>());
+    return __onedpl::equal(::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
+                              __onedpl::__internal::__pstl_equal());
 }
 
 // [alg.move]
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __d_first);
+    auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __d_first);
 
-    using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
-
-    return __pstl::__internal::__pattern_walk2_brick(
-        __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __d_first,
-        [](_ForwardIterator1 __begin, _ForwardIterator1 __end, _ForwardIterator2 __res)
-        { return __pstl::__internal::__brick_move(__begin, __end, __res, __is_vector{}); });
+    return __onedpl::__internal::__pattern_walk2_brick(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last, __d_first,
+        __onedpl::__internal::__brick_move<decltype(__dispatch_tag)>{});
 }
 
 // [partial.sort]
 
 template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 partial_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __middle,
              _RandomAccessIterator __last, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    __pstl::__internal::__pattern_partial_sort(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                               __middle, __last, __comp);
+    __onedpl::__internal::__pattern_partial_sort(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
+                                                    __middle, __last, __comp);
 }
 
 template <class _ExecutionPolicy, class _RandomAccessIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 partial_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __middle,
              _RandomAccessIterator __last)
 {
-    typedef typename iterator_traits<_RandomAccessIterator>::value_type _InputType;
-    std::partial_sort(__exec, __first, __middle, __last, std::less<_InputType>());
+    __onedpl::partial_sort(::std::forward<_ExecutionPolicy>(__exec), __first, __middle, __last,
+                              __onedpl::__internal::__pstl_less());
 }
 
 // [partial.sort.copy]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _RandomAccessIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
 partial_sort_copy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
                   _RandomAccessIterator __d_first, _RandomAccessIterator __d_last, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __d_first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __d_first);
 
-    return __pstl::__internal::__pattern_partial_sort_copy(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
-                                                           __first, __last, __d_first, __d_last, __comp);
+    return __onedpl::__internal::__pattern_partial_sort_copy(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last, __d_first, __d_last, __comp);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _RandomAccessIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
 partial_sort_copy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
                   _RandomAccessIterator __d_first, _RandomAccessIterator __d_last)
 {
-    return std::partial_sort_copy(std::forward<_ExecutionPolicy>(__exec), __first, __last, __d_first, __d_last,
-                                  std::less<>());
+    return __onedpl::partial_sort_copy(::std::forward<_ExecutionPolicy>(__exec), __first, __last, __d_first,
+                                          __d_last, __onedpl::__internal::__pstl_less());
 }
 
 // [is.sorted]
 template <class _ExecutionPolicy, class _ForwardIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 is_sorted_until(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
-    const _ForwardIterator __res =
-        __pstl::__internal::__pattern_adjacent_find(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                    __last, __pstl::__internal::__reorder_pred<_Compare>(__comp),
-                                                    /*first_semantic*/ false);
-    return __res == __last ? __last : std::next(__res);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
+
+    const _ForwardIterator __res = __onedpl::__internal::__pattern_adjacent_find(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+        __onedpl::__internal::__reorder_pred<_Compare>(__comp), __onedpl::__internal::__first_semantic());
+    return __res == __last ? __last : __onedpl::__internal::__pstl_next(__res);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 is_sorted_until(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
 {
-    typedef typename std::iterator_traits<_ForwardIterator>::value_type _InputType;
-    return is_sorted_until(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::less<_InputType>());
+    return __onedpl::is_sorted_until(::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                        __onedpl::__internal::__pstl_less());
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 is_sorted(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
-    return __pstl::__internal::__pattern_adjacent_find(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                       __last, __pstl::__internal::__reorder_pred<_Compare>(__comp),
-                                                       /*or_semantic*/ true) == __last;
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
+
+    return __onedpl::__internal::__pattern_adjacent_find(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                            __first, __last,
+                                                            __onedpl::__internal::__reorder_pred<_Compare>(__comp),
+                                                            __onedpl::__internal::__or_semantic()) == __last;
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 is_sorted(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
 {
-    typedef typename std::iterator_traits<_ForwardIterator>::value_type _InputType;
-    return std::is_sorted(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::less<_InputType>());
+    return __onedpl::is_sorted(::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                  __onedpl::__internal::__pstl_less());
 }
 
 // [alg.merge]
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
           class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 merge(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
       _ForwardIterator2 __last2, _ForwardIterator __d_first, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2, __d_first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first1, __first2, __d_first);
 
-    return __pstl::__internal::__pattern_merge(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1,
-                                               __last1, __first2, __last2, __d_first, __comp);
+    return __onedpl::__internal::__pattern_merge(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first1,
+                                                    __last1, __first2, __last2, __d_first, __comp);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 merge(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
       _ForwardIterator2 __last2, _ForwardIterator __d_first)
 {
-    return std::merge(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __d_first,
-                      std::less<>());
+    return __onedpl::merge(::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __d_first,
+                              __onedpl::__internal::__pstl_less());
 }
 
 template <class _ExecutionPolicy, class _BidirectionalIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 inplace_merge(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __middle,
               _BidirectionalIterator __last, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    __pstl::__internal::__pattern_inplace_merge(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                __middle, __last, __comp);
+    __onedpl::__internal::__pattern_inplace_merge(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
+                                                     __middle, __last, __comp);
 }
 
 template <class _ExecutionPolicy, class _BidirectionalIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 inplace_merge(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __middle,
               _BidirectionalIterator __last)
 {
-    typedef typename std::iterator_traits<_BidirectionalIterator>::value_type _InputType;
-    std::inplace_merge(__exec, __first, __middle, __last, std::less<_InputType>());
+    __onedpl::inplace_merge(::std::forward<_ExecutionPolicy>(__exec), __first, __middle, __last,
+                               __onedpl::__internal::__pstl_less());
 }
 
 // [includes]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
          _ForwardIterator2 __last2, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first1, __first2);
 
-    return __pstl::__internal::__pattern_includes(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1,
-                                                  __last1, __first2, __last2, __comp);
+    return __onedpl::__internal::__pattern_includes(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                       __first1, __last1, __first2, __last2, __comp);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
          _ForwardIterator2 __last2)
 {
-    return std::includes(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, std::less<>());
+    return __onedpl::includes(::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
+                                 __onedpl::__internal::__pstl_less());
 }
 
 // [set.union]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
           class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 set_union(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
           _ForwardIterator2 __last2, _ForwardIterator __result, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2, __result);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first1, __first2, __result);
 
-    return __pstl::__internal::__pattern_set_union(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1,
-                                                   __last1, __first2, __last2, __result, __comp);
+    return __onedpl::__internal::__pattern_set_union(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                        __first1, __last1, __first2, __last2, __result, __comp);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 set_union(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
           _ForwardIterator2 __last2, _ForwardIterator __result)
 {
-    return std::set_union(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
-                          std::less<>());
+    return __onedpl::set_union(::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
+                                  __result, __onedpl::__internal::__pstl_less());
 }
 
 // [set.intersection]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
           class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 set_intersection(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                  _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2, __result);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first1, __first2, __result);
 
-    return __pstl::__internal::__pattern_set_intersection(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
-                                                          __first1, __last1, __first2, __last2, __result, __comp);
+    return __onedpl::__internal::__pattern_set_intersection(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                               __first1, __last1, __first2, __last2, __result, __comp);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 set_intersection(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                  _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result)
 {
-    return std::set_intersection(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
-                                 std::less<>());
+    return __onedpl::set_intersection(::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
+                                         __result, __onedpl::__internal::__pstl_less());
 }
 
 // [set.difference]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
           class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 set_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2, __result);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first1, __first2, __result);
 
-    return __pstl::__internal::__pattern_set_difference(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
-                                                        __first1, __last1, __first2, __last2, __result, __comp);
+    return __onedpl::__internal::__pattern_set_difference(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                             __first1, __last1, __first2, __last2, __result, __comp);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 set_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result)
 {
-    return std::set_difference(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
-                               std::less<>());
+    return __onedpl::set_difference(::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
+                                       __result, __onedpl::__internal::__pstl_less());
 }
 
 // [set.symmetric.difference]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator,
           class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 set_symmetric_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                          _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result,
                          _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2, __result);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first1, __first2, __result);
 
-    return __pstl::__internal::__pattern_set_symmetric_difference(
-        __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result, __comp);
+    return __onedpl::__internal::__pattern_set_symmetric_difference(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
+        __comp);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 set_symmetric_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                          _ForwardIterator2 __first2, _ForwardIterator2 __last2, _ForwardIterator __result)
 {
-    return std::set_symmetric_difference(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
-                                         __result, std::less<>());
+    return __onedpl::set_symmetric_difference(::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2,
+                                                 __last2, __result, __onedpl::__internal::__pstl_less());
 }
 
 // [is.heap]
 template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
 is_heap_until(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    return __pstl::__internal::__pattern_is_heap_until(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                       __last, __comp);
+    return __onedpl::__internal::__pattern_is_heap_until(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                            __first, __last, __comp);
 }
 
 template <class _ExecutionPolicy, class _RandomAccessIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator>
 is_heap_until(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last)
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator>::value_type _InputType;
-    return std::is_heap_until(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::less<_InputType>());
+    return __onedpl::is_heap_until(::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                      __onedpl::__internal::__pstl_less());
 }
 
 template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 is_heap(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
 {
-    return std::is_heap_until(std::forward<_ExecutionPolicy>(__exec), __first, __last, __comp) == __last;
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
+
+    return __onedpl::__internal::__pattern_is_heap(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
+                                                      __last, __comp);
 }
 
 template <class _ExecutionPolicy, class _RandomAccessIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 is_heap(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last)
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator>::value_type _InputType;
-    return std::is_heap(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::less<_InputType>());
+    return __onedpl::is_heap(::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                __onedpl::__internal::__pstl_less());
 }
 
 // [alg.min.max]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 min_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
-    return __pstl::__internal::__pattern_min_element(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                     __last, __comp);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
+
+    return __onedpl::__internal::__pattern_min_element(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                          __first, __last, __comp);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 min_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
 {
-    typedef typename std::iterator_traits<_ForwardIterator>::value_type _InputType;
-    return std::min_element(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::less<_InputType>());
+    return __onedpl::min_element(::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                    __onedpl::__internal::__pstl_less());
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 max_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
 {
-    return min_element(std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                       __pstl::__internal::__reorder_pred<_Compare>(__comp));
+    return __onedpl::min_element(::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                    __onedpl::__internal::__reorder_pred<_Compare>(__comp));
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 max_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
 {
-    typedef typename std::iterator_traits<_ForwardIterator>::value_type _InputType;
-    return std::min_element(std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                            __pstl::__internal::__reorder_pred<std::less<_InputType>>(std::less<_InputType>()));
+    return __onedpl::min_element(::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                    __onedpl::__internal::__reorder_pred<__onedpl::__internal::__pstl_less>(
+                                        __onedpl::__internal::__pstl_less()));
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator, _ForwardIterator>>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, ::std::pair<_ForwardIterator, _ForwardIterator>>
 minmax_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
-    return __pstl::__internal::__pattern_minmax_element(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                        __last, __comp);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
+
+    return __onedpl::__internal::__pattern_minmax_element(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                             __first, __last, __comp);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, std::pair<_ForwardIterator, _ForwardIterator>>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, ::std::pair<_ForwardIterator, _ForwardIterator>>
 minmax_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
 {
-    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
-    return std::minmax_element(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::less<_ValueType>());
+    return __onedpl::minmax_element(::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                       __onedpl::__internal::__pstl_less());
 }
 
 // [alg.nth.element]
 
 template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 nth_element(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __nth,
             _RandomAccessIterator __last, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    __pstl::__internal::__pattern_nth_element(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __nth,
-                                              __last, __comp);
+    __onedpl::__internal::__pattern_nth_element(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first,
+                                                   __nth, __last, __comp);
 }
 
 template <class _ExecutionPolicy, class _RandomAccessIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 nth_element(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __nth,
             _RandomAccessIterator __last)
 {
-    typedef typename iterator_traits<_RandomAccessIterator>::value_type _InputType;
-    std::nth_element(std::forward<_ExecutionPolicy>(__exec), __first, __nth, __last, std::less<_InputType>());
+    __onedpl::nth_element(::std::forward<_ExecutionPolicy>(__exec), __first, __nth, __last,
+                             __onedpl::__internal::__pstl_less());
 }
 
 // [alg.lex.comparison]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Compare>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 lexicographical_compare(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                         _ForwardIterator2 __first2, _ForwardIterator2 __last2, _Compare __comp)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first1, __first2);
 
-    return __pstl::__internal::__pattern_lexicographical_compare(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
-                                                                 __first1, __last1, __first2, __last2, __comp);
+    return __onedpl::__internal::__pattern_lexicographical_compare(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __comp);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
 lexicographical_compare(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                         _ForwardIterator2 __first2, _ForwardIterator2 __last2)
 {
-    return std::lexicographical_compare(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2,
-                                        std::less<>());
+    return __onedpl::lexicographical_compare(::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2,
+                                                __last2, __onedpl::__internal::__pstl_less());
 }
 
-} // namespace std
+// [shift.left]
 
-#endif /* _PSTL_GLUE_ALGORITHM_IMPL_H */
+template <class _ExecutionPolicy, class _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+shift_left(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
+           typename ::std::iterator_traits<_ForwardIterator>::difference_type __n)
+{
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
+
+    return __onedpl::__internal::__pattern_shift_left(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                         __first, __last, __n);
+}
+
+// [shift.right]
+
+template <class _ExecutionPolicy, class _BidirectionalIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _BidirectionalIterator>
+shift_right(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last,
+            typename ::std::iterator_traits<_BidirectionalIterator>::difference_type __n)
+{
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
+
+    return __onedpl::__internal::__pattern_shift_right(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                          __first, __last, __n);
+}
+
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_GLUE_ALGORITHM_IMPL_H
diff --git a/libstdc++-v3/include/pstl/glue_algorithm_ranges_defs.h b/libstdc++-v3/include/pstl/glue_algorithm_ranges_defs.h
new file mode 100644
index 000000000000..34573df037a6
--- /dev/null
+++ b/libstdc++-v3/include/pstl/glue_algorithm_ranges_defs.h
@@ -0,0 +1,358 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_GLUE_ALGORITHM_RANGES_DEFS_H
+#define _ONEDPL_GLUE_ALGORITHM_RANGES_DEFS_H
+
+#include "../functional"
+#include "execution_defs.h"
+#include "utils_ranges.h"
+
+namespace std::__onedpl
+{
+namespace experimental
+{
+namespace ranges
+{
+
+// [alg.any_of]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Predicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+any_of(_ExecutionPolicy&& __exec, _Range&& __rng, _Predicate __pred);
+
+// [alg.all_of]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Predicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+all_of(_ExecutionPolicy&& __exec, _Range&& __rng, _Predicate __pred);
+
+// [alg.none_of]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Predicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+none_of(_ExecutionPolicy&& __exec, _Range&& __rng, _Predicate __pred);
+
+// [alg.foreach]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Function>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+for_each(_ExecutionPolicy&& __exec, _Range&& __rng, _Function __f);
+
+// [alg.find]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Predicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+find_if(_ExecutionPolicy&& __exec, _Range&& __rng, _Predicate __pred);
+
+template <typename _ExecutionPolicy, typename _Range, typename _Predicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+find_if_not(_ExecutionPolicy&& __exec, _Range&& __rng, _Predicate __pred);
+
+template <typename _ExecutionPolicy, typename _Range, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+find(_ExecutionPolicy&& __exec, _Range&& __rng, const _Tp& __value);
+
+// [alg.find.end]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+find_end(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _BinaryPredicate __pred);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+find_end(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2);
+
+// [alg.find_first_of]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+find_first_of(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _BinaryPredicate __pred);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+find_first_of(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2);
+
+// [alg.adjacent_find]
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+adjacent_find(_ExecutionPolicy&& __exec, _Range&& __rng);
+
+template <typename _ExecutionPolicy, typename _Range, typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+adjacent_find(_ExecutionPolicy&& __exec, _Range&& __rng, _BinaryPredicate __pred);
+
+// [alg.count]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+count(_ExecutionPolicy&& __exec, _Range&& __rng, const _Tp& __value);
+
+template <typename _ExecutionPolicy, typename _Range, typename _Predicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+count_if(_ExecutionPolicy&& __exec, _Range&& __rng, _Predicate __pred);
+
+// [alg.search]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+search(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _BinaryPredicate __pred);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+search(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2);
+
+template <typename _ExecutionPolicy, typename _Range, typename _Size, typename _Tp, typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+search_n(_ExecutionPolicy&& __exec, _Range&& __rng, _Size __count, const _Tp& __value, _BinaryPredicate __pred);
+
+template <typename _ExecutionPolicy, typename _Range, typename _Size, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+search_n(_ExecutionPolicy&& __exec, _Range&& __rng, _Size __count, const _Tp& __value);
+
+// [alg.copy]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+copy(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __result);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Predicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+copy_if(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result, _Predicate __pred);
+
+// [alg.swap]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+swap_ranges(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2);
+
+// [alg.transform]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _UnaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+transform(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result, _UnaryOperation __op);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Range3, typename _BinaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+transform(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _Range3&& __result, _BinaryOperation __op);
+
+// [alg.remove]
+
+template <typename _ExecutionPolicy, typename _Range, typename _UnaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+remove_if(_ExecutionPolicy&& __exec, _Range&& __rng, _UnaryPredicate __pred);
+
+template <typename _ExecutionPolicy, typename _Range, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+remove(_ExecutionPolicy&& __exec, _Range&& __rng, const _Tp& __value);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Predicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+remove_copy_if(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result, _Predicate __pred);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+remove_copy(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result, const _Tp& __value);
+
+// [alg.unique]
+
+template <typename _ExecutionPolicy, typename _Range, typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+unique(_ExecutionPolicy&& __exec, _Range&& __rng, _BinaryPredicate __pred);
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+unique(_ExecutionPolicy&& __exec, _Range&& __rng);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+unique_copy(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result, _BinaryPredicate __pred);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+unique_copy(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result);
+
+// [alg.reverse]
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+reverse(_ExecutionPolicy&& __exec, _Range&& __rng);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+reverse_copy(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+rotate_copy(_ExecutionPolicy&& __exec, _Range1&& __rng, __onedpl::__internal::__difference_t<_Range1> __rotate_value,
+            _Range2&& __result);
+
+// [alg.replace]
+
+template <typename _ExecutionPolicy, typename _Range, typename _UnaryPredicate, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+replace_if(_ExecutionPolicy&& __exec, _Range&& __rng, _UnaryPredicate __pred, const _Tp& __new_value);
+
+template <typename _ExecutionPolicy, typename _Range, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+replace(_ExecutionPolicy&& __exec, _Range&& __rng, const _Tp& __old_value, const _Tp& __new_value);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _UnaryPredicate, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+replace_copy_if(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result, _UnaryPredicate __pred,
+                const _Tp& __new_value);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+replace_copy(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result, const _Tp& __old_value,
+             const _Tp& __new_value);
+
+// [alg.sort]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Compare, typename _Proj = __onedpl::identity>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+sort(_ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp, _Proj __proj = {});
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+sort(_ExecutionPolicy&& __exec, _Range&& __rng);
+
+// [stable.sort]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+stable_sort(_ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp);
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+stable_sort(_ExecutionPolicy&& __exec, _Range&& __rng);
+
+// [is.sorted]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+is_sorted_until(_ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp);
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+is_sorted_until(_ExecutionPolicy&& __exec, _Range&& __rng);
+
+template <typename _ExecutionPolicy, typename _Range, typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+is_sorted(_ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp);
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+is_sorted(_ExecutionPolicy&& __exec, _Range&& __rng);
+
+// [alg.equal]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+equal(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _BinaryPredicate __p);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+equal(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2);
+
+// [alg.move]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+move(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2);
+
+// [alg.merge]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Range3, typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range3>>
+merge(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _Range3&& __rng3, _Compare __comp);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Range3>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range3>>
+merge(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _Range3&& __rng3);
+
+// [alg.min.max]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+min_element(_ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp);
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+min_element(_ExecutionPolicy&& __exec, _Range&& __rng);
+
+template <typename _ExecutionPolicy, typename _Range, typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+max_element(_ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp);
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+max_element(_ExecutionPolicy&& __exec, _Range&& __rng);
+
+template <typename _ExecutionPolicy, typename _Range, typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<
+    _ExecutionPolicy,
+    ::std::pair<__onedpl::__internal::__difference_t<_Range>, __onedpl::__internal::__difference_t<_Range>>>
+minmax_element(_ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp);
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<
+    _ExecutionPolicy,
+    ::std::pair<__onedpl::__internal::__difference_t<_Range>, __onedpl::__internal::__difference_t<_Range>>>
+minmax_element(_ExecutionPolicy&& __exec, _Range&& __rng);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Range3, typename _Range4,
+          typename _BinaryPredicate, typename _BinaryOperator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range3>>
+reduce_by_segment(_ExecutionPolicy&& __exec, _Range1&& __keys, _Range2&& __values, _Range3&& __out_keys,
+                  _Range4&& __out_values, _BinaryPredicate __binary_pred, _BinaryOperator __binary_op);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Range3, typename _Range4,
+          typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range3>>
+reduce_by_segment(_ExecutionPolicy&& __exec, _Range1&& __keys, _Range2&& __values, _Range3&& __out_keys,
+                  _Range4&& __out_values, _BinaryPredicate __binary_pred);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Range3, typename _Range4>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range3>>
+reduce_by_segment(_ExecutionPolicy&& __exec, _Range1&& __keys, _Range2&& __values, _Range3&& __out_keys,
+                  _Range4&& __out_values);
+} // namespace ranges
+} // namespace experimental
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_GLUE_ALGORITHM_RANGES_DEFS_H
diff --git a/libstdc++-v3/include/pstl/glue_algorithm_ranges_impl.h b/libstdc++-v3/include/pstl/glue_algorithm_ranges_impl.h
new file mode 100644
index 000000000000..b6a36c95eeee
--- /dev/null
+++ b/libstdc++-v3/include/pstl/glue_algorithm_ranges_impl.h
@@ -0,0 +1,2091 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_GLUE_ALGORITHM_RANGES_IMPL_H
+#define _ONEDPL_GLUE_ALGORITHM_RANGES_IMPL_H
+
+#include <utility>
+#include "functional_impl.h" // for __onedpl::identity
+#if _ONEDPL_CPP20_RANGES_PRESENT
+#    include <ranges>
+#    include <type_traits>
+#    include <iterator>
+#    include <algorithm> // std::ranges::sort, std::ranges::stable_sort
+#    include <concepts>  // for std::copy_constructible, std::indirectly_unary_invocable, std::indirectly_writable
+#endif
+
+#include "utils_ranges.h" // __difference_t
+
+#include "execution_defs.h"
+#include "oneapi/dpl/pstl/ranges_defs.h"
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+#    include "algorithm_ranges_impl.h"
+#endif
+
+#if _ONEDPL_HETERO_BACKEND
+#    include "hetero/algorithm_ranges_impl_hetero.h"
+#    include "hetero/algorithm_impl_hetero.h" //TODO: for __brick_copy
+#endif
+
+namespace std::__onedpl
+{
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+namespace ranges
+{
+
+// [alg.foreach]
+
+namespace __internal
+{
+
+struct __for_each_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+             std::indirectly_unary_invocable<std::projected<std::ranges::iterator_t<_R>, _Proj>>  _Fun>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> && std::ranges::sized_range<_R>
+
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Fun __f, _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        __onedpl::__internal::__ranges::__pattern_for_each(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __r, __f, __proj);
+
+        return {std::ranges::begin(__r) + std::ranges::size(__r)};
+    }
+}; //__for_each_fn
+}  //__internal
+
+inline constexpr __internal::__for_each_fn for_each;
+
+// [alg.transform]
+
+namespace __internal
+{
+struct __transform_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R,
+             std::ranges::random_access_range _OutRange, std::copy_constructible _F, typename _Proj = std::identity>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> && std::ranges::sized_range<_R>
+        && std::ranges::sized_range<_OutRange> && std::indirectly_writable<std::ranges::iterator_t<_OutRange>,
+                 std::indirect_result_t<_F&, std::projected<std::ranges::iterator_t<_R>, _Proj>>>
+
+    std::ranges::unary_transform_result<std::ranges::borrowed_iterator_t<_R>, std::ranges::borrowed_iterator_t<_OutRange>>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _OutRange&& __out_r, _F __op, _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+
+        using _Size = std::common_type_t<std::ranges::range_size_t<_R>, std::ranges::range_size_t<_OutRange>>;
+        const _Size __size = std::ranges::min((_Size)std::ranges::size(__r), (_Size)std::ranges::size(__out_r));
+
+        __onedpl::__internal::__ranges::__pattern_transform(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
+            std::ranges::take_view(__r, __size), std::ranges::take_view(__out_r, __size), __op, __proj);
+
+        return {std::ranges::begin(__r) + __size, std::ranges::begin(__out_r) +  __size};
+    }
+
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R1, std::ranges::random_access_range _R2,
+             std::ranges::random_access_range _OutRange, std::copy_constructible _F, typename _Proj1 = std::identity,
+             typename _Proj2 = std::identity>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> && (std::ranges::sized_range<_R1>
+        || std::ranges::sized_range<_R2>) && std::ranges::sized_range<_OutRange>
+        && std::indirectly_writable<std::ranges::iterator_t<_OutRange>,
+            std::indirect_result_t<_F&, std::projected<std::ranges::iterator_t<_R1>, _Proj1>,
+            std::projected<std::ranges::iterator_t<_R2>, _Proj2>>>
+
+    std::ranges::binary_transform_result<std::ranges::borrowed_iterator_t<_R1>, std::ranges::borrowed_iterator_t<_R2>,
+        std::ranges::borrowed_iterator_t<_OutRange>>
+    operator()(_ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _F __binary_op,
+               _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+
+        using _Size = std::common_type_t<__onedpl::__internal::__range_size_t<_R1>,
+            __onedpl::__internal::__range_size_t<_R2>, std::ranges::range_size_t<_OutRange>>;
+        _Size __size = std::ranges::size(__out_r);
+        if constexpr(std::ranges::sized_range<_R1>)
+            __size = std::ranges::min(__size, (_Size)std::ranges::size(__r1));
+        if constexpr(std::ranges::sized_range<_R2>)
+            __size = std::ranges::min(__size, (_Size)std::ranges::size(__r2));
+
+        //take_view doesn't make unsized range sized, so subrange is used below
+        __onedpl::__internal::__ranges::__pattern_transform(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
+            std::ranges::subrange(std::ranges::begin(__r1), std::ranges::begin(__r1) + __size),
+            std::ranges::subrange(std::ranges::begin(__r2), std::ranges::begin(__r2) + __size),
+            std::ranges::take_view(__out_r, __size), __binary_op, __proj1, __proj2);
+
+        return {std::ranges::begin(__r1) + __size, std::ranges::begin(__r2) + __size, std::ranges::begin(__out_r) + __size};
+    }
+}; //__transform_fn
+}  //__internal
+
+inline constexpr __internal::__transform_fn transform;
+
+// [alg.find_if]
+
+namespace __internal
+{
+struct __find_if_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+              std::indirect_unary_predicate<std::projected<std::ranges::iterator_t<_R>, _Proj>> _Pred>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R>
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Pred __pred, _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_find_if(__dispatch_tag,
+            std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __pred, __proj);
+    }
+}; //__find_if_fn
+}  //__internal
+
+inline constexpr __internal::__find_if_fn find_if;
+
+// [alg.find_if_not]
+
+namespace __internal
+{
+struct __find_if_not_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+              std::indirect_unary_predicate<std::projected<std::ranges::iterator_t<_R>, _Proj>> _Pred>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R>
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Pred __pred, _Proj __proj = {}) const
+    {
+        return __onedpl::ranges::find_if(std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r),
+            __onedpl::__internal::__not_pred<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy,
+            _Pred>>(__pred), __proj);
+    }
+}; //__find_if_not_fn
+}  //__internal
+
+inline constexpr __internal::__find_if_not_fn find_if_not;
+
+// [alg.find]
+
+namespace __internal
+{
+struct __find_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+              typename _T = __onedpl::projected_value_t<std::ranges::iterator_t<_R>, _Proj>>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R> &&
+                 std::indirect_binary_predicate<std::ranges::equal_to,
+                                                std::projected<std::ranges::iterator_t<_R>, _Proj>, const _T*>
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, const _T& __value, _Proj __proj = {}) const
+    {
+        return __onedpl::ranges::find_if(std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r),
+            __onedpl::__internal::__equal_value<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy,
+            const _T>>(__value), __proj);
+    }
+}; //__find_fn
+}  //__internal
+
+inline constexpr __internal::__find_fn find;
+
+// [alg.find_first_of]
+
+namespace __internal
+{
+struct __find_first_of_fn
+{
+
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R1, std::ranges::random_access_range _R2,
+             typename _Pred = std::ranges::equal_to, typename _Proj1 = std::identity, typename _Proj2 = std::identity>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>>
+        && std::indirectly_comparable<std::ranges::iterator_t<_R1>, std::ranges::iterator_t<_R2>, _Pred, _Proj1, _Proj2>
+        && std::ranges::sized_range<_R1> && std::ranges::sized_range<_R2>
+
+    std::ranges::borrowed_iterator_t<_R1>
+    operator()(_ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _Pred __pred = {}, _Proj1 __proj1 = {},
+               _Proj2 __proj2 = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_find_first_of(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R1>(__r1), std::forward<_R2>(__r2),
+            __pred, __proj1, __proj2);
+    }
+}; //__find_first_of_fn
+}  //__internal
+
+inline constexpr __internal::__find_first_of_fn find_first_of;
+
+// [alg.find_end]
+
+namespace __internal
+{
+struct __find_end_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R1, std::ranges::random_access_range _R2,
+             typename _Pred = std::ranges::equal_to, typename _Proj1 = std::identity, typename _Proj2 = std::identity>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>>
+        && std::indirectly_comparable<std::ranges::iterator_t<_R1>, std::ranges::iterator_t<_R2>, _Pred, _Proj1, _Proj2>
+        && std::ranges::sized_range<_R1> && std::ranges::sized_range<_R2>
+
+    std::ranges::borrowed_subrange_t<_R1>
+    operator()(_ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _Pred __pred = {}, _Proj1 __proj1 = {},
+               _Proj2 __proj2 = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_find_end(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R1>(__r1), std::forward<_R2>(__r2),
+            __pred, __proj1, __proj2);
+    }
+}; //__find_end_fn
+}  //__internal
+
+inline constexpr __internal::__find_end_fn find_end;
+
+// [alg.any_of]
+
+namespace __internal
+{
+struct __any_of_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+             std::indirect_unary_predicate<std::projected<std::ranges::iterator_t<_R>, _Proj>> _Pred>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> && std::ranges::sized_range<_R>
+    bool
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Pred __pred, _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_any_of(__dispatch_tag,
+            std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __pred, __proj);
+    }
+}; //__any_of_fn
+}  //__internal
+
+inline constexpr __internal::__any_of_fn any_of;
+
+// [alg.all_of]
+
+namespace __internal
+{
+struct __all_of_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+             std::indirect_unary_predicate<std::projected<std::ranges::iterator_t<_R>, _Proj>> _Pred>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> && std::ranges::sized_range<_R>
+    bool
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Pred __pred, _Proj __proj = {}) const
+    {
+        return !__onedpl::ranges::any_of(std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r),
+            __onedpl::__internal::__not_pred<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, _Pred>>(__pred),
+            __proj);
+    }
+}; //__all_of_fn
+}  //__internal
+
+inline constexpr __internal::__all_of_fn all_of;
+
+// [alg.none_of]
+
+namespace __internal
+{
+struct __none_of_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+             std::indirect_unary_predicate<std::projected<std::ranges::iterator_t<_R>, _Proj>> _Pred>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> && std::ranges::sized_range<_R>
+    bool
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Pred __pred, _Proj __proj = {}) const
+    {
+        return !__onedpl::ranges::any_of(std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r),
+            __pred, __proj);
+    }
+}; //__none_of_fn
+}  //__internal
+
+inline constexpr __internal::__none_of_fn none_of;
+
+// [alg.adjacent_find]
+
+namespace __internal
+{
+struct __adjacent_find_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+              std::indirect_binary_predicate<std::projected<std::ranges::iterator_t<_R>, _Proj>,
+                                             std::projected<std::ranges::iterator_t<_R>, _Proj>>
+                  _Pred = std::ranges::equal_to>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R>
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Pred __pred = {}, _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_adjacent_find_ranges(__dispatch_tag,
+            std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __pred, __proj);
+    }
+}; //__adjacent_find_fn
+}  //__internal
+
+inline constexpr __internal::__adjacent_find_fn adjacent_find;
+
+// [alg.search]
+
+namespace __internal
+{
+struct __search_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R1, std::ranges::random_access_range _R2,
+              typename _Pred = std::ranges::equal_to, typename _Proj1 = std::identity, typename _Proj2 = std::identity>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R1> && std::ranges::sized_range<_R2> &&
+                 std::indirectly_comparable<std::ranges::iterator_t<_R1>, std::ranges::iterator_t<_R2>, _Pred, _Proj1,
+                                            _Proj2>
+    std::ranges::borrowed_subrange_t<_R1>
+    operator()(_ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _Pred __pred = {}, _Proj1 __proj1 = {},
+               _Proj2 __proj2 = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_search(__dispatch_tag,
+            std::forward<_ExecutionPolicy>(__exec), std::forward<_R1>(__r1), std::forward<_R2>(__r2), __pred, __proj1,
+            __proj2);
+    }
+}; //__search_fn
+}  //__internal
+
+inline constexpr __internal::__search_fn search;
+
+// [alg.search_n]
+
+namespace __internal
+{
+struct __search_n_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Pred = std::ranges::equal_to,
+              typename _Proj = std::identity,
+              typename _T = __onedpl::projected_value_t<std::ranges::iterator_t<_R>, _Proj>>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R> &&
+                 std::indirectly_comparable<std::ranges::iterator_t<_R>, const _T*, _Pred, _Proj>
+    std::ranges::borrowed_subrange_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, std::ranges::range_difference_t<_R> __count, const _T& __value,
+               _Pred __pred = {}, _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_search_n(__dispatch_tag,
+            std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __count, __value, __pred, __proj);
+    }
+}; //__search_n_fn
+}  //__internal
+
+inline constexpr __internal::__search_n_fn search_n;
+
+// [alg.count_if]
+
+namespace __internal
+{
+struct __count_if_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+             std::indirect_unary_predicate<std::projected<std::ranges::iterator_t<_R>, _Proj>> _Pred>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> && std::ranges::sized_range<_R>
+
+    std::ranges::range_difference_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Pred __pred, _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_count_if(__dispatch_tag,
+            std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __pred, __proj);
+    }
+}; //__count_if_fn
+}  //__internal
+
+inline constexpr __internal::__count_if_fn count_if;
+
+// [alg.count]
+
+namespace __internal
+{
+
+struct __count_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+             typename _T = __onedpl::projected_value_t<std::ranges::iterator_t<_R>, _Proj>>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> && std::ranges::sized_range<_R>
+        && std::indirect_binary_predicate<std::ranges::equal_to, std::projected<std::ranges::iterator_t<_R>, _Proj>,
+                                          const _T*>
+    std::ranges::range_difference_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, const _T& __value, _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_count(__dispatch_tag,
+            std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __value, __proj);
+    }
+}; //__count_fn
+}  //__internal
+
+inline constexpr __internal::__count_fn count;
+
+// [alg.equal]
+
+namespace __internal
+{
+struct __equal_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R1, std::ranges::random_access_range _R2,
+             typename _Pred = std::ranges::equal_to, typename _Proj1 = std::identity, typename _Proj2 = std::identity>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>>
+           && (std::ranges::sized_range<_R1> || std::ranges::sized_range<_R2>)
+           && std::indirectly_comparable<std::ranges::iterator_t<_R1>, std::ranges::iterator_t<_R2>, _Pred, _Proj1,
+           _Proj2>
+    bool
+    operator()(_ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _Pred __pred = {}, _Proj1 __proj1 = {},
+               _Proj2 __proj2 = {}) const
+    {
+        if constexpr(!std::ranges::sized_range<_R1> || !std::ranges::sized_range<_R2>)
+            return false;
+        else
+        {
+            const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+            return __onedpl::__internal::__ranges::__pattern_equal(__dispatch_tag,
+                std::forward<_ExecutionPolicy>(__exec), std::forward<_R1>(__r1), std::forward<_R2>(__r2), __pred,
+                __proj1, __proj2);
+        }
+    }
+}; //__equal_fn
+}  //__internal
+
+inline constexpr __internal::__equal_fn equal;
+
+// [alg.is_sorted]
+
+namespace __internal
+{
+struct __is_sorted_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+             std::indirect_strict_weak_order<std::projected<std::ranges::iterator_t<_R>, _Proj>>
+             _Comp = std::ranges::less>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> && std::ranges::sized_range<_R>
+    bool
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Comp __comp = {}, _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_is_sorted(__dispatch_tag,
+            std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __comp, __proj);
+    }
+}; //__is_sorted_fn
+}  //__internal
+
+inline constexpr __internal::__is_sorted_fn is_sorted;
+
+// [alg.stable_sort]
+
+namespace __internal
+{
+struct __stable_sort_fn_pred
+{
+    template <typename... Args>
+    auto
+    operator()(Args&&... __args) const
+    {
+        return std::ranges::stable_sort(std::forward<decltype(__args)>(__args)...);
+    }
+};
+
+struct __stable_sort_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Comp = std::ranges::less,
+              typename _Proj = std::identity>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R> && std::sortable<std::ranges::iterator_t<_R>, _Comp, _Proj>
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Comp __comp = {}, _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_sort_ranges(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __comp, __proj,
+            __internal::__stable_sort_fn_pred{});
+    }
+}; //__stable_sort_fn
+}  //__internal
+
+inline constexpr __internal::__stable_sort_fn stable_sort;
+
+// [alg.sort]
+
+namespace __internal
+{
+struct __sort_fn_pred
+{
+    template <typename... Args>
+    auto
+    operator()(Args&&... __args) const
+    {
+        return std::ranges::sort(std::forward<Args>(__args)...);
+    }
+};
+
+struct __sort_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Comp = std::ranges::less,
+              typename _Proj = std::identity>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R> && std::sortable<std::ranges::iterator_t<_R>, _Comp, _Proj>
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Comp __comp = {}, _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_sort_ranges(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __comp, __proj,
+            __internal::__sort_fn_pred{});
+    }
+}; //__sort_fn
+}  //__internal
+
+inline constexpr __internal::__sort_fn sort;
+
+// [alg.min_element]
+
+namespace __internal
+{
+struct __min_element_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+             std::indirect_strict_weak_order<std::projected<std::ranges::iterator_t<_R>, _Proj>>
+             _Comp = std::ranges::less>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> && std::ranges::sized_range<_R>
+
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Comp __comp = {}, _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_min_element(__dispatch_tag,
+            std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __comp, __proj);
+    }
+}; //__min_element_fn
+}  //__internal
+
+inline constexpr __internal::__min_element_fn min_element;
+
+// [alg.max_element]
+
+namespace __internal
+{
+struct __max_element_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+             std::indirect_strict_weak_order<std::projected<std::ranges::iterator_t<_R>, _Proj>> _Comp = std::ranges::less>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> && std::ranges::sized_range<_R>
+
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Comp __comp = {}, _Proj __proj = {}) const
+    {
+        return __onedpl::ranges::min_element(std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r),
+            __onedpl::__internal::__reorder_pred(__comp), __proj);
+    }
+}; //__max_element_fn
+}  //__internal
+
+inline constexpr __internal::__max_element_fn max_element;
+
+// [alg.minmax_element]
+
+namespace __internal
+{
+struct __minmax_element_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+         std::indirect_strict_weak_order<std::projected<std::ranges::iterator_t<_R>, _Proj>> _Comp = std::ranges::less>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> && std::ranges::sized_range<_R>
+
+    std::ranges::minmax_element_result<std::ranges::borrowed_iterator_t<_R>>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Comp __comp = {}, _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        const auto& [__min, __max] =
+            __onedpl::__internal::__ranges::__pattern_minmax_element(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
+            std::forward<_R>(__r), __comp, __proj);
+
+        return {__min, __max};
+    }
+}; //__minmax_element_fn
+} //__internal
+
+inline constexpr __internal::__minmax_element_fn minmax_element;
+
+// [alg.min]
+
+namespace __internal
+{
+
+struct __min_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+             std::indirect_strict_weak_order<std::projected<std::ranges::iterator_t<_R>, _Proj>> _Comp = std::ranges::less>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> && std::ranges::sized_range<_R>
+             && std::indirectly_copyable_storable<std::ranges::iterator_t<_R>, std::ranges::range_value_t<_R>*>
+
+    std::ranges::range_value_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Comp __comp = {}, _Proj __proj = {}) const
+    {
+        assert(std::ranges::size(__r) > 0);
+
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_min(__dispatch_tag,
+            std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __comp, __proj);
+    }
+
+}; //__min_fn
+} //__internal
+
+inline constexpr __internal::__min_fn min;
+
+// [alg.max]
+
+namespace __internal
+{
+
+struct __max_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+             std::indirect_strict_weak_order<std::projected<std::ranges::iterator_t<_R>, _Proj>> _Comp = std::ranges::less>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> && std::ranges::sized_range<_R>
+             && std::indirectly_copyable_storable<std::ranges::iterator_t<_R>, std::ranges::range_value_t<_R>*>
+
+    std::ranges::range_value_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Comp __comp = {}, _Proj __proj = {}) const
+    {
+        assert(std::ranges::size(__r) > 0);
+
+        return __onedpl::ranges::min(std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r),
+            __onedpl::__internal::__reorder_pred(__comp), __proj);
+    }
+
+}; //__max_fn
+} //__internal
+
+inline constexpr __internal::__max_fn max;
+
+// [alg.minmax]
+
+namespace __internal
+{
+
+struct __minmax_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+             std::indirect_strict_weak_order<std::projected<std::ranges::iterator_t<_R>, _Proj>> _Comp = std::ranges::less>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> && std::ranges::sized_range<_R>
+             && std::indirectly_copyable_storable<std::ranges::iterator_t<_R>, std::ranges::range_value_t<_R>*>
+
+    std::ranges::minmax_result<std::ranges::range_value_t<_R>>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Comp __comp = {}, _Proj __proj = {}) const
+    {
+        assert(std::ranges::size(__r) > 0);
+
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        const auto& [__min, __max] = __onedpl::__internal::__ranges::__pattern_minmax(__dispatch_tag,
+            std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __comp, __proj);
+
+        return {__min, __max};
+    }
+
+}; //__minmax_fn
+} //__internal
+
+inline constexpr __internal::__minmax_fn minmax;
+
+// [alg.copy]
+
+namespace __internal
+{
+struct __copy_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _InRange,
+             std::ranges::random_access_range _OutRange>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>>
+        && std::ranges::sized_range<_InRange> && std::ranges::sized_range<_OutRange>
+        && std::indirectly_copyable<std::ranges::iterator_t<_InRange>, std::ranges::iterator_t<_OutRange>>
+
+    std::ranges::copy_result<std::ranges::borrowed_iterator_t<_InRange>, std::ranges::borrowed_iterator_t<_OutRange>>
+    operator()(_ExecutionPolicy&& __exec, _InRange&& __in_r, _OutRange&& __out_r) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+
+        using _Size = std::common_type_t<std::ranges::range_size_t<_InRange>, std::ranges::range_size_t<_OutRange>>;
+        const _Size __size = std::ranges::min((_Size)std::ranges::size(__in_r), (_Size)std::ranges::size(__out_r));
+
+        __onedpl::__internal::__ranges::__pattern_copy(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
+            std::ranges::take_view(__in_r, __size), std::ranges::take_view(__out_r, __size));
+
+        return {std::ranges::begin(__in_r) + __size, std::ranges::begin(__out_r) +  __size};
+    }
+}; //__copy_fn
+}  //__internal
+
+inline constexpr __internal::__copy_fn copy;
+
+// [alg.copy_if]
+
+namespace __internal
+{
+struct __copy_if_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _InRange,
+              std::ranges::random_access_range _OutRange, typename _Proj = std::identity,
+              std::indirect_unary_predicate<std::projected<std::ranges::iterator_t<_InRange>, _Proj>> _Pred>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_InRange> && std::ranges::sized_range<_OutRange> &&
+                 std::indirectly_copyable<std::ranges::iterator_t<_InRange>, std::ranges::iterator_t<_OutRange>>
+    std::ranges::copy_if_result<std::ranges::borrowed_iterator_t<_InRange>, std::ranges::borrowed_iterator_t<_OutRange>>
+    operator()(_ExecutionPolicy&& __exec, _InRange&& __in_r, _OutRange&& __out_r, _Pred __pred, _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        // No minimum common size is calculated here, because the size of the output range is unknown
+        return __onedpl::__internal::__ranges::__pattern_copy_if_ranges(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
+            std::forward<_InRange>(__in_r), std::forward<_OutRange>(__out_r), __pred, __proj);
+    }
+}; //__copy_if_fn
+}  //__internal
+
+inline constexpr __internal::__copy_if_fn copy_if;
+
+// [alg.merge]
+
+namespace __internal
+{
+struct __merge_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R1, std::ranges::random_access_range _R2,
+              std::ranges::random_access_range _OutRange, typename _Comp = std::ranges::less,
+              typename _Proj1 = std::identity, typename _Proj2 = std::identity>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R1> && std::ranges::sized_range<_R2> &&
+                 std::ranges::sized_range<_OutRange> &&
+                 std::mergeable<std::ranges::iterator_t<_R1>, std::ranges::iterator_t<_R2>,
+                                std::ranges::iterator_t<_OutRange>, _Comp, _Proj1, _Proj2>
+    std::ranges::merge_result<std::ranges::borrowed_iterator_t<_R1>, std::ranges::borrowed_iterator_t<_R2>,
+                              std::ranges::borrowed_iterator_t<_OutRange>>
+    operator()(_ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _Comp __comp = {},
+               _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const
+    {
+        // TODO: develop a strategy to get a common minimum size
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_merge_ranges(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R1>(__r1), std::forward<_R2>(__r2),
+            std::forward<_OutRange>(__out_r), __comp, __proj1, __proj2);
+    }
+}; //__merge_fn
+}  //__internal
+
+inline constexpr __internal::__merge_fn merge;
+
+// [includes]
+namespace __internal
+{
+struct __includes_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R1, std::ranges::random_access_range _R2,
+              typename _Proj1 = std::identity, typename _Proj2 = std::identity,
+              std::indirect_strict_weak_order<std::projected<std::ranges::iterator_t<_R1>, _Proj1>,
+                                              std::projected<std::ranges::iterator_t<_R2>, _Proj2>>
+                  _Comp = std::ranges::less>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R1> && std::ranges::sized_range<_R2>
+
+    bool
+    operator()(_ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _Comp __comp = {}, _Proj1 __proj1 = {},
+               _Proj2 __proj2 = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_includes(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R1>(__r1), std::forward<_R2>(__r2),
+            __comp, __proj1, __proj2);
+    }
+}; //__includes_fn
+} // namespace __internal
+
+inline constexpr __internal::__includes_fn includes;
+
+// [set.union]
+namespace __internal
+{
+struct __set_union_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R1, std::ranges::random_access_range _R2,
+              std::ranges::random_access_range _OutRange, typename _Comp = std::ranges::less,
+              typename _Proj1 = std::identity, typename _Proj2 = std::identity>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R1> && std::ranges::sized_range<_R2> &&
+                 std::ranges::sized_range<_OutRange> &&
+                 std::mergeable<std::ranges::iterator_t<_R1>, std::ranges::iterator_t<_R2>,
+                                std::ranges::iterator_t<_OutRange>, _Comp, _Proj1, _Proj2>
+
+    std::ranges::set_union_result<std::ranges::borrowed_iterator_t<_R1>, std::ranges::borrowed_iterator_t<_R2>,
+                                  std::ranges::borrowed_iterator_t<_OutRange>>
+    operator()(_ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _Comp __comp = {},
+               _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_set_union(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R1>(__r1), std::forward<_R2>(__r2),
+            std::forward<_OutRange>(__out_r), __comp, __proj1, __proj2);
+    }
+}; //__set_union_fn
+} // namespace __internal
+
+inline constexpr __internal::__set_union_fn set_union;
+
+// [set.intersection]
+
+namespace __internal
+{
+struct __set_intersection_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R1, std::ranges::random_access_range _R2,
+              std::ranges::random_access_range _OutRange, typename _Comp = std::ranges::less,
+              typename _Proj1 = std::identity, typename _Proj2 = std::identity>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R1> && std::ranges::sized_range<_R2> &&
+                 std::ranges::sized_range<_OutRange> &&
+                 std::mergeable<std::ranges::iterator_t<_R1>, std::ranges::iterator_t<_R2>,
+                                std::ranges::iterator_t<_OutRange>, _Comp, _Proj1, _Proj2>
+
+    std::ranges::set_intersection_result<std::ranges::borrowed_iterator_t<_R1>, std::ranges::borrowed_iterator_t<_R2>,
+                                         std::ranges::borrowed_iterator_t<_OutRange>>
+    operator()(_ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _Comp __comp = {},
+               _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_set_intersection(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R1>(__r1), std::forward<_R2>(__r2),
+            std::forward<_OutRange>(__out_r), __comp, __proj1, __proj2);
+    }
+}; //__set_intersection_fn
+} // namespace __internal
+
+inline constexpr __internal::__set_intersection_fn set_intersection;
+
+// [set.difference]
+
+namespace __internal
+{
+struct __set_difference_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R1, std::ranges::random_access_range _R2,
+              std::ranges::random_access_range _OutRange, typename _Comp = std::ranges::less,
+              typename _Proj1 = std::identity, typename _Proj2 = std::identity>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R1> && std::ranges::sized_range<_R2> &&
+                 std::ranges::sized_range<_OutRange> &&
+                 std::mergeable<std::ranges::iterator_t<_R1>, std::ranges::iterator_t<_R2>,
+                                std::ranges::iterator_t<_OutRange>, _Comp, _Proj1, _Proj2>
+
+    std::ranges::set_difference_result<std::ranges::borrowed_iterator_t<_R1>,
+                                       std::ranges::borrowed_iterator_t<_OutRange>>
+    operator()(_ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _Comp __comp = {},
+               _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_set_difference(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R1>(__r1), std::forward<_R2>(__r2),
+            std::forward<_OutRange>(__out_r), __comp, __proj1, __proj2);
+    }
+}; //__set_difference_fn
+} // namespace __internal
+
+inline constexpr __internal::__set_difference_fn set_difference;
+
+// [set.symmetric.difference]
+
+namespace __internal
+{
+struct __set_symmetric_difference_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R1, std::ranges::random_access_range _R2,
+              std::ranges::random_access_range _OutRange, typename _Comp = std::ranges::less,
+              typename _Proj1 = std::identity, typename _Proj2 = std::identity>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R1> && std::ranges::sized_range<_R2> &&
+                 std::ranges::sized_range<_OutRange> &&
+                 std::mergeable<std::ranges::iterator_t<_R1>, std::ranges::iterator_t<_R2>,
+                                std::ranges::iterator_t<_OutRange>, _Comp, _Proj1, _Proj2>
+
+    std::ranges::set_symmetric_difference_result<std::ranges::borrowed_iterator_t<_R1>,
+                                                 std::ranges::borrowed_iterator_t<_R2>,
+                                                 std::ranges::borrowed_iterator_t<_OutRange>>
+    operator()(_ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _Comp __comp = {},
+               _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_set_symmetric_difference(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R1>(__r1), std::forward<_R2>(__r2),
+            std::forward<_OutRange>(__out_r), __comp, __proj1, __proj2);
+    }
+}; //__set_symmetric_difference_fn
+} // namespace __internal
+
+inline constexpr __internal::__set_symmetric_difference_fn set_symmetric_difference;
+
+// [alg.fill]
+
+namespace __internal
+{
+
+struct __fill_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _T = std::ranges::range_value_t<_R>>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+             std::ranges::sized_range<_R> && std::indirectly_writable<std::ranges::iterator_t<_R>, const _T&>
+
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, const _T& __value) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_fill(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
+            std::forward<_R>(__r), __value);
+    }
+}; //__fill_fn
+
+} //__internal
+
+inline constexpr __internal::__fill_fn fill;
+
+// [alg.move]
+
+namespace __internal
+{
+
+struct __move_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _InRange, std::ranges::random_access_range _OutRange>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>>
+        && std::ranges::sized_range<_InRange> && std::ranges::sized_range<_OutRange>
+        && std::indirectly_movable<std::ranges::iterator_t<_InRange>, std::ranges::iterator_t<_OutRange>>
+
+    std::ranges::move_result<std::ranges::borrowed_iterator_t<_InRange>, std::ranges::borrowed_iterator_t<_OutRange>>
+    operator()(_ExecutionPolicy&& __exec, _InRange&& __r, _OutRange&& __out_r) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+
+        using _Size = std::common_type_t<std::ranges::range_size_t<_InRange>, std::ranges::range_size_t<_OutRange>>;
+        const _Size __size = std::ranges::min((_Size)std::ranges::size(__r), (_Size)std::ranges::size(__out_r));
+
+        __onedpl::__internal::__ranges::__pattern_move(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
+            std::ranges::take_view(__r, __size), std::ranges::take_view(__out_r, __size));
+
+        return {std::ranges::begin(__r) + __size, std::ranges::begin(__out_r) + __size};
+    }
+}; //__move_fn
+} //__internal
+
+inline constexpr __internal::__move_fn move;
+
+// [alg.swap]
+namespace __internal
+{
+
+struct __swap_ranges_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R1, std::ranges::random_access_range _R2>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R1> && std::ranges::sized_range<_R2> &&
+                 std::indirectly_swappable<std::ranges::iterator_t<_R1>, std::ranges::iterator_t<_R2>>
+
+    std::ranges::swap_ranges_result<std::ranges::borrowed_iterator_t<_R1>, std::ranges::borrowed_iterator_t<_R2>>
+    operator()(_ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2) const
+    {
+        using _Size = std::common_type_t<std::ranges::range_size_t<_R1>, std::ranges::range_size_t<_R2>>;
+        const _Size __size = std::ranges::min((_Size)std::ranges::size(__r1), (_Size)std::ranges::size(__r2));
+
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        __onedpl::__internal::__ranges::__pattern_swap_ranges(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
+                                                                 std::ranges::take_view(__r1, __size),
+                                                                 std::ranges::take_view(__r2, __size));
+
+        return {std::ranges::begin(__r1) + __size, std::ranges::begin(__r2) + __size};
+    }
+
+}; //__swap_ranges_fn
+} // namespace __internal
+
+inline constexpr __internal::__swap_ranges_fn swap_ranges;
+
+// [alg.replace]
+
+namespace __internal
+{
+struct __replace_if_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+              typename _T = std::ranges::range_value_t<_R>,
+              std::indirect_unary_predicate<std::projected<std::ranges::iterator_t<_R>, _Proj>> _Pred>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>>
+             && std::ranges::sized_range<_R> && std::indirectly_writable<std::ranges::iterator_t<_R>, const _T&>
+
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Pred __pred, const _T& __new_value, _Proj __proj = {}) const
+    {
+        return __onedpl::ranges::for_each(
+            std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r),
+            __onedpl::__internal::__replace_functor<
+                __onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _T>,
+                __onedpl::__internal::__unary_op<_Pred, _Proj>>(
+                __new_value, __onedpl::__internal::__unary_op<_Pred, _Proj>{__pred, __proj}));
+    }
+}; //__replace_if_fn
+} //__internal
+
+inline constexpr __internal::__replace_if_fn replace_if;
+
+namespace __internal
+{
+struct __replace_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+              typename _T1 = __onedpl::projected_value_t<std::ranges::iterator_t<_R>, _Proj>,
+              typename _T2 = std::ranges::range_value_t<_R>>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>>
+             && std::ranges::sized_range<_R> && std::indirectly_writable<std::ranges::iterator_t<_R>, const _T2&>
+             && std::indirect_binary_predicate<std::ranges::equal_to,
+                                               std::projected<std::ranges::iterator_t<_R>, _Proj>, const _T1*>
+
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, const _T1& __old_value, const _T2& __new_value,
+               _Proj __proj = {}) const
+    {
+        return __onedpl::ranges::replace_if(
+            std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r),
+            __onedpl::__internal::__equal_value<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _T1>>(
+                __old_value),
+            __new_value, __proj);
+    }
+}; //__replace_fn
+} //__internal
+
+inline constexpr __internal::__replace_fn replace;
+
+// [alg.reverse]
+
+namespace __internal
+{
+struct __reverse_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::permutable<std::ranges::iterator_t<_R>> && std::ranges::sized_range<_R>
+
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+
+        __onedpl::__internal::__ranges::__pattern_reverse(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
+                                                             __r);
+        return std::ranges::begin(__r) + std::ranges::size(__r);
+    }
+
+}; //__reverse_fn
+} // namespace __internal
+
+inline constexpr __internal::__reverse_fn reverse;
+
+// [alg.reverse_copy]
+
+namespace __internal
+{
+struct __reverse_copy_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _InRange,
+              std::ranges::random_access_range _OutRange>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_InRange> && std::ranges::sized_range<_OutRange> &&
+                 std::indirectly_copyable<std::ranges::iterator_t<_InRange>, std::ranges::iterator_t<_OutRange>>
+
+    std::ranges::in_in_out_result<std::ranges::borrowed_iterator_t<_InRange>,
+                                  std::ranges::borrowed_iterator_t<_InRange>,
+                                  std::ranges::borrowed_iterator_t<_OutRange>>
+    operator()(_ExecutionPolicy&& __exec, _InRange&& __in_r, _OutRange&& __out_r) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+
+        using _Size = std::common_type_t<std::ranges::range_size_t<_InRange>, std::ranges::range_size_t<_OutRange>>;
+        const _Size __in_size = std::ranges::size(__in_r);
+        const _Size __out_size = std::ranges::size(__out_r);
+        const _Size __min_size = std::ranges::min(__in_size, __out_size);
+
+        auto __first_in = std::ranges::begin(__in_r);
+        auto __first_out = std::ranges::begin(__out_r);
+
+        auto __last_in = __first_in + __in_size;
+        auto __stop_in = __first_in + (__in_size - __min_size);
+        auto __stop_out = __first_out + __min_size;
+
+        __onedpl::__internal::__ranges::__pattern_reverse_copy(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::ranges::subrange(__stop_in, __last_in),
+            std::ranges::subrange(__first_out, __stop_out));
+
+        return {__last_in, __stop_in, __stop_out};
+    }
+
+}; //__reverse_copy_fn
+} // namespace __internal
+
+inline constexpr __internal::__reverse_copy_fn reverse_copy;
+
+// [alg.is_sorted_until]
+
+namespace __internal
+{
+
+struct __is_sorted_until_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+             std::indirect_strict_weak_order<std::projected<std::ranges::iterator_t<_R>, _Proj>>
+             _Comp = std::ranges::less>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> && std::ranges::sized_range<_R>
+
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Comp __comp = {}, _Proj __proj = {}) const
+    {
+        auto __last = std::ranges::begin(__r) + std::ranges::size(__r);
+
+        auto __it = __onedpl::ranges::adjacent_find(std::forward<_ExecutionPolicy>(__exec), __r,
+                                                       __onedpl::__internal::__reorder_pred<_Comp>(__comp), __proj);
+        return __it == __last ? __last : ++__it;
+    }
+}; //__is_sorted_until_fn
+} //__internal
+
+inline constexpr __internal::__is_sorted_until_fn is_sorted_until;
+
+// [alg.mismatch]
+
+namespace __internal
+{
+
+struct __mismatch_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R1, std::ranges::random_access_range _R2,
+             typename _Pred = std::ranges::equal_to, typename _Proj1 = std::identity, typename _Proj2 = std::identity>
+    requires std::indirectly_comparable<std::ranges::iterator_t<_R1>, std::ranges::iterator_t<_R2>, _Pred, _Proj1, _Proj2>
+        && __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>>
+        && (std::ranges::sized_range<_R1> || std::ranges::sized_range<_R2>)
+
+    std::ranges::mismatch_result<std::ranges::borrowed_iterator_t<_R1>, std::ranges::borrowed_iterator_t<_R2>>
+    operator()(_ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _Pred __pred = {}, _Proj1 __proj1 = {}, _Proj2 __proj2 = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        if constexpr (std::ranges::sized_range<_R1> && std::ranges::sized_range<_R2>)
+        {
+            const auto& [__it_1, __it_2] = __onedpl::__internal::__ranges::__pattern_mismatch(
+                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R1>(__r1),
+                std::forward<_R2>(__r2), __pred, __proj1, __proj2);
+
+            return {__it_1, __it_2};
+        }
+        else if constexpr (!std::ranges::sized_range<_R1>)
+        {
+            auto __sized_range =
+                std::ranges::subrange(std::ranges::begin(__r1), std::ranges::begin(__r1) + std::ranges::size(__r2));
+            const auto& [__it_1, __it_2] = __onedpl::__internal::__ranges::__pattern_mismatch(
+                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __sized_range, std::forward<_R2>(__r2), __pred,
+                __proj1, __proj2);
+
+            return {std::ranges::begin(__r1) + (__it_1 - __sized_range.begin()), __it_2};
+        }
+        else
+        {
+            static_assert(!std::ranges::sized_range<_R2>);
+
+            auto __sized_range =
+                std::ranges::subrange(std::ranges::begin(__r2), std::ranges::begin(__r2) + std::ranges::size(__r1));
+            const auto& [__it_1, __it_2] = __onedpl::__internal::__ranges::__pattern_mismatch(
+                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R1>(__r1), __sized_range, __pred,
+                __proj1, __proj2);
+
+            return {__it_1, std::ranges::begin(__r2) + (__it_2 - __sized_range.begin())};
+        }
+    }
+
+}; //__mismatch_fn
+} //__internal
+
+inline constexpr __internal::__mismatch_fn mismatch;
+
+// [alg.remove_if]
+
+namespace __internal
+{
+
+struct __remove_if_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+         std::indirect_unary_predicate<std::projected<std::ranges::iterator_t<_R>, _Proj>> _Pred>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>>
+        && std::permutable<std::ranges::iterator_t<_R>> && std::ranges::sized_range<_R>
+
+    std::ranges::borrowed_subrange_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Pred __pred, _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_remove_if(__dispatch_tag,
+            std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __pred, __proj);
+    }
+
+}; //__remove_if_fn
+} //__internal
+
+inline constexpr __internal::__remove_if_fn remove_if;
+
+// [alg.remove]
+
+namespace __internal
+{
+
+struct __remove_fn
+{
+    template<typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+             typename _T = __onedpl::projected_value_t<std::ranges::iterator_t<_R>, _Proj>>
+    requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>>
+        && std::permutable<std::ranges::iterator_t<_R>> && std::indirect_binary_predicate<std::ranges::equal_to,
+            std::projected<std::ranges::iterator_t<_R>, _Proj>, const _T*> && std::ranges::sized_range<_R>
+
+    std::ranges::borrowed_subrange_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, const _T& __value, _Proj __proj = {}) const
+    {
+        return __onedpl::ranges::remove_if(std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r),
+            [__value](auto&& __a) { return std::ranges::equal_to{}(__a, __value);}, __proj);
+    }
+
+}; //__remove_fn
+} //__internal
+
+inline constexpr __internal::__remove_fn remove;
+
+// [alg.unique]
+
+namespace __internal
+{
+struct __unique_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _R, typename _Proj = std::identity,
+              std::indirect_equivalence_relation<std::projected<std::ranges::iterator_t<_R>, _Proj>> _Comp =
+                  std::ranges::equal_to>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::permutable<std::ranges::iterator_t<_R>> && std::ranges::sized_range<_R>
+
+    std::ranges::borrowed_subrange_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, _Comp __comp = {}, _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_unique(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __comp, __proj);
+    }
+}; //__unique_fn
+} // namespace __internal
+
+inline constexpr __internal::__unique_fn unique;
+
+namespace __internal
+{
+struct __unique_copy_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _InRange,
+              std::ranges::random_access_range _OutRange, typename _Proj = std::identity,
+              std::indirect_equivalence_relation<std::projected<std::ranges::iterator_t<_InRange>, _Proj>> _Comp =
+                  std::ranges::equal_to>
+        requires __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_InRange> && std::ranges::sized_range<_OutRange> &&
+                 std::indirectly_copyable<std::ranges::iterator_t<_InRange>, std::ranges::iterator_t<_OutRange>>
+
+    std::ranges::unique_copy_result<std::ranges::borrowed_iterator_t<_InRange>,
+                                    std::ranges::borrowed_iterator_t<_OutRange>>
+    operator()(_ExecutionPolicy&& __exec, _InRange&& __in_r, _OutRange&& __out_r, _Comp __comp = {},
+               _Proj __proj = {}) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+        return __onedpl::__internal::__ranges::__pattern_unique_copy(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_InRange>(__in_r),
+            std::forward<_OutRange>(__out_r), __comp, __proj);
+    }
+}; //__unique_fn
+} // namespace __internal
+
+inline constexpr __internal::__unique_copy_fn unique_copy;
+
+} //ranges
+
+#endif //_ONEDPL_CPP20_RANGES_PRESENT
+
+#if _ONEDPL_HETERO_BACKEND
+namespace experimental
+{
+namespace ranges
+{
+
+// [alg.any_of]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Predicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+any_of(_ExecutionPolicy&& __exec, _Range&& __rng, _Predicate __pred)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng);
+
+    return __onedpl::__internal::__ranges::__pattern_any_of(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                               views::all_read(::std::forward<_Range>(__rng)), __pred);
+}
+
+// [alg.all_of]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Predicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+all_of(_ExecutionPolicy&& __exec, _Range&& __rng, _Predicate __pred)
+{
+    return !any_of(
+        ::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng),
+        __onedpl::__internal::__not_pred<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, _Predicate>>(
+            __pred));
+}
+
+// [alg.none_of]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Predicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+none_of(_ExecutionPolicy&& __exec, _Range&& __rng, _Predicate __pred)
+{
+    return !any_of(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng), __pred);
+}
+
+// [alg.foreach]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Function>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+for_each(_ExecutionPolicy&& __exec, _Range&& __rng, _Function __f)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng);
+
+    __onedpl::__internal::__ranges::__pattern_walk_n(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __f,
+                                                        views::all(::std::forward<_Range>(__rng)));
+}
+
+// [alg.find]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Predicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+find_if(_ExecutionPolicy&& __exec, _Range&& __rng, _Predicate __pred)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng);
+
+    return __onedpl::__internal::__ranges::__pattern_find_if(__dispatch_tag,
+                                                                ::std::forward<_ExecutionPolicy>(__exec),
+                                                                views::all_read(::std::forward<_Range>(__rng)), __pred);
+}
+
+template <typename _ExecutionPolicy, typename _Range, typename _Predicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+find_if_not(_ExecutionPolicy&& __exec, _Range&& __rng, _Predicate __pred)
+{
+    return find_if(
+        ::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng),
+        __onedpl::__internal::__not_pred<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, _Predicate>>(
+            __pred));
+}
+
+template <typename _ExecutionPolicy, typename _Range, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+find(_ExecutionPolicy&& __exec, _Range&& __rng, const _Tp& __value)
+{
+    return find_if(
+        ::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng),
+        __onedpl::__internal::__equal_value<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _Tp>>(
+            __value));
+}
+
+// [alg.find.end]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+find_end(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _BinaryPredicate __pred)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng1, __rng2);
+
+    return __onedpl::__internal::__ranges::__pattern_find_end(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), views::all_read(::std::forward<_Range1>(__rng1)),
+        views::all_read(::std::forward<_Range2>(__rng2)), __pred);
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+find_end(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2)
+{
+    return find_end(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range1>(__rng1),
+                    ::std::forward<_Range2>(__rng2), __onedpl::__internal::__pstl_equal());
+}
+
+// [alg.find_first_of]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+find_first_of(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _BinaryPredicate __pred)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng1, __rng2);
+
+    return __onedpl::__internal::__ranges::__pattern_find_first_of(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), views::all_read(::std::forward<_Range1>(__rng1)),
+        views::all_read(::std::forward<_Range2>(__rng2)), __pred);
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+find_first_of(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2)
+{
+    return find_first_of(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range1>(__rng1),
+                         ::std::forward<_Range2>(__rng2), __onedpl::__internal::__pstl_equal());
+}
+
+// [alg.adjacent_find]
+
+template <typename _ExecutionPolicy, typename _Range, typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+adjacent_find(_ExecutionPolicy&& __exec, _Range&& __rng, _BinaryPredicate __pred)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng);
+
+    return __onedpl::__internal::__ranges::__pattern_adjacent_find(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), views::all_read(::std::forward<_Range>(__rng)),
+        __pred, __onedpl::__internal::__first_semantic());
+}
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+adjacent_find(_ExecutionPolicy&& __exec, _Range&& __rng)
+{
+    using _ValueType = __onedpl::__internal::__value_t<_Range>;
+    return adjacent_find(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng),
+                         ::std::equal_to<_ValueType>());
+}
+
+// [alg.count]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Predicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+count_if(_ExecutionPolicy&& __exec, _Range&& __rng, _Predicate __pred)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng);
+
+    return __onedpl::__internal::__ranges::__pattern_count(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                              views::all_read(::std::forward<_Range>(__rng)), __pred);
+}
+
+template <typename _ExecutionPolicy, typename _Range, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+count(_ExecutionPolicy&& __exec, _Range&& __rng, const _Tp& __value)
+{
+    return count_if(
+        ::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng),
+        __onedpl::__internal::__equal_value<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _Tp>>(
+            __value));
+}
+
+// [alg.search]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+search(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _BinaryPredicate __pred)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng1, __rng2);
+
+    return __onedpl::__internal::__ranges::__pattern_search(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), views::all_read(::std::forward<_Range1>(__rng1)),
+        views::all_read(::std::forward<_Range2>(__rng2)), __pred);
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+search(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2)
+{
+    return search(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range1>(__rng1),
+                  ::std::forward<_Range2>(__rng2), __onedpl::__internal::__pstl_equal());
+}
+
+template <typename _ExecutionPolicy, typename _Range, typename _Size, typename _Tp, typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+search_n(_ExecutionPolicy&& __exec, _Range&& __rng, _Size __count, const _Tp& __value, _BinaryPredicate __pred)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng);
+
+    return __onedpl::__internal::__ranges::__pattern_search_n(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), views::all_read(::std::forward<_Range>(__rng)),
+        __count, __value, __pred);
+}
+
+template <typename _ExecutionPolicy, typename _Range, typename _Size, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+search_n(_ExecutionPolicy&& __exec, _Range&& __rng, _Size __count, const _Tp& __value)
+{
+    return search_n(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng), __count, __value,
+                    __onedpl::__internal::__pstl_equal());
+}
+
+// [alg.copy]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+copy(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result)
+{
+    auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng, __result);
+
+    __onedpl::__internal::__ranges::__pattern_walk_n(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+        __onedpl::__internal::__brick_copy<decltype(__dispatch_tag)>{},
+        views::all_read(::std::forward<_Range1>(__rng)), views::all_write(::std::forward<_Range2>(__result)));
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Predicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+copy_if(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result, _Predicate __pred)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng, __result);
+
+    return __onedpl::__internal::__ranges::__pattern_copy_if(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), views::all_read(::std::forward<_Range1>(__rng)),
+        views::all_write(::std::forward<_Range2>(__result)), __pred);
+}
+
+// [alg.swap]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+swap_ranges(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng1, __rng2);
+
+    return __onedpl::__internal::__ranges::__pattern_swap(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
+                                                             views::all(std::forward<_Range1>(__rng1)),
+                                                             views::all(std::forward<_Range2>(__rng2)));
+}
+
+namespace __internal
+{
+template <typename _UnaryOperation>
+struct __transform_fn
+{
+    _UnaryOperation __op;
+
+    // TODO investigate why we can't use __onedpl::__internal::__transform_functor
+    // instead this predicate
+    template <typename _TArg, typename _TRes>
+    void
+    operator()(_TArg x, _TRes& z) const
+    {
+        z = __op(x);
+    }
+};
+} // namespace __internal
+
+// [alg.transform]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _UnaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+transform(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result, _UnaryOperation __op)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng, __result);
+
+    __onedpl::__internal::__ranges::__pattern_walk_n(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __internal::__transform_fn<_UnaryOperation>{__op},
+        views::all_read(::std::forward<_Range1>(__rng)), views::all_write(::std::forward<_Range2>(__result)));
+}
+
+namespace __internal
+{
+template <typename _BinaryOperation>
+struct __transform_fn2
+{
+    _BinaryOperation __op;
+
+    // TODO investigate why we can't use __onedpl::__internal::__transform_functor
+    // instead this predicate
+    template <typename _TArg1, typename _TArg2, typename _TRes>
+    void
+    operator()(_TArg1 x, _TArg2 y, _TRes& z) const
+    {
+        z = __op(x, y);
+    }
+};
+} // namespace __internal
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Range3, typename _BinaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+transform(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _Range3&& __result, _BinaryOperation __op)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng1, __rng2, __result);
+
+    __onedpl::__internal::__ranges::__pattern_walk_n(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __internal::__transform_fn2<_BinaryOperation>{__op},
+        views::all_read(::std::forward<_Range1>(__rng1)), views::all_read(::std::forward<_Range2>(__rng2)),
+        views::all_write(::std::forward<_Range3>(__result)));
+}
+
+// [alg.remove]
+
+template <typename _ExecutionPolicy, typename _Range, typename _UnaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+remove_if(_ExecutionPolicy&& __exec, _Range&& __rng, _UnaryPredicate __pred)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng);
+
+    return __onedpl::__internal::__ranges::__pattern_remove_if(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), views::all(::std::forward<_Range>(__rng)), __pred);
+}
+
+template <typename _ExecutionPolicy, typename _Range, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+remove(_ExecutionPolicy&& __exec, _Range&& __rng, const _Tp& __value)
+{
+    return remove_if(
+        ::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng),
+        __onedpl::__internal::__equal_value<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _Tp>>(
+            __value));
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Predicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+remove_copy_if(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result, _Predicate __pred)
+{
+    return copy_if(
+        ::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range1>(__rng), ::std::forward<_Range2>(__result),
+        __onedpl::__internal::__not_pred<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, _Predicate>>(
+            __pred));
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+remove_copy(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result, const _Tp& __value)
+{
+    return copy_if(
+        ::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range1>(__rng), ::std::forward<_Range2>(__result),
+        __onedpl::__internal::__not_equal_value<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _Tp>>(
+            __value));
+}
+
+// [alg.unique]
+
+template <typename _ExecutionPolicy, typename _Range, typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+unique(_ExecutionPolicy&& __exec, _Range&& __rng, _BinaryPredicate __pred)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng);
+
+    return __onedpl::__internal::__ranges::__pattern_unique(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                               views::all(::std::forward<_Range>(__rng)), __pred);
+}
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+unique(_ExecutionPolicy&& __exec, _Range&& __rng)
+{
+    return unique(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng),
+                  __onedpl::__internal::__pstl_equal());
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+unique_copy(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result, _BinaryPredicate __pred)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng, __result);
+
+    return __onedpl::__internal::__ranges::__pattern_unique_copy(
+        __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), views::all_read(std::forward<_Range1>(__rng)),
+        views::all_write(std::forward<_Range2>(__result)), __pred);
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+unique_copy(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result)
+{
+    return unique_copy(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range1>(__rng),
+                       ::std::forward<_Range2>(__result), __onedpl::__internal::__pstl_equal());
+}
+
+// [alg.reverse]
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+reverse(_ExecutionPolicy&& __exec, _Range&& __rng)
+{
+    auto __v = views::all(::std::forward<_Range>(__rng));
+    auto __n = __v.size();
+    auto __n_2 = __n / 2;
+
+    auto __r1 = __v | views::take(__n_2);
+    auto __r2 = __v | views::reverse | views::take(__n_2);
+    swap_ranges(::std::forward<_ExecutionPolicy>(__exec), __r1, __r2);
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+reverse_copy(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result)
+{
+    auto __src = views::all_read(::std::forward<_Range1>(__rng));
+    copy(::std::forward<_ExecutionPolicy>(__exec), __src | views::reverse, ::std::forward<_Range2>(__result));
+    return __src.size();
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+rotate_copy(_ExecutionPolicy&& __exec, _Range1&& __rng, __onedpl::__internal::__difference_t<_Range1> __rotate_value,
+            _Range2&& __result)
+{
+    auto __src = views::all_read(::std::forward<_Range1>(__rng));
+    copy(::std::forward<_ExecutionPolicy>(__exec), __src | views::rotate(__rotate_value),
+         ::std::forward<_Range2>(__result));
+    return __src.size();
+}
+
+// [alg.replace]
+
+template <typename _ExecutionPolicy, typename _Range, typename _UnaryPredicate, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+replace_if(_ExecutionPolicy&& __exec, _Range&& __rng, _UnaryPredicate __pred, const _Tp& __new_value)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng);
+
+    __onedpl::__internal::__ranges::__pattern_walk_n(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+        __onedpl::__internal::__replace_functor<
+            __onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _Tp>,
+            __onedpl::__internal::__ref_or_copy<_ExecutionPolicy, _UnaryPredicate>>(__new_value, __pred),
+        views::all(::std::forward<_Range>(__rng)));
+}
+
+template <typename _ExecutionPolicy, typename _Range, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+replace(_ExecutionPolicy&& __exec, _Range&& __rng, const _Tp& __old_value, const _Tp& __new_value)
+{
+    replace_if(
+        ::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng),
+        __onedpl::__internal::__equal_value<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _Tp>>(
+            __old_value),
+        __new_value);
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _UnaryPredicate, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+replace_copy_if(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result, _UnaryPredicate __pred,
+                const _Tp& __new_value)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng, __result);
+
+    auto __src = views::all_read(::std::forward<_Range1>(__rng));
+    __onedpl::__internal::__ranges::__pattern_walk_n(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+        __onedpl::__internal::__replace_copy_functor<
+            __onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _Tp>,
+            ::std::conditional_t<__onedpl::__internal::__is_const_callable_object_v<_UnaryPredicate>,
+                                 _UnaryPredicate,
+                                 __onedpl::__internal::__ref_or_copy<_ExecutionPolicy, _UnaryPredicate>>>(
+            __new_value, __pred),
+        __src, views::all_write(::std::forward<_Range2>(__result)));
+    return __src.size();
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range1>>
+replace_copy(_ExecutionPolicy&& __exec, _Range1&& __rng, _Range2&& __result, const _Tp& __old_value,
+             const _Tp& __new_value)
+{
+    return replace_copy_if(
+        ::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range1>(__rng), ::std::forward<_Range2>(__result),
+        __onedpl::__internal::__equal_value<__onedpl::__internal::__ref_or_copy<_ExecutionPolicy, const _Tp>>(
+            __old_value),
+        __new_value);
+}
+
+// [alg.sort]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Compare, typename _Proj>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+sort(_ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp, _Proj __proj)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng);
+
+    __onedpl::__internal::__ranges::__pattern_stable_sort(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                             views::all(::std::forward<_Range>(__rng)), __comp, __proj);
+}
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+sort(_ExecutionPolicy&& __exec, _Range&& __rng)
+{
+    sort(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng),
+         __onedpl::__internal::__pstl_less());
+}
+
+// [stable.sort]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+stable_sort(_ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng);
+    __onedpl::__internal::__ranges::__pattern_stable_sort(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
+                                                             views::all(std::forward<_Range>(__rng)), __comp,
+                                                             __onedpl::identity{});
+}
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+stable_sort(_ExecutionPolicy&& __exec, _Range&& __rng)
+{
+    stable_sort(std::forward<_ExecutionPolicy>(__exec), std::forward<_Range>(__rng),
+         __onedpl::__internal::__pstl_less());
+}
+
+// [is.sorted]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+is_sorted_until(_ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng);
+
+    auto __view = views::all_read(::std::forward<_Range>(__rng));
+    const auto __res = __onedpl::__internal::__ranges::__pattern_adjacent_find(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __view,
+        __onedpl::__internal::__reorder_pred<_Compare>(__comp), __onedpl::__internal::__first_semantic());
+
+    return __res == __view.size() ? __res : __res + 1;
+}
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+is_sorted_until(_ExecutionPolicy&& __exec, _Range&& __rng)
+{
+    return is_sorted_until(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng),
+                           __onedpl::__internal::__pstl_less());
+}
+
+template <typename _ExecutionPolicy, typename _Range, typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+is_sorted(_ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng);
+
+    auto __view = views::all_read(::std::forward<_Range>(__rng));
+    return __onedpl::__internal::__ranges::__pattern_adjacent_find(
+               __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __view,
+               __onedpl::__internal::__reorder_pred<_Compare>(__comp),
+               __onedpl::__internal::__or_semantic()) == __view.size();
+}
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+is_sorted(_ExecutionPolicy&& __exec, _Range&& __rng)
+{
+    return is_sorted(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng),
+                     __onedpl::__internal::__pstl_less());
+}
+
+// [alg.equal]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+equal(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _BinaryPredicate __p)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng1, __rng2);
+
+    return __onedpl::__internal::__ranges::__pattern_equal(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                              views::all_read(::std::forward<_Range1>(__rng1)),
+                                                              views::all_read(::std::forward<_Range2>(__rng2)), __p);
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool>
+equal(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2)
+{
+    return equal(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range1>(__rng1),
+                 ::std::forward<_Range2>(__rng2), __onedpl::__internal::__pstl_equal());
+}
+
+// [alg.move]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
+move(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2)
+{
+    auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng1, __rng2);
+
+    __onedpl::__internal::__ranges::__pattern_walk_n(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+        __onedpl::__internal::__brick_move<decltype(__dispatch_tag)>{},
+        views::all_read(::std::forward<_Range1>(__rng1)), views::all_write(::std::forward<_Range2>(__rng2)));
+}
+
+// [alg.merge]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Range3, typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range3>>
+merge(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _Range3&& __rng3, _Compare __comp)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng1, __rng2, __rng3);
+
+    auto __view_res = views::all_write(::std::forward<_Range3>(__rng3));
+    __onedpl::__internal::__ranges::__pattern_merge(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
+                                                       views::all_read(std::forward<_Range1>(__rng1)),
+                                                       views::all_read(std::forward<_Range2>(__rng2)), __view_res,
+                                                       __comp, __onedpl::identity{}, __onedpl::identity{});
+
+    return __view_res.size();
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Range3>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range3>>
+merge(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _Range3&& __rng3)
+{
+    return merge(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range1>(__rng1),
+                 ::std::forward<_Range2>(__rng2), ::std::forward<_Range3>(__rng3),
+                 __onedpl::__internal::__pstl_less());
+}
+
+// [alg.min.max]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+min_element(_ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng);
+
+    return __onedpl::__internal::__ranges::__pattern_min_element(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), views::all_read(::std::forward<_Range>(__rng)),
+        __comp);
+}
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+min_element(_ExecutionPolicy&& __exec, _Range&& __rng)
+{
+    return min_element(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng),
+                       __onedpl::__internal::__pstl_less());
+}
+
+template <typename _ExecutionPolicy, typename _Range, typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+max_element(_ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp)
+{
+    return min_element(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng),
+                       __onedpl::__internal::__reorder_pred<_Compare>(__comp));
+}
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__difference_t<_Range>>
+max_element(_ExecutionPolicy&& __exec, _Range&& __rng)
+{
+    return min_element(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng),
+                       __onedpl::__internal::__reorder_pred<__onedpl::__internal::__pstl_less>(
+                           __onedpl::__internal::__pstl_less()));
+}
+
+template <typename _ExecutionPolicy, typename _Range, typename _Compare>
+__onedpl::__internal::__enable_if_execution_policy<
+    _ExecutionPolicy,
+    ::std::pair<__onedpl::__internal::__difference_t<_Range>, __onedpl::__internal::__difference_t<_Range>>>
+minmax_element(_ExecutionPolicy&& __exec, _Range&& __rng, _Compare __comp)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng);
+
+    return __onedpl::__internal::__ranges::__pattern_minmax_element(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), views::all_read(::std::forward<_Range>(__rng)),
+        __comp);
+}
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<
+    _ExecutionPolicy,
+    ::std::pair<__onedpl::__internal::__difference_t<_Range>, __onedpl::__internal::__difference_t<_Range>>>
+minmax_element(_ExecutionPolicy&& __exec, _Range&& __rng)
+{
+    return minmax_element(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range>(__rng),
+                          __onedpl::__internal::__pstl_less());
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Range3, typename _Range4,
+          typename _BinaryPredicate, typename _BinaryOperator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range3>>
+reduce_by_segment(_ExecutionPolicy&& __exec, _Range1&& __keys, _Range2&& __values, _Range3&& __out_keys,
+                  _Range4&& __out_values, _BinaryPredicate __binary_pred, _BinaryOperator __binary_op)
+{
+    const auto __dispatch_tag =
+        __onedpl::__ranges::__select_backend(__exec, __keys, __values, __out_keys, __out_values);
+
+    return __onedpl::__internal::__ranges::__pattern_reduce_by_segment(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), views::all_read(::std::forward<_Range1>(__keys)),
+        views::all_read(::std::forward<_Range2>(__values)), views::all_write(::std::forward<_Range3>(__out_keys)),
+        views::all_write(::std::forward<_Range4>(__out_values)), __binary_pred, __binary_op);
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Range3, typename _Range4,
+          typename _BinaryPredicate>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range3>>
+reduce_by_segment(_ExecutionPolicy&& __exec, _Range1&& __keys, _Range2&& __values, _Range3&& __out_keys,
+                  _Range4&& __out_values, _BinaryPredicate __binary_pred)
+{
+    return reduce_by_segment(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range1>(__keys),
+                             ::std::forward<_Range2>(__values), ::std::forward<_Range3>(__out_keys),
+                             ::std::forward<_Range4>(__out_values), __binary_pred,
+                             __onedpl::__internal::__pstl_plus());
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Range3, typename _Range4>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range3>>
+reduce_by_segment(_ExecutionPolicy&& __exec, _Range1&& __keys, _Range2&& __values, _Range3&& __out_keys,
+                  _Range4&& __out_values)
+{
+    return reduce_by_segment(::std::forward<_ExecutionPolicy>(__exec), ::std::forward<_Range1>(__keys),
+                             ::std::forward<_Range2>(__values), ::std::forward<_Range3>(__out_keys),
+                             ::std::forward<_Range4>(__out_values), __onedpl::__internal::__pstl_equal());
+}
+
+} // namespace ranges
+} // namespace experimental
+
+#endif //_ONEDPL_HETERO_BACKEND
+
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_GLUE_ALGORITHM_RANGES_IMPL_H
diff --git a/libstdc++-v3/include/pstl/glue_execution_defs.h b/libstdc++-v3/include/pstl/glue_execution_defs.h
index e7b36c7dd10e..d5a73ba00993 100644
--- a/libstdc++-v3/include/pstl/glue_execution_defs.h
+++ b/libstdc++-v3/include/pstl/glue_execution_defs.h
@@ -1,54 +1,63 @@
 // -*- C++ -*-
-//===-- glue_execution_defs.h ---------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_GLUE_EXECUTION_DEFS_H
-#define _PSTL_GLUE_EXECUTION_DEFS_H
+#ifndef _ONEDPL_GLUE_EXECUTION_DEFS_H
+#define _ONEDPL_GLUE_EXECUTION_DEFS_H
 
 #include <type_traits>
 
 #include "execution_defs.h"
 
+#if !_ONEDPL_CPP17_EXECUTION_POLICIES_PRESENT
 namespace std
 {
 // Type trait
-using __pstl::execution::is_execution_policy;
-#if defined(_PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT)
-#    if defined(__INTEL_COMPILER)
-template <class _Tp>
-constexpr bool is_execution_policy_v = is_execution_policy<_Tp>::value;
+using __onedpl::execution::is_execution_policy;
+#    if __INTEL_COMPILER
+template <class T>
+inline constexpr bool is_execution_policy_v = is_execution_policy<T>::value;
 #    else
-using __pstl::execution::is_execution_policy_v;
+using __onedpl::is_execution_policy_v;
 #    endif
-#endif
 
 namespace execution
 {
 // Standard C++ policy classes
-using __pstl::execution::parallel_policy;
-using __pstl::execution::parallel_unsequenced_policy;
-using __pstl::execution::sequenced_policy;
-
+using __onedpl::execution::parallel_policy;
+using __onedpl::execution::parallel_unsequenced_policy;
+using __onedpl::execution::sequenced_policy;
 // Standard predefined policy instances
-using __pstl::execution::par;
-using __pstl::execution::par_unseq;
-using __pstl::execution::seq;
-
+using __onedpl::execution::par;
+using __onedpl::execution::par_unseq;
+using __onedpl::execution::seq;
 // Implementation-defined names
 // Unsequenced policy is not yet standard, but for consistency
 // we include it into namespace std::execution as well
-using __pstl::execution::unseq;
-using __pstl::execution::unsequenced_policy;
+using __onedpl::execution::unseq;
+using __onedpl::execution::unsequenced_policy;
 } // namespace execution
 } // namespace std
+#endif // !_ONEDPL_CPP17_EXECUTION_POLICIES_PRESENT
+
+#if _ONEDPL_BACKEND_SYCL
+#    include "hetero/algorithm_impl_hetero.h"
+#    include "hetero/numeric_impl_hetero.h"
+#endif
 
 #include "algorithm_impl.h"
 #include "numeric_impl.h"
 #include "parallel_backend.h"
 
-#endif /* _PSTL_GLUE_EXECUTION_DEFS_H */
+#endif // _ONEDPL_GLUE_EXECUTION_DEFS_H
diff --git a/libstdc++-v3/include/pstl/glue_memory_defs.h b/libstdc++-v3/include/pstl/glue_memory_defs.h
index 2eb4e5dca6b5..d5e0506f8d15 100644
--- a/libstdc++-v3/include/pstl/glue_memory_defs.h
+++ b/libstdc++-v3/include/pstl/glue_memory_defs.h
@@ -1,80 +1,87 @@
 // -*- C++ -*-
-//===-- glue_memory_defs.h ------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_GLUE_MEMORY_DEFS_H
-#define _PSTL_GLUE_MEMORY_DEFS_H
+#ifndef _ONEDPL_GLUE_MEMORY_DEFS_H
+#define _ONEDPL_GLUE_MEMORY_DEFS_H
 
-#include <bits/stl_iterator_base_types.h>
 #include "execution_defs.h"
 
-namespace std
+namespace std::__onedpl
 {
 
 // [uninitialized.copy]
 
 template <class _ExecutionPolicy, class _InputIterator, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 uninitialized_copy(_ExecutionPolicy&& __exec, _InputIterator __first, _InputIterator __last, _ForwardIterator __result);
 
 template <class _ExecutionPolicy, class _InputIterator, class _Size, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 uninitialized_copy_n(_ExecutionPolicy&& __exec, _InputIterator __first, _Size __n, _ForwardIterator __result);
 
 // [uninitialized.move]
 
 template <class _ExecutionPolicy, class _InputIterator, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 uninitialized_move(_ExecutionPolicy&& __exec, _InputIterator __first, _InputIterator __last, _ForwardIterator __result);
 
 template <class _ExecutionPolicy, class _InputIterator, class _Size, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 uninitialized_move_n(_ExecutionPolicy&& __exec, _InputIterator __first, _Size __n, _ForwardIterator __result);
 
 // [uninitialized.fill]
 
-template <class _ExecutionPolicy, class _ForwardIterator, class _Tp _GLIBCXX26_ALGO_DEF_VAL_T(_ForwardIterator)>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+template <class _ExecutionPolicy, class _ForwardIterator,
+          class _Tp = typename std::iterator_traits<_ForwardIterator>::value_type>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 uninitialized_fill(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
 
-template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Tp _GLIBCXX26_ALGO_DEF_VAL_T(_ForwardIterator)>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+template <class _ExecutionPolicy, class _ForwardIterator, class _Size,
+          class _Tp = typename std::iterator_traits<_ForwardIterator>::value_type>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 uninitialized_fill_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n, const _Tp& __value);
 
 // [specialized.destroy]
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 destroy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Size>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 destroy_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n);
 
 // [uninitialized.construct.default]
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 uninitialized_default_construct(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Size>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 uninitialized_default_construct_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n);
 
 // [uninitialized.construct.value]
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 uninitialized_value_construct(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Size>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 uninitialized_value_construct_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n);
 
-} //  namespace std
-#endif /* _PSTL_GLUE_MEMORY_DEFS_H */
+} // namespace std::__onedpl
+#endif // _ONEDPL_GLUE_MEMORY_DEFS_H
diff --git a/libstdc++-v3/include/pstl/glue_memory_impl.h b/libstdc++-v3/include/pstl/glue_memory_impl.h
index 0f37fbbf2140..2f13917d5baa 100644
--- a/libstdc++-v3/include/pstl/glue_memory_impl.h
+++ b/libstdc++-v3/include/pstl/glue_memory_impl.h
@@ -1,350 +1,315 @@
 // -*- C++ -*-
-//===-- glue_memory_impl.h ------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_GLUE_MEMORY_IMPL_H
-#define _PSTL_GLUE_MEMORY_IMPL_H
+#ifndef _ONEDPL_GLUE_MEMORY_IMPL_H
+#define _ONEDPL_GLUE_MEMORY_IMPL_H
 
+#include "execution_defs.h"
 #include "utils.h"
+
+#if _ONEDPL_HETERO_BACKEND
+#    include "hetero/algorithm_impl_hetero.h"
+#    include "hetero/memory_impl_hetero.h"
+#endif
+
+#include "memory_fwd.h"
 #include "algorithm_fwd.h"
 
 #include "execution_impl.h"
 
-namespace std
+#include <type_traits>
+
+namespace std::__onedpl
 {
 
 // [uninitialized.copy]
 
 template <class _ExecutionPolicy, class _InputIterator, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 uninitialized_copy(_ExecutionPolicy&& __exec, _InputIterator __first, _InputIterator __last, _ForwardIterator __result)
 {
-    typedef typename iterator_traits<_InputIterator>::value_type _ValueType1;
-    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType2;
-    typedef typename iterator_traits<_InputIterator>::reference _ReferenceType1;
-    typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType2;
+    using _OutValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
+    using _OutRefType = typename std::iterator_traits<_ForwardIterator>::reference;
+    using _InRefType = typename std::iterator_traits<_InputIterator>::reference;
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
+    auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __result);
 
-    using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
-
-    return __pstl::__internal::__invoke_if_else(
-        std::conjunction<std::is_trivially_copyable<_ValueType1>, std::is_trivially_default_constructible<_ValueType1>,
-                         std::is_trivially_copyable<_ValueType2>, std::is_trivially_default_constructible<_ValueType2>>(),
-        [&]()
-        {
-            return __pstl::__internal::__pattern_walk2_brick(
-                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
-                [](_InputIterator __begin, _InputIterator __end, _ForwardIterator __res)
-                { return __pstl::__internal::__brick_copy(__begin, __end, __res, __is_vector{}); });
-        },
-        [&]()
-        {
-            return __pstl::__internal::__pattern_walk2(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                       __last, __result,
-                                                       [](_ReferenceType1 __val1, _ReferenceType2 __val2)
-                                                       { ::new (std::addressof(__val2)) _ValueType2(__val1); });
-        });
+    if constexpr (__onedpl::__internal::__trivial_uninitialized_copy<_OutValueType, _OutRefType, _InRefType>)
+    {
+        return __onedpl::__internal::__pattern_walk2_brick(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
+            __onedpl::__internal::__brick_copy<decltype(__dispatch_tag)>{});
+    }
+    else
+    {
+        return __onedpl::__internal::__pattern_walk2(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
+            __onedpl::__internal::__op_uninitialized_copy<std::decay_t<_ExecutionPolicy>>{});
+    }
 }
 
 template <class _ExecutionPolicy, class _InputIterator, class _Size, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 uninitialized_copy_n(_ExecutionPolicy&& __exec, _InputIterator __first, _Size __n, _ForwardIterator __result)
 {
-    typedef typename iterator_traits<_InputIterator>::value_type _ValueType1;
-    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType2;
-    typedef typename iterator_traits<_InputIterator>::reference _ReferenceType1;
-    typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType2;
+    using _OutValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
+    using _OutRefType = typename std::iterator_traits<_ForwardIterator>::reference;
+    using _InRefType = typename std::iterator_traits<_InputIterator>::reference;
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
+    auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __result);
 
-    using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
-
-    return __pstl::__internal::__invoke_if_else(
-        std::conjunction<std::is_trivially_copyable<_ValueType1>, std::is_trivially_default_constructible<_ValueType1>,
-                         std::is_trivially_copyable<_ValueType2>, std::is_trivially_default_constructible<_ValueType2>>(),
-        [&]()
-        {
-            return __pstl::__internal::__pattern_walk2_brick_n(
-                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
-                [](_InputIterator __begin, _Size __sz, _ForwardIterator __res)
-                { return __pstl::__internal::__brick_copy_n(__begin, __sz, __res, __is_vector{}); });
-        },
-        [&]()
-        {
-            return __pstl::__internal::__pattern_walk2_n(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
-                                                         __first, __n, __result,
-                                                         [](_ReferenceType1 __val1, _ReferenceType2 __val2)
-                                                         { ::new (std::addressof(__val2)) _ValueType2(__val1); });
-        });
+    if constexpr (__onedpl::__internal::__trivial_uninitialized_copy<_OutValueType, _OutRefType, _InRefType>)
+    {
+        return __onedpl::__internal::__pattern_walk2_brick_n(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
+            __onedpl::__internal::__brick_copy_n<decltype(__dispatch_tag)>{});
+    }
+    else
+    {
+        return __onedpl::__internal::__pattern_walk2_n(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
+            __onedpl::__internal::__op_uninitialized_copy<std::decay_t<_ExecutionPolicy>>{});
+    }
 }
 
 // [uninitialized.move]
 
 template <class _ExecutionPolicy, class _InputIterator, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 uninitialized_move(_ExecutionPolicy&& __exec, _InputIterator __first, _InputIterator __last, _ForwardIterator __result)
 {
-    typedef typename iterator_traits<_InputIterator>::value_type _ValueType1;
-    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType2;
-    typedef typename iterator_traits<_InputIterator>::reference _ReferenceType1;
-    typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType2;
+    using _OutValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
+    using _OutRefType = typename std::iterator_traits<_ForwardIterator>::reference;
+    using _InRefType = typename std::iterator_traits<_InputIterator>::reference;
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
+    auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __result);
 
-    using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
-
-    return __pstl::__internal::__invoke_if_else(
-        std::conjunction<std::is_trivially_copyable<_ValueType1>, std::is_trivially_default_constructible<_ValueType1>,
-                         std::is_trivially_copyable<_ValueType2>, std::is_trivially_default_constructible<_ValueType2>>(),
-        [&]()
-        {
-            return __pstl::__internal::__pattern_walk2_brick(
-                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
-                [](_InputIterator __begin, _InputIterator __end, _ForwardIterator __res)
-                { return __pstl::__internal::__brick_copy(__begin, __end, __res, __is_vector{}); });
-        },
-        [&]()
-        {
-            return __pstl::__internal::__pattern_walk2(
-                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
-                [](_ReferenceType1 __val1, _ReferenceType2 __val2)
-                { ::new (std::addressof(__val2)) _ValueType2(std::move(__val1)); });
-        });
+    if constexpr (__onedpl::__internal::__trivial_uninitialized_move<_OutValueType, _OutRefType, _InRefType>)
+    {
+        return __onedpl::__internal::__pattern_walk2_brick(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
+            __onedpl::__internal::__brick_copy<decltype(__dispatch_tag)>{});
+    }
+    else
+    {
+        return __onedpl::__internal::__pattern_walk2(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
+            __onedpl::__internal::__op_uninitialized_move<std::decay_t<_ExecutionPolicy>>{});
+    }
 }
 
 template <class _ExecutionPolicy, class _InputIterator, class _Size, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 uninitialized_move_n(_ExecutionPolicy&& __exec, _InputIterator __first, _Size __n, _ForwardIterator __result)
 {
-    typedef typename iterator_traits<_InputIterator>::value_type _ValueType1;
-    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType2;
-    typedef typename iterator_traits<_InputIterator>::reference _ReferenceType1;
-    typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType2;
+    using _OutValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
+    using _OutRefType = typename std::iterator_traits<_ForwardIterator>::reference;
+    using _InRefType = typename std::iterator_traits<_InputIterator>::reference;
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
+    auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __result);
 
-    using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
-
-    return __pstl::__internal::__invoke_if_else(
-        std::conjunction<std::is_trivially_copyable<_ValueType1>, std::is_trivially_default_constructible<_ValueType1>,
-                         std::is_trivially_copyable<_ValueType2>, std::is_trivially_default_constructible<_ValueType2>>(),
-        [&]()
-        {
-            return __pstl::__internal::__pattern_walk2_brick_n(
-                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
-                [](_InputIterator __begin, _Size __sz, _ForwardIterator __res)
-                { return __pstl::__internal::__brick_copy_n(__begin, __sz, __res, __is_vector{}); });
-        },
-        [&]()
-        {
-            return __pstl::__internal::__pattern_walk2_n(
-                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
-                [](_ReferenceType1 __val1, _ReferenceType2 __val2)
-                { ::new (std::addressof(__val2)) _ValueType2(std::move(__val1)); });
-        });
+    if constexpr (__onedpl::__internal::__trivial_uninitialized_move<_OutValueType, _OutRefType, _InRefType>)
+    {
+        return __onedpl::__internal::__pattern_walk2_brick_n(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
+            __onedpl::__internal::__brick_copy_n<decltype(__dispatch_tag)>{});
+    }
+    else
+    {
+        return __onedpl::__internal::__pattern_walk2_n(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n, __result,
+            __onedpl::__internal::__op_uninitialized_move<std::decay_t<_ExecutionPolicy>>{});
+    }
 }
 
 // [uninitialized.fill]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 uninitialized_fill(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
 {
-    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
-    typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType;
+    using _ValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
-
-    __pstl::__internal::__invoke_if_else(
-        std::is_arithmetic<_ValueType>(),
-        [&]()
-        {
-            __pstl::__internal::__pattern_walk_brick(
-                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                [&__value](_ForwardIterator __begin, _ForwardIterator __end)
-                { __pstl::__internal::__brick_fill(__begin, __end, _ValueType(__value), __is_vector{}); });
-        },
-        [&]()
-        {
-            __pstl::__internal::__pattern_walk1(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                                [&__value](_ReferenceType __val)
-                                                { ::new (std::addressof(__val)) _ValueType(__value); });
-        });
+    if constexpr (__onedpl::__internal::__trivial_uninitialized_fill<_ValueType, _Tp>)
+    {
+        __onedpl::__internal::__pattern_fill(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                                _ValueType(__value));
+    }
+    else
+    {
+        __onedpl::__internal::__pattern_uninitialized_walk1(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
+            __onedpl::__internal::__op_uninitialized_fill<_Tp, std::decay_t<_ExecutionPolicy>>{__value});
+    }
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 uninitialized_fill_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n, const _Tp& __value)
 {
-    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
-    typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType;
+    using _ValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
-
-    return __pstl::__internal::__invoke_if_else(
-        std::is_arithmetic<_ValueType>(),
-        [&]()
-        {
-            return __pstl::__internal::__pattern_walk_brick_n(
-                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n,
-                [&__value](_ForwardIterator __begin, _Size __count)
-                { return __pstl::__internal::__brick_fill_n(__begin, __count, _ValueType(__value), __is_vector{}); });
-        },
-        [&]()
-        {
-            return __pstl::__internal::__pattern_walk1_n(
-                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n,
-                [&__value](_ReferenceType __val) { ::new (std::addressof(__val)) _ValueType(__value); });
-        });
+    if constexpr (__onedpl::__internal::__trivial_uninitialized_fill<_ValueType, _Tp>)
+    {
+        return __onedpl::__internal::__pattern_fill_n(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
+                                                         __first, __n, _ValueType(__value));
+    }
+    else
+    {
+        return __onedpl::__internal::__pattern_uninitialized_walk1_n(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n,
+            __onedpl::__internal::__op_uninitialized_fill<_Tp, std::decay_t<_ExecutionPolicy>>{__value});
+    }
 }
 
 // [specialized.destroy]
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 destroy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
 {
-    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
-    typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType;
+    using _ValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    if constexpr (!std::is_trivially_destructible_v<_ValueType>)
+    {
+        const auto __dispatch_tag =
+#if (_PSTL_ICPX_OMP_SIMD_DESTROY_WINDOWS_BROKEN || _ONEDPL_ICPX_OMP_SIMD_DESTROY_WINDOWS_BROKEN)
+            __onedpl::__internal::__select_backend(__onedpl::__internal::__get_unvectorized_policy(__exec),
+                                                      __first);
+#else
+            __onedpl::__internal::__select_backend(__exec, __first);
+#endif
 
-    __pstl::__internal::__invoke_if_not(std::is_trivially_destructible<_ValueType>(),
-                                        [&]()
-                                        {
-                                            __pstl::__internal::__pattern_walk1(
-                                                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                                [](_ReferenceType __val) { __val.~_ValueType(); });
-                                        });
+        __onedpl::__internal::__pattern_walk1(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
+            __onedpl::__internal::__op_destroy<std::decay_t<_ExecutionPolicy>>{});
+    }
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Size>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 destroy_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n)
 {
-    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
-    typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType;
+    using _ValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    if constexpr (std::is_trivially_destructible_v<_ValueType>)
+    {
+        return __onedpl::__internal::__pstl_next(__first, __n);
+    }
+    else
+    {
+        const auto __dispatch_tag =
+#if (_PSTL_ICPX_OMP_SIMD_DESTROY_WINDOWS_BROKEN || _ONEDPL_ICPX_OMP_SIMD_DESTROY_WINDOWS_BROKEN)
+            __onedpl::__internal::__select_backend(__onedpl::__internal::__get_unvectorized_policy(__exec),
+                                                      __first);
+#else
+            __onedpl::__internal::__select_backend(__exec, __first);
+#endif
 
-    return __pstl::__internal::__invoke_if_else(
-        std::is_trivially_destructible<_ValueType>(), [&]() { return std::next(__first, __n); },
-        [&]()
-        {
-            return __pstl::__internal::__pattern_walk1_n(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
-                                                         __first, __n,
-                                                         [](_ReferenceType __val) { __val.~_ValueType(); });
-        });
+        return __onedpl::__internal::__pattern_walk1_n(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n,
+            __onedpl::__internal::__op_destroy<std::decay_t<_ExecutionPolicy>>{});
+    }
 }
 
 // [uninitialized.construct.default]
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 uninitialized_default_construct(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
 {
-    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
-    typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType;
+    using _ValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    if constexpr (!std::is_trivially_default_constructible_v<_ValueType>)
+    {
+        const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    __pstl::__internal::__invoke_if_not(std::conjunction<std::is_trivially_copyable<_ValueType>, std::is_trivially_default_constructible<_ValueType>>(),
-                                        [&]()
-                                        {
-                                            __pstl::__internal::__pattern_walk1(
-                                                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                                [](_ReferenceType __val) { ::new (std::addressof(__val)) _ValueType; });
-                                        });
+        __onedpl::__internal::__pattern_uninitialized_walk1(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
+            __onedpl::__internal::__op_uninitialized_default_construct<std::decay_t<_ExecutionPolicy>>{});
+    }
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Size>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 uninitialized_default_construct_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n)
 {
-    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
-    typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType;
+    using _ValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    if constexpr (std::is_trivially_default_constructible_v<_ValueType>)
+    {
+        return __onedpl::__internal::__pstl_next(__first, __n);
+    }
+    else
+    {
+        const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    return __pstl::__internal::__invoke_if_else(
-        std::conjunction<std::is_trivially_copyable<_ValueType>, std::is_trivially_default_constructible<_ValueType>>(),
-        [&]() { return std::next(__first, __n); },
-        [&]()
-        {
-            return __pstl::__internal::__pattern_walk1_n(
-                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n,
-                [](_ReferenceType __val) { ::new (std::addressof(__val)) _ValueType; });
-        });
+        return __onedpl::__internal::__pattern_uninitialized_walk1_n(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n,
+            __onedpl::__internal::__op_uninitialized_default_construct<std::decay_t<_ExecutionPolicy>>{});
+    }
 }
 
 // [uninitialized.construct.value]
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy>
 uninitialized_value_construct(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
 {
-    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
-    typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType;
+    using _ValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
-
-    __pstl::__internal::__invoke_if_else(
-        std::conjunction<std::is_trivially_copyable<_ValueType>, std::is_trivially_default_constructible<_ValueType>>(),
-        [&]()
-        {
-            __pstl::__internal::__pattern_walk_brick(
-                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                [](_ForwardIterator __begin, _ForwardIterator __end)
-                { __pstl::__internal::__brick_fill(__begin, __end, _ValueType(), __is_vector{}); });
-        },
-        [&]()
-        {
-            __pstl::__internal::__pattern_walk1(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                                [](_ReferenceType __val)
-                                                { ::new (std::addressof(__val)) _ValueType(); });
-        });
+    if constexpr (__onedpl::__internal::__trivial_uninitialized_value_construct<_ValueType>)
+    {
+        __onedpl::__internal::__pattern_fill(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                                _ValueType());
+    }
+    else
+    {
+        __onedpl::__internal::__pattern_uninitialized_walk1(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
+            __onedpl::__internal::__op_uninitialized_value_construct<std::decay_t<_ExecutionPolicy>>{});
+    }
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Size>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator>
 uninitialized_value_construct_n(_ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n)
 {
-    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
-    typedef typename iterator_traits<_ForwardIterator>::reference _ReferenceType;
+    using _ValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
+    auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
 
-    using __is_vector = typename decltype(__dispatch_tag)::__is_vector;
-
-    return __pstl::__internal::__invoke_if_else(
-        std::conjunction<std::is_trivially_copyable<_ValueType>, std::is_trivially_default_constructible<_ValueType>>(),
-        [&]()
-        {
-            return __pstl::__internal::__pattern_walk_brick_n(
-                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n,
-                [](_ForwardIterator __begin, _Size __count)
-                { return __pstl::__internal::__brick_fill_n(__begin, __count, _ValueType(), __is_vector{}); });
-        },
-        [&]()
-        {
-            return __pstl::__internal::__pattern_walk1_n(
-                __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n,
-                [](_ReferenceType __val) { ::new (std::addressof(__val)) _ValueType(); });
-        });
+    if constexpr (__onedpl::__internal::__trivial_uninitialized_value_construct<_ValueType>)
+    {
+        return __onedpl::__internal::__pattern_fill_n(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
+                                                         __first, __n, _ValueType());
+    }
+    else
+    {
+        return __onedpl::__internal::__pattern_uninitialized_walk1_n(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __n,
+            __onedpl::__internal::__op_uninitialized_value_construct<std::decay_t<_ExecutionPolicy>>{});
+    }
 }
 
-} // namespace std
+} // namespace std::__onedpl
 
-#endif /* _PSTL_GLUE_MEMORY_IMPL_H */
+#endif // _ONEDPL_GLUE_MEMORY_IMPL_H
diff --git a/libstdc++-v3/include/pstl/glue_memory_ranges_impl.h b/libstdc++-v3/include/pstl/glue_memory_ranges_impl.h
new file mode 100644
index 000000000000..dd0c658ecd53
--- /dev/null
+++ b/libstdc++-v3/include/pstl/glue_memory_ranges_impl.h
@@ -0,0 +1,205 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_GLUE_MEMORY_RANGES_IMPL_H
+#define _ONEDPL_GLUE_MEMORY_RANGES_IMPL_H
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+
+#include <utility>
+#include <ranges>
+#include <functional>
+#include <type_traits>
+#include <iterator>
+
+#include <concepts> // for std::default_initializable, std::constructible_from, std::destructible
+
+#include "execution_defs.h"
+#include "oneapi/dpl/pstl/ranges_defs.h"
+
+#include "memory_ranges_impl.h"
+#if _ONEDPL_HETERO_BACKEND
+#    include "hetero/memory_ranges_impl_hetero.h"
+#endif
+
+#include "execution_impl.h"
+
+namespace std::__onedpl
+{
+namespace ranges
+{
+namespace __internal
+{
+// C++20 analogue of nothrow-random-access-range proposed for C++26 in P3179R9; exposition only
+// Semantic requirements are listed in the oneDPL specification
+template <typename _R>
+concept __nothrow_random_access_range =
+    std::ranges::random_access_range<_R> &&
+    std::is_lvalue_reference_v<std::iter_reference_t<std::ranges::iterator_t<_R>>> &&
+    std::same_as<std::remove_cvref_t<std::iter_reference_t<std::ranges::iterator_t<_R>>>,
+                 std::iter_value_t<std::ranges::iterator_t<_R>>>;
+
+} // namespace __internal
+
+namespace __internal
+{
+struct __uninitialized_default_construct_fn
+{
+    template <typename _ExecutionPolicy, __nothrow_random_access_range _R>
+        requires std::default_initializable<std::ranges::range_value_t<_R>> &&
+                 __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R>
+
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+
+        return __onedpl::__internal::__ranges::__pattern_uninitialized_default_construct(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r));
+    }
+}; //__uninitialized_default_construct_fn
+} // namespace __internal
+
+inline constexpr __internal::__uninitialized_default_construct_fn uninitialized_default_construct;
+
+namespace __internal
+{
+struct __uninitialized_value_construct_fn
+{
+    template <typename _ExecutionPolicy, __nothrow_random_access_range _R>
+        requires std::default_initializable<std::ranges::range_value_t<_R>> &&
+                 __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R>
+
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+
+        return __onedpl::__internal::__ranges::__pattern_uninitialized_value_construct(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r));
+    }
+}; //__uninitialized_value_construct_fn
+} // namespace __internal
+
+inline constexpr __internal::__uninitialized_value_construct_fn uninitialized_value_construct;
+
+namespace __internal
+{
+struct __uninitialized_copy_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _InRange,
+              __nothrow_random_access_range _OutRange>
+        requires std::constructible_from<std::ranges::range_value_t<_OutRange>,
+                                         std::ranges::range_reference_t<_InRange>> &&
+                 __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_InRange> && std::ranges::sized_range<_OutRange>
+
+    std::ranges::uninitialized_copy_result<std::ranges::borrowed_iterator_t<_InRange>,
+                                           std::ranges::borrowed_iterator_t<_OutRange>>
+    operator()(_ExecutionPolicy&& __exec, _InRange&& __in_r, _OutRange&& __out_r) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+
+        return __onedpl::__internal::__ranges::__pattern_uninitialized_copy(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_InRange>(__in_r),
+            std::forward<_OutRange>(__out_r));
+    }
+}; //__uninitialized_copy_fn
+} // namespace __internal
+
+inline constexpr __internal::__uninitialized_copy_fn uninitialized_copy;
+
+namespace __internal
+{
+struct __uninitialized_move_fn
+{
+    template <typename _ExecutionPolicy, std::ranges::random_access_range _InRange,
+              __nothrow_random_access_range _OutRange>
+        requires std::constructible_from<std::ranges::range_value_t<_OutRange>,
+                                         std::ranges::range_rvalue_reference_t<_InRange>> &&
+                 __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_InRange> && std::ranges::sized_range<_OutRange>
+
+    std::ranges::uninitialized_move_result<std::ranges::borrowed_iterator_t<_InRange>,
+                                           std::ranges::borrowed_iterator_t<_OutRange>>
+    operator()(_ExecutionPolicy&& __exec, _InRange&& __in_r, _OutRange&& __out_r) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+
+        return __onedpl::__internal::__ranges::__pattern_uninitialized_move(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_InRange>(__in_r),
+            std::forward<_OutRange>(__out_r));
+    }
+}; //__uninitialized_move_fn
+} // namespace __internal
+
+inline constexpr __internal::__uninitialized_move_fn uninitialized_move;
+
+namespace __internal
+{
+struct __uninitialized_fill_fn
+{
+    template <typename _ExecutionPolicy, __nothrow_random_access_range _R, typename _T = std::ranges::range_value_t<_R>>
+        requires std::constructible_from<std::ranges::range_value_t<_R>, const _T&> &&
+                 __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R>
+
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r, const _T& __value) const
+    {
+        const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec);
+
+        return __onedpl::__internal::__ranges::__pattern_uninitialized_fill(
+            __dispatch_tag, std::forward<_ExecutionPolicy>(__exec), std::forward<_R>(__r), __value);
+    }
+}; //__uninitialized_fill_fn
+} // namespace __internal
+
+inline constexpr __internal::__uninitialized_fill_fn uninitialized_fill;
+
+namespace __internal
+{
+struct __destroy_fn
+{
+    template <typename _ExecutionPolicy, __nothrow_random_access_range _R>
+        requires std::destructible<std::ranges::range_value_t<_R>> &&
+                 __onedpl::is_execution_policy_v<std::remove_cvref_t<_ExecutionPolicy>> &&
+                 std::ranges::sized_range<_R>
+
+    std::ranges::borrowed_iterator_t<_R>
+    operator()(_ExecutionPolicy&& __exec, _R&& __r) const
+    {
+        const auto __tag =
+#    if (_PSTL_ICPX_OMP_SIMD_DESTROY_WINDOWS_BROKEN || _ONEDPL_ICPX_OMP_SIMD_DESTROY_WINDOWS_BROKEN)
+            __onedpl::__internal::__select_backend(__onedpl::__internal::__get_unvectorized_policy(__exec));
+#    else
+            __onedpl::__internal::__select_backend(__exec);
+#    endif
+
+        return __onedpl::__internal::__ranges::__pattern_destroy(__tag, std::forward<_ExecutionPolicy>(__exec),
+                                                                    std::forward<_R>(__r));
+    }
+}; //__destroy_fn
+} // namespace __internal
+
+inline constexpr __internal::__destroy_fn destroy;
+
+} // namespace ranges
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_CPP20_RANGES_PRESENT
+#endif // _ONEDPL_GLUE_MEMORY_RANGES_IMPL_H
diff --git a/libstdc++-v3/include/pstl/glue_numeric_defs.h b/libstdc++-v3/include/pstl/glue_numeric_defs.h
index 9029a05f0ddd..7c0976abb7a5 100644
--- a/libstdc++-v3/include/pstl/glue_numeric_defs.h
+++ b/libstdc++-v3/include/pstl/glue_numeric_defs.h
@@ -1,78 +1,130 @@
 // -*- C++ -*-
-//===-- glue_numeric_defs.h -----------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_GLUE_NUMERIC_DEFS_H
-#define _PSTL_GLUE_NUMERIC_DEFS_H
+#ifndef _ONEDPL_GLUE_NUMERIC_DEFS_H
+#define _ONEDPL_GLUE_NUMERIC_DEFS_H
+
+#include <iterator>
 
 #include "execution_defs.h"
+#if _ONEDPL_BACKEND_SYCL
+#    include "hetero/dpcpp/execution_sycl_defs.h"
+#endif
 
-namespace std
+namespace std::__onedpl
 {
 // [reduce]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp, class _BinaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
 reduce(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Tp __init,
        _BinaryOperation __binary_op);
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
 reduce(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Tp __init);
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
-                                                 typename iterator_traits<_ForwardIterator>::value_type>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      typename ::std::iterator_traits<_ForwardIterator>::value_type>
 reduce(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
 transform_reduce(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                  _ForwardIterator2 __first2, _Tp __init);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation1,
           class _BinaryOperation2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
 transform_reduce(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                  _ForwardIterator2 __first2, _Tp __init, _BinaryOperation1 __binary_op1,
                  _BinaryOperation2 __binary_op2);
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp, class _BinaryOperation, class _UnaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
 transform_reduce(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Tp __init,
                  _BinaryOperation __binary_op, _UnaryOperation __unary_op);
 
 // [exclusive.scan]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                _ForwardIterator2 __result, _Tp __init);
 
+#if !_ONEDPL_EXCLUSIVE_SCAN_WITH_BINARY_OP_AMBIGUITY
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op);
+#else
+template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
+_ForwardIterator2
+exclusive_scan(__onedpl::execution::sequenced_policy, _ForwardIterator1 __first, _ForwardIterator1 __last,
+               _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op);
+
+template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
+_ForwardIterator2
+exclusive_scan(__onedpl::execution::unsequenced_policy, _ForwardIterator1 __first, _ForwardIterator1 __last,
+               _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op);
+
+template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
+_ForwardIterator2
+exclusive_scan(__onedpl::execution::parallel_policy, _ForwardIterator1 __first, _ForwardIterator1 __last,
+               _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op);
+
+template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
+_ForwardIterator2
+exclusive_scan(__onedpl::execution::parallel_unsequenced_policy, _ForwardIterator1 __first, _ForwardIterator1 __last,
+               _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op);
+
+#    if _ONEDPL_BACKEND_SYCL
+template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation, class... PolicyParams>
+_ForwardIterator2
+exclusive_scan(const __onedpl::execution::device_policy<PolicyParams...>& __exec, _ForwardIterator1 __first,
+               _ForwardIterator1 __last, _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op);
+
+#        if _ONEDPL_FPGA_DEVICE
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation, class KernelName,
+          int factor>
+_ForwardIterator2
+exclusive_scan(const __onedpl::execution::fpga_policy<factor, KernelName>& __exec, _ForwardIterator1 __first,
+               _ForwardIterator1 __last, _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op);
+#pragma GCC diagnostic pop
+#        endif // _ONEDPL_FPGA_DEVICE
+#    endif     // _ONEDPL_BACKEND_SYCL
+
+#endif // _ONEDPL_EXCLUSIVE_SCAN_WITH_BINARY_OP_AMBIGUITY
 
 // [inclusive.scan]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 inclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                _ForwardIterator2 __result);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 inclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                _ForwardIterator2 __result, _BinaryOperation __binary_op);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 inclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                _ForwardIterator2 __result, _BinaryOperation __binary_op, _Tp __init);
 
@@ -80,7 +132,7 @@ inclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIte
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation,
           class _UnaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 transform_exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                          _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op,
                          _UnaryOperation __unary_op);
@@ -89,28 +141,28 @@ transform_exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryOperation,
           class _UnaryOperation, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 transform_inclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                          _ForwardIterator2 __result, _BinaryOperation __binary_op, _UnaryOperation __unary_op,
                          _Tp __init);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _UnaryOperation,
           class _BinaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 transform_inclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                          _ForwardIterator2 __result, _BinaryOperation __binary_op, _UnaryOperation __unary_op);
 
 // [adjacent.difference]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 adjacent_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
-                    _ForwardIterator2 __d_first, _BinaryOperation __op);
+                    _ForwardIterator2 __d_first, _BinaryOperation op);
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 adjacent_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                     _ForwardIterator2 __d_first);
 
-} // namespace std
-#endif /* _PSTL_GLUE_NUMERIC_DEFS_H */
+} // namespace std::__onedpl
+#endif // _ONEDPL_GLUE_NUMERIC_DEFS_H
diff --git a/libstdc++-v3/include/pstl/glue_numeric_impl.h b/libstdc++-v3/include/pstl/glue_numeric_impl.h
index fe2d0fd47e24..911bf31b9989 100644
--- a/libstdc++-v3/include/pstl/glue_numeric_impl.h
+++ b/libstdc++-v3/include/pstl/glue_numeric_impl.h
@@ -1,225 +1,286 @@
 // -*- C++ -*-
-//===-- glue_numeric_impl.h -----------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_GLUE_NUMERIC_IMPL_H
-#define _PSTL_GLUE_NUMERIC_IMPL_H
+#ifndef _ONEDPL_GLUE_NUMERIC_IMPL_H
+#define _ONEDPL_GLUE_NUMERIC_IMPL_H
 
-#include <functional>
+#include "functional_impl.h" // for __onedpl::identity
 
 #include "utils.h"
-#include "numeric_fwd.h"
 
-namespace std
+#if _ONEDPL_HETERO_BACKEND
+#    include "hetero/algorithm_impl_hetero.h"
+#    include "hetero/numeric_impl_hetero.h"
+#endif
+
+#include "numeric_fwd.h"
+#include "execution_impl.h"
+
+namespace std::__onedpl
 {
 
 // [reduce]
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp, class _BinaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
 reduce(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Tp __init,
        _BinaryOperation __binary_op)
 {
     return transform_reduce(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::move(__init), __binary_op,
-                            __pstl::__internal::__no_op());
+                            __onedpl::identity{});
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
 reduce(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Tp __init)
 {
-    return transform_reduce(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::move(__init), std::plus<_Tp>(),
-                            __pstl::__internal::__no_op());
+    return transform_reduce(std::forward<_ExecutionPolicy>(__exec), __first, __last, std::move(__init),
+                            std::plus<_Tp>(), __onedpl::identity{});
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
-                                                 typename iterator_traits<_ForwardIterator>::value_type>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      typename ::std::iterator_traits<_ForwardIterator>::value_type>
 reduce(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
 {
-    typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
+    using _ValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
     return transform_reduce(std::forward<_ExecutionPolicy>(__exec), __first, __last, _ValueType{},
-                            std::plus<_ValueType>(), __pstl::__internal::__no_op());
+                            std::plus<_ValueType>(), __onedpl::identity{});
 }
 
 // [transform.reduce]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
 transform_reduce(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                  _ForwardIterator2 __first2, _Tp __init)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2);
+    using _InputType = typename std::iterator_traits<_ForwardIterator1>::value_type;
 
-    typedef typename iterator_traits<_ForwardIterator1>::value_type _InputType;
-    return __pstl::__internal::__pattern_transform_reduce(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
-                                                          __first1, __last1, __first2, std::move(__init), std::plus<_InputType>(),
-                                                          std::multiplies<_InputType>());
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first1, __first2);
+
+    return __onedpl::__internal::__pattern_transform_reduce(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, std::move(__init),
+        ::std::plus<_InputType>(), ::std::multiplies<_InputType>());
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation1,
           class _BinaryOperation2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
 transform_reduce(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
                  _ForwardIterator2 __first2, _Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2);
-    return __pstl::__internal::__pattern_transform_reduce(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
-                                                          __first1, __last1, __first2, std::move(__init), __binary_op1,
-                                                          __binary_op2);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first1, __first2);
+
+    return __onedpl::__internal::__pattern_transform_reduce(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                               __first1, __last1, __first2, std::move(__init),
+                                                               __binary_op1, __binary_op2);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator, class _Tp, class _BinaryOperation, class _UnaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
 transform_reduce(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Tp __init,
                  _BinaryOperation __binary_op, _UnaryOperation __unary_op)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
-    return __pstl::__internal::__pattern_transform_reduce(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
-                                                          __first, __last, std::move(__init), __binary_op, __unary_op);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first);
+
+    return __onedpl::__internal::__pattern_transform_reduce(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                               __first, __last, std::move(__init), __binary_op,
+                                                               __unary_op);
 }
 
 // [exclusive.scan]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                _ForwardIterator2 __result, _Tp __init)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
-
-    using namespace __pstl;
-    return __internal::__pattern_transform_scan(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                                __result, __pstl::__internal::__no_op(), __init, std::plus<_Tp>(),
-                                                /*inclusive=*/std::false_type());
+    return transform_exclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, __init,
+                                    std::plus<_Tp>(), __onedpl::identity{});
 }
 
+#if !_ONEDPL_EXCLUSIVE_SCAN_WITH_BINARY_OP_AMBIGUITY
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
-
-    using namespace __pstl;
-    return __internal::__pattern_transform_scan(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                                __result, __pstl::__internal::__no_op(), std::move(__init), __binary_op,
-                                                /*inclusive=*/std::false_type());
+    return transform_exclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, __init,
+                                    __binary_op, __onedpl::identity{});
 }
+#else
+template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
+_ForwardIterator2
+exclusive_scan(__onedpl::execution::sequenced_policy __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
+               _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op)
+{
+    return transform_exclusive_scan(__exec, __first, __last, __result, __init, __binary_op, __onedpl::identity{});
+}
+
+template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
+_ForwardIterator2
+exclusive_scan(__onedpl::execution::unsequenced_policy __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
+               _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op)
+{
+    return transform_exclusive_scan(__exec, __first, __last, __result, __init, __binary_op, __onedpl::identity{});
+}
+
+template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
+_ForwardIterator2
+exclusive_scan(__onedpl::execution::parallel_policy __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
+               _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op)
+{
+    return transform_exclusive_scan(__exec, __first, __last, __result, __init, __binary_op, __onedpl::identity{});
+}
+
+template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
+_ForwardIterator2
+exclusive_scan(__onedpl::execution::parallel_unsequenced_policy __exec, _ForwardIterator1 __first,
+               _ForwardIterator1 __last, _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op)
+{
+    return transform_exclusive_scan(__exec, __first, __last, __result, __init, __binary_op, __onedpl::identity{});
+}
+
+#    if _ONEDPL_BACKEND_SYCL
+template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation, class... PolicyParams>
+_ForwardIterator2
+exclusive_scan(const __onedpl::execution::device_policy<PolicyParams...>& __exec, _ForwardIterator1 __first,
+               _ForwardIterator1 __last, _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op)
+{
+    return transform_exclusive_scan(__exec, __first, __last, __result, __init, __binary_op, __onedpl::identity{});
+}
+
+#        if _ONEDPL_FPGA_DEVICE
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation, class KernelName,
+          int factor>
+_ForwardIterator2
+exclusive_scan(const __onedpl::execution::fpga_policy<factor, KernelName>& __exec, _ForwardIterator1 __first,
+               _ForwardIterator1 __last, _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op)
+{
+    return transform_exclusive_scan(__exec, __first, __last, __result, __init, __binary_op, __onedpl::identity{});
+}
+#pragma GCC diagnostic pop
+#        endif // _ONEDPL_FPGA_DEVICE
+#    endif     // _ONEDPL_BACKEND_SYCL
+
+#endif // _ONEDPL_EXCLUSIVE_SCAN_WITH_BINARY_OP_AMBIGUITY
 
 // [inclusive.scan]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 inclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                _ForwardIterator2 __result)
 {
-    typedef typename iterator_traits<_ForwardIterator1>::value_type _InputType;
+    using _InputType = typename std::iterator_traits<_ForwardIterator1>::value_type;
     return transform_inclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
-                                    std::plus<_InputType>(), __pstl::__internal::__no_op());
+                                    std::plus<_InputType>(), __onedpl::identity{});
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 inclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                _ForwardIterator2 __result, _BinaryOperation __binary_op)
 {
     return transform_inclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, __binary_op,
-                                    __pstl::__internal::__no_op());
+                                    __onedpl::identity{});
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 inclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                _ForwardIterator2 __result, _BinaryOperation __binary_op, _Tp __init)
 {
     return transform_inclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, __binary_op,
-                                    __pstl::__internal::__no_op(), std::move(__init));
+                                    __onedpl::identity{}, __init);
 }
 
 // [transform.exclusive.scan]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation,
           class _UnaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 transform_exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                          _ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op,
                          _UnaryOperation __unary_op)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __result);
 
-    return __pstl::__internal::__pattern_transform_scan(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                        __last, __result, __unary_op, std::move(__init), __binary_op,
-                                                        /*inclusive=*/std::false_type());
+    return __onedpl::__internal::__pattern_transform_scan(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                             __first, __last, __result, __unary_op, __init, __binary_op,
+                                                             /*inclusive=*/::std::false_type());
 }
 
 // [transform.inclusive.scan]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryOperation,
           class _UnaryOperation, class _Tp>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 transform_inclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                          _ForwardIterator2 __result, _BinaryOperation __binary_op, _UnaryOperation __unary_op,
                          _Tp __init)
 {
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __result);
 
-    return __pstl::__internal::__pattern_transform_scan(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
-                                                        __last, __result, __unary_op, std::move(__init), __binary_op,
-                                                        /*inclusive=*/std::true_type());
+    return __onedpl::__internal::__pattern_transform_scan(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                             __first, __last, __result, __unary_op, __init, __binary_op,
+                                                             /*inclusive=*/::std::true_type());
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _UnaryOperation,
           class _BinaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 transform_inclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                          _ForwardIterator2 __result, _BinaryOperation __binary_op, _UnaryOperation __unary_op)
 {
-    if (__first != __last)
-    {
-        auto __tmp = __unary_op(*__first);
-        *__result = __tmp;
-        return transform_inclusive_scan(std::forward<_ExecutionPolicy>(__exec), ++__first, __last, ++__result,
-                                        __binary_op, __unary_op, __tmp);
-    }
-    else
-    {
-        return __result;
-    }
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __result);
+
+    return __onedpl::__internal::__pattern_transform_scan(__dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec),
+                                                             __first, __last, __result, __unary_op, __binary_op,
+                                                             /*inclusive=*/::std::true_type());
 }
 
 // [adjacent.difference]
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryOperation>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 adjacent_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                     _ForwardIterator2 __d_first, _BinaryOperation __op)
 {
-
     if (__first == __last)
         return __d_first;
 
-    auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __d_first);
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(__exec, __first, __d_first);
 
-    return __pstl::__internal::__pattern_adjacent_difference(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
-                                                             __first, __last, __d_first, __op);
+    return __onedpl::__internal::__pattern_adjacent_difference(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), __first, __last, __d_first, __op);
 }
 
 template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
-__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
 adjacent_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
                     _ForwardIterator2 __d_first)
 {
-    typedef typename iterator_traits<_ForwardIterator1>::value_type _ValueType;
-    return adjacent_difference(std::forward<_ExecutionPolicy>(__exec), __first, __last, __d_first,
-                               std::minus<_ValueType>());
+    using _ValueType = typename std::iterator_traits<_ForwardIterator1>::value_type;
+    return adjacent_difference(::std::forward<_ExecutionPolicy>(__exec), __first, __last, __d_first,
+                               ::std::minus<_ValueType>());
 }
 
-} // namespace std
+} // namespace std::__onedpl
 
-#endif /* _PSTL_GLUE_NUMERIC_IMPL_H_ */
+#endif // _ONEDPL_GLUE_NUMERIC_IMPL_H
diff --git a/libstdc++-v3/include/pstl/glue_numeric_ranges_defs.h b/libstdc++-v3/include/pstl/glue_numeric_ranges_defs.h
new file mode 100644
index 000000000000..b870535b35aa
--- /dev/null
+++ b/libstdc++-v3/include/pstl/glue_numeric_ranges_defs.h
@@ -0,0 +1,116 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_GLUE_NUMERIC_RANGES_DEFS_H
+#define _ONEDPL_GLUE_NUMERIC_RANGES_DEFS_H
+
+#include "execution_defs.h"
+#include "utils_ranges.h"
+
+namespace std::__onedpl
+{
+namespace experimental
+{
+namespace ranges
+{
+
+// [reduce]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Tp, typename _BinaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+reduce(_ExecutionPolicy&& __exec, _Range&& __rng, _Tp __init, _BinaryOperation __binary_op);
+
+template <typename _ExecutionPolicy, typename _Range, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+reduce(_ExecutionPolicy&& __exec, _Range&& __rng, _Tp __init);
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__value_t<_Range>>
+reduce(_ExecutionPolicy&& __exec, _Range&& __rng);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+transform_reduce(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _Tp __init);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Tp, typename _BinaryOperation1,
+          typename _BinaryOperation2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+transform_reduce(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _Tp __init,
+                 _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2);
+
+template <typename _ExecutionPolicy, typename _Range, typename _Tp, typename _BinaryOperation, typename _UnaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+transform_reduce(_ExecutionPolicy&& __exec, _Range&& __rng, _Tp __init, _BinaryOperation __binary_op,
+                 _UnaryOperation __unary_op);
+
+// [exclusive.scan]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+exclusive_scan(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _Tp __init);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Tp, typename _BinaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+exclusive_scan(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _Tp __init, _BinaryOperation __binary_op);
+
+// [inclusive.scan]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+inclusive_scan(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _BinaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+inclusive_scan(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _BinaryOperation __binary_op);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Tp, typename _BinaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+inclusive_scan(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _BinaryOperation __binary_op, _Tp __init);
+
+// [transform.exclusive.scan]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Tp, typename _BinaryOperation,
+          typename _UnaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+transform_exclusive_scan(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _Tp __init,
+                         _BinaryOperation __binary_op, _UnaryOperation __unary_op);
+
+// [transform.inclusive.scan]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _BinaryOperation,
+          typename _UnaryOperation, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+transform_inclusive_scan(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _BinaryOperation __binary_op,
+                         _UnaryOperation __unary_op, _Tp __init);
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _UnaryOperation,
+          typename _BinaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+transform_inclusive_scan(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _BinaryOperation __binary_op,
+                         _UnaryOperation __unary_op);
+
+} // namespace ranges
+} // namespace experimental
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_GLUE_NUMERIC_RANGES_DEFS_H
diff --git a/libstdc++-v3/include/pstl/glue_numeric_ranges_impl.h b/libstdc++-v3/include/pstl/glue_numeric_ranges_impl.h
new file mode 100644
index 000000000000..05d1ea6d3c32
--- /dev/null
+++ b/libstdc++-v3/include/pstl/glue_numeric_ranges_impl.h
@@ -0,0 +1,203 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_GLUE_NUMERIC_RANGES_IMPL_H
+#define _ONEDPL_GLUE_NUMERIC_RANGES_IMPL_H
+
+#include "execution_defs.h"
+#include "utils_ranges.h"
+#include "glue_numeric_defs.h"
+#include "functional_impl.h" // for __onedpl::identity
+
+#if _ONEDPL_HETERO_BACKEND
+#    include "hetero/numeric_ranges_impl_hetero.h"
+
+namespace std::__onedpl
+{
+namespace experimental
+{
+namespace ranges
+{
+
+// [reduce]
+
+template <typename _ExecutionPolicy, typename _Range, typename _Tp, typename _BinaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+reduce(_ExecutionPolicy&& __exec, _Range&& __rng, _Tp __init, _BinaryOperation __binary_op)
+{
+    return transform_reduce(std::forward<_ExecutionPolicy>(__exec), std::forward<_Range>(__rng), std::move(__init),
+                            __binary_op, __onedpl::identity{});
+}
+
+template <typename _ExecutionPolicy, typename _Range, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+reduce(_ExecutionPolicy&& __exec, _Range&& __rng, _Tp __init)
+{
+    return transform_reduce(std::forward<_ExecutionPolicy>(__exec), std::forward<_Range>(__rng), std::move(__init),
+                            std::plus<_Tp>(), __onedpl::identity{});
+}
+
+template <typename _ExecutionPolicy, typename _Range>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, __onedpl::__internal::__value_t<_Range>>
+reduce(_ExecutionPolicy&& __exec, _Range&& __rng)
+{
+    using _ValueType = __onedpl::__internal::__value_t<_Range>;
+    return transform_reduce(std::forward<_ExecutionPolicy>(__exec), std::forward<_Range>(__rng), _ValueType{},
+                            std::plus<_ValueType>(), __onedpl::identity{});
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+transform_reduce(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _Tp __init)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng1, __rng2);
+
+    using _ValueType = __onedpl::__internal::__value_t<_Range1>;
+    return __onedpl::__internal::__ranges::__pattern_transform_reduce(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), views::all_read(::std::forward<_Range1>(__rng1)),
+        views::all_read(::std::forward<_Range2>(__rng2)), std::move(__init), ::std::plus<_ValueType>(),
+        ::std::multiplies<_ValueType>());
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Tp, typename _BinaryOperation1,
+          typename _BinaryOperation2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+transform_reduce(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _Tp __init,
+                 _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng1, __rng2);
+
+    return __onedpl::__internal::__ranges::__pattern_transform_reduce(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), views::all_read(::std::forward<_Range1>(__rng1)),
+        views::all_read(::std::forward<_Range2>(__rng2)), std::move(__init), __binary_op1, __binary_op2);
+}
+
+template <typename _ExecutionPolicy, typename _Range, typename _Tp, typename _BinaryOperation, typename _UnaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
+transform_reduce(_ExecutionPolicy&& __exec, _Range&& __rng, _Tp __init, _BinaryOperation __binary_op,
+                 _UnaryOperation __unary_op)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng);
+
+    return __onedpl::__internal::__ranges::__pattern_transform_reduce(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), views::all_read(::std::forward<_Range>(__rng)),
+        std::move(__init), __binary_op, __unary_op);
+}
+
+// [exclusive.scan]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+exclusive_scan(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _Tp __init)
+{
+    return transform_exclusive_scan(std::forward<_ExecutionPolicy>(__exec), std::forward<_Range1>(__rng1),
+                                    std::forward<_Range2>(__rng2), __init, std::plus<_Tp>(), __onedpl::identity{});
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Tp, typename _BinaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+exclusive_scan(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _Tp __init, _BinaryOperation __binary_op)
+{
+    return transform_exclusive_scan(std::forward<_ExecutionPolicy>(__exec), std::forward<_Range1>(__rng1),
+                                    std::forward<_Range2>(__rng2), __init, __binary_op, __onedpl::identity{});
+}
+
+// [inclusive.scan]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+inclusive_scan(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2)
+{
+    using _ValueType = __onedpl::__internal::__value_t<_Range1>;
+    return transform_inclusive_scan(std::forward<_ExecutionPolicy>(__exec), std::forward<_Range1>(__rng1),
+                                    std::forward<_Range2>(__rng2), std::plus<_ValueType>(), __onedpl::identity{});
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _BinaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+inclusive_scan(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _BinaryOperation __binary_op)
+{
+    return transform_inclusive_scan(std::forward<_ExecutionPolicy>(__exec), std::forward<_Range1>(__rng1),
+                                    std::forward<_Range2>(__rng2), __binary_op, __onedpl::identity{});
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Tp, typename _BinaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+inclusive_scan(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _BinaryOperation __binary_op, _Tp __init)
+{
+    return transform_inclusive_scan(std::forward<_ExecutionPolicy>(__exec), std::forward<_Range1>(__rng1),
+                                    std::forward<_Range2>(__rng2), __binary_op, __onedpl::identity{}, __init);
+}
+
+// [transform.exclusive.scan]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _Tp, typename _BinaryOperation,
+          typename _UnaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+transform_exclusive_scan(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _Tp __init,
+                         _BinaryOperation __binary_op, _UnaryOperation __unary_op)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng1, __rng2);
+
+    return __onedpl::__internal::__ranges::__pattern_transform_scan(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), views::all_read(::std::forward<_Range1>(__rng1)),
+        views::all_write(::std::forward<_Range2>(__rng2)), __unary_op, __init, __binary_op,
+        /*inclusive=*/::std::false_type());
+}
+
+// [transform.inclusive.scan]
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _BinaryOperation,
+          typename _UnaryOperation, typename _Tp>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+transform_inclusive_scan(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _BinaryOperation __binary_op,
+                         _UnaryOperation __unary_op, _Tp __init)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng1, __rng2);
+
+    return __onedpl::__internal::__ranges::__pattern_transform_scan(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), views::all_read(::std::forward<_Range1>(__rng1)),
+        views::all_write(::std::forward<_Range2>(__rng2)), __unary_op, __init, __binary_op,
+        /*inclusive=*/::std::true_type());
+}
+
+template <typename _ExecutionPolicy, typename _Range1, typename _Range2, typename _UnaryOperation,
+          typename _BinaryOperation>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
+                                                      __onedpl::__internal::__difference_t<_Range2>>
+transform_inclusive_scan(_ExecutionPolicy&& __exec, _Range1&& __rng1, _Range2&& __rng2, _BinaryOperation __binary_op,
+                         _UnaryOperation __unary_op)
+{
+    const auto __dispatch_tag = __onedpl::__ranges::__select_backend(__exec, __rng1, __rng2);
+
+    return __onedpl::__internal::__ranges::__pattern_transform_scan(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(__exec), views::all_read(::std::forward<_Range1>(__rng1)),
+        views::all_write(::std::forward<_Range2>(__rng2)), __unary_op, __binary_op, /*inclusive=*/::std::true_type());
+}
+
+} // namespace ranges
+} // namespace experimental
+} // namespace std::__onedpl
+
+#endif //_ONEDPL_HETERO_BACKEND
+
+#endif // _ONEDPL_GLUE_NUMERIC_RANGES_IMPL_H
diff --git a/libstdc++-v3/include/pstl/histogram_binhash_utils.h b/libstdc++-v3/include/pstl/histogram_binhash_utils.h
new file mode 100644
index 000000000000..763fe16f9534
--- /dev/null
+++ b/libstdc++-v3/include/pstl/histogram_binhash_utils.h
@@ -0,0 +1,123 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_HISTOGRAM_BINHASH_UTILS_H
+#define _ONEDPL_HISTOGRAM_BINHASH_UTILS_H
+#include <algorithm>
+#include <utility>
+#include <iterator>
+#include <cstdint>
+#include <type_traits>
+#include <cassert>
+#include <limits>
+
+namespace std::__onedpl
+{
+namespace __internal
+{
+template <typename _T1, typename = void>
+struct __evenly_divided_binhash;
+
+template <typename _T1>
+struct __evenly_divided_binhash<_T1, ::std::enable_if_t<::std::is_floating_point_v<_T1>>>
+{
+    _T1 __minimum;
+    _T1 __maximum;
+    _T1 __scale;
+
+    __evenly_divided_binhash(const _T1& __min, const _T1& __max, ::std::size_t __num_bins)
+        : __minimum(__min), __maximum(__max), __scale(_T1(__num_bins) / (__max - __min))
+    {
+        assert(__num_bins < ::std::numeric_limits<::std::int32_t>::max());
+    }
+
+    template <typename _T2>
+    ::std::int32_t
+    get_bin(_T2 __value) const
+    {
+        ::std::int32_t ret = -1;
+        if ((__value >= __minimum) && (__value < __maximum))
+        {
+            ret = (__value - __minimum) * __scale;
+        }
+        return ret;
+    }
+};
+
+template <typename _T1>
+struct __evenly_divided_binhash<_T1, ::std::enable_if_t<!::std::is_floating_point_v<_T1>>>
+{
+    _T1 __minimum;
+    _T1 __range_size;
+    ::std::int32_t __num_bins;
+    __evenly_divided_binhash(const _T1& __min, const _T1& __max, ::std::size_t __num_bins_)
+        : __minimum(__min), __range_size(__max - __min), __num_bins(__num_bins_)
+    {
+        assert(__num_bins < ::std::numeric_limits<::std::int32_t>::max());
+    }
+
+    template <typename _T2>
+    ::std::int32_t
+    get_bin(_T2 __value) const
+    {
+        ::std::int32_t ret = -1;
+        if ((__value >= __minimum) && (__value < (__minimum + __range_size)))
+        {
+            ret = ::std::uint64_t(__value - __minimum) * ::std::uint64_t(__num_bins) / __range_size;
+        }
+        return ret;
+    }
+};
+
+template <typename _Acc, typename _T2, typename _T3>
+::std::int32_t
+__custom_boundary_get_bin_helper(_Acc __acc, ::std::int32_t __size, _T2 __value, _T3 __min, _T3 __max)
+{
+    std::int32_t ret = -1;
+    if (__value >= __min && __value < __max)
+    {
+        _T2* __value_ptr = &__value;
+        ret = __onedpl::__internal::__pstl_upper_bound(__acc, std::int32_t{0}, __size, __value_ptr, std::less<_T2>{},
+                                                          __onedpl::identity{}, __onedpl::identity{}) - 1;
+    }
+    return ret;
+}
+
+template <typename _RandomAccessIterator>
+struct __custom_boundary_binhash
+{
+    _RandomAccessIterator __boundary_first;
+    _RandomAccessIterator __boundary_last;
+    __custom_boundary_binhash(_RandomAccessIterator __boundary_first_, _RandomAccessIterator __boundary_last_)
+        : __boundary_first(__boundary_first_), __boundary_last(__boundary_last_)
+    {
+        assert(std::distance(__boundary_first, __boundary_last) < std::numeric_limits<std::int32_t>::max());
+    }
+
+    template <typename _T2>
+    auto
+    get_bin(_T2 __value) const
+    {
+        auto __size = ::std::distance(__boundary_first, __boundary_last);
+        return __custom_boundary_get_bin_helper(__boundary_first, __size, __value, __boundary_first[0],
+                                                __boundary_first[__size - 1]);
+    }
+};
+
+} // end namespace __internal
+} // end namespace dpl
+} // end namespace oneapi
+
+#endif // _ONEDPL_HISTOGRAM_BINHASH_UTILS_H
diff --git a/libstdc++-v3/include/pstl/histogram_extension_defs.h b/libstdc++-v3/include/pstl/histogram_extension_defs.h
new file mode 100644
index 000000000000..50f75d26c9aa
--- /dev/null
+++ b/libstdc++-v3/include/pstl/histogram_extension_defs.h
@@ -0,0 +1,40 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_HISTOGRAM_EXTENSION_DEFS_H
+#define _ONEDPL_HISTOGRAM_EXTENSION_DEFS_H
+
+#include "onedpl_config.h"
+
+namespace std::__onedpl
+{
+
+template <typename _ExecutionPolicy, typename _RandomAccessIterator1, typename _Size, typename _ValueType,
+          typename _RandomAccessIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator2>
+histogram(_ExecutionPolicy&& exec, _RandomAccessIterator1 first, _RandomAccessIterator1 last, _Size num_bins,
+          _ValueType first_bin_min_val, _ValueType last_bin_max_val, _RandomAccessIterator2 histogram_first);
+
+template <typename _ExecutionPolicy, typename _RandomAccessIterator1, typename _RandomAccessIterator2,
+          typename _RandomAccessIterator3>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator3>
+histogram(_ExecutionPolicy&& exec, _RandomAccessIterator1 first, _RandomAccessIterator1 last,
+          _RandomAccessIterator2 boundary_first, _RandomAccessIterator2 boundary_last,
+          _RandomAccessIterator3 histogram_first);
+
+} // end namespace dpl
+} // end namespace oneapi
+
+#endif // _ONEDPL_HISTOGRAM_EXTENSION_DEFS_H
diff --git a/libstdc++-v3/include/pstl/histogram_impl.h b/libstdc++-v3/include/pstl/histogram_impl.h
new file mode 100644
index 000000000000..da465187e0aa
--- /dev/null
+++ b/libstdc++-v3/include/pstl/histogram_impl.h
@@ -0,0 +1,153 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_HISTOGRAM_IMPL_H
+#define _ONEDPL_HISTOGRAM_IMPL_H
+
+#include "histogram_extension_defs.h"
+#include "histogram_binhash_utils.h"
+#include "execution_impl.h"
+#include "iterator_impl.h"
+#include "algorithm_fwd.h"
+
+#if _ONEDPL_HETERO_BACKEND
+#    include "hetero/histogram_impl_hetero.h"
+#endif
+
+namespace std::__onedpl
+{
+
+namespace __internal
+{
+
+template <class _ForwardIterator, class _IdxHashFunc, class _RandomAccessIterator, class _IsVector>
+void
+__brick_histogram(_ForwardIterator __first, _ForwardIterator __last, _IdxHashFunc __func,
+                  _RandomAccessIterator __histogram_first, _IsVector) noexcept
+{
+    for (; __first != __last; ++__first)
+    {
+        std::int32_t __bin = __func.get_bin(*__first);
+        if (__bin >= 0)
+        {
+            ++__histogram_first[__bin];
+        }
+    }
+}
+
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Size, class _IdxHashFunc,
+          class _RandomAccessIterator>
+void
+__pattern_histogram(_Tag, _ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
+                    _Size __num_bins, _IdxHashFunc __func, _RandomAccessIterator __histogram_first)
+{
+    using _HistogramValueT = typename std::iterator_traits<_RandomAccessIterator>::value_type;
+    static_assert(__onedpl::__internal::__is_serial_tag_v<_Tag> ||
+                  __onedpl::__internal::__is_parallel_forward_tag_v<_Tag>);
+    __pattern_fill(_Tag{}, std::forward<_ExecutionPolicy>(__exec), __histogram_first, __histogram_first + __num_bins,
+                   _HistogramValueT{0});
+    __brick_histogram(__first, __last, __func, __histogram_first, typename _Tag::__is_vector{});
+}
+
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _Size, class _IdxHashFunc,
+          class _RandomAccessIterator2>
+void
+__pattern_histogram(__onedpl::__internal::__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec,
+                    _RandomAccessIterator1 __first, _RandomAccessIterator1 __last, _Size __num_bins,
+                    _IdxHashFunc __func, _RandomAccessIterator2 __histogram_first)
+{
+    using __backend_tag = typename __onedpl::__internal::__parallel_tag<_IsVector>::__backend_tag;
+    using _HistogramValueT = typename std::iterator_traits<_RandomAccessIterator2>::value_type;
+    using _DiffType = typename std::iterator_traits<_RandomAccessIterator2>::difference_type;
+
+    _DiffType __n = __last - __first;
+    if (__n == 0)
+    {
+        // when n == 0, we must fill the output histogram with zeros
+        __pattern_fill(__onedpl::__internal::__parallel_tag<_IsVector>{}, std::forward<_ExecutionPolicy>(__exec),
+                       __histogram_first, __histogram_first + __num_bins, _HistogramValueT{0});
+    }
+    else
+    {
+        auto __tls =
+            __par_backend::__make_enumerable_tls<std::vector<_HistogramValueT>>(__num_bins, _HistogramValueT{0});
+
+        //main histogram loop
+        //TODO: add defaulted grain-size option for __parallel_for and use larger one here to account for overhead
+        __par_backend::__parallel_for(
+            __backend_tag{}, __exec, __first, __last,
+            [__func, &__tls](_RandomAccessIterator1 __first_local, _RandomAccessIterator1 __last_local) {
+                __internal::__brick_histogram(__first_local, __last_local, __func,
+                                              __tls.get_for_current_thread().begin(), _IsVector{});
+            });
+        // now accumulate temporary storage into output histogram
+        const std::size_t __num_temporary_copies = __tls.size();
+        __par_backend::__parallel_for(
+            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), _Size{0}, __num_bins,
+            [__num_temporary_copies, __histogram_first, &__tls](auto __hist_start_id, auto __hist_end_id) {
+                const _DiffType __local_n = __hist_end_id - __hist_start_id;
+                //initialize output histogram with first local histogram via assign
+                __internal::__brick_walk2_n(__tls.get_with_id(0).begin() + __hist_start_id, __local_n,
+                                            __histogram_first + __hist_start_id,
+                                            __onedpl::__internal::__pstl_assign(), _IsVector{});
+                for (std::size_t __i = 1; __i < __num_temporary_copies; ++__i)
+                {
+                    //accumulate into output histogram with other local histogram via += operator
+                    __internal::__brick_walk2_n(
+                        __tls.get_with_id(__i).begin() + __hist_start_id, __local_n,
+                        __histogram_first + __hist_start_id,
+                        [](_HistogramValueT __x, _HistogramValueT& __y) { __y += __x; }, _IsVector{});
+                }
+            });
+    }
+}
+
+} // namespace __internal
+
+template <typename _ExecutionPolicy, typename _RandomAccessIterator1, typename _Size, typename _ValueType,
+          typename _RandomAccessIterator2>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator2>
+histogram(_ExecutionPolicy&& exec, _RandomAccessIterator1 first, _RandomAccessIterator1 last, _Size num_bins,
+          _ValueType first_bin_min_val, _ValueType last_bin_max_val, _RandomAccessIterator2 histogram_first)
+{
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(exec, first, histogram_first);
+
+    __onedpl::__internal::__pattern_histogram(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(exec), first, last, num_bins,
+        __onedpl::__internal::__evenly_divided_binhash<_ValueType>(first_bin_min_val, last_bin_max_val, num_bins),
+        histogram_first);
+    return histogram_first + num_bins;
+}
+
+template <typename _ExecutionPolicy, typename _RandomAccessIterator1, typename _RandomAccessIterator2,
+          typename _RandomAccessIterator3>
+__onedpl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _RandomAccessIterator3>
+histogram(_ExecutionPolicy&& exec, _RandomAccessIterator1 first, _RandomAccessIterator1 last,
+          _RandomAccessIterator2 boundary_first, _RandomAccessIterator2 boundary_last,
+          _RandomAccessIterator3 histogram_first)
+{
+    const auto __dispatch_tag = __onedpl::__internal::__select_backend(exec, first, boundary_first, histogram_first);
+
+    ::std::ptrdiff_t num_bins = boundary_last - boundary_first - 1;
+    __onedpl::__internal::__pattern_histogram(
+        __dispatch_tag, ::std::forward<_ExecutionPolicy>(exec), first, last, num_bins,
+        __onedpl::__internal::__custom_boundary_binhash{boundary_first, boundary_last}, histogram_first);
+    return histogram_first + num_bins;
+}
+
+} // end namespace dpl
+} // end namespace oneapi
+
+#endif // _ONEDPL_HISTOGRAM_IMPL_H
diff --git a/libstdc++-v3/include/pstl/iterator_defs.h b/libstdc++-v3/include/pstl/iterator_defs.h
new file mode 100644
index 000000000000..837f3bda7d35
--- /dev/null
+++ b/libstdc++-v3/include/pstl/iterator_defs.h
@@ -0,0 +1,111 @@
+// -*- C++ -*-
+//===-- iterator_defs.h ---------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_ITERATOR_DEFS_H
+#define _ONEDPL_ITERATOR_DEFS_H
+
+#include <iterator>
+#include <type_traits>
+#include "utils.h"
+
+namespace std::__onedpl
+{
+namespace __internal
+{
+
+// If std::iterator_traits<_IteratorType>::iterator_category is well-formed - compare it with _IteratorTag
+template <typename _IteratorTag, typename _IteratorType, typename = void>
+struct __is_iterator_of_category_dispatch : std::false_type
+{
+};
+
+template <typename _IteratorTag, typename _IteratorType>
+struct __is_iterator_of_category_dispatch<_IteratorTag, _IteratorType,
+                                          std::void_t<typename std::iterator_traits<_IteratorType>::iterator_category>>
+    : std::is_base_of<_IteratorTag, typename std::iterator_traits<_IteratorType>::iterator_category>
+{
+};
+
+// If _IteratorType::iterator_concept is well-formed - compare it with _IteratorTag
+template <typename _IteratorTag, typename _IteratorType, typename = void>
+struct __is_iterator_of_concept_dispatch : __is_iterator_of_category_dispatch<_IteratorTag, _IteratorType>
+{
+};
+
+template <typename _IteratorTag, typename _IteratorType>
+struct __is_iterator_of_concept_dispatch<_IteratorTag, _IteratorType,
+                                         std::void_t<typename _IteratorType::iterator_concept>>
+    : std::is_base_of<_IteratorTag, typename _IteratorType::iterator_concept>
+{
+};
+
+// Since C++20 allows user specializations for std::iterator_traits to define
+// iterator_concept alias into the actual iterator category, we need to check it first
+// Primary template std::iterator_traits::iterator_concept does not provide iterator_concept alias
+template <typename _IteratorTag, typename _IteratorType, typename = void>
+struct __is_iterator_of_traits_concept_dispatch : __is_iterator_of_concept_dispatch<_IteratorTag, _IteratorType>
+{
+};
+
+template <typename _IteratorTag, typename _IteratorType>
+struct __is_iterator_of_traits_concept_dispatch<
+    _IteratorTag, _IteratorType, std::void_t<typename std::iterator_traits<_IteratorType>::iterator_concept>>
+    : std::is_base_of<_IteratorTag, typename std::iterator_traits<_IteratorType>::iterator_concept>
+{
+};
+
+// Until C++23, std::move_iterator::iterator_concept is std::input_iterator_tag and
+// std::random_access_iterator<std::move_iterator<...>> returns false even if the
+// base iterator is random access. Making the dispatch based on the base iterator type
+// considers std::move_iterator<random-access> a random access iterator
+template <typename _IteratorTag, typename _IteratorType>
+struct __is_iterator_of_move_dispatch : __is_iterator_of_traits_concept_dispatch<_IteratorTag, _IteratorType>
+{
+};
+
+template <typename _IteratorTag, typename _BaseIteratorType>
+struct __is_iterator_of_move_dispatch<_IteratorTag, std::move_iterator<_BaseIteratorType>>
+    : __is_iterator_of_traits_concept_dispatch<_IteratorTag, _BaseIteratorType>
+{
+};
+
+template <typename _IteratorTag, typename... _IteratorTypes>
+struct __is_iterator_of
+    : std::conjunction<__is_iterator_of_move_dispatch<_IteratorTag, std::decay_t<_IteratorTypes>>...>
+{
+};
+
+// Make is_random_access_iterator and is_forward_iterator not to fail with a 'hard' error when it's used in
+// SFINAE with a non-iterator type by providing a default value.
+template <typename... _IteratorTypes>
+struct __is_random_access_iterator : __is_iterator_of<std::random_access_iterator_tag, _IteratorTypes...>
+{
+};
+
+template <typename... _IteratorTypes>
+struct __is_forward_iterator : __is_iterator_of<std::forward_iterator_tag, _IteratorTypes...>
+{
+};
+
+template <typename... _IteratorTypes>
+inline constexpr bool __is_random_access_iterator_v = __is_random_access_iterator<_IteratorTypes...>::value;
+
+template <typename... _IteratorTypes>
+inline constexpr bool __is_forward_iterator_v = __is_forward_iterator<_IteratorTypes...>::value;
+
+} // namespace __internal
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_ITERATOR_DEFS_H
diff --git a/libstdc++-v3/include/pstl/iterator_impl.h b/libstdc++-v3/include/pstl/iterator_impl.h
new file mode 100644
index 000000000000..b9b207b2d868
--- /dev/null
+++ b/libstdc++-v3/include/pstl/iterator_impl.h
@@ -0,0 +1,1050 @@
+// -*- C++ -*-
+//===-- iterator_impl.h ---------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_ITERATOR_IMPL_H
+#define _ONEDPL_ITERATOR_IMPL_H
+
+#include <iterator>
+#include <tuple>
+#include <cassert>
+#include <type_traits>
+
+#include "onedpl_config.h"
+#include "utils.h"
+#include "tuple_impl.h"
+
+namespace std::__onedpl
+{
+namespace __internal
+{
+template <size_t _Np>
+struct __tuple_util
+{
+    template <typename _TupleType, typename _DifferenceType>
+    static void
+    __increment(_TupleType& __it, _DifferenceType __forward)
+    {
+        ::std::get<_Np - 1>(__it) = ::std::get<_Np - 1>(__it) + __forward;
+        __tuple_util<_Np - 1>::__increment(__it, __forward);
+    }
+    template <typename _TupleType>
+    static void
+    __pre_increment(_TupleType& __it)
+    {
+        ++::std::get<_Np - 1>(__it);
+        __tuple_util<_Np - 1>::__pre_increment(__it);
+    }
+};
+
+template <>
+struct __tuple_util<0>
+{
+    template <typename _TupleType, typename _DifferenceType>
+    static void
+    __increment(_TupleType&, _DifferenceType)
+    {
+    }
+    template <typename _TupleType>
+    static void
+    __pre_increment(_TupleType&)
+    {
+    }
+};
+
+template <typename _TupleReturnType>
+struct __make_references
+{
+    template <typename _TupleType, ::std::size_t... _Ip>
+    _TupleReturnType
+    operator()(const _TupleType& __t, ::std::index_sequence<_Ip...>)
+    {
+        return _TupleReturnType(*::std::get<_Ip>(__t)...);
+    }
+};
+
+template <typename _Iter, typename = void>
+struct __is_legacy_passed_directly : std::false_type
+{
+};
+
+template <typename _Iter>
+struct __is_legacy_passed_directly<_Iter, std::enable_if_t<_Iter::is_passed_directly::value>> : std::true_type
+{
+};
+
+template <typename _T>
+struct __is_reversed_indirectly_device_accessible_it;
+
+template <typename T>
+constexpr auto is_onedpl_indirectly_device_accessible(T)
+    -> std::disjunction<
+#if _ONEDPL_BACKEND_SYCL
+        __onedpl::__internal::__is_known_usm_vector_iter<std::decay_t<T>>,             // USM vector iterator
+#endif // _ONEDPL_BACKEND_SYCL
+        std::is_pointer<std::decay_t<T>>,                                                 // USM pointer
+        __onedpl::__internal::__is_legacy_passed_directly<std::decay_t<T>>,            // legacy passed directly iter
+        __onedpl::__internal::__is_reversed_indirectly_device_accessible_it<std::decay_t<T>>>; // reverse iterator
+
+struct __is_onedpl_indirectly_device_accessible_fn
+{
+    template <typename T>
+    constexpr auto
+    operator()(T t) const -> decltype(is_onedpl_indirectly_device_accessible(t));
+};
+
+inline constexpr __is_onedpl_indirectly_device_accessible_fn __is_onedpl_indirectly_device_accessible;
+
+//zip_iterator version for forward iterator
+//== and != comparison is performed only on the first element of the tuple
+//
+//zip_forward_iterator is implemented as an internal class and should remain so. Users should never encounter
+//this class or be returned a type of its value_type, reference, etc as the tuple-like type used internally
+//is variable dependent on the C++ standard library version and could cause an inconsistent ABI due to resulting
+//layout changes of this class.
+template <typename... _Types>
+class zip_forward_iterator
+{
+    template <typename... _Ts>
+    using __tuple_t =
+#if _ONEDPL_CAN_USE_STD_TUPLE_PROXY_ITERATOR
+        ::std::tuple<_Ts...>;
+#else
+        __onedpl::__internal::tuple<_Ts...>;
+#endif
+
+    static const ::std::size_t __num_types = sizeof...(_Types);
+    using __it_types = __tuple_t<_Types...>;
+
+  public:
+    using difference_type = std::make_signed_t<std::size_t>;
+    using value_type = __tuple_t<typename std::iterator_traits<_Types>::value_type...>;
+    using reference = __tuple_t<typename std::iterator_traits<_Types>::reference...>;
+    using pointer = __tuple_t<typename std::iterator_traits<_Types>::pointer...>;
+    using iterator_category = std::forward_iterator_tag;
+
+    zip_forward_iterator() : __my_it_() {}
+    explicit zip_forward_iterator(_Types... __args) : __my_it_(__tuple_t<_Types...>{__args...}) {}
+
+    // On windows, this requires clause is necessary so that concepts in MSVC STL do not detect the iterator as
+    // dereferenceable when a source iterator is a sycl_iterator, which is a supported type.
+    reference
+    operator*() const _ONEDPL_CPP20_REQUIRES(std::indirectly_readable<_Types> &&...)
+    {
+        return __make_references<reference>()(__my_it_, ::std::make_index_sequence<__num_types>());
+    }
+
+    zip_forward_iterator&
+    operator++()
+    {
+        __tuple_util<__num_types>::__pre_increment(__my_it_);
+        return *this;
+    }
+    zip_forward_iterator
+    operator++(int)
+    {
+        zip_forward_iterator __it(*this);
+        ++(*this);
+        return __it;
+    }
+
+    bool
+    operator==(const zip_forward_iterator& __it) const
+    {
+        return ::std::get<0>(__my_it_) == ::std::get<0>(__it.__my_it_);
+    }
+    bool
+    operator!=(const zip_forward_iterator& __it) const
+    {
+        return !(*this == __it);
+    }
+
+    __it_types
+    base() const
+    {
+        return __my_it_;
+    }
+
+  private:
+    __it_types __my_it_;
+};
+
+} // namespace __internal
+} // namespace std::__onedpl
+
+namespace std::__onedpl
+{
+
+template <typename T>
+struct is_indirectly_device_accessible
+    : decltype(__onedpl::__internal::__is_onedpl_indirectly_device_accessible(std::declval<T>()))
+{
+    static_assert(std::is_same_v<decltype(decltype(__onedpl::__internal::__is_onedpl_indirectly_device_accessible(
+                                     std::declval<T>()))::value),
+                                 const bool>,
+                  "Return type of is_onedpl_indirectly_device_accessible does not have the characteristics of a "
+                  "bool_constant");
+};
+
+template <typename T>
+inline constexpr bool is_indirectly_device_accessible_v = is_indirectly_device_accessible<T>::value;
+
+template <typename _Ip>
+class counting_iterator
+{
+    static_assert(::std::is_integral_v<_Ip>, "Cannot instantiate counting_iterator with a non-integer type");
+
+  public:
+    using difference_type = std::make_signed_t<_Ip>;
+    using value_type = _Ip;
+    using pointer = const _Ip*;
+    // There is no storage behind the iterator, so we return a value instead of reference.
+    using reference = _Ip;
+    using iterator_category = std::random_access_iterator_tag;
+
+    counting_iterator() : __my_counter_() {}
+    explicit counting_iterator(_Ip __init) : __my_counter_(__init) {}
+
+    reference operator*() const { return __my_counter_; }
+    reference operator[](difference_type __i) const { return *(*this + __i); }
+
+    difference_type
+    operator-(const counting_iterator& __it) const
+    {
+        return __my_counter_ - __it.__my_counter_;
+    }
+
+    counting_iterator&
+    operator+=(difference_type __forward)
+    {
+        __my_counter_ += __forward;
+        return *this;
+    }
+    counting_iterator&
+    operator-=(difference_type __backward)
+    {
+        return *this += -__backward;
+    }
+    counting_iterator&
+    operator++()
+    {
+        return *this += 1;
+    }
+    counting_iterator&
+    operator--()
+    {
+        return *this -= 1;
+    }
+
+    counting_iterator
+    operator++(int)
+    {
+        counting_iterator __it(*this);
+        ++(*this);
+        return __it;
+    }
+    counting_iterator
+    operator--(int)
+    {
+        counting_iterator __it(*this);
+        --(*this);
+        return __it;
+    }
+
+    counting_iterator
+    operator-(difference_type __backward) const
+    {
+        return counting_iterator(__my_counter_ - __backward);
+    }
+    counting_iterator
+    operator+(difference_type __forward) const
+    {
+        return counting_iterator(__my_counter_ + __forward);
+    }
+    friend counting_iterator
+    operator+(difference_type __forward, const counting_iterator __it)
+    {
+        return __it + __forward;
+    }
+
+    bool
+    operator==(const counting_iterator& __it) const
+    {
+        return *this - __it == 0;
+    }
+    bool
+    operator!=(const counting_iterator& __it) const
+    {
+        return !(*this == __it);
+    }
+    bool
+    operator<(const counting_iterator& __it) const
+    {
+        return *this - __it < 0;
+    }
+    bool
+    operator>(const counting_iterator& __it) const
+    {
+        return __it < *this;
+    }
+    bool
+    operator<=(const counting_iterator& __it) const
+    {
+        return !(*this > __it);
+    }
+    bool
+    operator>=(const counting_iterator& __it) const
+    {
+        return !(*this < __it);
+    }
+
+    friend std::true_type
+    is_onedpl_indirectly_device_accessible(counting_iterator)
+    {
+        return {}; //minimal body provided to avoid warnings of non-template-friend in g++
+    }
+
+  private:
+    _Ip __my_counter_;
+};
+
+template <typename... _Types>
+class zip_iterator
+{
+    static_assert(sizeof...(_Types) > 0, "Cannot instantiate zip_iterator with empty template parameter pack");
+    static const ::std::size_t __num_types = sizeof...(_Types);
+    using __it_types = __onedpl::__internal::tuple<_Types...>;
+
+  public:
+    using difference_type = std::make_signed_t<std::size_t>;
+    using value_type = __onedpl::__internal::tuple<typename std::iterator_traits<_Types>::value_type...>;
+    using reference = __onedpl::__internal::tuple<typename std::iterator_traits<_Types>::reference...>;
+    using pointer = std::tuple<typename std::iterator_traits<_Types>::pointer...>;
+    using iterator_category = std::random_access_iterator_tag;
+    using is_zip = ::std::true_type;
+
+    zip_iterator() : __my_it_() {}
+    explicit zip_iterator(_Types... __args) : __my_it_(::std::make_tuple(__args...)) {}
+    explicit zip_iterator(std::tuple<_Types...> __arg) : __my_it_(__arg) {}
+
+    // On windows, this requires clause is necessary so that concepts in MSVC STL do not detect the iterator as
+    // dereferenceable when a source iterator is a sycl_iterator, which is a supported type.
+    reference
+    operator*() const _ONEDPL_CPP20_REQUIRES(std::indirectly_readable<_Types> &&...)
+    {
+        return __onedpl::__internal::__make_references<reference>()(__my_it_,
+                                                                       ::std::make_index_sequence<__num_types>());
+    }
+
+    reference operator[](difference_type __i) const { return *(*this + __i); }
+
+    difference_type
+    operator-(const zip_iterator& __it) const
+    {
+        return ::std::get<0>(__my_it_) - ::std::get<0>(__it.__my_it_);
+    }
+
+    zip_iterator&
+    operator+=(difference_type __forward)
+    {
+        __onedpl::__internal::__tuple_util<__num_types>::__increment(__my_it_, __forward);
+        return *this;
+    }
+    zip_iterator&
+    operator-=(difference_type __backward)
+    {
+        return *this += -__backward;
+    }
+    zip_iterator&
+    operator++()
+    {
+        return *this += 1;
+    }
+    zip_iterator&
+    operator--()
+    {
+        return *this -= 1;
+    }
+
+    zip_iterator
+    operator++(int)
+    {
+        zip_iterator __it(*this);
+        ++(*this);
+        return __it;
+    }
+    zip_iterator
+    operator--(int)
+    {
+        zip_iterator __it(*this);
+        --(*this);
+        return __it;
+    }
+
+    zip_iterator
+    operator-(difference_type __backward) const
+    {
+        zip_iterator __it(*this);
+        return __it -= __backward;
+    }
+    zip_iterator
+    operator+(difference_type __forward) const
+    {
+        zip_iterator __it(*this);
+        return __it += __forward;
+    }
+    friend zip_iterator
+    operator+(difference_type __forward, const zip_iterator& __it)
+    {
+        return __it + __forward;
+    }
+
+    bool
+    operator==(const zip_iterator& __it) const
+    {
+        return *this - __it == 0;
+    }
+    __it_types
+    base() const
+    {
+        return __my_it_;
+    }
+
+    bool
+    operator!=(const zip_iterator& __it) const
+    {
+        return !(*this == __it);
+    }
+    bool
+    operator<(const zip_iterator& __it) const
+    {
+        return *this - __it < 0;
+    }
+    bool
+    operator>(const zip_iterator& __it) const
+    {
+        return __it < *this;
+    }
+    bool
+    operator<=(const zip_iterator& __it) const
+    {
+        return !(*this > __it);
+    }
+    bool
+    operator>=(const zip_iterator& __it) const
+    {
+        return !(*this < __it);
+    }
+
+    friend auto
+    is_onedpl_indirectly_device_accessible(zip_iterator)
+        -> std::conjunction<__onedpl::is_indirectly_device_accessible<_Types>...>
+    {
+        return {}; //minimal body provided to avoid warnings of non-template-friend in g++
+    }
+
+  private:
+    __it_types __my_it_;
+};
+
+template <typename... _Tp>
+zip_iterator<_Tp...>
+make_zip_iterator(_Tp... __args)
+{
+    return zip_iterator<_Tp...>(__args...);
+}
+
+template <typename... _Tp>
+zip_iterator<_Tp...>
+make_zip_iterator(std::tuple<_Tp...> __arg)
+{
+    return zip_iterator<_Tp...>(__arg);
+}
+
+template <typename _Iter, typename _UnaryFunc>
+class transform_iterator
+{
+  private:
+    _Iter __my_it_;
+    _UnaryFunc __my_unary_func_;
+
+    static_assert(std::is_invocable_v<const std::decay_t<_UnaryFunc>, typename std::iterator_traits<_Iter>::reference>,
+                  "_UnaryFunc does not have a const-qualified call operator which accepts the reference type of the "
+                  "base iterator as argument.");
+
+  public:
+    using difference_type = typename std::iterator_traits<_Iter>::difference_type;
+    using reference = decltype(__my_unary_func_(std::declval<typename std::iterator_traits<_Iter>::reference>()));
+    using value_type = std::remove_reference_t<reference>;
+    using pointer = typename std::iterator_traits<_Iter>::pointer;
+    using iterator_category = typename std::iterator_traits<_Iter>::iterator_category;
+
+    //default constructor will only be present if both the unary functor and iterator are default constructible
+    transform_iterator() = default;
+
+    //only enable this constructor if the unary functor is default constructible
+    template <typename _UnaryFuncLocal = _UnaryFunc,
+              std::enable_if_t<std::is_default_constructible_v<_UnaryFuncLocal>, int> = 0>
+    transform_iterator(_Iter __it) : __my_it_(std::move(__it))
+    {
+    }
+
+    transform_iterator(_Iter __it, _UnaryFunc __unary_func)
+        : __my_it_(std::move(__it)), __my_unary_func_(std::move(__unary_func))
+    {
+    }
+
+    transform_iterator(const transform_iterator&) = default;
+    transform_iterator&
+    operator=(const transform_iterator& __input)
+    {
+        __my_it_ = __input.__my_it_;
+
+        // If copy assignment is available, copy the functor, otherwise skip it.
+        // For non-copy assignable functors, this copy assignment operator departs from the sycl 2020 specification
+        // requirement of device copyable types for copy assignment to be the same as a bitwise copy of the object.
+        // TODO: Explore (ABI breaking) change to use std::optional or similar and using copy constructor to implement
+        //       copy assignment to better comply with SYCL 2020 specification.
+        if constexpr (std::is_copy_assignable_v<_UnaryFunc>)
+        {
+            __my_unary_func_ = __input.__my_unary_func_;
+        }
+        return *this;
+    }
+
+    // On windows, this requires clause is necessary so that concepts in MSVC STL do not detect the iterator as
+    // dereferenceable when the source iterator is a sycl_iterator, which is a supported type.
+    reference
+    operator*() const _ONEDPL_CPP20_REQUIRES(std::indirectly_readable<_Iter>)
+    {
+        return __my_unary_func_(*__my_it_);
+    }
+    reference operator[](difference_type __i) const { return *(*this + __i); }
+    transform_iterator&
+    operator++()
+    {
+        ++__my_it_;
+        return *this;
+    }
+    transform_iterator&
+    operator--()
+    {
+        --__my_it_;
+        return *this;
+    }
+    transform_iterator
+    operator++(int)
+    {
+        transform_iterator __it(*this);
+        ++(*this);
+        return __it;
+    }
+    transform_iterator
+    operator--(int)
+    {
+        transform_iterator __it(*this);
+        --(*this);
+        return __it;
+    }
+    transform_iterator
+    operator+(difference_type __forward) const
+    {
+        return {__my_it_ + __forward, __my_unary_func_};
+    }
+    transform_iterator
+    operator-(difference_type __backward) const
+    {
+        return {__my_it_ - __backward, __my_unary_func_};
+    }
+    transform_iterator&
+    operator+=(difference_type __forward)
+    {
+        __my_it_ += __forward;
+        return *this;
+    }
+    transform_iterator&
+    operator-=(difference_type __backward)
+    {
+        __my_it_ -= __backward;
+        return *this;
+    }
+    friend transform_iterator
+    operator+(difference_type __forward, const transform_iterator& __it)
+    {
+        return __it + __forward;
+    }
+    difference_type
+    operator-(const transform_iterator& __it) const
+    {
+        return __my_it_ - __it.__my_it_;
+    }
+    bool
+    operator==(const transform_iterator& __it) const
+    {
+        return __my_it_ == __it.__my_it_;
+    }
+    bool
+    operator!=(const transform_iterator& __it) const
+    {
+        return !(*this == __it);
+    }
+    bool
+    operator<(const transform_iterator& __it) const
+    {
+        return *this - __it < 0;
+    }
+    bool
+    operator>(const transform_iterator& __it) const
+    {
+        return __it < *this;
+    }
+    bool
+    operator<=(const transform_iterator& __it) const
+    {
+        return !(*this > __it);
+    }
+    bool
+    operator>=(const transform_iterator& __it) const
+    {
+        return !(*this < __it);
+    }
+
+    _Iter
+    base() const
+    {
+        return __my_it_;
+    }
+    _UnaryFunc
+    functor() const
+    {
+        return __my_unary_func_;
+    }
+    friend auto
+    is_onedpl_indirectly_device_accessible(transform_iterator) -> __onedpl::is_indirectly_device_accessible<_Iter>
+    {
+        return {}; //minimal body provided to avoid warnings of non-template-friend in g++
+    }
+};
+
+template <typename _Iter, typename _UnaryFunc>
+transform_iterator<_Iter, _UnaryFunc>
+make_transform_iterator(_Iter __it, _UnaryFunc __unary_func)
+{
+    return transform_iterator<_Iter, _UnaryFunc>(__it, __unary_func);
+}
+
+namespace __internal
+{
+
+//functor concept
+struct __functor_concept
+{
+    template <typename _T>
+    static auto
+    test(int) -> decltype(::std::declval<_T>()(0), ::std::true_type{});
+
+    template <typename _T>
+    static auto
+    test(...) -> ::std::false_type;
+};
+
+template <typename _T>
+inline constexpr bool __is_functor = decltype(__functor_concept::test<_T>(0))::value;
+
+} // namespace __internal
+
+template <typename SourceIterator, typename _Permutation>
+class permutation_iterator
+{
+  public:
+    using IndexMap = std::conditional_t<
+        !__internal::__is_functor<_Permutation>, _Permutation,
+        transform_iterator<counting_iterator<typename ::std::iterator_traits<SourceIterator>::difference_type>,
+                           _Permutation>>;
+    using difference_type = typename std::iterator_traits<SourceIterator>::difference_type;
+    using value_type = typename std::iterator_traits<SourceIterator>::value_type;
+    using pointer = typename std::iterator_traits<SourceIterator>::pointer;
+    using reference = typename std::iterator_traits<SourceIterator>::reference;
+    using base_type = SourceIterator;
+    using iterator_category = std::random_access_iterator_tag;
+    using is_permutation = std::true_type;
+
+    permutation_iterator() = default;
+
+    template <typename _T = _Permutation, ::std::enable_if_t<!__internal::__is_functor<_T>, int> = 0>
+    permutation_iterator(SourceIterator input1, _Permutation input2) : my_source_it(input1), my_index(input2)
+    {
+    }
+
+    template <typename _T = _Permutation, ::std::enable_if_t<__internal::__is_functor<_T>, int> = 0>
+    permutation_iterator(SourceIterator input1, _Permutation __f, difference_type __idx = 0)
+        : my_source_it(input1), my_index(counting_iterator<difference_type>(__idx), __f)
+    {
+    }
+
+  private:
+    template <typename _T = _Permutation, ::std::enable_if_t<__internal::__is_functor<_T>, int> = 0>
+    permutation_iterator(SourceIterator input1, IndexMap input2) : my_source_it(input1), my_index(input2)
+    {
+    }
+
+  public:
+    SourceIterator
+    base() const
+    {
+        return my_source_it;
+    }
+
+    auto
+    map() const
+    {
+        if constexpr (__internal::__is_functor<_Permutation>)
+            return my_index.functor();
+        else
+            return my_index;
+    }
+
+    // On windows, this requires clause is necessary so that concepts in MSVC STL do not detect the iterator as
+    // dereferenceable when the source or map iterator is a sycl_iterator, which is a supported type for both.
+    reference
+    operator*() const
+        _ONEDPL_CPP20_REQUIRES(std::indirectly_readable<SourceIterator> && std::indirectly_readable<IndexMap>)
+    {
+        return my_source_it[*my_index];
+    }
+
+    reference operator[](difference_type __i) const { return *(*this + __i); }
+
+    permutation_iterator&
+    operator++()
+    {
+        ++my_index;
+        return *this;
+    }
+
+    permutation_iterator
+    operator++(int)
+    {
+        permutation_iterator it(*this);
+        ++(*this);
+        return it;
+    }
+
+    permutation_iterator&
+    operator--()
+    {
+        --my_index;
+        return *this;
+    }
+
+    permutation_iterator
+    operator--(int)
+    {
+        permutation_iterator it(*this);
+        --(*this);
+        return it;
+    }
+
+    permutation_iterator
+    operator+(difference_type forward) const
+    {
+        return permutation_iterator(my_source_it, my_index + forward);
+    }
+
+    permutation_iterator
+    operator-(difference_type backward) const
+    {
+        return permutation_iterator(my_source_it, my_index - backward);
+    }
+
+    permutation_iterator&
+    operator+=(difference_type forward)
+    {
+        my_index += forward;
+        return *this;
+    }
+
+    permutation_iterator&
+    operator-=(difference_type forward)
+    {
+        my_index -= forward;
+        return *this;
+    }
+
+    difference_type
+    operator-(const permutation_iterator& it) const
+    {
+        return my_index - it.my_index;
+    }
+
+    friend permutation_iterator
+    operator+(difference_type forward, const permutation_iterator& it)
+    {
+        return permutation_iterator(it.my_source_it, it.my_index + forward);
+    }
+
+    bool
+    operator==(const permutation_iterator& it) const
+    {
+        return *this - it == 0;
+    }
+    bool
+    operator!=(const permutation_iterator& it) const
+    {
+        return !(*this == it);
+    }
+    bool
+    operator<(const permutation_iterator& it) const
+    {
+        return *this - it < 0;
+    }
+    bool
+    operator>(const permutation_iterator& it) const
+    {
+        return it < *this;
+    }
+    bool
+    operator<=(const permutation_iterator& it) const
+    {
+        return !(*this > it);
+    }
+    bool
+    operator>=(const permutation_iterator& it) const
+    {
+        return !(*this < it);
+    }
+
+    friend auto
+    is_onedpl_indirectly_device_accessible(permutation_iterator)
+        -> std::conjunction<__onedpl::is_indirectly_device_accessible<SourceIterator>,
+                            __onedpl::is_indirectly_device_accessible<permutation_iterator::IndexMap>>
+    {
+        return {}; //minimal body provided to avoid warnings of non-template-friend in g++
+    }
+
+  private:
+    SourceIterator my_source_it;
+    IndexMap my_index;
+};
+
+template <typename SourceIterator, typename IndexMap, typename... StartIndex>
+permutation_iterator<SourceIterator, IndexMap>
+make_permutation_iterator(SourceIterator source, IndexMap map, StartIndex... idx)
+{
+    return permutation_iterator<SourceIterator, IndexMap>(source, map, idx...);
+}
+
+namespace internal
+{
+// Copyable implementation of ignore to allow creation of temporary buffers using the type.
+struct ignore_copyable
+{
+    template <typename T>
+    ignore_copyable&
+    operator=(T&&)
+    {
+        return *this;
+    }
+
+    template <typename T>
+    const ignore_copyable&
+    operator=(T&&) const
+    {
+        return *this;
+    }
+
+    bool
+    operator==(const ignore_copyable&) const
+    {
+        return true;
+    }
+
+    bool
+    operator!=(const ignore_copyable& other) const
+    {
+        return !(*this == other);
+    }
+};
+
+inline constexpr ignore_copyable ignore{};
+} // namespace internal
+
+class discard_iterator
+{
+  public:
+    using difference_type = std::ptrdiff_t;
+    using value_type = internal::ignore_copyable;
+    using pointer = void*;
+    using reference = value_type;
+    using iterator_category = std::random_access_iterator_tag;
+    using is_discard = ::std::true_type;
+
+    discard_iterator() : __my_position_() {}
+    explicit discard_iterator(difference_type __init) : __my_position_(__init) {}
+
+    reference operator*() const { return internal::ignore; }
+    reference operator[](difference_type) const { return internal::ignore; }
+
+    // GCC Bug 66297: constexpr non-static member functions of non-literal types
+#if __GNUC__ && _ONEDPL_GCC_VERSION < 70200 && !(__INTEL_COMPILER || __clang__)
+#    define _ONEDPL_CONSTEXPR_FIX
+#else
+#    define _ONEDPL_CONSTEXPR_FIX constexpr
+#endif
+
+    _ONEDPL_CONSTEXPR_FIX difference_type
+    operator-(const discard_iterator& __it) const
+    {
+        return __my_position_ - __it.__my_position_;
+    }
+
+    _ONEDPL_CONSTEXPR_FIX bool
+    operator==(const discard_iterator& __it) const
+    {
+        return __my_position_ == __it.__my_position_;
+    }
+    _ONEDPL_CONSTEXPR_FIX bool
+    operator!=(const discard_iterator& __it) const
+    {
+        return !(*this == __it);
+    }
+#undef _ONEDPL_CONSTEXPR_FIX
+
+    bool
+    operator<(const discard_iterator& __it) const
+    {
+        return *this - __it < 0;
+    }
+    bool
+    operator>(const discard_iterator& __it) const
+    {
+        return __it < *this;
+    }
+
+    discard_iterator&
+    operator++()
+    {
+        return *this += 1;
+    }
+    discard_iterator&
+    operator--()
+    {
+        return *this -= 1;
+    }
+    discard_iterator
+    operator++(int)
+    {
+        discard_iterator __it(*this);
+        ++(*this);
+        return __it;
+    }
+    discard_iterator
+    operator--(int)
+    {
+        discard_iterator __it(*this);
+        --(*this);
+        return __it;
+    }
+    discard_iterator&
+    operator+=(difference_type __forward)
+    {
+        __my_position_ += __forward;
+        return *this;
+    }
+    discard_iterator&
+    operator-=(difference_type __backward)
+    {
+        *this += -__backward;
+        return *this;
+    }
+
+    discard_iterator
+    operator+(difference_type __forward) const
+    {
+        return discard_iterator(__my_position_ + __forward);
+    }
+    discard_iterator
+    operator-(difference_type __backward) const
+    {
+        return discard_iterator(__my_position_ - __backward);
+    }
+    friend discard_iterator
+    operator+(difference_type __forward, const discard_iterator& __it)
+    {
+        return __it + __forward;
+    }
+    bool
+    operator<=(const discard_iterator& __it) const
+    {
+        return !(*this > __it);
+    }
+    bool
+    operator>=(const discard_iterator& __it) const
+    {
+        return !(*this < __it);
+    }
+
+    friend std::true_type
+    is_onedpl_indirectly_device_accessible(discard_iterator)
+    {
+        return {}; //minimal body provided to avoid warnings of non-template-friend in g++
+    }
+
+  private:
+    difference_type __my_position_;
+};
+
+} // namespace std::__onedpl
+
+namespace std::__onedpl
+{
+namespace __internal
+{
+template <typename _T>
+struct __is_reversed_indirectly_device_accessible_it : std::false_type
+{
+};
+
+template <typename _BaseIter>
+struct __is_reversed_indirectly_device_accessible_it<std::reverse_iterator<_BaseIter>>
+    : __onedpl::is_indirectly_device_accessible<_BaseIter>
+{
+};
+
+struct make_zipiterator_functor
+{
+    template <typename... Args>
+    auto
+    operator()(Args&&... args) const -> decltype(__onedpl::make_zip_iterator(::std::forward<Args>(args)...))
+    {
+        return __onedpl::make_zip_iterator(::std::forward<Args>(args)...);
+    }
+};
+
+// The functions are required because
+// after applying a functor to each element of a tuple
+// we may need to get a zip iterator
+
+template <typename F, template <typename...> class TBig, typename... T, typename... RestTuples>
+auto
+map_zip(F f, TBig<T...> in, RestTuples... rest)
+    -> decltype(map_tuple_impl(make_zipiterator_functor{}, ::std::make_index_sequence<sizeof...(T)>(), in, rest...))
+{
+    return map_tuple_impl(make_zipiterator_functor{}, f, ::std::make_index_sequence<sizeof...(T)>(), in, rest...);
+}
+
+} // namespace __internal
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_ITERATOR_IMPL_H
diff --git a/libstdc++-v3/include/pstl/memory_fwd.h b/libstdc++-v3/include/pstl/memory_fwd.h
new file mode 100644
index 000000000000..a4ac25631a71
--- /dev/null
+++ b/libstdc++-v3/include/pstl/memory_fwd.h
@@ -0,0 +1,53 @@
+// -*- C++ -*-
+//===-- memory_fwd.h ------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_MEMORY_FWD_H
+#define _ONEDPL_MEMORY_FWD_H
+
+namespace std::__onedpl
+{
+namespace __internal
+{
+
+template <typename... _ExecutionPolicy>
+struct __op_uninitialized_copy;
+
+template <typename... _ExecutionPolicy>
+struct __op_uninitialized_move;
+
+template <typename _SourceT, typename... _ExecutionPolicy>
+struct __op_uninitialized_fill;
+
+template <typename... _ExecutionPolicy>
+struct __op_destroy;
+
+template <typename... _ExecutionPolicy>
+struct __op_uninitialized_default_construct;
+
+template <typename... _ExecutionPolicy>
+struct __op_uninitialized_value_construct;
+
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Function>
+void
+__pattern_uninitialized_walk1(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Function);
+
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Function>
+_ForwardIterator
+__pattern_uninitialized_walk1_n(_Tag, _ExecutionPolicy&&, _ForwardIterator, _Size, _Function);
+
+} // namespace __internal
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_MEMORY_FWD_H
diff --git a/libstdc++-v3/include/pstl/memory_impl.h b/libstdc++-v3/include/pstl/memory_impl.h
index 080b6cada5bf..db7316dcd1be 100644
--- a/libstdc++-v3/include/pstl/memory_impl.h
+++ b/libstdc++-v3/include/pstl/memory_impl.h
@@ -1,20 +1,29 @@
 // -*- C++ -*-
-//===-- memory_impl.h -----------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_MEMORY_IMPL_H
-#define _PSTL_MEMORY_IMPL_H
+#ifndef _ONEDPL_MEMORY_IMPL_H
+#define _ONEDPL_MEMORY_IMPL_H
 
 #include <iterator>
+#include <type_traits>
 
+#include "memory_fwd.h"
 #include "unseq_backend_simd.h"
+#include "algorithm_fwd.h"
 
-namespace __pstl
+namespace std::__onedpl
 {
 namespace __internal
 {
@@ -26,12 +35,12 @@ namespace __internal
 template <typename _ForwardIterator, typename _OutputIterator>
 _OutputIterator
 __brick_uninitialized_move(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result,
-                           /*vector=*/std::false_type) noexcept
+                           /*vector=*/::std::false_type) noexcept
 {
-    using _ValueType = typename std::iterator_traits<_OutputIterator>::value_type;
-    for (; __first != __last; ++__first, (void) ++__result)
+    using _ValueType = typename ::std::iterator_traits<_OutputIterator>::value_type;
+    for (; __first != __last; ++__first, (void)++__result)
     {
-        ::new (std::addressof(*__result)) _ValueType(std::move(*__first));
+        ::new (::std::addressof(*__result)) _ValueType(::std::move(*__first));
     }
     return __result;
 }
@@ -39,22 +48,22 @@ __brick_uninitialized_move(_ForwardIterator __first, _ForwardIterator __last, _O
 template <typename _RandomAccessIterator, typename _OutputIterator>
 _OutputIterator
 __brick_uninitialized_move(_RandomAccessIterator __first, _RandomAccessIterator __last, _OutputIterator __result,
-                           /*vector=*/std::true_type) noexcept
+                           /*vector=*/::std::true_type) noexcept
 {
-    using __ValueType = typename std::iterator_traits<_OutputIterator>::value_type;
-    using _ReferenceType1 = typename std::iterator_traits<_RandomAccessIterator>::reference;
-    using _ReferenceType2 = typename std::iterator_traits<_OutputIterator>::reference;
+    using __ValueType = typename ::std::iterator_traits<_OutputIterator>::value_type;
+    using _ReferenceType1 = typename ::std::iterator_traits<_RandomAccessIterator>::reference;
+    using _ReferenceType2 = typename ::std::iterator_traits<_OutputIterator>::reference;
 
-    return __unseq_backend::__simd_walk_2(
-        __first, __last - __first, __result,
-        [](_ReferenceType1 __x, _ReferenceType2 __y) { ::new (std::addressof(__y)) __ValueType(std::move(__x)); });
+    return __unseq_backend::__simd_walk_n(__last - __first,
+        [](_ReferenceType1 __x, _ReferenceType2 __y) { ::new (::std::addressof(__y)) __ValueType(::std::move(__x)); },
+        __first, __result);
 }
 
 template <typename _Iterator>
 void
-__brick_destroy(_Iterator __first, _Iterator __last, /*vector*/ std::false_type) noexcept
+__brick_destroy(_Iterator __first, _Iterator __last, /*vector*/ ::std::false_type) noexcept
 {
-    using _ValueType = typename std::iterator_traits<_Iterator>::value_type;
+    using _ValueType = typename ::std::iterator_traits<_Iterator>::value_type;
 
     for (; __first != __last; ++__first)
         __first->~_ValueType();
@@ -62,12 +71,12 @@ __brick_destroy(_Iterator __first, _Iterator __last, /*vector*/ std::false_type)
 
 template <typename _RandomAccessIterator>
 void
-__brick_destroy(_RandomAccessIterator __first, _RandomAccessIterator __last, /*vector*/ std::true_type) noexcept
+__brick_destroy(_RandomAccessIterator __first, _RandomAccessIterator __last, /*vector*/ ::std::true_type) noexcept
 {
-    using _ValueType = typename std::iterator_traits<_RandomAccessIterator>::value_type;
-    using _ReferenceType = typename std::iterator_traits<_RandomAccessIterator>::reference;
+    using _ValueType = typename ::std::iterator_traits<_RandomAccessIterator>::value_type;
+    using _ReferenceType = typename ::std::iterator_traits<_RandomAccessIterator>::reference;
 
-    __unseq_backend::__simd_walk_1(__first, __last - __first, [](_ReferenceType __x) { __x.~_ValueType(); });
+    __unseq_backend::__simd_walk_n(__last - __first, [](_ReferenceType __x) { __x.~_ValueType(); }, __first);
 }
 
 //------------------------------------------------------------------------
@@ -77,12 +86,12 @@ __brick_destroy(_RandomAccessIterator __first, _RandomAccessIterator __last, /*v
 template <typename _ForwardIterator, typename _OutputIterator>
 _OutputIterator
 __brick_uninitialized_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result,
-                           /*vector=*/std::false_type) noexcept
+                           /*vector=*/::std::false_type) noexcept
 {
-    using _ValueType = typename std::iterator_traits<_OutputIterator>::value_type;
-    for (; __first != __last; ++__first, (void) ++__result)
+    using _ValueType = typename ::std::iterator_traits<_OutputIterator>::value_type;
+    for (; __first != __last; ++__first, (void)++__result)
     {
-        ::new (std::addressof(*__result)) _ValueType(*__first);
+        ::new (::std::addressof(*__result)) _ValueType(*__first);
     }
     return __result;
 }
@@ -90,18 +99,132 @@ __brick_uninitialized_copy(_ForwardIterator __first, _ForwardIterator __last, _O
 template <typename _RandomAccessIterator, typename _OutputIterator>
 _OutputIterator
 __brick_uninitialized_copy(_RandomAccessIterator __first, _RandomAccessIterator __last, _OutputIterator __result,
-                           /*vector=*/std::true_type) noexcept
+                           /*vector=*/::std::true_type) noexcept
 {
-    using __ValueType = typename std::iterator_traits<_OutputIterator>::value_type;
-    using _ReferenceType1 = typename std::iterator_traits<_RandomAccessIterator>::reference;
-    using _ReferenceType2 = typename std::iterator_traits<_OutputIterator>::reference;
+    using __ValueType = typename ::std::iterator_traits<_OutputIterator>::value_type;
+    using _ReferenceType1 = typename ::std::iterator_traits<_RandomAccessIterator>::reference;
+    using _ReferenceType2 = typename ::std::iterator_traits<_OutputIterator>::reference;
 
-    return __unseq_backend::__simd_walk_2(
-        __first, __last - __first, __result,
-        [](_ReferenceType1 __x, _ReferenceType2 __y) { ::new (std::addressof(__y)) __ValueType(__x); });
+    return __unseq_backend::__simd_walk_n(__last - __first,
+        [](_ReferenceType1 __x, _ReferenceType2 __y) { ::new (::std::addressof(__y)) __ValueType(__x); },
+        __first, __result);
+}
+
+template <typename _ExecutionPolicy>
+struct __op_uninitialized_copy<_ExecutionPolicy>
+{
+    template <typename _SourceT, typename _TargetT>
+    void
+    operator()(_SourceT&& __source, _TargetT& __target) const
+    {
+        using _TargetValueType = std::decay_t<_TargetT>;
+
+        ::new (std::addressof(__target)) _TargetValueType(std::forward<_SourceT>(__source));
+    }
+};
+
+//------------------------------------------------------------------------
+// uninitialized move
+//------------------------------------------------------------------------
+
+template <typename _ExecutionPolicy>
+struct __op_uninitialized_move<_ExecutionPolicy>
+{
+    template <typename _SourceT, typename _TargetT>
+    void
+    operator()(_SourceT&& __source, _TargetT& __target) const
+    {
+        using _TargetValueType = ::std::decay_t<_TargetT>;
+
+        ::new (::std::addressof(__target)) _TargetValueType(::std::move(__source));
+    }
+};
+
+//------------------------------------------------------------------------
+// uninitialized fill
+//------------------------------------------------------------------------
+
+template <typename _SourceT, typename _ExecutionPolicy>
+struct __op_uninitialized_fill<_SourceT, _ExecutionPolicy>
+{
+    __ref_or_copy<_ExecutionPolicy, const _SourceT> __source;
+
+    template <typename _TargetT>
+    void
+    operator()(_TargetT& __target) const
+    {
+        using _TargetValueType = ::std::decay_t<_TargetT>;
+
+        ::new (::std::addressof(__target)) _TargetValueType(__source);
+    }
+};
+
+//------------------------------------------------------------------------
+// destroy
+//------------------------------------------------------------------------
+
+template <typename _ExecutionPolicy>
+struct __op_destroy<_ExecutionPolicy>
+{
+    template <typename _TargetT>
+    void
+    operator()(_TargetT& __target) const
+    {
+        using _TargetValueType = ::std::decay_t<_TargetT>;
+        __target.~_TargetValueType();
+    }
+};
+
+//------------------------------------------------------------------------
+// uninitialized default_construct
+//------------------------------------------------------------------------
+
+template <typename _ExecutionPolicy>
+struct __op_uninitialized_default_construct<_ExecutionPolicy>
+{
+    template <typename _TargetT>
+    void
+    operator()(_TargetT& __target) const
+    {
+        using _TargetValueType = ::std::decay_t<_TargetT>;
+
+        ::new (::std::addressof(__target)) _TargetValueType;
+    }
+};
+
+//------------------------------------------------------------------------
+// uninitialized value_construct
+//------------------------------------------------------------------------
+
+template <typename _ExecutionPolicy>
+struct __op_uninitialized_value_construct<_ExecutionPolicy>
+{
+    template <typename _TargetT>
+    void
+    operator()(_TargetT& __target) const
+    {
+        using _TargetValueType = ::std::decay_t<_TargetT>;
+
+        ::new (::std::addressof(__target)) _TargetValueType();
+    }
+};
+
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Function>
+void
+__pattern_uninitialized_walk1(_Tag tag, _ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
+                              _Function __f)
+{
+    __pattern_walk1(tag, std::forward<_ExecutionPolicy>(__exec), __first, __last, __f);
+}
+
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Function>
+_ForwardIterator
+__pattern_uninitialized_walk1_n(_Tag tag, _ExecutionPolicy&& __exec, _ForwardIterator __first, _Size __n, _Function __f)
+{
+    return __pattern_walk1_n(tag, std::forward<_ExecutionPolicy>(__exec), __first, __n, __f);
 }
 
 } // namespace __internal
-} // namespace __pstl
+} // namespace std::__onedpl
 
-#endif /* _PSTL_MEMORY_IMPL_H */
+#endif // _ONEDPL_MEMORY_IMPL_H
diff --git a/libstdc++-v3/include/pstl/memory_ranges_impl.h b/libstdc++-v3/include/pstl/memory_ranges_impl.h
new file mode 100644
index 000000000000..b9b2d7fa64c5
--- /dev/null
+++ b/libstdc++-v3/include/pstl/memory_ranges_impl.h
@@ -0,0 +1,278 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_MEMORY_RANGES_IMPL_H
+#define _ONEDPL_MEMORY_RANGES_IMPL_H
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+
+#include <ranges>
+#include <utility>
+#include <cassert>
+#include <functional>
+#include <type_traits>
+
+#include "memory_fwd.h"
+#include "algorithm_fwd.h"
+#include "execution_impl.h"
+
+namespace std::__onedpl
+{
+namespace __internal
+{
+namespace __ranges
+{
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_uninitialized_default_construct
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_uninitialized_default_construct(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    using _ValueType = std::ranges::range_value_t<_R>;
+
+    auto __first = std::ranges::begin(__r);
+    auto __last = __first + std::ranges::size(__r);
+
+    if constexpr (!std::is_trivially_default_constructible_v<_ValueType>)
+    {
+        __onedpl::__internal::__pattern_uninitialized_walk1(
+            __tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
+            __onedpl::__internal::__op_uninitialized_default_construct<std::decay_t<_ExecutionPolicy>>{});
+    }
+
+    return __last;
+}
+
+template <typename _ExecutionPolicy, typename _R>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_uninitialized_default_construct(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r)
+{
+    return std::ranges::uninitialized_default_construct(std::forward<_R>(__r));
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_uninitialized_value_construct
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_uninitialized_value_construct(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    using _ValueType = std::ranges::range_value_t<_R>;
+
+    auto __first = std::ranges::begin(__r);
+    auto __last = __first + std::ranges::size(__r);
+    if constexpr (__onedpl::__internal::__trivial_uninitialized_value_construct<_ValueType>)
+    {
+        __onedpl::__internal::__pattern_fill(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                                _ValueType());
+    }
+    else
+    {
+        __onedpl::__internal::__pattern_uninitialized_walk1(
+            __tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
+            __onedpl::__internal::__op_uninitialized_value_construct<std::decay_t<_ExecutionPolicy>>{});
+    }
+
+    return __last;
+}
+
+template <typename _ExecutionPolicy, typename _R>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_uninitialized_value_construct(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r)
+{
+    return std::ranges::uninitialized_value_construct(std::forward<_R>(__r));
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_uninitialized_copy
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _InRange, typename _OutRange>
+std::ranges::uninitialized_copy_result<std::ranges::borrowed_iterator_t<_InRange>,
+                                       std::ranges::borrowed_iterator_t<_OutRange>>
+__pattern_uninitialized_copy(_Tag __tag, _ExecutionPolicy&& __exec, _InRange&& __in_r, _OutRange&& __out_r)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    using _OutValueType = std::ranges::range_value_t<_OutRange>;
+    using _OutRefType = std::ranges::range_reference_t<_OutRange>;
+    using _InRefType = std::ranges::range_reference_t<_InRange>;
+
+    auto __first1 = std::ranges::begin(__in_r);
+    auto __first2 = std::ranges::begin(__out_r);
+
+    const auto __n = __onedpl::__ranges::__min_size_calc{}(__in_r, __out_r);
+    if (__n == 0)
+        return {__first1, __first2};
+
+    auto __last1 = __first1 + __n;
+    auto __last2 = __first2 + __n;
+
+    if constexpr (__onedpl::__internal::__trivial_uninitialized_copy<_OutValueType, _OutRefType, _InRefType>)
+    {
+        __onedpl::__internal::__pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
+                                                       __first2, __onedpl::__internal::__brick_copy<_Tag>{});
+    }
+    else
+    {
+        __onedpl::__internal::__pattern_walk2(
+            __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2,
+            __onedpl::__internal::__op_uninitialized_copy<std::decay_t<_ExecutionPolicy>>{});
+    }
+
+    return {__last1, __last2};
+}
+
+template <typename _ExecutionPolicy, typename _InRange, typename _OutRange>
+std::ranges::uninitialized_copy_result<std::ranges::borrowed_iterator_t<_InRange>,
+                                       std::ranges::borrowed_iterator_t<_OutRange>>
+__pattern_uninitialized_copy(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _InRange&& __in_r,
+                             _OutRange&& __out_r)
+{
+    return std::ranges::uninitialized_copy(std::forward<_InRange>(__in_r), std::forward<_OutRange>(__out_r));
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_uninitialized_move
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _InRange, typename _OutRange>
+std::ranges::uninitialized_move_result<std::ranges::borrowed_iterator_t<_InRange>,
+                                       std::ranges::borrowed_iterator_t<_OutRange>>
+__pattern_uninitialized_move(_Tag __tag, _ExecutionPolicy&& __exec, _InRange&& __in_r, _OutRange&& __out_r)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    using _OutValueType = std::ranges::range_value_t<_OutRange>;
+    using _OutRefType = std::ranges::range_reference_t<_OutRange>;
+    using _InRefType = std::ranges::range_reference_t<_InRange>;
+
+    auto __first1 = std::ranges::begin(__in_r);
+    auto __first2 = std::ranges::begin(__out_r);
+
+    const auto __n = __onedpl::__ranges::__min_size_calc{}(__in_r, __out_r);
+    if (__n == 0)
+        return {__first1, __first2};
+
+    auto __last1 = __first1 + __n;
+    auto __last2 = __first2 + __n;
+
+    if constexpr (__onedpl::__internal::__trivial_uninitialized_move<_OutValueType, _OutRefType, _InRefType>)
+    {
+        __onedpl::__internal::__pattern_walk2_brick(__tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
+                                                       __first2, __onedpl::__internal::__brick_copy<_Tag>{});
+    }
+    else
+    {
+        __onedpl::__internal::__pattern_walk2(
+            __tag, std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2,
+            __onedpl::__internal::__op_uninitialized_move<std::decay_t<_ExecutionPolicy>>{});
+    }
+
+    return {__last1, __last2};
+}
+
+template <typename _ExecutionPolicy, typename _InRange, typename _OutRange>
+std::ranges::uninitialized_move_result<std::ranges::borrowed_iterator_t<_InRange>,
+                                       std::ranges::borrowed_iterator_t<_OutRange>>
+__pattern_uninitialized_move(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _InRange&& __in_r,
+                             _OutRange&& __out_r)
+{
+    return std::ranges::uninitialized_move(std::forward<_InRange>(__in_r), std::forward<_OutRange>(__out_r));
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// __pattern_uninitialized_fill
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R, typename _T>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_uninitialized_fill(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r, const _T& __value)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    using _ValueType = std::ranges::range_value_t<_R>;
+
+    auto __first = std::ranges::begin(__r);
+    auto __last = __first + std::ranges::size(__r);
+
+    if constexpr (__onedpl::__internal::__trivial_uninitialized_fill<_ValueType, _T>)
+    {
+        __onedpl::__internal::__pattern_fill(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                                _ValueType(__value));
+    }
+    else
+    {
+        __onedpl::__internal::__pattern_uninitialized_walk1(
+            __tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
+            __onedpl::__internal::__op_uninitialized_fill<_T, std::decay_t<_ExecutionPolicy>>{__value});
+    }
+
+    return __last;
+}
+
+template <typename _ExecutionPolicy, typename _R, typename _T>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_uninitialized_fill(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r,
+                             const _T& __value)
+{
+    return std::ranges::uninitialized_fill(std::forward<_R>(__r), __value);
+}
+
+//---------------------------------------------------------------------------------------------------------------------
+// pattern_destroy
+//---------------------------------------------------------------------------------------------------------------------
+
+template <typename _Tag, typename _ExecutionPolicy, typename _R>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_destroy(_Tag __tag, _ExecutionPolicy&& __exec, _R&& __r)
+{
+    static_assert(__is_parallel_tag_v<_Tag> || typename _Tag::__is_vector{});
+
+    using _ValueType = std::ranges::range_value_t<_R>;
+
+    auto __first = std::ranges::begin(__r);
+    auto __last = __first + std::ranges::size(__r);
+
+    if constexpr (!std::is_trivially_destructible_v<_ValueType>)
+    {
+        __onedpl::__internal::__pattern_walk1(
+            __tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
+            __onedpl::__internal::__op_destroy<std::decay_t<_ExecutionPolicy>>{});
+    }
+    return __last;
+}
+
+template <typename _ExecutionPolicy, typename _R>
+std::ranges::borrowed_iterator_t<_R>
+__pattern_destroy(__serial_tag</*IsVector*/ std::false_type>, _ExecutionPolicy&&, _R&& __r)
+{
+    return std::ranges::destroy(std::forward<_R>(__r));
+}
+
+} // namespace __ranges
+} // namespace __internal
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_CPP20_RANGES_PRESENT
+#endif // _ONEDPL_MEMORY_RANGES_IMPL_H
diff --git a/libstdc++-v3/include/pstl/numeric_fwd.h b/libstdc++-v3/include/pstl/numeric_fwd.h
index e98e3b1e12b8..a552f5b2b778 100644
--- a/libstdc++-v3/include/pstl/numeric_fwd.h
+++ b/libstdc++-v3/include/pstl/numeric_fwd.h
@@ -1,19 +1,25 @@
 // -*- C++ -*-
-//===-- numeric_fwd.h --------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_NUMERIC_FWD_H
-#define _PSTL_NUMERIC_FWD_H
+#ifndef _ONEDPL_NUMERIC_FWD_H
+#define _ONEDPL_NUMERIC_FWD_H
 
 #include <type_traits>
 #include <utility>
 
-namespace __pstl
+namespace std::__onedpl
 {
 namespace __internal
 {
@@ -26,12 +32,12 @@ template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _Tp,
           class _BinaryOperation2>
 _Tp __brick_transform_reduce(_RandomAccessIterator1, _RandomAccessIterator1, _RandomAccessIterator2, _Tp,
                              _BinaryOperation1, _BinaryOperation2,
-                             /*__is_vector=*/std::true_type) noexcept;
+                             /*__is_vector=*/::std::true_type) noexcept;
 
 template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation1, class _BinaryOperation2>
 _Tp __brick_transform_reduce(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _Tp, _BinaryOperation1,
                              _BinaryOperation2,
-                             /*__is_vector=*/std::false_type) noexcept;
+                             /*__is_vector=*/::std::false_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp,
           class _BinaryOperation1, class _BinaryOperation2>
@@ -51,11 +57,23 @@ __pattern_transform_reduce(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _Rando
 
 template <class _RandomAccessIterator, class _Tp, class _UnaryOperation, class _BinaryOperation>
 _Tp __brick_transform_reduce(_RandomAccessIterator, _RandomAccessIterator, _Tp, _BinaryOperation, _UnaryOperation,
-                             /*is_vector=*/std::true_type) noexcept;
+                             /*is_vector=*/::std::true_type) noexcept;
 
 template <class _ForwardIterator, class _Tp, class _BinaryOperation, class _UnaryOperation>
 _Tp __brick_transform_reduce(_ForwardIterator, _ForwardIterator, _Tp, _BinaryOperation, _UnaryOperation,
-                             /*is_vector=*/std::false_type) noexcept;
+                             /*is_vector=*/::std::false_type) noexcept;
+
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp,
+          class _BinaryOperation1, class _BinaryOperation2>
+_Tp
+__pattern_transform_reduce(_Tag, _ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _Tp,
+                           _BinaryOperation1, _BinaryOperation2 __bnary_op2) noexcept;
+
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
+          class _Tp, class _BinaryOperation1, class _BinaryOperation2>
+_Tp
+__pattern_transform_reduce(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1,
+                           _RandomAccessIterator1, _RandomAccessIterator2, _Tp, _BinaryOperation1, _BinaryOperation2);
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _Tp, class _BinaryOperation,
           class _UnaryOperation>
@@ -76,14 +94,14 @@ __pattern_transform_reduce(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _Rando
 //------------------------------------------------------------------------
 
 template <class _ForwardIterator, class _OutputIterator, class _UnaryOperation, class _Tp, class _BinaryOperation>
-std::pair<_OutputIterator, _Tp> __brick_transform_scan(_ForwardIterator, _ForwardIterator, _OutputIterator,
-                                                       _UnaryOperation, _Tp, _BinaryOperation,
-                                                       /*Inclusive*/ std::false_type) noexcept;
+::std::pair<_OutputIterator, _Tp> __brick_transform_scan(_ForwardIterator, _ForwardIterator, _OutputIterator,
+                                                         _UnaryOperation, _Tp, _BinaryOperation,
+                                                         /*Inclusive*/ ::std::false_type) noexcept;
 
 template <class _RandomAccessIterator, class _OutputIterator, class _UnaryOperation, class _Tp, class _BinaryOperation>
-std::pair<_OutputIterator, _Tp> __brick_transform_scan(_RandomAccessIterator, _RandomAccessIterator, _OutputIterator,
-                                                       _UnaryOperation, _Tp, _BinaryOperation,
-                                                       /*Inclusive*/ std::true_type) noexcept;
+::std::pair<_OutputIterator, _Tp> __brick_transform_scan(_RandomAccessIterator, _RandomAccessIterator, _OutputIterator,
+                                                         _UnaryOperation, _Tp, _BinaryOperation,
+                                                         /*Inclusive*/ ::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator, class _UnaryOperation,
           class _Tp, class _BinaryOperation, class _Inclusive>
@@ -93,40 +111,47 @@ __pattern_transform_scan(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIte
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator,
           class _UnaryOperation, class _Tp, class _BinaryOperation, class _Inclusive>
-typename std::enable_if<!std::is_floating_point<_Tp>::value, _OutputIterator>::type
-__pattern_transform_scan(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&&, _RandomAccessIterator,
-                         _RandomAccessIterator, _OutputIterator, _UnaryOperation, _Tp, _BinaryOperation, _Inclusive);
+::std::enable_if_t<!::std::is_floating_point_v<_Tp>, _OutputIterator>
+__pattern_transform_scan(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
+                         _OutputIterator, _UnaryOperation, _Tp, _BinaryOperation, _Inclusive);
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator,
           class _UnaryOperation, class _Tp, class _BinaryOperation, class _Inclusive>
-typename std::enable_if<std::is_floating_point<_Tp>::value, _OutputIterator>::type
+::std::enable_if_t<::std::is_floating_point_v<_Tp>, _OutputIterator>
 __pattern_transform_scan(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator, _RandomAccessIterator,
                          _OutputIterator, _UnaryOperation, _Tp, _BinaryOperation, _Inclusive);
 
+// transform_scan without initial element
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator, class _UnaryOperation,
+          class _BinaryOperation, class _Inclusive>
+_OutputIterator
+__pattern_transform_scan(_Tag, _ExecutionPolicy&& __exec, _ForwardIterator, _ForwardIterator, _OutputIterator,
+                         _UnaryOperation, _BinaryOperation, _Inclusive);
+
 //------------------------------------------------------------------------
 // adjacent_difference
 //------------------------------------------------------------------------
 
 template <class _ForwardIterator, class _OutputIterator, class _BinaryOperation>
 _OutputIterator __brick_adjacent_difference(_ForwardIterator, _ForwardIterator, _OutputIterator, _BinaryOperation,
-                                            /*is_vector*/ std::false_type) noexcept;
+                                            /*is_vector*/ ::std::false_type) noexcept;
 
 template <class _RandomAccessIterator, class _OutputIterator, class _BinaryOperation>
 _OutputIterator __brick_adjacent_difference(_RandomAccessIterator, _RandomAccessIterator, _OutputIterator,
                                             _BinaryOperation,
-                                            /*is_vector*/ std::true_type) noexcept;
+                                            /*is_vector*/ ::std::true_type) noexcept;
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator, class _BinaryOperation>
 _OutputIterator
 __pattern_adjacent_difference(_Tag, _ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _OutputIterator,
                               _BinaryOperation) noexcept;
 
-template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator,
+template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
           class _BinaryOperation>
-_OutputIterator
-__pattern_adjacent_difference(_ExecutionPolicy&&, _OutputIterator, _OutputIterator, _OutputIterator, _BinaryOperation,
-                              _IsVector, /*is_parallel*/ std::true_type);
+_RandomAccessIterator2
+__pattern_adjacent_difference(__parallel_tag<_IsVector>, _ExecutionPolicy&&, _RandomAccessIterator1,
+                              _RandomAccessIterator1, _RandomAccessIterator2, _BinaryOperation);
 
 } // namespace __internal
-} // namespace __pstl
-#endif /* _PSTL_NUMERIC_FWD_H */
+} // namespace std::__onedpl
+#endif // _ONEDPL_NUMERIC_FWD_H
diff --git a/libstdc++-v3/include/pstl/numeric_impl.h b/libstdc++-v3/include/pstl/numeric_impl.h
index af6f6a2c8d57..a8dddb771f44 100644
--- a/libstdc++-v3/include/pstl/numeric_impl.h
+++ b/libstdc++-v3/include/pstl/numeric_impl.h
@@ -1,26 +1,33 @@
 // -*- C++ -*-
-//===-- numeric_impl.h ----------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_NUMERIC_IMPL_H
-#define _PSTL_NUMERIC_IMPL_H
+#ifndef _ONEDPL_NUMERIC_IMPL_H
+#define _ONEDPL_NUMERIC_IMPL_H
 
+#include <cassert>
 #include <iterator>
 #include <type_traits>
 #include <numeric>
 
-#include "parallel_backend.h"
-#include "pstl_config.h"
 #include "execution_impl.h"
 #include "unseq_backend_simd.h"
 #include "algorithm_fwd.h"
 
-namespace __pstl
+#include "parallel_backend.h"
+
+namespace std::__onedpl
 {
 namespace __internal
 {
@@ -33,9 +40,9 @@ template <class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _Bi
 _Tp
 __brick_transform_reduce(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _Tp __init,
                          _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2,
-                         /*is_vector=*/std::false_type) noexcept
+                         /*is_vector=*/::std::false_type) noexcept
 {
-    return std::inner_product(__first1, __last1, __first2, std::move(__init), __binary_op1, __binary_op2);
+    return ::std::inner_product(__first1, __last1, __first2, std::move(__init), __binary_op1, __binary_op2);
 }
 
 template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _Tp, class _BinaryOperation1,
@@ -44,9 +51,9 @@ _Tp
 __brick_transform_reduce(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
                          _RandomAccessIterator2 __first2, _Tp __init, _BinaryOperation1 __binary_op1,
                          _BinaryOperation2 __binary_op2,
-                         /*is_vector=*/std::true_type) noexcept
+                         /*is_vector=*/::std::true_type) noexcept
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type _DifferenceType;
+    using _DifferenceType = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
     return __unseq_backend::__simd_transform_reduce(
         __last1 - __first1, std::move(__init), __binary_op1,
         [=, &__binary_op2](_DifferenceType __i) { return __binary_op2(__first1[__i], __first2[__i]); });
@@ -59,6 +66,8 @@ __pattern_transform_reduce(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1,
                            _ForwardIterator2 __first2, _Tp __init, _BinaryOperation1 __binary_op1,
                            _BinaryOperation2 __binary_op2) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __brick_transform_reduce(__first1, __last1, __first2, std::move(__init), __binary_op1, __binary_op2,
                                     typename _Tag::__is_vector{});
 }
@@ -66,28 +75,26 @@ __pattern_transform_reduce(_Tag, _ExecutionPolicy&&, _ForwardIterator1 __first1,
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
           class _Tp, class _BinaryOperation1, class _BinaryOperation2>
 _Tp
-__pattern_transform_reduce(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
+__pattern_transform_reduce(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1,
                            _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _Tp __init,
                            _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    return __internal::__except_handler(
-        [&]()
-        {
-            return __par_backend::__parallel_transform_reduce(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
-                [__first1, __first2, __binary_op2](_RandomAccessIterator1 __i) mutable
-                { return __binary_op2(*__i, *(__first2 + (__i - __first1))); },
-                std::move(__init),
-                __binary_op1, // Combine
-                [__first1, __first2, __binary_op1, __binary_op2](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j,
-                                                                 _Tp __init) -> _Tp
-                {
-                    return __internal::__brick_transform_reduce(__i, __j, __first2 + (__i - __first1), std::move(__init),
-                                                                __binary_op1, __binary_op2, _IsVector{});
-                });
-        });
+    return __internal::__except_handler([&]() {
+        return __par_backend::__parallel_transform_reduce(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
+            [__first1, __first2, __binary_op2](_RandomAccessIterator1 __i) mutable {
+                return __binary_op2(*__i, *(__first2 + (__i - __first1)));
+            },
+            std::move(__init),
+            __binary_op1, // Combine
+            [__first1, __first2, __binary_op1, __binary_op2](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j,
+                                                             _Tp __init_) -> _Tp {
+                return __internal::__brick_transform_reduce(__i, __j, __first2 + (__i - __first1), std::move(__init_),
+                                                            __binary_op1, __binary_op2, _IsVector{});
+            });
+    });
 }
 
 //------------------------------------------------------------------------
@@ -97,18 +104,22 @@ __pattern_transform_reduce(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& _
 template <class _ForwardIterator, class _Tp, class _BinaryOperation, class _UnaryOperation>
 _Tp
 __brick_transform_reduce(_ForwardIterator __first, _ForwardIterator __last, _Tp __init, _BinaryOperation __binary_op,
-                         _UnaryOperation __unary_op, /*is_vector=*/std::false_type) noexcept
+                         _UnaryOperation __unary_op, /*is_vector=*/::std::false_type) noexcept
 {
-    return std::transform_reduce(__first, __last, std::move(__init), __binary_op, __unary_op);
+    for (; __first != __last; ++__first)
+    {
+        __init = __binary_op(std::move(__init), __unary_op(*__first));
+    }
+    return __init;
 }
 
 template <class _RandomAccessIterator, class _Tp, class _UnaryOperation, class _BinaryOperation>
 _Tp
 __brick_transform_reduce(_RandomAccessIterator __first, _RandomAccessIterator __last, _Tp __init,
                          _BinaryOperation __binary_op, _UnaryOperation __unary_op,
-                         /*is_vector=*/std::true_type) noexcept
+                         /*is_vector=*/::std::true_type) noexcept
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type _DifferenceType;
+    using _DifferenceType = typename std::iterator_traits<_RandomAccessIterator>::difference_type;
     return __unseq_backend::__simd_transform_reduce(
         __last - __first, std::move(__init), __binary_op,
         [=, &__unary_op](_DifferenceType __i) { return __unary_op(__first[__i]); });
@@ -120,6 +131,8 @@ _Tp
 __pattern_transform_reduce(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, _Tp __init,
                            _BinaryOperation __binary_op, _UnaryOperation __unary_op) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_transform_reduce(__first, __last, std::move(__init), __binary_op, __unary_op,
                                                 typename _Tag::__is_vector{});
 }
@@ -127,22 +140,22 @@ __pattern_transform_reduce(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _Tp, class _BinaryOperation,
           class _UnaryOperation>
 _Tp
-__pattern_transform_reduce(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+__pattern_transform_reduce(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                            _RandomAccessIterator __last, _Tp __init, _BinaryOperation __binary_op,
                            _UnaryOperation __unary_op)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    return __internal::__except_handler(
-        [&]()
-        {
-            return __par_backend::__parallel_transform_reduce(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                [__unary_op](_RandomAccessIterator __i) mutable { return __unary_op(*__i); }, std::move(__init), __binary_op,
-                [__unary_op, __binary_op](_RandomAccessIterator __i, _RandomAccessIterator __j, _Tp __init) {
-                    return __internal::__brick_transform_reduce(__i, __j, std::move(__init), __binary_op, __unary_op, _IsVector{});
-                });
-        });
+    return __internal::__except_handler([&]() {
+        return __par_backend::__parallel_transform_reduce(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+            [__unary_op](_RandomAccessIterator __i) mutable { return __unary_op(*__i); }, std::move(__init),
+            __binary_op,
+            [__unary_op, __binary_op](_RandomAccessIterator __i, _RandomAccessIterator __j, _Tp __init_) {
+                return __internal::__brick_transform_reduce(__i, __j, std::move(__init_), __binary_op, __unary_op,
+                                                            _IsVector{});
+            });
+    });
 }
 
 //------------------------------------------------------------------------
@@ -153,70 +166,74 @@ __pattern_transform_reduce(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& _
 
 // Exclusive form
 template <class _ForwardIterator, class _OutputIterator, class _UnaryOperation, class _Tp, class _BinaryOperation>
-std::pair<_OutputIterator, _Tp>
+::std::pair<_OutputIterator, _Tp>
 __brick_transform_scan(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result,
                        _UnaryOperation __unary_op, _Tp __init, _BinaryOperation __binary_op,
-                       /*Inclusive*/ std::false_type, /*is_vector=*/std::false_type) noexcept
+                       /*Inclusive*/ ::std::false_type, /*is_vector=*/::std::false_type) noexcept
 {
-    for (; __first != __last; ++__first, (void) ++__result)
+    for (; __first != __last; ++__first, (void)++__result)
     {
-	_Tp __v = std::move(__init);
-        _PSTL_PRAGMA_FORCEINLINE
-        __init = __binary_op(__v, __unary_op(*__first));
-        *__result = std::move(__v);
+        // Copy the value pointed to by __first to avoid overwriting it when __result == __first
+        _Tp __temp = *__first;
+        *__result = __init;
+        _ONEDPL_PRAGMA_FORCEINLINE
+        __init = __binary_op(__init, __unary_op(__temp));
     }
-    return std::make_pair(__result, std::move(__init));
+    return ::std::make_pair(__result, __init);
 }
 
 // Inclusive form
 template <class _RandomAccessIterator, class _OutputIterator, class _UnaryOperation, class _Tp, class _BinaryOperation>
-std::pair<_OutputIterator, _Tp>
+::std::pair<_OutputIterator, _Tp>
 __brick_transform_scan(_RandomAccessIterator __first, _RandomAccessIterator __last, _OutputIterator __result,
                        _UnaryOperation __unary_op, _Tp __init, _BinaryOperation __binary_op,
-                       /*Inclusive*/ std::true_type, /*is_vector=*/std::false_type) noexcept
+                       /*Inclusive*/ ::std::true_type, /*is_vector=*/::std::false_type) noexcept
 {
-    for (; __first != __last; ++__first, (void) ++__result)
+    for (; __first != __last; ++__first, (void)++__result)
     {
-        _PSTL_PRAGMA_FORCEINLINE
+        _ONEDPL_PRAGMA_FORCEINLINE
         __init = __binary_op(__init, __unary_op(*__first));
         *__result = __init;
     }
-    return std::make_pair(__result, std::move(__init));
+    return ::std::make_pair(__result, __init);
 }
 
 // type is arithmetic and binary operation is a user defined operation.
 template <typename _Tp, typename _BinaryOperation>
-using is_arithmetic_udop = std::integral_constant<bool, std::is_arithmetic<_Tp>::value &&
-                                                            !std::is_same<_BinaryOperation, std::plus<_Tp>>::value>;
+using is_arithmetic_udop = ::std::integral_constant<bool, ::std::is_arithmetic_v<_Tp> &&
+                                                              !::std::is_same_v<_BinaryOperation, ::std::plus<_Tp>> &&
+                                                              !::std::is_same_v<_BinaryOperation, ::std::plus<void>>>;
 
 // [restriction] - T shall be DefaultConstructible.
 // [violation] - default ctor of T shall set the identity value for binary_op.
 template <class _RandomAccessIterator, class _OutputIterator, class _UnaryOperation, class _Tp, class _BinaryOperation,
           class _Inclusive>
-typename std::enable_if<!is_arithmetic_udop<_Tp, _BinaryOperation>::value, std::pair<_OutputIterator, _Tp>>::type
+::std::enable_if_t<!is_arithmetic_udop<_Tp, _BinaryOperation>::value, ::std::pair<_OutputIterator, _Tp>>
 __brick_transform_scan(_RandomAccessIterator __first, _RandomAccessIterator __last, _OutputIterator __result,
                        _UnaryOperation __unary_op, _Tp __init, _BinaryOperation __binary_op, _Inclusive,
-                       /*is_vector=*/std::true_type) noexcept
+                       /*is_vector=*/::std::true_type) noexcept
 {
-#if defined(_PSTL_UDS_PRESENT)
-    return __unseq_backend::__simd_scan(__first, __last - __first, __result, __unary_op, std::move(__init), __binary_op,
-                                        _Inclusive());
-#else
-    // We need to call serial brick here to call function for inclusive and exclusive scan that depends on _Inclusive() value
-    return __internal::__brick_transform_scan(__first, __last, __result, __unary_op, std::move(__init), __binary_op, _Inclusive(),
-                                              /*is_vector=*/std::false_type());
+#if _ONEDPL_UDS_PRESENT // PSTL_UDS_PRESENT
+    if (_Inclusive() || !__onedpl::__internal::__iterators_possibly_equal(__first, __result))
+    {
+        return __unseq_backend::__simd_scan(__first, __last - __first, __result, __unary_op, __init, __binary_op,
+                                            _Inclusive());
+    }
 #endif
+    // We need to call serial brick here to call function for inclusive and exclusive scan that depends on _Inclusive() value
+    return __internal::__brick_transform_scan(__first, __last, __result, __unary_op, __init, __binary_op, _Inclusive(),
+                                              /*is_vector=*/::std::false_type());
 }
 
 template <class _RandomAccessIterator, class _OutputIterator, class _UnaryOperation, class _Tp, class _BinaryOperation,
           class _Inclusive>
-typename std::enable_if<is_arithmetic_udop<_Tp, _BinaryOperation>::value, std::pair<_OutputIterator, _Tp>>::type
+::std::enable_if_t<is_arithmetic_udop<_Tp, _BinaryOperation>::value, ::std::pair<_OutputIterator, _Tp>>
 __brick_transform_scan(_RandomAccessIterator __first, _RandomAccessIterator __last, _OutputIterator __result,
                        _UnaryOperation __unary_op, _Tp __init, _BinaryOperation __binary_op, _Inclusive,
-                       /*is_vector=*/std::true_type) noexcept
+                       /*is_vector=*/::std::true_type) noexcept
 {
-    return __internal::__brick_transform_scan(__first, __last, __result, __unary_op, std::move(__init), __binary_op, _Inclusive(),
-                                              /*is_vector=*/std::false_type());
+    return __internal::__brick_transform_scan(__first, __last, __result, __unary_op, __init, __binary_op, _Inclusive(),
+                                              /*is_vector=*/::std::false_type());
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator, class _UnaryOperation,
@@ -226,87 +243,105 @@ __pattern_transform_scan(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _Fo
                          _OutputIterator __result, _UnaryOperation __unary_op, _Tp __init, _BinaryOperation __binary_op,
                          _Inclusive) noexcept
 {
-    return __internal::__brick_transform_scan(__first, __last, __result, __unary_op, std::move(__init), __binary_op, _Inclusive(),
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
+    return __internal::__brick_transform_scan(__first, __last, __result, __unary_op, __init, __binary_op, _Inclusive(),
                                               typename _Tag::__is_vector{})
         .first;
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator,
           class _UnaryOperation, class _Tp, class _BinaryOperation, class _Inclusive>
-typename std::enable_if<!std::is_floating_point<_Tp>::value, _OutputIterator>::type
-__pattern_transform_scan(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+::std::enable_if_t<!::std::is_floating_point_v<_Tp>, _OutputIterator>
+__pattern_transform_scan(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                          _RandomAccessIterator __last, _OutputIterator __result, _UnaryOperation __unary_op, _Tp __init,
                          _BinaryOperation __binary_op, _Inclusive)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type _DifferenceType;
+    using _DifferenceType = typename std::iterator_traits<_RandomAccessIterator>::difference_type;
 
-    return __internal::__except_handler(
-        [&]()
-        {
-            __par_backend::__parallel_transform_scan(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __last - __first,
-                [__first, __unary_op](_DifferenceType __i) mutable { return __unary_op(__first[__i]); }, std::move(__init),
-                __binary_op,
-                [__first, __unary_op, __binary_op](_DifferenceType __i, _DifferenceType __j, _Tp __init)
-                {
-                    // Execute serial __brick_transform_reduce, due to the explicit SIMD vectorization (reduction) requires a commutative operation for the guarantee of correct scan.
-                    return __internal::__brick_transform_reduce(__first + __i, __first + __j, std::move(__init), __binary_op,
-                                                                __unary_op,
-                                                                /*__is_vector*/ std::false_type());
-                },
-                [__first, __unary_op, __binary_op, __result](_DifferenceType __i, _DifferenceType __j, _Tp __init)
-                {
-                    return __internal::__brick_transform_scan(__first + __i, __first + __j, __result + __i, __unary_op,
-                                                              std::move(__init), __binary_op, _Inclusive(), _IsVector{})
-                        .second;
-                });
-            return __result + (__last - __first);
-        });
+    return __internal::__except_handler([&]() {
+        __par_backend::__parallel_transform_scan(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __last - __first,
+            [__first, __unary_op](_DifferenceType __i) mutable { return __unary_op(__first[__i]); }, __init,
+            __binary_op,
+            [__first, __unary_op, __binary_op](_DifferenceType __i, _DifferenceType __j, _Tp __init) {
+                // Execute serial __brick_transform_reduce, due to the explicit SIMD vectorization (reduction) requires a commutative operation for the guarantee of correct scan.
+                return __internal::__brick_transform_reduce(__first + __i, __first + __j, __init, __binary_op,
+                                                            __unary_op,
+                                                            /*__is_vector*/ ::std::false_type());
+            },
+            [__first, __unary_op, __binary_op, __result](_DifferenceType __i, _DifferenceType __j, _Tp __init) {
+                return __internal::__brick_transform_scan(__first + __i, __first + __j, __result + __i, __unary_op,
+                                                          __init, __binary_op, _Inclusive(), _IsVector{})
+                    .second;
+            });
+        return __result + (__last - __first);
+    });
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator,
           class _UnaryOperation, class _Tp, class _BinaryOperation, class _Inclusive>
-typename std::enable_if<std::is_floating_point<_Tp>::value, _OutputIterator>::type
-__pattern_transform_scan(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
+::std::enable_if_t<::std::is_floating_point_v<_Tp>, _OutputIterator>
+__pattern_transform_scan(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator __first,
                          _RandomAccessIterator __last, _OutputIterator __result, _UnaryOperation __unary_op, _Tp __init,
                          _BinaryOperation __binary_op, _Inclusive)
 {
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type _DifferenceType;
+    using _DifferenceType = typename std::iterator_traits<_RandomAccessIterator>::difference_type;
     _DifferenceType __n = __last - __first;
 
     if (__n <= 0)
     {
         return __result;
     }
-    return __internal::__except_handler(
-        [&]()
-        {
-            __par_backend::__parallel_strict_scan(
-                __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __n, std::move(__init),
-                [__first, __unary_op, __binary_op, __result](_DifferenceType __i, _DifferenceType __len)
-                {
-                    return __internal::__brick_transform_scan(__first + __i, __first + (__i + __len), __result + __i,
-                                                              __unary_op, _Tp{}, __binary_op, _Inclusive(), _IsVector{})
-                        .second;
-                },
-                __binary_op,
-                [__result, &__binary_op](_DifferenceType __i, _DifferenceType __len, _Tp __initial)
-                {
-                    return *(std::transform(__result + __i, __result + __i + __len, __result + __i,
-                                            [&__initial, &__binary_op](const _Tp& __x)
-                                            {
-                                                _PSTL_PRAGMA_FORCEINLINE
-                                                return __binary_op(__initial, __x);
-                                            }) -
-                             1);
-                },
-                [](_Tp) {});
-            return __result + (__last - __first);
-        });
+
+    return __internal::__except_handler([&]() {
+        __par_backend::__parallel_strict_scan(
+            __backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __n, __init,
+            [__first, __unary_op, __binary_op, __result](_DifferenceType __i, _DifferenceType __len) {
+                return __internal::__brick_transform_scan(__first + __i, __first + (__i + __len), __result + __i,
+                                                          __unary_op, _Tp{}, __binary_op, _Inclusive(), _IsVector{})
+                    .second;
+            },
+            __binary_op,
+            [__result, &__binary_op](_DifferenceType __i, _DifferenceType __len, _Tp __initial) {
+                return *(::std::transform(__result + __i, __result + __i + __len, __result + __i,
+                                          [&__initial, &__binary_op](const _Tp& __x) {
+                                              _ONEDPL_PRAGMA_FORCEINLINE
+                                              return __binary_op(__initial, __x);
+                                          }) -
+                         1);
+            },
+            [](_Tp) {});
+        return __result + (__last - __first);
+    });
+}
+
+// transform_scan without initial element
+template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator, class _UnaryOperation,
+          class _BinaryOperation, class _Inclusive>
+_OutputIterator
+__pattern_transform_scan(_Tag __tag, _ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
+                         _OutputIterator __result, _UnaryOperation __unary_op, _BinaryOperation __binary_op, _Inclusive)
+{
+    static_assert(__is_host_dispatch_tag_v<_Tag>);
+
+    using _ValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
+    if (__first != __last)
+    {
+        _ValueType __tmp = __unary_op(*__first);
+        *__result = __tmp;
+
+        return __pattern_transform_scan(__tag, ::std::forward<_ExecutionPolicy>(__exec), ++__first, __last, ++__result,
+                                        __unary_op, __tmp, __binary_op, _Inclusive());
+    }
+    else
+    {
+        return __result;
+    }
 }
 
 //------------------------------------------------------------------------
@@ -316,27 +351,27 @@ __pattern_transform_scan(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __e
 template <class _ForwardIterator, class _OutputIterator, class _BinaryOperation>
 _OutputIterator
 __brick_adjacent_difference(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __d_first,
-                            _BinaryOperation __op, /*is_vector*/ std::false_type) noexcept
+                            _BinaryOperation __op, /*is_vector*/ ::std::false_type) noexcept
 {
-    return std::adjacent_difference(__first, __last, __d_first, __op);
+    return ::std::adjacent_difference(__first, __last, __d_first, __op);
 }
 
-template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryOperation>
+template <class _RandomAccessIterator1, class _RandomAccessIterator2, class BinaryOperation>
 _RandomAccessIterator2
 __brick_adjacent_difference(_RandomAccessIterator1 __first, _RandomAccessIterator1 __last,
-                            _RandomAccessIterator2 __d_first, _BinaryOperation __op,
-                            /*is_vector=*/std::true_type) noexcept
+                            _RandomAccessIterator2 __d_first, BinaryOperation __op,
+                            /*is_vector=*/::std::true_type) noexcept
 {
-    _PSTL_ASSERT(__first != __last);
+    assert(__first != __last);
 
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::reference _ReferenceType1;
-    typedef typename std::iterator_traits<_RandomAccessIterator2>::reference _ReferenceType2;
+    using _ReferenceType1 = typename std::iterator_traits<_RandomAccessIterator1>::reference;
+    using _ReferenceType2 = typename std::iterator_traits<_RandomAccessIterator2>::reference;
 
     auto __n = __last - __first;
     *__d_first = *__first;
-    return __unseq_backend::__simd_walk_3(
-        __first + 1, __n - 1, __first, __d_first + 1,
-        [&__op](_ReferenceType1 __x, _ReferenceType1 __y, _ReferenceType2 __z) { __z = __op(__x, __y); });
+    return __unseq_backend::__simd_walk_n(__n - 1,
+        [&__op](_ReferenceType1 __x, _ReferenceType1 __y, _ReferenceType2 __z) { __z = __op(__x, __y); },
+        __first + 1, __first, __d_first + 1);
 }
 
 template <class _Tag, class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator, class _BinaryOperation>
@@ -344,37 +379,40 @@ _OutputIterator
 __pattern_adjacent_difference(_Tag, _ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last,
                               _OutputIterator __d_first, _BinaryOperation __op) noexcept
 {
+    static_assert(__is_serial_tag_v<_Tag> || __is_parallel_forward_tag_v<_Tag>);
+
     return __internal::__brick_adjacent_difference(__first, __last, __d_first, __op, typename _Tag::__is_vector{});
 }
 
 template <class _IsVector, class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
           class _BinaryOperation>
 _RandomAccessIterator2
-__pattern_adjacent_difference(__parallel_tag<_IsVector> __tag, _ExecutionPolicy&& __exec,
-                              _RandomAccessIterator1 __first, _RandomAccessIterator1 __last,
-                              _RandomAccessIterator2 __d_first, _BinaryOperation __op)
+__pattern_adjacent_difference(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _RandomAccessIterator1 __first,
+                              _RandomAccessIterator1 __last, _RandomAccessIterator2 __d_first, _BinaryOperation __op)
 {
-    _PSTL_ASSERT(__first != __last);
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::reference _ReferenceType1;
-    typedef typename std::iterator_traits<_RandomAccessIterator2>::reference _ReferenceType2;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
 
-    using __backend_tag = typename decltype(__tag)::__backend_tag;
+    assert(__first != __last);
+    using _ReferenceType1 = typename std::iterator_traits<_RandomAccessIterator1>::reference;
+    using _ReferenceType2 = typename std::iterator_traits<_RandomAccessIterator2>::reference;
 
     *__d_first = *__first;
-    __par_backend::__parallel_for(__backend_tag{}, std::forward<_ExecutionPolicy>(__exec), __first, __last - 1,
-                                  [&__op, __d_first, __first](_RandomAccessIterator1 __b, _RandomAccessIterator1 __e)
-                                  {
-                                      _RandomAccessIterator2 __d_b = __d_first + (__b - __first);
-                                      __internal::__brick_walk3(
-                                          __b, __e, __b + 1, __d_b + 1,
-                                          [&__op](_ReferenceType1 __x, _ReferenceType1 __y, _ReferenceType2 __z)
-                                          { __z = __op(__y, __x); },
-                                          _IsVector{});
-                                  });
-    return __d_first + (__last - __first);
+
+    return __internal::__except_handler([&]() {
+        __par_backend::__parallel_for(
+            __backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last - 1,
+            [&__op, __d_first, __first](_RandomAccessIterator1 __b, _RandomAccessIterator1 __e) {
+                _RandomAccessIterator2 __d_b = __d_first + (__b - __first);
+                __internal::__brick_walk3(
+                    __b, __e, __b + 1, __d_b + 1,
+                    [&__op](_ReferenceType1 __x, _ReferenceType1 __y, _ReferenceType2 __z) { __z = __op(__y, __x); },
+                    _IsVector{});
+            });
+        return __d_first + (__last - __first);
+    });
 }
 
 } // namespace __internal
-} // namespace __pstl
+} // namespace std::__onedpl
 
-#endif /* _PSTL_NUMERIC_IMPL_H */
+#endif // _ONEDPL_NUMERIC_IMPL_H
diff --git a/libstdc++-v3/include/pstl/omp/parallel_for.h b/libstdc++-v3/include/pstl/omp/parallel_for.h
new file mode 100644
index 000000000000..2cd93a27ba35
--- /dev/null
+++ b/libstdc++-v3/include/pstl/omp/parallel_for.h
@@ -0,0 +1,74 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_INTERNAL_OMP_PARALLEL_FOR_H
+#define _ONEDPL_INTERNAL_OMP_PARALLEL_FOR_H
+
+#include <cstddef>
+
+#include "util.h"
+
+namespace std::__onedpl
+{
+namespace __omp_backend
+{
+
+template <class _Index, class _Fp>
+void
+__parallel_for_body(_Index __first, _Index __last, _Fp __f, std::size_t __grainsize)
+{
+    // initial partition of the iteration space into chunks
+    auto __policy =
+        __onedpl::__omp_backend::__chunk_partitioner(__first, __last, omp_get_num_threads(), __grainsize);
+
+    // To avoid over-subscription we use taskloop for the nested parallelism
+    _ONEDPL_PRAGMA(omp taskloop untied mergeable)
+    for (std::size_t __chunk = 0; __chunk < __policy.__n_chunks; ++__chunk)
+    {
+        __onedpl::__omp_backend::__process_chunk(__policy, __first, __chunk, __f);
+    }
+}
+
+//------------------------------------------------------------------------
+// Notation:
+// Evaluation of brick f[i,j) for each subrange [i,j) of [first, last)
+//------------------------------------------------------------------------
+
+template <class _ExecutionPolicy, class _Index, class _Fp>
+void
+__parallel_for(__onedpl::__internal::__omp_backend_tag, _ExecutionPolicy&&, _Index __first, _Index __last, _Fp __f,
+               std::size_t __grainsize = __default_chunk_size)
+{
+    if (omp_in_parallel())
+    {
+        // we don't create a nested parallel region in an existing parallel
+        // region: just create tasks
+        __onedpl::__omp_backend::__parallel_for_body(__first, __last, __f, __grainsize);
+    }
+    else
+    {
+        // in any case (nested or non-nested) one parallel region is created and
+        // only one thread creates a set of tasks
+        _ONEDPL_PRAGMA(omp parallel)
+        _ONEDPL_PRAGMA(omp single nowait)
+        {
+            __onedpl::__omp_backend::__parallel_for_body(__first, __last, __f, __grainsize);
+        }
+    }
+}
+
+} // namespace __omp_backend
+} // namespace std::__onedpl
+#endif // _ONEDPL_INTERNAL_OMP_PARALLEL_FOR_H
diff --git a/libstdc++-v3/include/pstl/omp/parallel_for_each.h b/libstdc++-v3/include/pstl/omp/parallel_for_each.h
new file mode 100644
index 000000000000..b6362bb8b442
--- /dev/null
+++ b/libstdc++-v3/include/pstl/omp/parallel_for_each.h
@@ -0,0 +1,65 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_INTERNAL_OMP_PARALLEL_FOR_EACH_H
+#define _ONEDPL_INTERNAL_OMP_PARALLEL_FOR_EACH_H
+
+#include "util.h"
+
+namespace std::__onedpl
+{
+namespace __omp_backend
+{
+
+template <class _ForwardIterator, class _Fp>
+void
+__parallel_for_each_body(_ForwardIterator __first, _ForwardIterator __last, _Fp __f)
+{
+    using DifferenceType = typename std::iterator_traits<_ForwardIterator>::difference_type;
+    // TODO: Think of an approach to remove the std::distance call
+    auto __size = std::distance(__first, __last);
+
+    _ONEDPL_PRAGMA(omp taskloop untied mergeable)
+    for (DifferenceType __index = 0; __index < __size; ++__index)
+    {
+        // TODO: Think of an approach to remove the increment here each time.
+        auto __iter = std::next(__first, __index);
+        __f(*__iter);
+    }
+}
+
+template <class _ExecutionPolicy, class _ForwardIterator, class _Fp>
+void
+__parallel_for_each(__onedpl::__internal::__omp_backend_tag, _ExecutionPolicy&&, _ForwardIterator __first,
+                    _ForwardIterator __last, _Fp __f)
+{
+    if (omp_in_parallel())
+    {
+        // we don't create a nested parallel region in an existing parallel
+        // region: just create tasks
+        __onedpl::__omp_backend::__parallel_for_each_body(__first, __last, __f);
+    }
+    else
+    {
+        // in any case (nested or non-nested) one parallel region is created and
+        // only one thread creates a set of tasks
+        _ONEDPL_PRAGMA(omp parallel)
+        _ONEDPL_PRAGMA(omp single nowait) { __onedpl::__omp_backend::__parallel_for_each_body(__first, __last, __f); }
+    }
+}
+
+} // namespace __omp_backend
+} // namespace std::__onedpl
+#endif // _ONEDPL_INTERNAL_OMP_PARALLEL_FOR_EACH_H
diff --git a/libstdc++-v3/include/pstl/omp/parallel_invoke.h b/libstdc++-v3/include/pstl/omp/parallel_invoke.h
new file mode 100644
index 000000000000..fddbe9b4a308
--- /dev/null
+++ b/libstdc++-v3/include/pstl/omp/parallel_invoke.h
@@ -0,0 +1,55 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_INTERNAL_OMP_PARALLEL_INVOKE_H
+#define _ONEDPL_INTERNAL_OMP_PARALLEL_INVOKE_H
+
+#include "util.h"
+
+namespace std::__onedpl
+{
+namespace __omp_backend
+{
+
+template <typename _F1, typename _F2>
+void
+__parallel_invoke_body(_F1&& __f1, _F2&& __f2)
+{
+    _ONEDPL_PRAGMA(omp taskgroup)
+    {
+        _ONEDPL_PRAGMA(omp task untied mergeable) { std::forward<_F1>(__f1)(); }
+        _ONEDPL_PRAGMA(omp task untied mergeable) { std::forward<_F2>(__f2)(); }
+    }
+}
+
+template <class _ExecutionPolicy, typename _F1, typename _F2>
+void
+__parallel_invoke(__onedpl::__internal::__omp_backend_tag, _ExecutionPolicy&&, _F1&& __f1, _F2&& __f2)
+{
+    if (omp_in_parallel())
+    {
+        __onedpl::__omp_backend::__parallel_invoke_body(std::forward<_F1>(__f1), std::forward<_F2>(__f2));
+    }
+    else
+    {
+        _ONEDPL_PRAGMA(omp parallel)
+        _ONEDPL_PRAGMA(omp single nowait)
+        __onedpl::__omp_backend::__parallel_invoke_body(std::forward<_F1>(__f1), std::forward<_F2>(__f2));
+    }
+}
+
+} // namespace __omp_backend
+} // namespace std::__onedpl
+#endif // _ONEDPL_INTERNAL_OMP_PARALLEL_INVOKE_H
diff --git a/libstdc++-v3/include/pstl/omp/parallel_merge.h b/libstdc++-v3/include/pstl/omp/parallel_merge.h
new file mode 100644
index 000000000000..4e1e80c610a5
--- /dev/null
+++ b/libstdc++-v3/include/pstl/omp/parallel_merge.h
@@ -0,0 +1,102 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_INTERNAL_OMP_PARALLEL_MERGE_H
+#define _ONEDPL_INTERNAL_OMP_PARALLEL_MERGE_H
+
+#include "util.h"
+
+namespace std::__onedpl
+{
+namespace __omp_backend
+{
+
+template <typename _RandomAccessIterator1, typename _RandomAccessIterator2, typename _RandomAccessIterator3,
+          typename _Compare, typename _LeafMerge>
+void
+__parallel_merge_body(std::size_t __size_x, std::size_t __size_y, _RandomAccessIterator1 __xs,
+                      _RandomAccessIterator1 __xe, _RandomAccessIterator2 __ys, _RandomAccessIterator2 __ye,
+                      _RandomAccessIterator3 __zs, _Compare __comp, _LeafMerge __leaf_merge)
+{
+
+    if (__size_x + __size_y <= __onedpl::__omp_backend::__default_chunk_size)
+    {
+        __leaf_merge(__xs, __xe, __ys, __ye, __zs, __comp);
+        return;
+    }
+
+    _RandomAccessIterator1 __xm;
+    _RandomAccessIterator2 __ym;
+
+    if (__size_x < __size_y)
+    {
+        __ym = __ys + (__size_y / 2);
+        __xm = std::upper_bound(__xs, __xe, *__ym, __comp);
+    }
+    else
+    {
+        __xm = __xs + (__size_x / 2);
+        __ym = std::lower_bound(__ys, __ye, *__xm, __comp);
+    }
+
+    auto __zm = __zs + (__xm - __xs) + (__ym - __ys);
+
+    _ONEDPL_PRAGMA(omp task untied mergeable default(none)
+                     firstprivate(__xs, __xm, __ys, __ym, __zs, __comp, __leaf_merge))
+    __onedpl::__omp_backend::__parallel_merge_body(__xm - __xs, __ym - __ys, __xs, __xm, __ys, __ym, __zs, __comp,
+                                                      __leaf_merge);
+
+    _ONEDPL_PRAGMA(omp task untied mergeable default(none)
+                     firstprivate(__xm, __xe, __ym, __ye, __zm, __comp, __leaf_merge))
+    __onedpl::__omp_backend::__parallel_merge_body(__xe - __xm, __ye - __ym, __xm, __xe, __ym, __ye, __zm, __comp,
+                                                      __leaf_merge);
+
+    _ONEDPL_PRAGMA(omp taskwait)
+}
+
+template <class _ExecutionPolicy, typename _RandomAccessIterator1, typename _RandomAccessIterator2,
+          typename _RandomAccessIterator3, typename _Compare, typename _LeafMerge>
+void
+__parallel_merge(__onedpl::__internal::__omp_backend_tag, _ExecutionPolicy&& /*__exec*/, _RandomAccessIterator1 __xs,
+                 _RandomAccessIterator1 __xe, _RandomAccessIterator2 __ys, _RandomAccessIterator2 __ye,
+                 _RandomAccessIterator3 __zs, _Compare __comp, _LeafMerge __leaf_merge)
+{
+    std::size_t __size_x = __xe - __xs;
+    std::size_t __size_y = __ye - __ys;
+
+    /*
+     * Run the merge in parallel by chunking it up. Use the smaller range (if any) as the iteration range, and the
+     * larger range as the search range.
+     */
+
+    if (omp_in_parallel())
+    {
+        __onedpl::__omp_backend::__parallel_merge_body(__size_x, __size_y, __xs, __xe, __ys, __ye, __zs, __comp,
+                                                          __leaf_merge);
+    }
+    else
+    {
+        _ONEDPL_PRAGMA(omp parallel)
+        {
+            _ONEDPL_PRAGMA(omp single nowait)
+            __onedpl::__omp_backend::__parallel_merge_body(__size_x, __size_y, __xs, __xe, __ys, __ye, __zs, __comp,
+                                                              __leaf_merge);
+        }
+    }
+}
+
+} // namespace __omp_backend
+} // namespace std::__onedpl
+#endif // _ONEDPL_INTERNAL_OMP_PARALLEL_MERGE_H
diff --git a/libstdc++-v3/include/pstl/omp/parallel_reduce.h b/libstdc++-v3/include/pstl/omp/parallel_reduce.h
new file mode 100644
index 000000000000..f7011f58e573
--- /dev/null
+++ b/libstdc++-v3/include/pstl/omp/parallel_reduce.h
@@ -0,0 +1,80 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_INTERNAL_OMP_PARALLEL_REDUCE_H
+#define _ONEDPL_INTERNAL_OMP_PARALLEL_REDUCE_H
+
+#include "util.h"
+
+namespace std::__onedpl
+{
+namespace __omp_backend
+{
+
+template <class _RandomAccessIterator, class _Value, typename _RealBody, typename _Reduction>
+_Value
+__parallel_reduce_body(_RandomAccessIterator __first, _RandomAccessIterator __last, _Value __identity,
+                       _RealBody __real_body, _Reduction __reduce)
+{
+    if (__should_run_serial(__first, __last, __default_chunk_size))
+    {
+        return __real_body(__first, __last, __identity);
+    }
+
+    auto __middle = __first + ((__last - __first) / 2);
+    _Value __v1(__identity), __v2(__identity);
+    __parallel_invoke_body(
+        [&]() { __v1 = __parallel_reduce_body(__first, __middle, __identity, __real_body, __reduce); },
+        [&]() { __v2 = __parallel_reduce_body(__middle, __last, __identity, __real_body, __reduce); });
+
+    return __reduce(__v1, __v2);
+}
+
+//------------------------------------------------------------------------
+// Notation:
+//      r(i,j,init) returns reduction of init with reduction over [i,j)
+//      c(x,y) combines values x and y that were the result of r
+//------------------------------------------------------------------------
+
+template <class _ExecutionPolicy, class _RandomAccessIterator, class _Value, typename _RealBody, typename _Reduction>
+_Value
+__parallel_reduce(__onedpl::__internal::__omp_backend_tag, _ExecutionPolicy&&, _RandomAccessIterator __first,
+                  _RandomAccessIterator __last, _Value __identity, _RealBody __real_body, _Reduction __reduction)
+{
+    // We don't create a nested parallel region in an existing parallel region:
+    // just create tasks.
+    if (omp_in_parallel())
+    {
+        return __onedpl::__omp_backend::__parallel_reduce_body(__first, __last, __identity, __real_body,
+                                                                  __reduction);
+    }
+
+    // In any case (nested or non-nested) one parallel region is created and only
+    // one thread creates a set of tasks.
+    _Value __res = __identity;
+
+    _ONEDPL_PRAGMA(omp parallel)
+    _ONEDPL_PRAGMA(omp single nowait)
+    {
+        __res =
+            __onedpl::__omp_backend::__parallel_reduce_body(__first, __last, __identity, __real_body, __reduction);
+    }
+
+    return __res;
+}
+
+} // namespace __omp_backend
+} // namespace std::__onedpl
+#endif // _ONEDPL_INTERNAL_OMP_PARALLEL_REDUCE_H
diff --git a/libstdc++-v3/include/pstl/omp/parallel_scan.h b/libstdc++-v3/include/pstl/omp/parallel_scan.h
new file mode 100644
index 000000000000..1b312af60d7f
--- /dev/null
+++ b/libstdc++-v3/include/pstl/omp/parallel_scan.h
@@ -0,0 +1,143 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_INTERNAL_OMP_PARALLEL_SCAN_H
+#define _ONEDPL_INTERNAL_OMP_PARALLEL_SCAN_H
+
+#include "parallel_invoke.h"
+
+namespace std::__onedpl
+{
+namespace __omp_backend
+{
+
+template <typename _Index>
+_Index
+__split(_Index __m)
+{
+    _Index __k = 1;
+    while (2 * __k < __m)
+        __k *= 2;
+    return __k;
+}
+
+template <typename _Index, typename _Tp, typename _Rp, typename _Cp>
+void
+__upsweep(_Index __i, _Index __m, _Index __tilesize, _Tp* __r, _Index __lastsize, _Rp __reduce, _Cp __combine)
+{
+    if (__m == 1)
+        __r[0] = __reduce(__i * __tilesize, __lastsize);
+    else
+    {
+        _Index __k = __split(__m);
+        __onedpl::__omp_backend::__parallel_invoke_body(
+            [=] { __onedpl::__omp_backend::__upsweep(__i, __k, __tilesize, __r, __tilesize, __reduce, __combine); },
+            [=] {
+                __onedpl::__omp_backend::__upsweep(__i + __k, __m - __k, __tilesize, __r + __k, __lastsize, __reduce,
+                                                      __combine);
+            });
+        if (__m == 2 * __k)
+            __r[__m - 1] = __combine(__r[__k - 1], __r[__m - 1]);
+    }
+}
+
+template <typename _Index, typename _Tp, typename _Cp, typename _Sp>
+void
+__downsweep(_Index __i, _Index __m, _Index __tilesize, _Tp* __r, _Index __lastsize, _Tp __initial, _Cp __combine,
+            _Sp __scan)
+{
+    if (__m == 1)
+        __scan(__i * __tilesize, __lastsize, __initial);
+    else
+    {
+        const _Index __k = __split(__m);
+        __onedpl::__omp_backend::__parallel_invoke_body(
+            [=] {
+                __onedpl::__omp_backend::__downsweep(__i, __k, __tilesize, __r, __tilesize, __initial, __combine,
+                                                        __scan);
+            },
+            // Assumes that __combine never throws.
+            // TODO: Consider adding a requirement for user functors to be constant.
+            [=, &__combine] {
+                __onedpl::__omp_backend::__downsweep(__i + __k, __m - __k, __tilesize, __r + __k, __lastsize,
+                                                        __combine(__initial, __r[__k - 1]), __combine, __scan);
+            });
+    }
+}
+
+template <typename _Index, typename _Tp, typename _Rp, typename _Cp, typename _Sp, typename _Ap>
+void
+__parallel_strict_scan_body(_Index __n, _Tp __initial, _Rp __reduce, _Cp __combine, _Sp __scan, _Ap __apex)
+{
+    _Index __p = omp_get_num_threads();
+    const _Index __slack = 4;
+    _Index __tilesize = (__n - 1) / (__slack * __p) + 1;
+    _Index __m = (__n - 1) / __tilesize;
+    __buffer<_Tp> __buf(__m + 1);
+    _Tp* __r = __buf.get();
+
+    __onedpl::__omp_backend::__upsweep(_Index(0), _Index(__m + 1), __tilesize, __r, __n - __m * __tilesize, __reduce,
+                                          __combine);
+
+    std::size_t __k = __m + 1;
+    _Tp __t = __r[__k - 1];
+    while ((__k &= __k - 1))
+    {
+        __t = __combine(__r[__k - 1], __t);
+    }
+
+    __apex(__combine(__initial, __t));
+    __onedpl::__omp_backend::__downsweep(_Index(0), _Index(__m + 1), __tilesize, __r, __n - __m * __tilesize,
+                                            __initial, __combine, __scan);
+}
+
+template <class _ExecutionPolicy, typename _Index, typename _Tp, typename _Rp, typename _Cp, typename _Sp, typename _Ap>
+void
+__parallel_strict_scan(__onedpl::__internal::__omp_backend_tag, _ExecutionPolicy&&, _Index __n, _Tp __initial,
+                       _Rp __reduce, _Cp __combine, _Sp __scan, _Ap __apex)
+{
+    if (__n <= __default_chunk_size)
+    {
+        _Tp __sum = __initial;
+        if (__n)
+        {
+            __sum = __combine(__sum, __reduce(_Index(0), __n));
+        }
+        __apex(__sum);
+        if (__n)
+        {
+            __scan(_Index(0), __n, __initial);
+        }
+        return;
+    }
+
+    if (omp_in_parallel())
+    {
+        __onedpl::__omp_backend::__parallel_strict_scan_body(__n, __initial, __reduce, __combine, __scan, __apex);
+    }
+    else
+    {
+        _ONEDPL_PRAGMA(omp parallel)
+        _ONEDPL_PRAGMA(omp single nowait)
+        {
+            __onedpl::__omp_backend::__parallel_strict_scan_body(__n, __initial, __reduce, __combine, __scan,
+                                                                    __apex);
+        }
+    }
+}
+
+} // namespace __omp_backend
+} // namespace std::__onedpl
+#endif // _ONEDPL_INTERNAL_OMP_PARALLEL_SCAN_H
diff --git a/libstdc++-v3/include/pstl/omp/parallel_stable_partial_sort.h b/libstdc++-v3/include/pstl/omp/parallel_stable_partial_sort.h
new file mode 100644
index 000000000000..53cee385f1aa
--- /dev/null
+++ b/libstdc++-v3/include/pstl/omp/parallel_stable_partial_sort.h
@@ -0,0 +1,37 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_INTERNAL_OMP_PARALLEL_STABLE_PARTIAL_SORT_H
+#define _ONEDPL_INTERNAL_OMP_PARALLEL_STABLE_PARTIAL_SORT_H
+
+#include "util.h"
+
+namespace std::__onedpl
+{
+namespace __omp_backend
+{
+
+template <typename _RandomAccessIterator, typename _Compare, typename _LeafSort>
+void
+__parallel_stable_partial_sort(_RandomAccessIterator __xs, _RandomAccessIterator __xe, _Compare __comp,
+                               _LeafSort __leaf_sort, std::size_t /* __nsort */)
+{
+    // TODO: "Parallel partial sort needs to be implemented.");
+    __leaf_sort(__xs, __xe, __comp);
+}
+
+} // namespace __omp_backend
+} // namespace std::__onedpl
+#endif // _ONEDPL_INTERNAL_OMP_PARALLEL_STABLE_PARTIAL_SORT_H
diff --git a/libstdc++-v3/include/pstl/omp/parallel_stable_sort.h b/libstdc++-v3/include/pstl/omp/parallel_stable_sort.h
new file mode 100644
index 000000000000..aa2b0d227031
--- /dev/null
+++ b/libstdc++-v3/include/pstl/omp/parallel_stable_sort.h
@@ -0,0 +1,167 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_INTERNAL_OMP_PARALLEL_STABLE_SORT_H
+#define _ONEDPL_INTERNAL_OMP_PARALLEL_STABLE_SORT_H
+
+#include "util.h"
+#include "parallel_merge.h"
+
+namespace std::__onedpl
+{
+namespace __omp_backend
+{
+
+namespace __sort_details
+{
+struct __move_value
+{
+    template <typename _Iterator, typename _OutputIterator>
+    void
+    operator()(_Iterator __x, _OutputIterator __z) const
+    {
+        *__z = std::move(*__x);
+    }
+};
+
+template <typename _RandomAccessIterator, typename _OutputIterator>
+_OutputIterator
+__parallel_move_range(_RandomAccessIterator __first1, _RandomAccessIterator __last1, _OutputIterator __d_first)
+{
+    std::size_t __size = __last1 - __first1;
+
+    // Perform serial moving of small chunks
+
+    if (__size <= __default_chunk_size)
+    {
+        return std::move(__first1, __last1, __d_first);
+    }
+
+    // Perform parallel moving of larger chunks
+    auto __policy =
+        __onedpl::__omp_backend::__chunk_partitioner(__first1, __last1, omp_get_num_threads(), __default_chunk_size);
+
+    _ONEDPL_PRAGMA(omp taskloop)
+    for (std::size_t __chunk = 0; __chunk < __policy.__n_chunks; ++__chunk)
+    {
+        __onedpl::__omp_backend::__process_chunk(__policy, __first1, __chunk,
+                                                    [&](auto __chunk_first, auto __chunk_last) {
+                                                        auto __chunk_offset = __chunk_first - __first1;
+                                                        auto __output_it = __d_first + __chunk_offset;
+                                                        std::move(__chunk_first, __chunk_last, __output_it);
+                                                    });
+    }
+
+    return __d_first + __size;
+}
+
+struct __move_range
+{
+    template <typename _RandomAccessIterator, typename _OutputIterator>
+    _OutputIterator
+    operator()(_RandomAccessIterator __first1, _RandomAccessIterator __last1, _OutputIterator __d_first) const
+    {
+        return __onedpl::__omp_backend::__sort_details::__parallel_move_range(__first1, __last1, __d_first);
+    }
+};
+} // namespace __sort_details
+
+template <typename _RandomAccessIterator, typename _Compare, typename _LeafSort>
+void
+__parallel_stable_sort_body(_RandomAccessIterator __xs, _RandomAccessIterator __xe, _Compare __comp,
+                            _LeafSort __leaf_sort)
+{
+    using _ValueType = typename std::iterator_traits<_RandomAccessIterator>::value_type;
+    using _VecType = typename std::vector<_ValueType>;
+    using _OutputIterator = typename _VecType::iterator;
+    using _MoveValue = __onedpl::__omp_backend::__sort_details::__move_value;
+    using _MoveRange = __onedpl::__omp_backend::__sort_details::__move_range;
+
+    if (__should_run_serial(__xs, __xe, __default_chunk_size))
+    {
+        __leaf_sort(__xs, __xe, __comp);
+    }
+    else
+    {
+        std::size_t __size = __xe - __xs;
+        auto __mid = __xs + (__size / 2);
+        __onedpl::__omp_backend::__parallel_invoke_body(
+            [&]() { __parallel_stable_sort_body(__xs, __mid, __comp, __leaf_sort); },
+            [&]() { __parallel_stable_sort_body(__mid, __xe, __comp, __leaf_sort); });
+
+        // Perform a parallel merge of the sorted ranges into __output_data.
+        _VecType __output_data(__size);
+        _MoveValue __move_value;
+        _MoveRange __move_range;
+        __utils::__serial_move_merge __merge(__size);
+        __onedpl::__omp_backend::__parallel_merge_body(
+            __mid - __xs, __xe - __mid, __xs, __mid, __mid, __xe, __output_data.begin(), __comp,
+            [&__merge, &__move_value, &__move_range](_RandomAccessIterator __as, _RandomAccessIterator __ae,
+                                                     _RandomAccessIterator __bs, _RandomAccessIterator __be,
+                                                     _OutputIterator __cs, _Compare __comp) {
+                __merge(__as, __ae, __bs, __be, __cs, __comp, __move_value, __move_value, __move_range, __move_range);
+            });
+
+        // Move the values from __output_data back in the original source range.
+        __onedpl::__omp_backend::__sort_details::__parallel_move_range(__output_data.begin(), __output_data.end(),
+                                                                          __xs);
+    }
+}
+
+template <class _ExecutionPolicy, typename _RandomAccessIterator, typename _Compare, typename _LeafSort>
+void
+__parallel_stable_sort(__onedpl::__internal::__omp_backend_tag, _ExecutionPolicy&& /*__exec*/,
+                       _RandomAccessIterator __xs, _RandomAccessIterator __xe, _Compare __comp, _LeafSort __leaf_sort,
+                       std::size_t __nsort = 0)
+{
+    auto __count = static_cast<std::size_t>(__xe - __xs);
+    if (__count <= __default_chunk_size || __nsort < __count)
+    {
+        __leaf_sort(__xs, __xe, __comp);
+        return;
+    }
+
+    // TODO: the partial sort implementation should
+    // be shared with the other backends.
+
+    if (omp_in_parallel())
+    {
+        if (__count <= __nsort)
+        {
+            __onedpl::__omp_backend::__parallel_stable_sort_body(__xs, __xe, __comp, __leaf_sort);
+        }
+        else
+        {
+            __onedpl::__omp_backend::__parallel_stable_partial_sort(__xs, __xe, __comp, __leaf_sort, __nsort);
+        }
+    }
+    else
+    {
+        _ONEDPL_PRAGMA(omp parallel)
+        _ONEDPL_PRAGMA(omp single nowait)
+        if (__count <= __nsort)
+        {
+            __onedpl::__omp_backend::__parallel_stable_sort_body(__xs, __xe, __comp, __leaf_sort);
+        }
+        else
+        {
+            __onedpl::__omp_backend::__parallel_stable_partial_sort(__xs, __xe, __comp, __leaf_sort, __nsort);
+        }
+    }
+}
+
+} // namespace __omp_backend
+} // namespace std::__onedpl
+#endif // _ONEDPL_INTERNAL_OMP_PARALLEL_STABLE_SORT_H
diff --git a/libstdc++-v3/include/pstl/omp/parallel_transform_reduce.h b/libstdc++-v3/include/pstl/omp/parallel_transform_reduce.h
new file mode 100644
index 000000000000..623d2c68a8e7
--- /dev/null
+++ b/libstdc++-v3/include/pstl/omp/parallel_transform_reduce.h
@@ -0,0 +1,118 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_INTERNAL_OMP_PARALLEL_TRANSFORM_REDUCE_H
+#define _ONEDPL_INTERNAL_OMP_PARALLEL_TRANSFORM_REDUCE_H
+
+#include "util.h"
+
+namespace std::__onedpl
+{
+namespace __omp_backend
+{
+
+//------------------------------------------------------------------------
+// parallel_transform_reduce
+//
+// Notation:
+//      r(i,j,init) returns reduction of init with reduction over [i,j)
+//      u(i) returns f(i,i+1,identity) for a hypothetical left identity element
+//      of r c(x,y) combines values x and y that were the result of r or u
+//------------------------------------------------------------------------
+
+template <class _RandomAccessIterator, class _UnaryOp, class _Value, class _Combiner, class _Reduction>
+_Value
+__transform_reduce_body(_RandomAccessIterator __first, _RandomAccessIterator __last, _UnaryOp __unary_op, _Value __init,
+                        _Combiner __combiner, _Reduction __reduction)
+{
+    const std::size_t __num_threads = omp_get_num_threads();
+    const std::size_t __size = __last - __first;
+
+    // Serial fallback. The condition is equivalent to __chunk_partitioner returning 1 chunk
+    // after reserving the first __num_threads items to initialize the accumulators.
+    // The separate check avoids the risk of __first + __num_threads pointing after __last.
+    if (__size <= __num_threads + __default_chunk_size)
+    {
+        return __reduction(__first, __last, std::move(__init));
+    }
+
+    auto __policy = __onedpl::__omp_backend::__chunk_partitioner(__first + __num_threads, __last, __num_threads,
+                                                                    __default_chunk_size);
+
+    // Here, we cannot use OpenMP UDR because we must store the init value in
+    // the combiner and it will be used several times. Although there should be
+    // the only one; we manually generate the identity elements for each thread.
+    std::vector<_Value> __accums;
+    __accums.reserve(__num_threads);
+
+    // initialize accumulators for all threads
+    for (std::size_t __i = 0; __i < __num_threads; ++__i)
+    {
+        __accums.emplace_back(__unary_op(__first + __i));
+    }
+
+    // main loop
+    _ONEDPL_PRAGMA(omp taskloop shared(__accums))
+    for (std::size_t __chunk = 0; __chunk < __policy.__n_chunks; ++__chunk)
+    {
+        __onedpl::__omp_backend::__process_chunk(
+            __policy, __first + __num_threads, __chunk, [&](auto __chunk_first, auto __chunk_last) {
+                auto __thread_num = omp_get_thread_num();
+                __accums[__thread_num] = __reduction(__chunk_first, __chunk_last, std::move(__accums[__thread_num]));
+            });
+    }
+
+    // combine by accumulators
+    for (std::size_t __i = 0; __i < __num_threads; ++__i)
+    {
+        __init = __combiner(std::move(__init), std::move(__accums[__i]));
+    }
+
+    return std::move(__init);
+}
+
+template <class _ExecutionPolicy, class _RandomAccessIterator, class _UnaryOp, class _Value, class _Combiner,
+          class _Reduction>
+_Value
+__parallel_transform_reduce(__onedpl::__internal::__omp_backend_tag, _ExecutionPolicy&&,
+                            _RandomAccessIterator __first, _RandomAccessIterator __last, _UnaryOp __unary_op,
+                            _Value __init, _Combiner __combiner, _Reduction __reduction)
+{
+    _Value __result = std::move(__init);
+    if (omp_in_parallel())
+    {
+        // We don't create a nested parallel region in an existing parallel
+        // region: just create tasks
+        __result = __onedpl::__omp_backend::__transform_reduce_body(__first, __last, __unary_op, std::move(__result),
+                                                                       __combiner, __reduction);
+    }
+    else
+    {
+        // Create a parallel region, and a single thread will create tasks
+        // for the region.
+        _ONEDPL_PRAGMA(omp parallel)
+        _ONEDPL_PRAGMA(omp single nowait)
+        {
+            __result = __onedpl::__omp_backend::__transform_reduce_body(
+                __first, __last, __unary_op, std::move(__result), __combiner, __reduction);
+        }
+    }
+
+    return __result;
+}
+
+} // namespace __omp_backend
+} // namespace std::__onedpl
+#endif // _ONEDPL_INTERNAL_OMP_PARALLEL_TRANSFORM_REDUCE_H
diff --git a/libstdc++-v3/include/pstl/omp/parallel_transform_scan.h b/libstdc++-v3/include/pstl/omp/parallel_transform_scan.h
new file mode 100644
index 000000000000..bbd544cfe1ba
--- /dev/null
+++ b/libstdc++-v3/include/pstl/omp/parallel_transform_scan.h
@@ -0,0 +1,37 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_INTERNAL_OMP_PARALLEL_TRANSFORM_SCAN_H
+#define _ONEDPL_INTERNAL_OMP_PARALLEL_TRANSFORM_SCAN_H
+
+#include "util.h"
+
+namespace std::__onedpl
+{
+namespace __omp_backend
+{
+
+template <class _ExecutionPolicy, class _Index, class _Up, class _Tp, class _Cp, class _Rp, class _Sp>
+_Tp
+__parallel_transform_scan(__onedpl::__internal::__omp_backend_tag, _ExecutionPolicy&&, _Index __n, _Up /* __u */,
+                          _Tp __init, _Cp /* __combine */, _Rp /* __brick_reduce */, _Sp __scan)
+{
+    // TODO: parallelize this function.
+    return __scan(_Index(0), __n, __init);
+}
+
+} // namespace __omp_backend
+} // namespace std::__onedpl
+#endif // _ONEDPL_INTERNAL_OMP_PARALLEL_TRANSFORM_SCAN_H
diff --git a/libstdc++-v3/include/pstl/omp/util.h b/libstdc++-v3/include/pstl/omp/util.h
new file mode 100644
index 000000000000..bc8d80e9ae2b
--- /dev/null
+++ b/libstdc++-v3/include/pstl/omp/util.h
@@ -0,0 +1,196 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_INTERNAL_OMP_UTIL_H
+#define _ONEDPL_INTERNAL_OMP_UTIL_H
+
+#include <iterator>    // std::iterator_traits, std::distance
+#include <cstddef>     // std::size_t
+#include <memory>      // std::allocator
+#include <type_traits> // std::decay, is_integral_v, enable_if_t, common_type_t
+#include <utility>     // std::forward
+#include <omp.h>
+
+#include "../parallel_backend_utils.h"
+#include "../unseq_backend_simd.h"
+#include "../utils.h"
+
+namespace std::__onedpl
+{
+namespace __omp_backend
+{
+
+//------------------------------------------------------------------------
+// use to cancel execution
+//------------------------------------------------------------------------
+inline void
+__cancel_execution(__onedpl::__internal::__omp_backend_tag)
+{
+    // TODO: Figure out how to make cancellation work.
+}
+
+//------------------------------------------------------------------------
+// raw buffer
+//------------------------------------------------------------------------
+
+template <typename _Tp>
+using __buffer = __onedpl::__utils::__buffer_impl<_Tp, std::allocator>;
+
+// Preliminary size of each chunk: requires further discussion
+constexpr std::size_t __default_chunk_size = 2048;
+
+// Convenience function to determine when we should run serial.
+template <typename _Iterator, std::enable_if_t<!std::is_integral_v<_Iterator>, bool> = true>
+constexpr auto
+__should_run_serial(_Iterator __first, _Iterator __last, const std::size_t __cutoff) -> bool
+{
+    using _difference_type = typename std::iterator_traits<_Iterator>::difference_type;
+    auto __size = std::distance(__first, __last);
+    return __size <= static_cast<_difference_type>(__cutoff);
+}
+
+template <typename _Index, std::enable_if_t<std::is_integral_v<_Index>, bool> = true>
+constexpr auto
+__should_run_serial(_Index __first, _Index __last, const std::size_t __cutoff) -> bool
+{
+    using _difference_type = _Index;
+    auto __size = __last - __first;
+    return __size <= static_cast<_difference_type>(__cutoff);
+}
+
+struct __chunk_metrics
+{
+    std::size_t __n_chunks;
+    std::size_t __chunk_size;
+    // early chunks to get the leftover elements; these chunks will have size __chunk_size + 1
+    std::size_t __n_larger_chunks;
+};
+
+template <class _RandomAccessIterator>
+auto
+__chunk_partitioner(_RandomAccessIterator __first, _RandomAccessIterator __last, const std::size_t __num_threads,
+                    const std::size_t __preferred_min_chunk_size) -> __chunk_metrics
+{
+    // For sufficiently large inputs, this algorithm creates a number of chunks that is
+    // a multiple of the thread count for optimal load balancing.
+    // Leftover elements are evenly distributed across earlier chunks to improve processor prefetch utilization.
+
+    using _Size = std::common_type_t<decltype(__last - __first), std::size_t>;
+    const _Size __n = __last - __first;
+
+    std::size_t __n_chunks = 1;
+    std::size_t __chunk_size = __n;
+    std::size_t __n_larger_chunks = 0;
+
+    if (__n <= __preferred_min_chunk_size)
+    {
+        return __chunk_metrics{__n_chunks, __chunk_size, __n_larger_chunks};
+    }
+
+    // Aim for 3 chunks per thread for better load balancing
+    constexpr std::size_t __nominal_chunks_per_thread = 3;
+    std::size_t __nominal_n_chunks = __num_threads * __nominal_chunks_per_thread;
+
+    // This truncating division or the equivalents in if-else branches below will be accounted for with __n_larger_chunks
+    std::size_t __nominal_chunk_size = __n / __nominal_n_chunks;
+
+    // Large input. Limit chunk size to aid early-exit algorithms which cannot exit mid-way through a chunk.
+    constexpr std::size_t __preferred_max_chunk_size = 32768;
+    if (__nominal_chunk_size >= __preferred_max_chunk_size)
+    {
+        __n_chunks = // compute the number of chunks per thread, multiply by the number of threads
+            __onedpl::__internal::__dpl_ceiling_div(__n, __preferred_max_chunk_size * __num_threads) * __num_threads;
+        __chunk_size = __n / __n_chunks;
+    }
+    // Enough input for all threads with the nominal per-thread chunk count.
+    else if (__nominal_chunk_size >= __preferred_min_chunk_size)
+    {
+        __n_chunks = __nominal_n_chunks;
+        __chunk_size = __nominal_chunk_size;
+    }
+    // Enough input for all threads but not enough for the nominal per-thread chunk count.
+    else if (__n >= __num_threads * __preferred_min_chunk_size)
+    {
+        __n_chunks = (__n / (__preferred_min_chunk_size * __num_threads)) * __num_threads;
+        __chunk_size = __n / __n_chunks;
+    }
+    // Not enough input even for one chunk per thread.
+    else
+    {
+        __n_chunks = __n / __preferred_min_chunk_size;
+        __chunk_size = __n / __n_chunks;
+    }
+    __n_larger_chunks = __n - (__n_chunks * __chunk_size);
+    return __chunk_metrics{__n_chunks, __chunk_size, __n_larger_chunks};
+}
+
+template <typename _Iterator, typename _Index, typename _Func>
+void
+__process_chunk(const __chunk_metrics& __metrics, _Iterator __base, _Index __chunk_index, _Func __f)
+{
+    bool __is_larger_chunk = __chunk_index < __metrics.__n_larger_chunks;
+    std::size_t __n_previous_larger_chunks = __is_larger_chunk ? __chunk_index : __metrics.__n_larger_chunks;
+    _Iterator __first = __base + __chunk_index * __metrics.__chunk_size + __n_previous_larger_chunks;
+    __f(__first, __first + __metrics.__chunk_size + static_cast<std::size_t>(__is_larger_chunk));
+}
+
+namespace __detail
+{
+
+// Workaround for VS 2017: declare an alias to the CRTP base template
+template <typename _ValueType, typename... _Args>
+struct __enumerable_thread_local_storage;
+
+template <typename... _Ts>
+using __etls_base = __utils::__enumerable_thread_local_storage_base<__enumerable_thread_local_storage, _Ts...>;
+
+template <typename _ValueType, typename... _Args>
+struct __enumerable_thread_local_storage : public __etls_base<_ValueType, _Args...>
+{
+
+    template <typename... _LocalArgs>
+    __enumerable_thread_local_storage(_LocalArgs&&... __args)
+        : __etls_base<_ValueType, _Args...>({std::forward<_LocalArgs>(__args)...})
+    {
+    }
+
+    static std::size_t
+    get_num_threads()
+    {
+        return omp_in_parallel() ? omp_get_num_threads() : omp_get_max_threads();
+    }
+
+    static std::size_t
+    get_thread_num()
+    {
+        return omp_get_thread_num();
+    }
+};
+
+} // namespace __detail
+
+// enumerable thread local storage should only be created with this make function
+template <typename _ValueType, typename... _Args>
+__detail::__enumerable_thread_local_storage<_ValueType, std::remove_reference_t<_Args>...>
+__make_enumerable_tls(_Args&&... __args)
+{
+    return __detail::__enumerable_thread_local_storage<_ValueType, std::remove_reference_t<_Args>...>(
+        std::forward<_Args>(__args)...);
+}
+
+} // namespace __omp_backend
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_INTERNAL_OMP_UTIL_H
diff --git a/libstdc++-v3/include/pstl/onedpl_config.h b/libstdc++-v3/include/pstl/onedpl_config.h
new file mode 100644
index 000000000000..411d30eee9c8
--- /dev/null
+++ b/libstdc++-v3/include/pstl/onedpl_config.h
@@ -0,0 +1,392 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_CONFIG_H
+#define _ONEDPL_CONFIG_H
+
+// The version header also defines a few configuration macros used in this file
+#include "../internal/version_impl.h"
+
+// -- Check availability of parallel backends --
+
+#if __has_include(<tbb/tbb.h>)
+#    define _ONEDPL_TBB_AVAILABLE 1
+#endif
+#if ONEDPL_USE_TBB_BACKEND && !_ONEDPL_TBB_AVAILABLE
+#    error "Parallel execution policies with oneTBB or Intel(R) TBB support are enabled, but the library is not found"
+#endif
+
+#if defined(_OPENMP) && __has_include(<omp.h>)
+#    define _ONEDPL_OPENMP_AVAILABLE 1
+#endif
+// During compilation for a device _OPENMP may not be set, so avoid throwing an error if
+// __SYCL_DEVICE_ONLY__ found
+#if ONEDPL_USE_OPENMP_BACKEND && !_ONEDPL_OPENMP_AVAILABLE && !defined(__SYCL_DEVICE_ONLY__)
+#    error "Parallel execution policies with OpenMP* support are enabled, \
+        but OpenMP headers are not found or the compiler does not support OpenMP"
+#endif
+
+// -- Check availability of heterogeneous backends --
+
+// If DPCPP backend is explicitly requested, optimistically assume SYCL availability;
+// otherwise, make sure that it is definitely available additionally checking SYCL_LANGUAGE_VERSION
+#if __has_include(<sycl/sycl.hpp>) || __has_include(<CL/sycl.hpp>)
+#    if SYCL_LANGUAGE_VERSION || CL_SYCL_LANGUAGE_VERSION || ONEDPL_USE_DPCPP_BACKEND
+#        define _ONEDPL_SYCL_AVAILABLE 1
+#    endif
+#else
+#    if ONEDPL_USE_DPCPP_BACKEND
+#        error "Device execution policies are requested, but SYCL* headers are not found"
+#    endif
+#endif
+
+// If DPCPP backend is not explicitly turned off and SYCL is available, enable it
+#if (ONEDPL_USE_DPCPP_BACKEND || !defined(ONEDPL_USE_DPCPP_BACKEND)) && _ONEDPL_SYCL_AVAILABLE
+#    define _ONEDPL_BACKEND_SYCL 1
+#endif
+
+// If at least one heterogeneous backend is available, enable them
+#if _ONEDPL_BACKEND_SYCL
+#    if _ONEDPL_HETERO_BACKEND
+#        undef _ONEDPL_HETERO_BACKEND
+#    endif
+#    define _ONEDPL_HETERO_BACKEND 1
+#endif
+
+// -- Configure host backends and common parts --
+
+// Check the user-defined macro for warnings
+#if !defined(_PSTL_USAGE_WARNINGS) && defined(PSTL_USAGE_WARNINGS)
+#    define _PSTL_USAGE_WARNINGS PSTL_USAGE_WARNINGS
+// Check the internal macro for warnings
+#elif !defined(_PSTL_USAGE_WARNINGS)
+#    define _PSTL_USAGE_WARNINGS 0
+#endif
+
+// Portability "#pragma" definition
+#define _ONEDPL_PRAGMA(x) _Pragma(#x)
+
+// Machinery to check if some macro is defined to a pragma
+#define _ONEDPL_PREPEND(x, y) _ONEDPL_##x##y
+#define _ONEDPL_CHECK_PRAGMA_Pragma(...)  1 // It's a _Pragma
+#define _ONEDPL_CHECK_PRAGMA__pragma(...) 1 // It's a MSVC __pragma
+#define _ONEDPL_CHECK_PRAGMA              0 // It's an empty macro
+#define _ONEDPL_IS_PRAGMA(x) _ONEDPL_PREPEND(CHECK_PRAGMA, x) // Produces _ONEDPL_CHECK_PRAGMAx
+
+#define _ONEDPL_STRING_AUX(x) #x
+#define _ONEDPL_STRING(x) _ONEDPL_STRING_AUX(x)
+#define _ONEDPL_STRING_CONCAT(x, y) x #y
+
+// note that when ICC or Clang is in use, _ONEDPL_GCC_VERSION might not fully match
+// the actual GCC version on the system.
+#define _ONEDPL_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
+
+#if __clang__
+// according to clang documentation, version can be vendor specific
+#    define _ONEDPL_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
+#endif
+
+// Enable SIMD for compilers that support OpenMP 4.0
+#if (_OPENMP >= 201307) || __INTEL_LLVM_COMPILER || (__INTEL_COMPILER >= 1600) ||                                      \
+    (!defined(__INTEL_LLVM_COMPILER) && !defined(__INTEL_COMPILER) && _ONEDPL_GCC_VERSION >= 40900)
+#    define _ONEDPL_PRAGMA_SIMD _ONEDPL_PRAGMA(omp simd)
+#    define _ONEDPL_PRAGMA_DECLARE_SIMD _ONEDPL_PRAGMA(omp declare simd)
+#    define _ONEDPL_PRAGMA_SIMD_REDUCTION(PRM) _ONEDPL_PRAGMA(omp simd reduction(PRM))
+#elif defined(_PSTL_PRAGMA_SIMD)
+#    define _ONEDPL_PRAGMA_SIMD _PSTL_PRAGMA_SIMD
+#    define _ONEDPL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA_DECLARE_SIMD
+#    define _ONEDPL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
+#else //no simd
+#    define _ONEDPL_PRAGMA_SIMD
+#    define _ONEDPL_PRAGMA_DECLARE_SIMD
+#    define _ONEDPL_PRAGMA_SIMD_REDUCTION(PRM)
+#endif //Enable SIMD
+
+// Enable loop unrolling pragmas where supported
+#if (__INTEL_LLVM_COMPILER || __INTEL_COMPILER ||                                                                      \
+     (!defined(__INTEL_LLVM_COMPILER) && !defined(__INTEL_COMPILER) &&                                                 \
+      ((_ONEDPL_GCC_VERSION >= 80000) || (_ONEDPL_CLANG_VERSION >= 30700))))
+#    define _ONEDPL_PRAGMA_UNROLL _ONEDPL_PRAGMA(unroll)
+#else //no pragma unroll
+#    define _ONEDPL_PRAGMA_UNROLL
+#endif
+
+#if (__INTEL_LLVM_COMPILER || __INTEL_COMPILER)
+#    define _ONEDPL_PRAGMA_FORCEINLINE _ONEDPL_PRAGMA(forceinline)
+#elif defined(_PSTL_PRAGMA_FORCEINLINE)
+#    define _ONEDPL_PRAGMA_FORCEINLINE _PSTL_PRAGMA_FORCEINLINE
+#else
+#    define _ONEDPL_PRAGMA_FORCEINLINE
+#endif
+
+#if (__INTEL_LLVM_COMPILER >= 20230100 || __INTEL_COMPILER >= 1900 || _ONEDPL_GCC_VERSION >= 120000 ||                 \
+     _ONEDPL_CLANG_VERSION >= 110000)
+#    define _ONEDPL_PRAGMA_SIMD_SCAN(PRM) _ONEDPL_PRAGMA(omp simd reduction(inscan, PRM))
+#    define _ONEDPL_PRAGMA_SIMD_SCAN_EX(PRM, ...) _ONEDPL_PRAGMA(omp simd reduction(inscan, PRM) __VA_ARGS__)
+#    define _ONEDPL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _ONEDPL_PRAGMA(omp scan inclusive(PRM))
+#    define _ONEDPL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _ONEDPL_PRAGMA(omp scan exclusive(PRM))
+#elif (defined(_PSTL_PRAGMA_SIMD_SCAN) && _GLIBCXX_RELEASE != 10) // GCC 10 has issues
+#    define _ONEDPL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA_SIMD_SCAN(PRM)
+#    if _ONEDPL_IS_PRAGMA(_PSTL_PRAGMA_SIMD_SCAN())
+#        define _ONEDPL_PRAGMA_SIMD_SCAN_EX(PRM, ...) _PSTL_PRAGMA(omp simd reduction(inscan, PRM) __VA_ARGS__)
+#    else
+#        define _ONEDPL_PRAGMA_SIMD_SCAN_EX(PRM, ...)
+#    endif
+#    define _ONEDPL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
+#    define _ONEDPL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
+#else
+#    define _ONEDPL_PRAGMA_SIMD_SCAN(PRM)
+#    define _ONEDPL_PRAGMA_SIMD_SCAN_EX(PRM, ...)
+#    define _ONEDPL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
+#    define _ONEDPL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
+#endif
+
+// Required to check if libstdc++ is 5.1.0 or greater
+#if defined(__clang__)
+#    if __GLIBCXX__ && __has_include(<experimental/any>)
+#        define _ONEDPL_LIBSTDCXX_5_OR_GREATER 1
+#    else
+#        define _ONEDPL_LIBSTDCXX_5_OR_GREATER 0
+#    endif // __GLIBCXX__ && __has_include(<experimental/any>)
+#else
+#    define _ONEDPL_LIBSTDCXX_5_OR_GREATER (__GLIBCXX__ && _ONEDPL_GCC_VERSION >= 50100)
+#endif // defined(__clang__)
+
+// Should be defined to 1 for environments with a vendor implementation of C++17 execution policies
+#define _ONEDPL_CPP17_EXECUTION_POLICIES_PRESENT                                                                       \
+    (_ONEDPL___cplusplus >= 201703L && (_MSC_VER >= 1912 || (_GLIBCXX_RELEASE >= 9 && __GLIBCXX__ >= 20190503)))
+
+// In the SYCL backend reduce-then-scan path, we need to be able to differentiate between when a compiler enables
+// optimizations and when it does not. With GCC and clang-based compilers, we can detect this with the __OPTIMIZE__
+// flag.
+#if _ONEDPL_GCC_VERSION > 0 || defined(_ONEDPL_CLANG_VERSION)
+#    define _ONEDPL_DETECT_COMPILER_OPTIMIZATIONS_ENABLED __OPTIMIZE__
+#else
+#    define _ONEDPL_DETECT_COMPILER_OPTIMIZATIONS_ENABLED 0
+#endif
+
+#define _ONEDPL_EARLYEXIT_PRESENT (__INTEL_COMPILER >= 1800)
+#if (defined(_PSTL_PRAGMA_SIMD_EARLYEXIT) && _PSTL_EARLYEXIT_PRESENT)
+#    define _ONEDPL_PRAGMA_SIMD_EARLYEXIT _PSTL_PRAGMA_SIMD_EARLYEXIT
+#elif _ONEDPL_EARLYEXIT_PRESENT
+#    define _ONEDPL_PRAGMA_SIMD_EARLYEXIT _ONEDPL_PRAGMA(omp simd early_exit)
+#else
+#    define _ONEDPL_PRAGMA_SIMD_EARLYEXIT
+#endif
+
+#define _ONEDPL_MONOTONIC_PRESENT (__INTEL_COMPILER >= 1800)
+#if (defined(_PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC) && _PSTL_MONOTONIC_PRESENT)
+#    define _ONEDPL_PRAGMA_SIMD_ORDERED_MONOTONIC(PRM) _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(PRM)
+#    define _ONEDPL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(PRM1, PRM2)                                                    \
+        _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(PRM1, PRM2)
+#elif _ONEDPL_MONOTONIC_PRESENT
+#    define _ONEDPL_PRAGMA_SIMD_ORDERED_MONOTONIC(PRM) _ONEDPL_PRAGMA(omp ordered simd monotonic(PRM))
+#    define _ONEDPL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(PRM1, PRM2)                                                    \
+        _ONEDPL_PRAGMA(omp ordered simd monotonic(PRM1, PRM2))
+#else
+#    define _ONEDPL_PRAGMA_SIMD_ORDERED_MONOTONIC(PRM)
+#    define _ONEDPL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(PRM1, PRM2)
+#endif
+
+#if (_OPENMP >= 201307 || __INTEL_LLVM_COMPILER || __INTEL_COMPILER >= 1900 ||                                         \
+     !defined(__INTEL_LLVM_COMPILER) && !defined(__INTEL_COMPILER) && _ONEDPL_GCC_VERSION >= 40900)
+#    define _ONEDPL_UDR_PRESENT 1
+#else
+#    define _ONEDPL_UDR_PRESENT 0
+#endif
+
+// TODO: enable UDS on Windows with Intel LLVM-based compiler when it is fixed
+#if (__INTEL_LLVM_COMPILER >= 20230100 && !defined(_MSC_VER)) ||                                                       \
+    (__INTEL_COMPILER >= 1900 && __INTEL_COMPILER_BUILD_DATE >= 20180626)
+#    define _ONEDPL_UDS_PRESENT 1
+#else
+#    define _ONEDPL_UDS_PRESENT 0
+#endif
+
+// Declaration of reduction functor, where
+// NAME - the name of the functor
+// OP - type of the callable object with the reduction operation
+// omp_in - refers to the local partial result
+// omp_out - refers to the final value of the combiner operator
+// omp_priv - refers to the private copy of the initial value
+// omp_orig - refers to the original variable to be reduced
+#ifdef _PSTL_PRAGMA_DECLARE_REDUCTION
+#    define _ONEDPL_PRAGMA_DECLARE_REDUCTION(NAME, OP) _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
+#else
+#    define _ONEDPL_PRAGMA_DECLARE_REDUCTION(NAME, OP)                                                                 \
+        _ONEDPL_PRAGMA(omp declare reduction(NAME : OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
+#endif
+
+#if defined(_PSTL_PRAGMA_VECTOR_UNALIGNED) && (__INTEL_COMPILER < 1600)
+#    define _ONEDPL_PRAGMA_VECTOR_UNALIGNED _PSTL_PRAGMA_VECTOR_UNALIGNED
+#elif (__INTEL_COMPILER >= 1600)
+#    define _ONEDPL_PRAGMA_VECTOR_UNALIGNED _ONEDPL_PRAGMA(vector unaligned)
+#else
+#    define _ONEDPL_PRAGMA_VECTOR_UNALIGNED
+#endif
+
+// Check the user-defined macro to use non-temporal stores
+#ifndef _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
+#    if defined(PSTL_USE_NONTEMPORAL_STORES) && (__INTEL_LLVM_COMPILER || __INTEL_COMPILER >= 1600)
+#        define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED _ONEDPL_PRAGMA(vector nontemporal)
+#    else
+#        define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
+#    endif
+#endif
+
+#if _MSC_VER || __INTEL_COMPILER //the preprocessors don't type a message location
+#    define _ONEDPL_PRAGMA_LOCATION __FILE__ ":" _ONEDPL_STRING(__LINE__) ": [Parallel STL message]: "
+#else
+#    define _ONEDPL_PRAGMA_LOCATION " [Parallel STL message]: "
+#endif
+
+#ifndef _PSTL_PRAGMA_MESSAGE_IMPL
+#    define _PSTL_PRAGMA_MESSAGE_IMPL(x) _ONEDPL_PRAGMA(message(_ONEDPL_STRING_CONCAT(_ONEDPL_PRAGMA_LOCATION, x)))
+#endif
+
+#ifndef _PSTL_PRAGMA_MESSAGE
+#    if _PSTL_USAGE_WARNINGS
+#        define _PSTL_PRAGMA_MESSAGE(x) _PSTL_PRAGMA_MESSAGE_IMPL(x)
+#        define _PSTL_PRAGMA_MESSAGE_POLICIES(x) _PSTL_PRAGMA_MESSAGE_IMPL(x)
+#    else
+#        define _PSTL_PRAGMA_MESSAGE(x)
+#        define _PSTL_PRAGMA_MESSAGE_POLICIES(x)
+#    endif
+#endif
+
+// Some  C++ standard libraries contain 'exclusive_scan' declaration (version with binary_op)
+// w/o "enable_if". So, a call 'exclusive_scan' may be ambiguous in case of a custom policy using.
+#define _ONEDPL_EXCLUSIVE_SCAN_WITH_BINARY_OP_AMBIGUITY                                                                \
+    (_ONEDPL___cplusplus >= 201703L && __GLIBCXX__ && __GLIBCXX__ > 20190503)
+
+// some algorithms in <numeric> such as 'reduce' were added since libstdc++-9.3, we
+// have to provide our own implementation if legacy libstdc++ is in use.
+#define _ONEDPL_HAS_NUMERIC_SERIAL_IMPL                                                                                \
+    (__GLIBCXX__ && (_GLIBCXX_RELEASE < 9 || (_GLIBCXX_RELEASE == 9 && __GLIBCXX__ < 20200312)))
+
+//'present' macros
+// shift_left, shift_right; GCC 10; VS 2019 16.1
+#define _ONEDPL_CPP20_SHIFT_LEFT_RIGHT_PRESENT                                                                         \
+    (_ONEDPL___cplusplus >= 202002L && (_MSC_VER >= 1921 || _GLIBCXX_RELEASE >= 10))
+
+#if _ONEDPL_STD_FEATURE_MACROS_PRESENT
+#    define _ONEDPL_CPP23_TUPLE_LIKE_COMMON_REFERENCE_PRESENT                                                          \
+        (_ONEDPL___cplusplus >= 202302L && __cpp_lib_tuple_like >= 202207L)
+#    define _ONEDPL_CPP23_RANGES_ZIP_PRESENT (_ONEDPL___cplusplus >= 202302L && __cpp_lib_ranges_zip >= 202110L)
+#    define _ONEDPL_CPP26_DEFAULT_VALUE_TYPE_PRESENT (__cpp_lib_algorithm_default_value_type >= 202403L)
+#else
+#    define _ONEDPL_CPP23_TUPLE_LIKE_COMMON_REFERENCE_PRESENT 0
+#    define _ONEDPL_CPP23_RANGES_ZIP_PRESENT 0
+#    define _ONEDPL_CPP26_DEFAULT_VALUE_TYPE_PRESENT 0
+#endif
+
+// std::views::all on rvalue non-view ranges requires P2415R2 owning_view.
+// __cpp_lib_ranges >= 202110L
+// - libstdc++ (GCC or Clang+libstdc++): available since GCC 12
+// - libc++    (Clang+libc++):           available since LLVM 16
+// - MSVC STL:                           available since C++23
+#if defined(__cpp_lib_ranges)
+#    define _ONEDPL_CPP20_OWNING_VIEW_PRESENT (__cpp_lib_ranges >= 202110L)
+#elif defined(__GLIBCXX__)
+#    define _ONEDPL_CPP20_OWNING_VIEW_PRESENT (__GLIBCXX__ >= 20220728)
+#elif defined(_LIBCPP_VERSION)
+#    define _ONEDPL_CPP20_OWNING_VIEW_PRESENT (_LIBCPP_VERSION >= 16000)
+#else
+#    define _ONEDPL_CPP20_OWNING_VIEW_PRESENT (_ONEDPL___cplusplus >= 202302L)
+#endif
+
+// When C++20 concepts are available, we must use std::tuple as a proxy reference to satisfy iterator concepts, which
+// requires the changes to std::tuple in P2321R2 and the tuple-like basic_common_reference specialization in P2165R4.
+#define _ONEDPL_CAN_USE_STD_TUPLE_PROXY_ITERATOR                                                                       \
+    (!_ONEDPL_CPP20_CONCEPTS_PRESENT ||                                                                                \
+     (_ONEDPL_CPP23_RANGES_ZIP_PRESENT && _ONEDPL_CPP23_TUPLE_LIKE_COMMON_REFERENCE_PRESENT))
+
+#if _ONEDPL_CPP20_CONCEPTS_PRESENT
+#    define _ONEDPL_CPP20_REQUIRES(req) requires(req)
+#else
+#    define _ONEDPL_CPP20_REQUIRES(req)
+#endif
+
+#if defined(_MSC_VER) && __INTEL_LLVM_COMPILER < 20240100
+#    define _ONEDPL_ICPX_OMP_SIMD_DESTROY_WINDOWS_BROKEN 1
+#else
+#    define _ONEDPL_ICPX_OMP_SIMD_DESTROY_WINDOWS_BROKEN 0
+#endif
+
+// Most compilers do not correctly implement lastprivate(conditional: ...) in SIMD loops
+#if (__INTEL_HOST_OPENMP || __INTEL_COMPILER >= 1900)
+#    define _ONEDPL_OMP_SIMD_LASTPRIVATE_CONDITIONAL_BROKEN 0
+#else
+#    define _ONEDPL_OMP_SIMD_LASTPRIVATE_CONDITIONAL_BROKEN 1
+#endif
+
+// The implementation of std::bit_floor in MS STL does not meet requirements for SYCL device functions
+#if defined(_MSC_VER) && (__SYCL_DEVICE_ONLY__ || __SYCL_SINGLE_SOURCE__)
+#    define _ONEDPL_STD_BIT_FLOOR_BROKEN 1
+#else
+#    define _ONEDPL_STD_BIT_FLOOR_BROKEN 0
+#endif
+
+// The implementation of std::ranges algorithms in MS C++ standard library is done via C++ functions.
+#if defined(_MSC_VER) && (_MSC_VER < 1939)
+#    define _ONEDPL_STD_RANGES_ALGO_CPP_FUN 1
+#else
+#    define _ONEDPL_STD_RANGES_ALGO_CPP_FUN 0
+#endif
+
+// Hidden friend functions defined in a sibling nested class are given access to the enclosing friend class's
+// other nested classes' private members for most compilers(CWG1699). GCC < 13 and MSVC do not grant this access.
+#if defined(_MSC_VER) || (defined(__GNUC__) && !defined(__clang__) && _ONEDPL_GCC_VERSION < 130100)
+#    define _ONEDPL_HIDDEN_FRIENDS_SIBLING_ACCESS_BROKEN 1
+#else
+#    define _ONEDPL_HIDDEN_FRIENDS_SIBLING_ACCESS_BROKEN 0
+#endif
+
+// -- Configure heterogeneous backends --
+
+#if !defined(ONEDPL_ALLOW_DEFERRED_WAITING)
+#    define ONEDPL_ALLOW_DEFERRED_WAITING 0
+#endif
+
+#if defined(ONEDPL_USE_PREDEFINED_POLICIES)
+#    undef _ONEDPL_PREDEFINED_POLICIES
+#    define _ONEDPL_PREDEFINED_POLICIES ONEDPL_USE_PREDEFINED_POLICIES
+#elif !defined(_ONEDPL_PREDEFINED_POLICIES)
+#    define _ONEDPL_PREDEFINED_POLICIES 1
+#endif
+
+#if defined(ONEDPL_FPGA_DEVICE)
+#    undef _ONEDPL_FPGA_DEVICE
+#    define _ONEDPL_FPGA_DEVICE ONEDPL_FPGA_DEVICE
+    _ONEDPL_PRAGMA(
+        message("Support for FPGA devices in oneDPL algorithms is deprecated and will be removed in a future release"))
+#endif
+#if defined(ONEDPL_FPGA_EMULATOR)
+#    undef _ONEDPL_FPGA_EMU
+#    define _ONEDPL_FPGA_EMU ONEDPL_FPGA_EMULATOR
+#endif
+
+#if _ONEDPL_BACKEND_SYCL
+// Include sycl specific options
+// FPGA doesn't support sub-groups
+#    if !(_ONEDPL_FPGA_DEVICE)
+#        define _ONEDPL_USE_SUB_GROUPS 1
+#        define _ONEDPL_USE_GROUP_ALGOS 1
+#    endif
+
+#    define _ONEDPL_BUILT_IN_STABLE_NAME_PRESENT __has_builtin(__builtin_sycl_unique_stable_name)
+#endif // _ONEDPL_BACKEND_SYCL
+
+#endif // _ONEDPL_CONFIG_H
diff --git a/libstdc++-v3/include/pstl/parallel_backend.h b/libstdc++-v3/include/pstl/parallel_backend.h
index e9a90e11dba5..13433f23fb86 100644
--- a/libstdc++-v3/include/pstl/parallel_backend.h
+++ b/libstdc++-v3/include/pstl/parallel_backend.h
@@ -1,35 +1,51 @@
 // -*- C++ -*-
-//===-- parallel_backend.h ------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
+#ifndef _ONEDPL_PARALLEL_BACKEND_H
+#define _ONEDPL_PARALLEL_BACKEND_H
+#include "onedpl_config.h"
 
-#ifndef _PSTL_PARALLEL_BACKEND_H
-#define _PSTL_PARALLEL_BACKEND_H
-
-#if defined(_PSTL_PAR_BACKEND_SERIAL)
-#    include "parallel_backend_serial.h"
-namespace __pstl
-{
-namespace __par_backend = __serial_backend;
-}
-#elif defined(_PSTL_PAR_BACKEND_TBB)
+// Select a parallel backend
+#if ONEDPL_USE_TBB_BACKEND || (!defined(ONEDPL_USE_TBB_BACKEND) && !ONEDPL_USE_OPENMP_BACKEND && _ONEDPL_TBB_AVAILABLE)
+#    define _ONEDPL_PAR_BACKEND_TBB 1
 #    include "parallel_backend_tbb.h"
-namespace __pstl
-{
-namespace __par_backend = __tbb_backend;
-}
-#elif defined(_PSTL_PAR_BACKEND_OPENMP)
+#elif ONEDPL_USE_OPENMP_BACKEND || (!defined(ONEDPL_USE_OPENMP_BACKEND) && _ONEDPL_OPENMP_AVAILABLE)
+#    define _ONEDPL_PAR_BACKEND_OPENMP 1
 #    include "parallel_backend_omp.h"
-namespace __pstl
-{
-namespace __par_backend = __omp_backend;
-}
 #else
-_PSTL_PRAGMA_MESSAGE("Parallel backend was not specified");
+#    define _ONEDPL_PAR_BACKEND_SERIAL 1
+#    include "parallel_backend_serial.h"
 #endif
 
-#endif /* _PSTL_PARALLEL_BACKEND_H */
+#if _ONEDPL_BACKEND_SYCL
+#    include "hetero/dpcpp/parallel_backend_sycl.h"
+#    if _ONEDPL_FPGA_DEVICE
+#        include "hetero/dpcpp/parallel_backend_sycl_fpga.h"
+#    endif
+#endif
+
+namespace std::__onedpl
+{
+#if _ONEDPL_PAR_BACKEND_TBB
+namespace __par_backend = __tbb_backend;
+#elif _ONEDPL_PAR_BACKEND_OPENMP
+namespace __par_backend = __omp_backend;
+#elif _ONEDPL_PAR_BACKEND_SERIAL
+namespace __par_backend = __serial_backend;
+#else
+#    error "Parallel backend was not specified"
+#endif
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_PARALLEL_BACKEND_H
diff --git a/libstdc++-v3/include/pstl/parallel_backend_omp.h b/libstdc++-v3/include/pstl/parallel_backend_omp.h
new file mode 100644
index 000000000000..f608581b245c
--- /dev/null
+++ b/libstdc++-v3/include/pstl/parallel_backend_omp.h
@@ -0,0 +1,65 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+// This header guard is used to check inclusion of OpenMP backend.
+// Changing this macro may result in broken tests.
+#ifndef _ONEDPL_PARALLEL_BACKEND_OMP_H
+#define _ONEDPL_PARALLEL_BACKEND_OMP_H
+
+//------------------------------------------------------------------------
+// parallel_invoke
+//------------------------------------------------------------------------
+
+#include "./omp/parallel_invoke.h"
+
+//------------------------------------------------------------------------
+// parallel_for
+//------------------------------------------------------------------------
+
+#include "./omp/parallel_for.h"
+
+//------------------------------------------------------------------------
+// parallel_for_each
+//------------------------------------------------------------------------
+
+#include "./omp/parallel_for_each.h"
+
+//------------------------------------------------------------------------
+// parallel_reduce
+//------------------------------------------------------------------------
+
+#include "./omp/parallel_reduce.h"
+#include "./omp/parallel_transform_reduce.h"
+
+//------------------------------------------------------------------------
+// parallel_scan
+//------------------------------------------------------------------------
+
+#include "./omp/parallel_scan.h"
+#include "./omp/parallel_transform_scan.h"
+
+//------------------------------------------------------------------------
+// parallel_stable_sort
+//------------------------------------------------------------------------
+
+#include "./omp/parallel_stable_partial_sort.h"
+#include "./omp/parallel_stable_sort.h"
+
+//------------------------------------------------------------------------
+// parallel_merge
+//------------------------------------------------------------------------
+#include "./omp/parallel_merge.h"
+
+#endif //_ONEDPL_PARALLEL_BACKEND_OMP_H
diff --git a/libstdc++-v3/include/pstl/parallel_backend_serial.h b/libstdc++-v3/include/pstl/parallel_backend_serial.h
index db2da43eb060..925789cdda4e 100644
--- a/libstdc++-v3/include/pstl/parallel_backend_serial.h
+++ b/libstdc++-v3/include/pstl/parallel_backend_serial.h
@@ -1,63 +1,98 @@
 // -*- C++ -*-
-//===-- parallel_backend_serial.h -----------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_PARALLEL_BACKEND_SERIAL_H
-#define _PSTL_PARALLEL_BACKEND_SERIAL_H
+// This header guard is used to check inclusion of serial backend.
+// Changing this macro may result in broken tests.
+#ifndef _ONEDPL_PARALLEL_BACKEND_SERIAL_H
+#define _ONEDPL_PARALLEL_BACKEND_SERIAL_H
 
 #include <algorithm>
 #include <cstddef>
+#include <cstdint>
 #include <memory>
 #include <numeric>
 #include <utility>
+#include <type_traits>
+#include "parallel_backend_utils.h"
 
-namespace __pstl
+namespace std::__onedpl
 {
 namespace __serial_backend
 {
 
-template <typename _Tp>
-class __buffer
+namespace __detail
 {
-    std::allocator<_Tp> __allocator_;
-    _Tp* __ptr_;
-    const std::size_t __buf_size_;
-    __buffer(const __buffer&) = delete;
-    void
-    operator=(const __buffer&) = delete;
 
-  public:
-    __buffer(std::size_t __n) : __allocator_(), __ptr_(__allocator_.allocate(__n)), __buf_size_(__n) {}
-
-    operator bool() const { return __ptr_ != nullptr; }
-    _Tp*
-    get() const
+template <typename _ValueType>
+struct __enumerable_thread_local_storage
+{
+    template <typename... _LocalArgs>
+    __enumerable_thread_local_storage(_LocalArgs&&... __args) : __storage(std::forward<_LocalArgs>(__args)...)
     {
-        return __ptr_;
     }
-    ~__buffer() { __allocator_.deallocate(__ptr_, __buf_size_); }
+
+    std::size_t
+    size() const
+    {
+        return std::size_t{1};
+    }
+
+    _ValueType&
+    get_for_current_thread()
+    {
+        return __storage;
+    }
+
+    _ValueType&
+    get_with_id(std::size_t /*__i*/)
+    {
+        return get_for_current_thread();
+    }
+
+    _ValueType __storage;
 };
 
+} //namespace __detail
+
+// enumerable thread local storage should only be created from make function
+template <typename _ValueType, typename... Args>
+__detail::__enumerable_thread_local_storage<_ValueType>
+__make_enumerable_tls(Args&&... __args)
+{
+    return __detail::__enumerable_thread_local_storage<_ValueType>(std::forward<Args>(__args)...);
+}
+
+template <typename _Tp>
+using __buffer = __onedpl::__utils::__buffer_impl<_Tp, std::allocator>;
+
 inline void
-__cancel_execution()
+__cancel_execution(__onedpl::__internal::__serial_backend_tag)
 {
 }
 
 template <class _ExecutionPolicy, class _Index, class _Fp>
 void
-__parallel_for(__pstl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _Index __first, _Index __last, _Fp __f)
+__parallel_for(__onedpl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _Index __first, _Index __last,
+               _Fp __f, std::size_t /*__grainsize*/ = 1)
 {
     __f(__first, __last);
 }
 
 template <class _ExecutionPolicy, class _Value, class _Index, typename _RealBody, typename _Reduction>
 _Value
-__parallel_reduce(__pstl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _Index __first, _Index __last,
+__parallel_reduce(__onedpl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _Index __first, _Index __last,
                   const _Value& __identity, const _RealBody& __real_body, const _Reduction&)
 {
     if (__first == __last)
@@ -72,15 +107,15 @@ __parallel_reduce(__pstl::__internal::__serial_backend_tag, _ExecutionPolicy&&,
 
 template <class _ExecutionPolicy, class _Index, class _UnaryOp, class _Tp, class _BinaryOp, class _Reduce>
 _Tp
-__parallel_transform_reduce(__pstl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _Index __first, _Index __last,
-                            _UnaryOp, _Tp __init, _BinaryOp, _Reduce __reduce)
+__parallel_transform_reduce(__onedpl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _Index __first,
+                            _Index __last, _UnaryOp, _Tp __init, _BinaryOp, _Reduce __reduce)
 {
-    return __reduce(__first, __last, __init);
+    return __reduce(__first, __last, std::move(__init));
 }
 
 template <class _ExecutionPolicy, typename _Index, typename _Tp, typename _Rp, typename _Cp, typename _Sp, typename _Ap>
 void
-__parallel_strict_scan(__pstl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _Index __n, _Tp __initial,
+__parallel_strict_scan(__onedpl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _Index __n, _Tp __initial,
                        _Rp __reduce, _Cp __combine, _Sp __scan, _Ap __apex)
 {
     _Tp __sum = __initial;
@@ -93,7 +128,7 @@ __parallel_strict_scan(__pstl::__internal::__serial_backend_tag, _ExecutionPolic
 
 template <class _ExecutionPolicy, class _Index, class _UnaryOp, class _Tp, class _BinaryOp, class _Reduce, class _Scan>
 _Tp
-__parallel_transform_scan(__pstl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _Index __n, _UnaryOp,
+__parallel_transform_scan(__onedpl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _Index __n, _UnaryOp,
                           _Tp __init, _BinaryOp, _Reduce, _Scan __scan)
 {
     return __scan(_Index(0), __n, __init);
@@ -101,8 +136,8 @@ __parallel_transform_scan(__pstl::__internal::__serial_backend_tag, _ExecutionPo
 
 template <class _ExecutionPolicy, typename _RandomAccessIterator, typename _Compare, typename _LeafSort>
 void
-__parallel_stable_sort(__pstl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _RandomAccessIterator __first,
-                       _RandomAccessIterator __last, _Compare __comp, _LeafSort __leaf_sort, std::size_t = 0)
+__parallel_stable_sort(__onedpl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _RandomAccessIterator __first,
+                       _RandomAccessIterator __last, _Compare __comp, _LeafSort __leaf_sort, ::std::size_t = 0)
 {
     __leaf_sort(__first, __last, __comp);
 }
@@ -110,7 +145,7 @@ __parallel_stable_sort(__pstl::__internal::__serial_backend_tag, _ExecutionPolic
 template <class _ExecutionPolicy, typename _RandomAccessIterator1, typename _RandomAccessIterator2,
           typename _RandomAccessIterator3, typename _Compare, typename _LeafMerge>
 void
-__parallel_merge(__pstl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _RandomAccessIterator1 __first1,
+__parallel_merge(__onedpl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _RandomAccessIterator1 __first1,
                  _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2,
                  _RandomAccessIterator3 __outit, _Compare __comp, _LeafMerge __leaf_merge)
 {
@@ -119,13 +154,22 @@ __parallel_merge(__pstl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _
 
 template <class _ExecutionPolicy, typename _F1, typename _F2>
 void
-__parallel_invoke(__pstl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _F1&& __f1, _F2&& __f2)
+__parallel_invoke(__onedpl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _F1&& __f1, _F2&& __f2)
 {
-    std::forward<_F1>(__f1)();
-    std::forward<_F2>(__f2)();
+    ::std::forward<_F1>(__f1)();
+    ::std::forward<_F2>(__f2)();
+}
+
+template <class _ExecutionPolicy, class _ForwardIterator, class _Fp>
+void
+__parallel_for_each(__onedpl::__internal::__serial_backend_tag, _ExecutionPolicy&&, _ForwardIterator __begin,
+                    _ForwardIterator __end, _Fp __f)
+{
+    for (auto __iter = __begin; __iter != __end; ++__iter)
+        __f(*__iter);
 }
 
 } // namespace __serial_backend
-} // namespace __pstl
+} // namespace std::__onedpl
 
-#endif /* _PSTL_PARALLEL_BACKEND_SERIAL_H */
+#endif // _ONEDPL_PARALLEL_BACKEND_SERIAL_H
diff --git a/libstdc++-v3/include/pstl/parallel_backend_tasq.h b/libstdc++-v3/include/pstl/parallel_backend_tasq.h
new file mode 100644
index 000000000000..6d1487c467ae
--- /dev/null
+++ b/libstdc++-v3/include/pstl/parallel_backend_tasq.h
@@ -0,0 +1,171 @@
+// A task queue using a thread pool -*- C++ -*-
+
+// Copyright The GNU Toolchain Authors.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file pstl/parallel_backend_tasq.h
+ *  This is an internal header file, included by other library headers.
+ *  Do not attempt to use it directly. @headername{execution}
+ */
+
+
+#ifndef _PSTL_PARALLEL_BACKEND_TASQ_H
+#define _PSTL_PARALLEL_BACKEND_TASQ_H
+
+#include <algorithm>
+#include <cstddef>
+#include <memory>
+#include <numeric>
+#include <utility>
+#include <bits/task_queue.h>
+
+namespace __pstl
+{
+namespace __tasq_backend
+{
+
+template <typename _Tp>
+class __buffer
+{
+    std::allocator<_Tp> __allocator_;
+    _Tp* __ptr_;
+    const std::size_t __buf_size_;
+    __buffer(const __buffer&) = delete;
+    void
+    operator=(const __buffer&) = delete;
+
+  public:
+    __buffer(std::size_t __n) : __allocator_(), __ptr_(__allocator_.allocate(__n)), __buf_size_(__n) {}
+
+    operator bool() const { return __ptr_ != nullptr; }
+    _Tp*
+    get() const
+    {
+        return __ptr_;
+    }
+    ~__buffer() { __allocator_.deallocate(__ptr_, __buf_size_); }
+};
+
+inline void
+__cancel_execution()
+{
+}
+
+template <class _ExecutionPolicy, class _RAIter, class _Fp>
+void
+__parallel_for(__pstl::__internal::__tasq_backend_tag, _ExecutionPolicy&&,
+               _RAIter __first, _RAIter __last, _Fp __f)
+{
+    const unsigned __num_workers = __task_queue_workers();
+    const auto __d = __last - __first;
+    const decltype(__d) __chunk_size = __d / __num_workers;
+    vector<future<void>> __futs;
+    if (__chunk_size > __num_workers)
+    {
+        __futs.reserve(std::min(__num_workers, __d / __chunk_size);
+        while ((__last - __first) > __chunk_size)
+	{
+            auto __next = __first += __chunk_size;
+            __futs.push_back(std::__post_task_to_queue(__f, __first, __next));
+            __first = __next;
+        }
+    }
+    if (__first != __last)
+        __f(__first, __last);
+    for (auto& __fut : __futs)
+        __fut.get();
+}
+
+template <class _ExecutionPolicy, class _Value, class _Index, typename _RealBody, typename _Reduction>
+_Value
+__parallel_reduce(__pstl::__internal::__tasq_backend_tag, _ExecutionPolicy&&, _Index __first, _Index __last,
+                  const _Value& __identity, const _RealBody& __real_body, const _Reduction&)
+{
+    if (__first == __last)
+    {
+        return __identity;
+    }
+    else
+    {
+        return __real_body(__first, __last, __identity);
+    }
+}
+
+template <class _ExecutionPolicy, class _Index, class _UnaryOp, class _Tp, class _BinaryOp, class _Reduce>
+_Tp
+__parallel_transform_reduce(__pstl::__internal::__tasq_backend_tag, _ExecutionPolicy&&, _Index __first, _Index __last,
+                            _UnaryOp, _Tp __init, _BinaryOp, _Reduce __reduce)
+{
+    return __reduce(__first, __last, __init);
+}
+
+template <class _ExecutionPolicy, typename _Index, typename _Tp, typename _Rp, typename _Cp, typename _Sp, typename _Ap>
+void
+__parallel_strict_scan(__pstl::__internal::__tasq_backend_tag, _ExecutionPolicy&&, _Index __n, _Tp __initial,
+                       _Rp __reduce, _Cp __combine, _Sp __scan, _Ap __apex)
+{
+    _Tp __sum = __initial;
+    if (__n)
+        __sum = __combine(__sum, __reduce(_Index(0), __n));
+    __apex(__sum);
+    if (__n)
+        __scan(_Index(0), __n, __initial);
+}
+
+template <class _ExecutionPolicy, class _Index, class _UnaryOp, class _Tp, class _BinaryOp, class _Reduce, class _Scan>
+_Tp
+__parallel_transform_scan(__pstl::__internal::__tasq_backend_tag, _ExecutionPolicy&&, _Index __n, _UnaryOp,
+                          _Tp __init, _BinaryOp, _Reduce, _Scan __scan)
+{
+    return __scan(_Index(0), __n, __init);
+}
+
+template <class _ExecutionPolicy, typename _RandomAccessIterator, typename _Compare, typename _LeafSort>
+void
+__parallel_stable_sort(__pstl::__internal::__tasq_backend_tag, _ExecutionPolicy&&, _RandomAccessIterator __first,
+                       _RandomAccessIterator __last, _Compare __comp, _LeafSort __leaf_sort, std::size_t = 0)
+{
+    __leaf_sort(__first, __last, __comp);
+}
+
+template <class _ExecutionPolicy, typename _RandomAccessIterator1, typename _RandomAccessIterator2,
+          typename _RandomAccessIterator3, typename _Compare, typename _LeafMerge>
+void
+__parallel_merge(__pstl::__internal::__tasq_backend_tag, _ExecutionPolicy&&, _RandomAccessIterator1 __first1,
+                 _RandomAccessIterator1 __last1, _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2,
+                 _RandomAccessIterator3 __outit, _Compare __comp, _LeafMerge __leaf_merge)
+{
+    __leaf_merge(__first1, __last1, __first2, __last2, __outit, __comp);
+}
+
+template <class _ExecutionPolicy, typename _F1, typename _F2>
+void
+__parallel_invoke(__pstl::__internal::__tasq_backend_tag, _ExecutionPolicy&&, _F1&& __f1, _F2&& __f2)
+{
+    std::forward<_F1>(__f1)();
+    std::forward<_F2>(__f2)();
+}
+
+} // namespace __tasq_backend
+} // namespace __pstl
+
+#endif /* _PSTL_PARALLEL_BACKEND_TASQ_H */
diff --git a/libstdc++-v3/include/pstl/parallel_backend_tbb.h b/libstdc++-v3/include/pstl/parallel_backend_tbb.h
index 00a8b9fb635c..60342b65b89b 100644
--- a/libstdc++-v3/include/pstl/parallel_backend_tbb.h
+++ b/libstdc++-v3/include/pstl/parallel_backend_tbb.h
@@ -1,45 +1,50 @@
 // -*- C++ -*-
-//===-- parallel_backend_tbb.h --------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_PARALLEL_BACKEND_TBB_H
-#define _PSTL_PARALLEL_BACKEND_TBB_H
+// This header guard is used to check inclusion of TBB backend.
+// Changing this macro may result in broken tests.
+#ifndef _ONEDPL_PARALLEL_BACKEND_TBB_H
+#define _ONEDPL_PARALLEL_BACKEND_TBB_H
 
+#include <cassert>
 #include <algorithm>
 #include <type_traits>
+#include <functional> // for std::invoke
 
 #include "parallel_backend_utils.h"
+#include "execution_impl.h"
+#include "utils.h"
 
-#ifndef TBB_SUPPRESS_DEPRECATED_MESSAGES
-# define TBB_SUPPRESS_DEPRECATED_MESSAGES 1
-# define _GLIBCXX_UNDEF_SUPPRESS
-#endif
-
-// Bring in minimal required subset of Intel TBB
+// Bring in minimal required subset of Intel(R) Threading Building Blocks (Intel(R) TBB)
 #include <tbb/blocked_range.h>
 #include <tbb/parallel_for.h>
+#include <tbb/parallel_for_each.h>
 #include <tbb/parallel_reduce.h>
 #include <tbb/parallel_scan.h>
 #include <tbb/parallel_invoke.h>
 #include <tbb/task_arena.h>
 #include <tbb/tbb_allocator.h>
-#include <tbb/task.h>
-
-#ifdef _GLIBCXX_UNDEF_SUPPRESS
-# undef TBB_SUPPRESS_DEPRECATED_MESSAGES
-# undef _GLIBCXX_UNDEF_SUPPRESS
+#if TBB_INTERFACE_VERSION > 12000
+#    include <tbb/task.h>
 #endif
 
 #if TBB_INTERFACE_VERSION < 10000
 #    error Intel(R) Threading Building Blocks 2018 is required; older versions are not supported.
 #endif
 
-namespace __pstl
+namespace std::__onedpl
 {
 namespace __tbb_backend
 {
@@ -50,33 +55,11 @@ not an initialize array, because initialization/destruction
 would make the span be at least O(N). */
 // tbb::allocator can improve performance in some cases.
 template <typename _Tp>
-class __buffer
-{
-    tbb::tbb_allocator<_Tp> _M_allocator;
-    _Tp* _M_ptr;
-    const std::size_t _M_buf_size;
-    __buffer(const __buffer&) = delete;
-    void
-    operator=(const __buffer&) = delete;
-
-  public:
-    //! Try to obtain buffer of given size to store objects of _Tp type
-    __buffer(std::size_t n) : _M_allocator(), _M_ptr(_M_allocator.allocate(n)), _M_buf_size(n) {}
-    //! True if buffer was successfully obtained, zero otherwise.
-    operator bool() const { return _M_ptr != NULL; }
-    //! Return pointer to buffer, or  NULL if buffer could not be obtained.
-    _Tp*
-    get() const
-    {
-        return _M_ptr;
-    }
-    //! Destroy buffer
-    ~__buffer() { _M_allocator.deallocate(_M_ptr, _M_buf_size); }
-};
+using __buffer = __onedpl::__utils::__buffer_impl<_Tp, tbb::tbb_allocator>;
 
 // Wrapper for tbb::task
 inline void
-__cancel_execution()
+__cancel_execution(__onedpl::__internal::__tbb_backend_tag)
 {
 #if TBB_INTERFACE_VERSION <= 12000
     tbb::task::self().group()->cancel_group_execution();
@@ -109,10 +92,13 @@ class __parallel_for_body
 // wrapper over tbb::parallel_for
 template <class _ExecutionPolicy, class _Index, class _Fp>
 void
-__parallel_for(__pstl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _Index __first, _Index __last, _Fp __f)
+__parallel_for(__onedpl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _Index __first, _Index __last, _Fp __f,
+               std::size_t __grainsize = 1 /*matches the default grainsize value of tbb::blocked_range according to
+               the specification*/)
 {
     tbb::this_task_arena::isolate([=]() {
-        tbb::parallel_for(tbb::blocked_range<_Index>(__first, __last), __parallel_for_body<_Index, _Fp>(__f));
+        tbb::parallel_for(tbb::blocked_range<_Index>(__first, __last, __grainsize),
+                          __parallel_for_body<_Index, _Fp>(__f));
     });
 }
 
@@ -120,7 +106,7 @@ __parallel_for(__pstl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _Index
 // wrapper over tbb::parallel_reduce
 template <class _ExecutionPolicy, class _Value, class _Index, typename _RealBody, typename _Reduction>
 _Value
-__parallel_reduce(__pstl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _Index __first, _Index __last,
+__parallel_reduce(__onedpl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _Index __first, _Index __last,
                   const _Value& __identity, const _RealBody& __real_body, const _Reduction& __reduction)
 {
     return tbb::this_task_arena::isolate([__first, __last, &__identity, &__real_body, &__reduction]() -> _Value {
@@ -145,21 +131,21 @@ __parallel_reduce(__pstl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _In
 template <class _Index, class _Up, class _Tp, class _Cp, class _Rp>
 struct __par_trans_red_body
 {
-    alignas(_Tp) char _M_sum_storage[sizeof(_Tp)]; // Holds generalized non-commutative sum when has_sum==true
-    _Rp _M_brick_reduce;                           // Most likely to have non-empty layout
+    std::optional<_Tp> __lazy_sum;
+    _Rp _M_brick_reduce;
     _Up _M_u;
     _Cp _M_combine;
     bool _M_has_sum; // Put last to minimize size of class
-    _Tp&
+    _Tp
     sum()
     {
-        _PSTL_ASSERT_MSG(_M_has_sum, "sum expected");
-        return *(_Tp*)_M_sum_storage;
+        __TBB_ASSERT(_M_has_sum, "sum expected");
+        return std::move(__lazy_sum.value());
     }
     __par_trans_red_body(_Up __u, _Tp __init, _Cp __c, _Rp __r)
         : _M_brick_reduce(__r), _M_u(__u), _M_combine(__c), _M_has_sum(true)
     {
-        new (_M_sum_storage) _Tp(__init);
+        __lazy_sum.emplace(std::move(__init));
     }
 
     __par_trans_red_body(__par_trans_red_body& __left, tbb::split)
@@ -167,17 +153,11 @@ struct __par_trans_red_body
     {
     }
 
-    ~__par_trans_red_body()
-    {
-        // 17.6.5.12 tells us to not worry about catching exceptions from destructors.
-        if (_M_has_sum)
-            sum().~_Tp();
-    }
-
     void
     join(__par_trans_red_body& __rhs)
     {
-        sum() = _M_combine(sum(), __rhs.sum());
+        _Tp& __sum = __lazy_sum.value();
+        __sum = _M_combine(std::move(__sum), std::move(__rhs.__lazy_sum.value()));
     }
 
     void
@@ -187,24 +167,25 @@ struct __par_trans_red_body
         _Index __j = __range.end();
         if (!_M_has_sum)
         {
-            _PSTL_ASSERT_MSG(__range.size() > 1, "there should be at least 2 elements");
-            new (&_M_sum_storage)
-                _Tp(_M_combine(_M_u(__i), _M_u(__i + 1))); // The condition i+1 < j is provided by the grain size of 3
+            __TBB_ASSERT(__range.size() > 1, "there should be at least 2 elements");
+            __lazy_sum.emplace(_M_combine(_M_u(__i), _M_u(__i + 1)));
             _M_has_sum = true;
-            std::advance(__i, 2);
+            ::std::advance(__i, 2);
             if (__i == __j)
                 return;
         }
-        sum() = _M_brick_reduce(__i, __j, sum());
+        _Tp& __sum = __lazy_sum.value();
+        __sum = _M_brick_reduce(__i, __j, std::move(__sum));
     }
 };
 
 template <class _ExecutionPolicy, class _Index, class _Up, class _Tp, class _Cp, class _Rp>
 _Tp
-__parallel_transform_reduce(__pstl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _Index __first, _Index __last,
-                            _Up __u, _Tp __init, _Cp __combine, _Rp __brick_reduce)
+__parallel_transform_reduce(__onedpl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _Index __first,
+                            _Index __last, _Up __u, _Tp __init, _Cp __combine, _Rp __brick_reduce)
 {
-    __tbb_backend::__par_trans_red_body<_Index, _Up, _Tp, _Cp, _Rp> __body(__u, __init, __combine, __brick_reduce);
+    __tbb_backend::__par_trans_red_body<_Index, _Up, _Tp, _Cp, _Rp> __body(__u, std::move(__init), __combine,
+                                                                           __brick_reduce);
     // The grain size of 3 is used in order to provide minimum 2 elements for each body
     tbb::this_task_arena::isolate(
         [__first, __last, &__body]() { tbb::parallel_reduce(tbb::blocked_range<_Index>(__first, __last, 3), __body); });
@@ -247,7 +228,7 @@ class __trans_scan_body
     _Tp&
     sum() const
     {
-        _PSTL_ASSERT_MSG(_M_has_sum, "sum expected");
+        __TBB_ASSERT(_M_has_sum, "sum expected");
         return *const_cast<_Tp*>(reinterpret_cast<_Tp const*>(_M_sum_storage));
     }
 
@@ -308,6 +289,12 @@ __split(_Index __m)
 // __parallel_strict_scan
 //------------------------------------------------------------------------
 
+// TODO: Here are improvements to consider:
+// 1. Affinitize leaves of upsweep and leaves of downsweep.  For working sets that
+//    fit in cache, this might reduce memory interconnect load significantly.
+// 2. Add automatic tilesize adjustment.  Initial stealing during upsweep ought to provide a good hint.
+// 3. Use continuation-passing style for the tasks.  For downsweep, a binomial tree pattern is likely optimal.
+
 template <typename _Index, typename _Tp, typename _Rp, typename _Cp>
 void
 __upsweep(_Index __i, _Index __m, _Index __tilesize, _Tp* __r, _Index __lastsize, _Rp __reduce, _Cp __combine)
@@ -364,7 +351,7 @@ __downsweep(_Index __i, _Index __m, _Index __tilesize, _Tp* __r, _Index __lastsi
 // T must have a trivial constructor and destructor.
 template <class _ExecutionPolicy, typename _Index, typename _Tp, typename _Rp, typename _Cp, typename _Sp, typename _Ap>
 void
-__parallel_strict_scan(__pstl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _Index __n, _Tp __initial,
+__parallel_strict_scan(__onedpl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _Index __n, _Tp __initial,
                        _Rp __reduce, _Cp __combine, _Sp __scan, _Ap __apex)
 {
     tbb::this_task_arena::isolate([=, &__combine]() {
@@ -374,7 +361,7 @@ __parallel_strict_scan(__pstl::__internal::__tbb_backend_tag, _ExecutionPolicy&&
             const _Index __slack = 4;
             _Index __tilesize = (__n - 1) / (__slack * __p) + 1;
             _Index __m = (__n - 1) / __tilesize;
-            __buffer<_Tp> __buf(__m + 1);
+            __tbb_backend::__buffer<_Tp> __buf(__m + 1);
             _Tp* __r = __buf.get();
             __tbb_backend::__upsweep(_Index(0), _Index(__m + 1), __tilesize, __r, __n - __m * __tilesize, __reduce,
                                      __combine);
@@ -382,7 +369,7 @@ __parallel_strict_scan(__pstl::__internal::__tbb_backend_tag, _ExecutionPolicy&&
             // When __apex is a no-op and __combine has no side effects, a good optimizer
             // should be able to eliminate all code between here and __apex.
             // Alternatively, provide a default value for __apex that can be
-            // recognized by metaprogramming that conditionlly executes the following.
+            // recognized by metaprogramming that conditionally executes the following.
             size_t __k = __m + 1;
             _Tp __t = __r[__k - 1];
             while ((__k &= __k - 1))
@@ -404,8 +391,8 @@ __parallel_strict_scan(__pstl::__internal::__tbb_backend_tag, _ExecutionPolicy&&
 
 template <class _ExecutionPolicy, class _Index, class _Up, class _Tp, class _Cp, class _Rp, class _Sp>
 _Tp
-__parallel_transform_scan(__pstl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _Index __n, _Up __u, _Tp __init,
-                          _Cp __combine, _Rp __brick_reduce, _Sp __scan)
+__parallel_transform_scan(__onedpl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _Index __n, _Up __u,
+                          _Tp __init, _Cp __combine, _Rp __brick_reduce, _Sp __scan)
 {
     __trans_scan_body<_Index, _Up, _Tp, _Cp, _Rp, _Sp> __body(__u, __init, __combine, __brick_reduce, __scan);
     auto __range = tbb::blocked_range<_Index>(0, __n);
@@ -422,7 +409,6 @@ __parallel_transform_scan(__pstl::__internal::__tbb_backend_tag, _ExecutionPolic
 //
 // These are used by parallel implementations but do not depend on them.
 //------------------------------------------------------------------------
-#define _PSTL_MERGE_CUT_OFF 2000
 
 template <typename _Func>
 class __func_task;
@@ -437,14 +423,14 @@ class __task : public tbb::task
     __task*
     make_continuation(_Fn&& __f)
     {
-        return new (allocate_continuation()) __func_task<typename std::decay<_Fn>::type>(std::forward<_Fn>(__f));
+        return new (allocate_continuation()) __func_task<::std::decay_t<_Fn>>(::std::forward<_Fn>(__f));
     }
 
     template <typename _Fn>
     __task*
     make_child_of(__task* parent, _Fn&& __f)
     {
-        return new (parent->allocate_child()) __func_task<typename std::decay<_Fn>::type>(std::forward<_Fn>(__f));
+        return new (parent->allocate_child()) __func_task<::std::decay_t<_Fn>>(::std::forward<_Fn>(__f));
     }
 
     template <typename _Fn>
@@ -452,7 +438,7 @@ class __task : public tbb::task
     make_additional_child_of(tbb::task* parent, _Fn&& __f)
     {
         return new (tbb::task::allocate_additional_child_of(*parent))
-            __func_task<typename std::decay<_Fn>::type>(std::forward<_Fn>(__f));
+            __func_task<::std::decay_t<_Fn>>(::std::forward<_Fn>(__f));
     }
 
     inline void
@@ -494,7 +480,7 @@ class __func_task : public __task
 
   public:
     template <typename _Fn>
-    __func_task(_Fn&& __f) : _M_func{std::forward<_Fn>(__f)}
+    __func_task(_Fn&& __f) : _M_func{::std::forward<_Fn>(__f)}
     {
     }
 
@@ -513,7 +499,7 @@ class __root_task
   public:
     template <typename... Args>
     __root_task(Args&&... args)
-        : _M_task{new (tbb::task::allocate_root()) __func_task<_Func>{_Func(std::forward<Args>(args)...)}}
+        : _M_task{new (tbb::task::allocate_root()) __func_task<_Func>{_Func(::std::forward<Args>(args)...)}}
     {
     }
 
@@ -528,17 +514,16 @@ class __task : public tbb::detail::d1::task
     tbb::detail::d1::small_object_allocator _M_allocator{};
     tbb::detail::d1::execution_data* _M_execute_data{};
     __task* _M_parent{};
-    std::atomic<int> _M_refcount{};
+    ::std::atomic<int> _M_refcount{};
     bool _M_recycle{};
 
     template <typename _Fn>
     __task*
     allocate_func_task(_Fn&& __f)
     {
-        _PSTL_ASSERT(_M_execute_data != nullptr);
+        assert(_M_execute_data != nullptr);
         tbb::detail::d1::small_object_allocator __alloc{};
-        auto __t =
-            __alloc.new_object<__func_task<typename std::decay<_Fn>::type>>(*_M_execute_data, std::forward<_Fn>(__f));
+        auto __t = __alloc.new_object<__func_task<::std::decay_t<_Fn>>>(*_M_execute_data, ::std::forward<_Fn>(__f));
         __t->_M_allocator = __alloc;
         return __t;
     }
@@ -553,14 +538,14 @@ class __task : public tbb::detail::d1::task
     void
     set_ref_count(int __n)
     {
-        _M_refcount.store(__n, std::memory_order_release);
+        _M_refcount.store(__n, ::std::memory_order_release);
     }
 
     template <typename _Fn>
     __task*
     make_continuation(_Fn&& __f)
     {
-        auto __t = allocate_func_task(std::forward<_Fn&&>(__f));
+        auto __t = allocate_func_task(::std::forward<_Fn&&>(__f));
         __t->_M_parent = _M_parent;
         _M_parent = nullptr;
         return __t;
@@ -570,7 +555,7 @@ class __task : public tbb::detail::d1::task
     __task*
     make_child_of(__task* __parent, _Fn&& __f)
     {
-        auto __t = allocate_func_task(std::forward<_Fn&&>(__f));
+        auto __t = allocate_func_task(::std::forward<_Fn&&>(__f));
         __t->_M_parent = __parent;
         return __t;
     }
@@ -579,8 +564,8 @@ class __task : public tbb::detail::d1::task
     __task*
     make_additional_child_of(__task* __parent, _Fn&& __f)
     {
-        auto __t = make_child_of(__parent, std::forward<_Fn>(__f));
-        _PSTL_ASSERT(__parent->_M_refcount.load(std::memory_order_relaxed) > 0);
+        auto __t = make_child_of(__parent, ::std::forward<_Fn>(__f));
+        assert(__parent->_M_refcount.load(::std::memory_order_relaxed) > 0);
         ++__parent->_M_refcount;
         return __t;
     }
@@ -601,7 +586,7 @@ class __task : public tbb::detail::d1::task
     inline void
     spawn(__task* __t)
     {
-        _PSTL_ASSERT(_M_execute_data != nullptr);
+        assert(_M_execute_data != nullptr);
         tbb::detail::d1::spawn(*__t, *_M_execute_data->context);
     }
 
@@ -629,10 +614,10 @@ class __func_task : public __task
         _M_recycle = false;
         __task* __next = _M_func(this);
         return finalize(__next);
-    };
+    }
 
     __task*
-    cancel(tbb::detail::d1::execution_data& __ed) override
+    cancel(tbb::detail::d1::execution_data&) override
     {
         return finalize(nullptr);
     }
@@ -654,8 +639,8 @@ class __func_task : public __task
 
         this->~__func_task();
 
-        _PSTL_ASSERT(__parent != nullptr);
-        _PSTL_ASSERT(__parent->_M_refcount.load(std::memory_order_relaxed) > 0);
+        assert(__parent != nullptr);
+        assert(__parent->_M_refcount.load(::std::memory_order_relaxed) > 0);
 
         auto __refcount = --__parent->_M_refcount;
 
@@ -665,7 +650,7 @@ class __func_task : public __task
 
         if (__refcount == 0)
         {
-            _PSTL_ASSERT(__next == nullptr);
+            assert(__next == nullptr);
             return __parent;
         }
 
@@ -676,7 +661,7 @@ class __func_task : public __task
 
   public:
     template <typename _Fn>
-    __func_task(_Fn&& __f) : _M_func(std::forward<_Fn>(__f))
+    __func_task(_Fn&& __f) : _M_func(::std::forward<_Fn>(__f))
     {
     }
 
@@ -691,14 +676,14 @@ template <typename _Func>
 class __root_task : public __task
 {
     __task*
-    execute(tbb::detail::d1::execution_data& __ed) override
+    execute(tbb::detail::d1::execution_data&) override
     {
         _M_wait_object.release();
         return nullptr;
-    };
+    }
 
     __task*
-    cancel(tbb::detail::d1::execution_data& __ed) override
+    cancel(tbb::detail::d1::execution_data&) override
     {
         _M_wait_object.release();
         return nullptr;
@@ -713,24 +698,26 @@ class __root_task : public __task
     __root_task(Args&&... args) : _M_wait_object{1}
     {
         tbb::detail::d1::small_object_allocator __alloc{};
-        _M_func_task = __alloc.new_object<__func_task<_Func>>(_Func(std::forward<Args>(args)...));
+        _M_func_task = __alloc.new_object<__func_task<_Func>>(_Func(::std::forward<Args>(args)...));
         _M_func_task->_M_allocator = __alloc;
         _M_func_task->_M_parent = this;
-        _M_refcount.store(1, std::memory_order_relaxed);
+        _M_refcount.store(1, ::std::memory_order_relaxed);
     }
 
     friend class __task;
 };
 #endif // TBB_INTERFACE_VERSION <= 12000
 
+inline constexpr std::size_t __merge_cut_off = 2000;
+
 template <typename _RandomAccessIterator1, typename _RandomAccessIterator2, typename _Compare, typename _Cleanup,
           typename _LeafMerge>
 class __merge_func
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type _DifferenceType1;
-    typedef typename std::iterator_traits<_RandomAccessIterator2>::difference_type _DifferenceType2;
-    typedef typename std::common_type<_DifferenceType1, _DifferenceType2>::type _SizeType;
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::value_type _ValueType;
+    using _DifferenceType1 = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
+    using _DifferenceType2 = typename std::iterator_traits<_RandomAccessIterator2>::difference_type;
+    using _SizeType = typename std::common_type_t<_DifferenceType1, _DifferenceType2>;
+    using _ValueType = typename std::iterator_traits<_RandomAccessIterator1>::value_type;
 
     _RandomAccessIterator1 _M_x_beg;
     _RandomAccessIterator2 _M_z_beg;
@@ -742,18 +729,10 @@ class __merge_func
     _LeafMerge _M_leaf_merge;
     _SizeType _M_nsort; //number of elements to be sorted for partial_sort algorithm
 
-    static const _SizeType __merge_cut_off = _PSTL_MERGE_CUT_OFF;
-
     bool _root;   //means a task is merging root task
     bool _x_orig; //"true" means X(or left ) subrange is in the original container; false - in the buffer
     bool _y_orig; //"true" means Y(or right) subrange is in the original container; false - in the buffer
-    bool _split; //"true" means a merge task is a split task for parallel merging, the execution logic differs
-
-    bool
-    is_partial() const
-    {
-        return _M_nsort > 0;
-    }
+    bool _split;  //"true" means a merge task is a split task for parallel merging, the execution logic differs
 
     struct __move_value
     {
@@ -761,7 +740,7 @@ class __merge_func
         void
         operator()(Iterator1 __x, Iterator2 __z)
         {
-            *__z = std::move(*__x);
+            *__z = ::std::move(*__x);
         }
     };
 
@@ -771,7 +750,7 @@ class __merge_func
         void
         operator()(Iterator1 __x, Iterator2 __z)
         {
-            ::new (std::addressof(*__z)) _ValueType(std::move(*__x));
+            ::new (::std::addressof(*__z)) _ValueType(::std::move(*__x));
         }
     };
 
@@ -782,13 +761,13 @@ class __merge_func
         operator()(Iterator1 __first1, Iterator1 __last1, Iterator2 __first2)
         {
             if (__last1 - __first1 < __merge_cut_off)
-                return std::move(__first1, __last1, __first2);
+                return ::std::move(__first1, __last1, __first2);
 
             auto __n = __last1 - __first1;
             tbb::parallel_for(tbb::blocked_range<_SizeType>(0, __n, __merge_cut_off),
                               [__first1, __first2](const tbb::blocked_range<_SizeType>& __range) {
-                                  std::move(__first1 + __range.begin(), __first1 + __range.end(),
-                                            __first2 + __range.begin());
+                                  ::std::move(__first1 + __range.begin(), __first1 + __range.end(),
+                                              __first2 + __range.begin());
                               });
             return __first2 + __n;
         }
@@ -802,7 +781,7 @@ class __merge_func
         {
             if (__last1 - __first1 < __merge_cut_off)
             {
-                for (; __first1 != __last1; ++__first1, ++__first2)
+                for (; __first1 != __last1; ++__first1, (void)++__first2)
                     __move_value_construct()(__first1, __first2);
                 return __first2;
             }
@@ -819,9 +798,9 @@ class __merge_func
 
     struct __cleanup_range
     {
-        template <typename _Iterator>
+        template <typename Iterator>
         void
-        operator()(_Iterator __first, _Iterator __last)
+        operator()(Iterator __first, Iterator __last)
         {
             if (__last - __first < __merge_cut_off)
                 _Cleanup()(__first, __last);
@@ -841,8 +820,8 @@ class __merge_func
                  _Cleanup, _LeafMerge __leaf_merge, _SizeType __nsort, _RandomAccessIterator1 __x_beg,
                  _RandomAccessIterator2 __z_beg, bool __x_orig, bool __y_orig, bool __root)
         : _M_x_beg(__x_beg), _M_z_beg(__z_beg), _M_xs(__xs), _M_xe(__xe), _M_ys(__ys), _M_ye(__ye), _M_zs(__zs),
-          _M_comp(__comp), _M_leaf_merge(__leaf_merge), _M_nsort(__nsort), _root(__root),
-          _x_orig(__x_orig), _y_orig(__y_orig), _split(false)
+          _M_comp(__comp), _M_leaf_merge(__leaf_merge), _M_nsort(__nsort), _root(__root), _x_orig(__x_orig),
+          _y_orig(__y_orig), _split(false)
     {
     }
 
@@ -874,37 +853,42 @@ class __merge_func
     bool
     x_less_y()
     {
-        const auto __nx = (_M_xe - _M_xs);
-        const auto __ny = (_M_ye - _M_ys);
-        _PSTL_ASSERT(__nx > 0 && __ny > 0);
+        auto __nx = (_M_xe - _M_xs);
+        [[maybe_unused]] auto __ny = (_M_ye - _M_ys);
 
-        _PSTL_ASSERT(_x_orig == _y_orig);
-        _PSTL_ASSERT(!is_partial());
+        assert(__nx > 0 && __ny > 0);
+        assert(_M_nsort > 0);
+
+        auto __kx = std::min(_M_nsort, __nx);
+        [[maybe_unused]] auto __ky = std::min(_M_nsort, __ny);
+
+        assert(_x_orig == _y_orig);
 
         if (_x_orig)
         {
-            _PSTL_ASSERT(std::is_sorted(_M_x_beg + _M_xs, _M_x_beg + _M_xe, _M_comp));
-            _PSTL_ASSERT(std::is_sorted(_M_x_beg + _M_ys, _M_x_beg + _M_ye, _M_comp));
-            return !_M_comp(*(_M_x_beg + _M_ys), *(_M_x_beg + _M_xe - 1));
+            assert(::std::is_sorted(_M_x_beg + _M_xs, _M_x_beg + _M_xs + __kx, _M_comp));
+            assert(::std::is_sorted(_M_x_beg + _M_ys, _M_x_beg + _M_ys + __ky, _M_comp));
+            return !std::invoke(_M_comp, *(_M_x_beg + _M_ys), *(_M_x_beg + _M_xs + __kx - 1));
         }
 
-        _PSTL_ASSERT(std::is_sorted(_M_z_beg + _M_xs, _M_z_beg + _M_xe, _M_comp));
-        _PSTL_ASSERT(std::is_sorted(_M_z_beg + _M_ys, _M_z_beg + _M_ye, _M_comp));
-        return !_M_comp(*(_M_z_beg + _M_zs + __nx), *(_M_z_beg + _M_zs + __nx - 1));
+        assert(::std::is_sorted(_M_z_beg + _M_xs, _M_z_beg + _M_xs + __kx, _M_comp));
+        assert(::std::is_sorted(_M_z_beg + _M_ys, _M_z_beg + _M_ys + __ky, _M_comp));
+        return !std::invoke(_M_comp, *(_M_z_beg + _M_zs + __nx), *(_M_z_beg + _M_zs + __kx - 1));
     }
     void
     move_x_range()
     {
         const auto __nx = (_M_xe - _M_xs);
-        const auto __ny = (_M_ye - _M_ys);
-        _PSTL_ASSERT(__nx > 0 && __ny > 0);
+        [[maybe_unused]] const auto __ny = (_M_ye - _M_ys);
+        assert(__nx > 0 && __ny > 0);
 
         if (_x_orig)
             __move_range_construct()(_M_x_beg + _M_xs, _M_x_beg + _M_xe, _M_z_beg + _M_zs);
         else
         {
             __move_range()(_M_z_beg + _M_zs, _M_z_beg + _M_zs + __nx, _M_x_beg + _M_xs);
-            __cleanup_range()(_M_z_beg + _M_zs, _M_z_beg + _M_zs + __nx);
+            if constexpr (!::std::is_trivially_destructible_v<_ValueType>)
+                __cleanup_range()(_M_z_beg + _M_zs, _M_z_beg + _M_zs + __nx);
         }
 
         _x_orig = !_x_orig;
@@ -913,14 +897,15 @@ class __merge_func
     move_y_range()
     {
         const auto __nx = (_M_xe - _M_xs);
-        const auto __ny = (_M_ye - _M_ys);
+        [[maybe_unused]] const auto __ny = (_M_ye - _M_ys);
 
         if (_y_orig)
             __move_range_construct()(_M_x_beg + _M_ys, _M_x_beg + _M_ye, _M_z_beg + _M_zs + __nx);
         else
         {
             __move_range()(_M_z_beg + _M_zs + __nx, _M_z_beg + _M_zs + __nx + __ny, _M_x_beg + _M_ys);
-            __cleanup_range()(_M_z_beg + _M_zs + __nx, _M_z_beg + _M_zs + __nx + __ny);
+            if constexpr (!::std::is_trivially_destructible_v<_ValueType>)
+                __cleanup_range()(_M_z_beg + _M_zs + __nx, _M_z_beg + _M_zs + __nx + __ny);
         }
 
         _y_orig = !_y_orig;
@@ -928,7 +913,8 @@ class __merge_func
     __task*
     merge_ranges(__task* __self)
     {
-        _PSTL_ASSERT(_x_orig == _y_orig); //two merged subrange must be lie into the same buffer
+        assert(_M_nsort > 0);
+        assert(_x_orig == _y_orig); //two merged subrange must be lie into the same buffer
 
         const auto __nx = (_M_xe - _M_xs);
         const auto __ny = (_M_ye - _M_ys);
@@ -944,24 +930,21 @@ class __merge_func
             _M_leaf_merge(_M_x_beg + _M_xs, _M_x_beg + _M_xe, _M_x_beg + _M_ys, _M_x_beg + _M_ye, _M_z_beg + _M_zs,
                           _M_comp, __move_value_construct(), __move_value_construct(), __move_range_construct(),
                           __move_range_construct());
-            _PSTL_ASSERT(parent_merge(__self)); //not root merging task
+            assert(parent_merge(__self)); //not root merging task
         }
         //merge to "origin"
         else
         {
-            _PSTL_ASSERT(_x_orig == _y_orig);
-
-            _PSTL_ASSERT(is_partial() || std::is_sorted(_M_z_beg + _M_xs, _M_z_beg + _M_xe, _M_comp));
-            _PSTL_ASSERT(is_partial() || std::is_sorted(_M_z_beg + _M_ys, _M_z_beg + _M_ye, _M_comp));
-
-            const auto __nx = (_M_xe - _M_xs);
-            const auto __ny = (_M_ye - _M_ys);
+            assert(_x_orig == _y_orig);
 
             _M_leaf_merge(_M_z_beg + _M_xs, _M_z_beg + _M_xe, _M_z_beg + _M_ys, _M_z_beg + _M_ye, _M_x_beg + _M_zs,
                           _M_comp, __move_value(), __move_value(), __move_range(), __move_range());
 
-            __cleanup_range()(_M_z_beg + _M_xs, _M_z_beg + _M_xe);
-            __cleanup_range()(_M_z_beg + _M_ys, _M_z_beg + _M_ye);
+            if constexpr (!::std::is_trivially_destructible_v<_ValueType>)
+            {
+                __cleanup_range()(_M_z_beg + _M_xs, _M_z_beg + _M_xe);
+                __cleanup_range()(_M_z_beg + _M_ys, _M_z_beg + _M_ye);
+            }
         }
         return nullptr;
     }
@@ -969,8 +952,8 @@ class __merge_func
     __task*
     process_ranges(__task* __self)
     {
-        _PSTL_ASSERT(_x_orig == _y_orig);
-        _PSTL_ASSERT(!_split);
+        assert(_x_orig == _y_orig);
+        assert(!_split);
 
         auto p = parent_merge(__self);
 
@@ -978,7 +961,7 @@ class __merge_func
         { //root merging task
 
             //optimization, just for sort algorithm, //{x} <= {y}
-            if (!is_partial() && x_less_y()) //we have a solution
+            if (x_less_y()) //we have a solution
             {
                 if (!_x_orig)
                 {                   //we have to move the solution to the origin
@@ -999,7 +982,7 @@ class __merge_func
         }
         //else: not root merging task (parent_merge() == NULL)
         //optimization, just for sort algorithm, //{x} <= {y}
-        if (!is_partial() && x_less_y())
+        if (x_less_y())
         {
             const auto id_range = _M_zs;
             p->set_odd(id_range, _x_orig);
@@ -1016,36 +999,41 @@ class __merge_func
     __task*
     split_merging(__task* __self)
     {
-        _PSTL_ASSERT(_x_orig == _y_orig);
+        assert(_x_orig == _y_orig);
+
         const auto __nx = (_M_xe - _M_xs);
         const auto __ny = (_M_ye - _M_ys);
-
         _SizeType __xm{};
         _SizeType __ym{};
+
         if (__nx < __ny)
         {
             __ym = _M_ys + __ny / 2;
 
             if (_x_orig)
-                __xm = std::upper_bound(_M_x_beg + _M_xs, _M_x_beg + _M_xe, *(_M_x_beg + __ym), _M_comp) - _M_x_beg;
+                __xm = ::std::upper_bound(_M_x_beg + _M_xs, _M_x_beg + _M_xs + __nx, *(_M_x_beg + __ym), _M_comp) -
+                       _M_x_beg;
             else
-                __xm = std::upper_bound(_M_z_beg + _M_xs, _M_z_beg + _M_xe, *(_M_z_beg + __ym), _M_comp) - _M_z_beg;
+                __xm = ::std::upper_bound(_M_z_beg + _M_xs, _M_z_beg + _M_xs + __nx, *(_M_z_beg + __ym), _M_comp) -
+                       _M_z_beg;
         }
         else
         {
             __xm = _M_xs + __nx / 2;
 
             if (_y_orig)
-                __ym = std::lower_bound(_M_x_beg + _M_ys, _M_x_beg + _M_ye, *(_M_x_beg + __xm), _M_comp) - _M_x_beg;
+                __ym = ::std::lower_bound(_M_x_beg + _M_ys, _M_x_beg + _M_ys + __ny, *(_M_x_beg + __xm), _M_comp) -
+                       _M_x_beg;
             else
-                __ym = std::lower_bound(_M_z_beg + _M_ys, _M_z_beg + _M_ye, *(_M_z_beg + __xm), _M_comp) - _M_z_beg;
+                __ym = ::std::lower_bound(_M_z_beg + _M_ys, _M_z_beg + _M_ys + __ny, *(_M_z_beg + __xm), _M_comp) -
+                       _M_z_beg;
         }
 
         auto __zm = _M_zs + ((__xm - _M_xs) + (__ym - _M_ys));
         __merge_func __right_func(__xm, _M_xe, __ym, _M_ye, __zm, _M_comp, _Cleanup(), _M_leaf_merge, _M_nsort,
                                   _M_x_beg, _M_z_beg, _x_orig, _y_orig, _root);
         __right_func._split = true;
-        auto __merge_task = __self->make_additional_child_of(__self->parent(), std::move(__right_func));
+        auto __merge_task = __self->make_additional_child_of(__self->parent(), ::std::move(__right_func));
         __self->spawn(__merge_task);
         __self->recycle_as_continuation();
 
@@ -1088,8 +1076,8 @@ operator()(__task* __self)
     {
         const _SizeType __nx = (_M_xe - _M_xs);
         const _SizeType __ny = (_M_ye - _M_ys);
-        _PSTL_ASSERT(__nx > 0);
-        _PSTL_ASSERT(__nx > 0);
+        assert(__nx > 0);
+        assert(__nx > 0);
 
         if (__nx < __ny)
             move_x_range();
@@ -1104,9 +1092,9 @@ template <typename _RandomAccessIterator1, typename _RandomAccessIterator2, type
 class __stable_sort_func
 {
   public:
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type _DifferenceType1;
-    typedef typename std::iterator_traits<_RandomAccessIterator2>::difference_type _DifferenceType2;
-    typedef typename std::common_type<_DifferenceType1, _DifferenceType2>::type _SizeType;
+    using _DifferenceType1 = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
+    using _DifferenceType2 = typename std::iterator_traits<_RandomAccessIterator2>::difference_type;
+    using _SizeType = typename std::common_type_t<_DifferenceType1, _DifferenceType2>;
 
   private:
     _RandomAccessIterator1 _M_xs, _M_xe, _M_x_beg;
@@ -1129,34 +1117,34 @@ class __stable_sort_func
     operator()(__task* __self);
 };
 
-#define _PSTL_STABLE_SORT_CUT_OFF 500
+#define _ONEDPL_STABLE_SORT_CUT_OFF 500
 
 template <typename _RandomAccessIterator1, typename _RandomAccessIterator2, typename _Compare, typename _LeafSort>
 __task*
 __stable_sort_func<_RandomAccessIterator1, _RandomAccessIterator2, _Compare, _LeafSort>::operator()(__task* __self)
 {
-    typedef __merge_func<_RandomAccessIterator1, _RandomAccessIterator2, _Compare, __utils::__serial_destroy,
-                         __utils::__serial_move_merge>
-        _MergeTaskType;
+    using _MergeTaskType = __merge_func<_RandomAccessIterator1, _RandomAccessIterator2, _Compare,
+                                        __utils::__serial_destroy, __utils::__serial_move_merge>;
+
+    assert(_M_nsort > 0);
 
     const _SizeType __n = _M_xe - _M_xs;
-    const _SizeType __nmerge = _M_nsort > 0 ? _M_nsort : __n;
-    const _SizeType __sort_cut_off = _PSTL_STABLE_SORT_CUT_OFF;
+    const _SizeType __nmerge = ::std::min(_M_nsort, __n);
+    const _SizeType __sort_cut_off = _ONEDPL_STABLE_SORT_CUT_OFF;
     if (__n <= __sort_cut_off)
     {
         _M_leaf_sort(_M_xs, _M_xe, _M_comp);
-        _PSTL_ASSERT(!_M_root);
+        assert(!_M_root);
         return nullptr;
     }
 
     const _RandomAccessIterator1 __xm = _M_xs + __n / 2;
     const _RandomAccessIterator2 __zm = _M_zs + (__xm - _M_xs);
-    const _RandomAccessIterator2 __ze = _M_zs + __n;
     _MergeTaskType __m(_MergeTaskType(_M_xs - _M_x_beg, __xm - _M_x_beg, __xm - _M_x_beg, _M_xe - _M_x_beg,
                                       _M_zs - _M_z_beg, _M_comp, __utils::__serial_destroy(),
                                       __utils::__serial_move_merge(__nmerge), _M_nsort, _M_x_beg, _M_z_beg,
                                       /*x_orig*/ true, /*y_orig*/ true, /*root*/ _M_root));
-    auto __parent = __self->make_continuation(std::move(__m));
+    auto __parent = __self->make_continuation(::std::move(__m));
     __parent->set_ref_count(2);
     auto __right = __self->make_child_of(
         __parent, __stable_sort_func(__xm, _M_xe, __zm, false, _M_comp, _M_leaf_sort, _M_nsort, _M_x_beg, _M_z_beg));
@@ -1170,21 +1158,19 @@ __stable_sort_func<_RandomAccessIterator1, _RandomAccessIterator2, _Compare, _Le
 
 template <class _ExecutionPolicy, typename _RandomAccessIterator, typename _Compare, typename _LeafSort>
 void
-__parallel_stable_sort(__pstl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _RandomAccessIterator __xs,
-                       _RandomAccessIterator __xe, _Compare __comp, _LeafSort __leaf_sort, std::size_t __nsort = 0)
+__parallel_stable_sort(__onedpl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _RandomAccessIterator __xs,
+                       _RandomAccessIterator __xe, _Compare __comp, _LeafSort __leaf_sort, ::std::size_t __nsort)
 {
     tbb::this_task_arena::isolate([=, &__nsort]() {
         //sorting based on task tree and parallel merge
-        typedef typename std::iterator_traits<_RandomAccessIterator>::value_type _ValueType;
-        typedef typename std::iterator_traits<_RandomAccessIterator>::difference_type _DifferenceType;
+        using _ValueType = typename std::iterator_traits<_RandomAccessIterator>::value_type;
+        using _DifferenceType = typename std::iterator_traits<_RandomAccessIterator>::difference_type;
         const _DifferenceType __n = __xe - __xs;
-        if (__nsort == __n)
-            __nsort = 0; // 'partial_sort' becomes 'sort'
 
-        const _DifferenceType __sort_cut_off = _PSTL_STABLE_SORT_CUT_OFF;
+        const _DifferenceType __sort_cut_off = _ONEDPL_STABLE_SORT_CUT_OFF;
         if (__n > __sort_cut_off)
         {
-            __buffer<_ValueType> __buf(__n);
+            __tbb_backend::__buffer<_ValueType> __buf(__n);
             __root_task<__stable_sort_func<_RandomAccessIterator, _ValueType*, _Compare, _LeafSort>> __root{
                 __xs, __xe, __buf.get(), true, __comp, __leaf_sort, __nsort, __xs, __buf.get()};
             __task::spawn_root_and_wait(__root);
@@ -1227,11 +1213,10 @@ __task*
 __merge_func_static<_RandomAccessIterator1, _RandomAccessIterator2, _RandomAccessIterator3, __M_Compare, _LeafMerge>::
 operator()(__task* __self)
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type _DifferenceType1;
-    typedef typename std::iterator_traits<_RandomAccessIterator2>::difference_type _DifferenceType2;
-    typedef typename std::common_type<_DifferenceType1, _DifferenceType2>::type _SizeType;
+    using _DifferenceType1 = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
+    using _DifferenceType2 = typename std::iterator_traits<_RandomAccessIterator2>::difference_type;
+    using _SizeType = typename std::common_type_t<_DifferenceType1, _DifferenceType2>;
     const _SizeType __n = (_M_xe - _M_xs) + (_M_ye - _M_ys);
-    const _SizeType __merge_cut_off = _PSTL_MERGE_CUT_OFF;
     if (__n <= __merge_cut_off)
     {
         _M_leaf_merge(_M_xs, _M_xe, _M_ys, _M_ye, _M_zs, _M_comp);
@@ -1243,12 +1228,12 @@ operator()(__task* __self)
     if (_M_xe - _M_xs < _M_ye - _M_ys)
     {
         __ym = _M_ys + (_M_ye - _M_ys) / 2;
-        __xm = std::upper_bound(_M_xs, _M_xe, *__ym, _M_comp);
+        __xm = ::std::upper_bound(_M_xs, _M_xe, *__ym, _M_comp);
     }
     else
     {
         __xm = _M_xs + (_M_xe - _M_xs) / 2;
-        __ym = std::lower_bound(_M_ys, _M_ye, *__xm, _M_comp);
+        __ym = ::std::lower_bound(_M_ys, _M_ye, *__xm, _M_comp);
     }
     const _RandomAccessIterator3 __zm = _M_zs + ((__xm - _M_xs) + (__ym - _M_ys));
     auto __right = __self->make_additional_child_of(
@@ -1264,15 +1249,14 @@ operator()(__task* __self)
 template <class _ExecutionPolicy, typename _RandomAccessIterator1, typename _RandomAccessIterator2,
           typename _RandomAccessIterator3, typename _Compare, typename _LeafMerge>
 void
-__parallel_merge(__pstl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _RandomAccessIterator1 __xs,
+__parallel_merge(__onedpl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _RandomAccessIterator1 __xs,
                  _RandomAccessIterator1 __xe, _RandomAccessIterator2 __ys, _RandomAccessIterator2 __ye,
                  _RandomAccessIterator3 __zs, _Compare __comp, _LeafMerge __leaf_merge)
 {
-    typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type _DifferenceType1;
-    typedef typename std::iterator_traits<_RandomAccessIterator2>::difference_type _DifferenceType2;
-    typedef typename std::common_type<_DifferenceType1, _DifferenceType2>::type _SizeType;
+    using _DifferenceType1 = typename std::iterator_traits<_RandomAccessIterator1>::difference_type;
+    using _DifferenceType2 = typename std::iterator_traits<_RandomAccessIterator2>::difference_type;
+    using _SizeType = typename std::common_type_t<_DifferenceType1, _DifferenceType2>;
     const _SizeType __n = (__xe - __xs) + (__ye - __ys);
-    const _SizeType __merge_cut_off = _PSTL_MERGE_CUT_OFF;
     if (__n <= __merge_cut_off)
     {
         // Fall back on serial merge
@@ -1281,9 +1265,8 @@ __parallel_merge(__pstl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _Ran
     else
     {
         tbb::this_task_arena::isolate([=]() {
-            typedef __merge_func_static<_RandomAccessIterator1, _RandomAccessIterator2, _RandomAccessIterator3,
-                                        _Compare, _LeafMerge>
-                _TaskType;
+            using _TaskType = __merge_func_static<_RandomAccessIterator1, _RandomAccessIterator2,
+                                                  _RandomAccessIterator3, _Compare, _LeafMerge>;
             __root_task<_TaskType> __root{__xs, __xe, __ys, __ye, __zs, __comp, __leaf_merge};
             __task::spawn_root_and_wait(__root);
         });
@@ -1293,15 +1276,73 @@ __parallel_merge(__pstl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _Ran
 //------------------------------------------------------------------------
 // parallel_invoke
 //------------------------------------------------------------------------
+
 template <class _ExecutionPolicy, typename _F1, typename _F2>
 void
-__parallel_invoke(__pstl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _F1&& __f1, _F2&& __f2)
+__parallel_invoke(__onedpl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _F1&& __f1, _F2&& __f2)
 {
     //TODO: a version of tbb::this_task_arena::isolate with variadic arguments pack should be added in the future
-    tbb::this_task_arena::isolate([&]() { tbb::parallel_invoke(std::forward<_F1>(__f1), std::forward<_F2>(__f2)); });
+    tbb::this_task_arena::isolate(
+        [&]() { tbb::parallel_invoke(::std::forward<_F1>(__f1), ::std::forward<_F2>(__f2)); });
+}
+
+//------------------------------------------------------------------------
+// parallel_for_each
+//------------------------------------------------------------------------
+
+template <class _ExecutionPolicy, class _ForwardIterator, class _Fp>
+void
+__parallel_for_each(__onedpl::__internal::__tbb_backend_tag, _ExecutionPolicy&&, _ForwardIterator __begin,
+                    _ForwardIterator __end, _Fp __f)
+{
+    tbb::this_task_arena::isolate([&]() { tbb::parallel_for_each(__begin, __end, __f); });
+}
+
+namespace __detail
+{
+
+// Workaround for VS 2017: declare an alias to the CRTP base template
+template <typename _ValueType, typename... _Args>
+struct __enumerable_thread_local_storage;
+
+template <typename... _Ts>
+using __etls_base = __utils::__enumerable_thread_local_storage_base<__enumerable_thread_local_storage, _Ts...>;
+
+template <typename _ValueType, typename... _Args>
+struct __enumerable_thread_local_storage : public __etls_base<_ValueType, _Args...>
+{
+
+    template <typename... _LocalArgs>
+    __enumerable_thread_local_storage(_LocalArgs&&... __args)
+        : __etls_base<_ValueType, _Args...>({std::forward<_LocalArgs>(__args)...})
+    {
+    }
+
+    static std::size_t
+    get_num_threads()
+    {
+        return tbb::this_task_arena::max_concurrency();
+    }
+
+    static std::size_t
+    get_thread_num()
+    {
+        return tbb::this_task_arena::current_thread_index();
+    }
+};
+
+} // namespace __detail
+
+// enumerable thread local storage should only be created with this make function
+template <typename _ValueType, typename... _Args>
+__detail::__enumerable_thread_local_storage<_ValueType, std::remove_reference_t<_Args>...>
+__make_enumerable_tls(_Args&&... __args)
+{
+    return __detail::__enumerable_thread_local_storage<_ValueType, std::remove_reference_t<_Args>...>(
+        std::forward<_Args>(__args)...);
 }
 
 } // namespace __tbb_backend
-} // namespace __pstl
+} // namespace std::__onedpl
 
-#endif /* _PSTL_PARALLEL_BACKEND_TBB_H */
+#endif // _ONEDPL_PARALLEL_BACKEND_TBB_H
diff --git a/libstdc++-v3/include/pstl/parallel_backend_utils.h b/libstdc++-v3/include/pstl/parallel_backend_utils.h
index 39eafad2fd18..235d82d89abc 100644
--- a/libstdc++-v3/include/pstl/parallel_backend_utils.h
+++ b/libstdc++-v3/include/pstl/parallel_backend_utils.h
@@ -1,25 +1,68 @@
 // -*- C++ -*-
-//===-- parallel_backend_utils.h ------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_PARALLEL_BACKEND_UTILS_H
-#define _PSTL_PARALLEL_BACKEND_UTILS_H
+#ifndef _ONEDPL_PARALLEL_BACKEND_UTILS_H
+#define _ONEDPL_PARALLEL_BACKEND_UTILS_H
 
+#include <atomic>
+#include <cstddef>
 #include <iterator>
+#include <optional>
+#include <tuple>
 #include <utility>
+#include <vector>
+#include <cassert>
 #include "utils.h"
+#include "memory_fwd.h"
+#include "functional_impl.h" // for __onedpl::identity, std::invoke
 
-namespace __pstl
+namespace std::__onedpl
 {
-
 namespace __utils
 {
 
+//------------------------------------------------------------------------
+// raw buffer (with specified _TAllocator)
+//------------------------------------------------------------------------
+
+template <typename _Tp, template <typename _T> typename _TAllocator>
+class __buffer_impl
+{
+    _TAllocator<_Tp> _M_allocator;
+    _Tp* _M_ptr = nullptr;
+    const ::std::size_t _M_buf_size = 0;
+
+    __buffer_impl(const __buffer_impl&) = delete;
+    void
+    operator=(const __buffer_impl&) = delete;
+
+  public:
+    //! Try to obtain buffer of given size to store objects of _Tp type
+    __buffer_impl(const std::size_t __n) : _M_allocator(), _M_ptr(_M_allocator.allocate(__n)), _M_buf_size(__n) {}
+    //! True if buffer was successfully obtained, zero otherwise.
+    operator bool() const { return _M_ptr != nullptr; }
+    //! Return pointer to buffer, or nullptr if buffer could not be obtained.
+    _Tp*
+    get() const
+    {
+        return _M_ptr;
+    }
+    //! Destroy buffer
+    ~__buffer_impl() { _M_allocator.deallocate(_M_ptr, _M_buf_size); }
+};
+
 //! Destroy sequence [xs,xe)
 struct __serial_destroy
 {
@@ -27,7 +70,7 @@ struct __serial_destroy
     void
     operator()(_RandomAccessIterator __zs, _RandomAccessIterator __ze)
     {
-        typedef typename std::iterator_traits<_RandomAccessIterator>::value_type _ValueType;
+        using _ValueType = typename std::iterator_traits<_RandomAccessIterator>::value_type;
         while (__zs != __ze)
         {
             --__ze;
@@ -36,12 +79,12 @@ struct __serial_destroy
     }
 };
 
-//! Merge sequences [__xs,__xe) and [__ys,__ye) to output sequence [__zs,(__xe-__xs)+(__ye-__ys)), using std::move
+//! Merge sequences [__xs,__xe) and [__ys,__ye) to output sequence [__zs,(__xe-__xs)+(__ye-__ys)), using ::std::move
 struct __serial_move_merge
 {
-    const std::size_t _M_nmerge;
+    const ::std::size_t _M_nmerge;
 
-    explicit __serial_move_merge(std::size_t __nmerge) : _M_nmerge(__nmerge) {}
+    explicit __serial_move_merge(::std::size_t __nmerge) : _M_nmerge(__nmerge) {}
     template <class _RandomAccessIterator1, class _RandomAccessIterator2, class _RandomAccessIterator3, class _Compare,
               class _MoveValueX, class _MoveValueY, class _MoveSequenceX, class _MoveSequenceY>
     void
@@ -49,11 +92,11 @@ struct __serial_move_merge
                _RandomAccessIterator2 __ye, _RandomAccessIterator3 __zs, _Compare __comp, _MoveValueX __move_value_x,
                _MoveValueY __move_value_y, _MoveSequenceX __move_sequence_x, _MoveSequenceY __move_sequence_y)
     {
-        constexpr bool __same_move_val = std::is_same<_MoveValueX, _MoveValueY>::value;
-        constexpr bool __same_move_seq = std::is_same<_MoveSequenceX, _MoveSequenceY>::value;
+        constexpr bool __same_move_val = ::std::is_same_v<_MoveValueX, _MoveValueY>;
+        constexpr bool __same_move_seq = ::std::is_same_v<_MoveSequenceX, _MoveSequenceY>;
 
-        auto __n = _M_nmerge;
-        _PSTL_ASSERT(__n > 0);
+        std::size_t __n = _M_nmerge;
+        assert(__n > 0);
 
         auto __nx = __xe - __xs;
         //auto __ny = __ye - __ys;
@@ -65,57 +108,89 @@ struct __serial_move_merge
             {
                 for (;;)
                 {
-                    if (__comp(*__ys, *__xs))
+                    if (std::invoke(__comp, *__ys, *__xs))
                     {
                         const auto __i = __zs - __zs_beg;
                         if (__i < __nx)
                             __move_value_x(__ys, __zs);
                         else
                             __move_value_y(__ys, __zs);
-                        ++__zs, --__n;
+                        ++__zs;
+                        --__n;
                         if (++__ys == __ye)
                         {
                             break;
                         }
                         else if (__n == 0)
                         {
-                            const auto __j = __zs - __zs_beg;
-                            if (__same_move_seq || __j < __nx)
+                            if constexpr (__same_move_seq)
+                            {
                                 __zs = __move_sequence_x(__ys, __ye, __zs);
+                            }
                             else
-                                __zs = __move_sequence_y(__ys, __ye, __zs);
+                            {
+                                const auto __j = __zs - __zs_beg;
+                                if (__j < __nx)
+                                    __zs = __move_sequence_x(__ys, __ye, __zs);
+                                else
+                                    __zs = __move_sequence_y(__ys, __ye, __zs);
+                            }
                             break;
                         }
                     }
                     else
                     {
-                        const auto __i = __zs - __zs_beg;
-                        if (__same_move_val || __i < __nx)
+                        if constexpr (__same_move_val)
+                        {
                             __move_value_x(__xs, __zs);
+                        }
                         else
-                            __move_value_y(__xs, __zs);
-                        ++__zs, --__n;
+                        {
+                            const auto __i = __zs - __zs_beg;
+                            if (__i < __nx)
+                                __move_value_x(__xs, __zs);
+                            else
+                                __move_value_y(__xs, __zs);
+                        }
+
+                        ++__zs;
+                        --__n;
                         if (++__xs == __xe)
                         {
-                            const auto __j = __zs - __zs_beg;
-                            if (__same_move_seq || __j < __nx)
+                            if constexpr (__same_move_seq)
+                            {
                                 __move_sequence_x(__ys, __ye, __zs);
+                            }
                             else
-                                __move_sequence_y(__ys, __ye, __zs);
+                            {
+                                const auto __j = __zs - __zs_beg;
+                                if (__j < __nx)
+                                    __move_sequence_x(__ys, __ye, __zs);
+                                else
+                                    __move_sequence_y(__ys, __ye, __zs);
+                            }
                             return;
                         }
                         else if (__n == 0)
                         {
-                            const auto __j = __zs - __zs_beg;
-                            if (__same_move_seq || __j < __nx)
+                            if constexpr (__same_move_seq)
                             {
                                 __zs = __move_sequence_x(__xs, __xe, __zs);
                                 __move_sequence_x(__ys, __ye, __zs);
                             }
                             else
                             {
-                                __zs = __move_sequence_y(__xs, __xe, __zs);
-                                __move_sequence_y(__ys, __ye, __zs);
+                                const auto __j = __zs - __zs_beg;
+                                if (__j < __nx)
+                                {
+                                    __zs = __move_sequence_x(__xs, __xe, __zs);
+                                    __move_sequence_x(__ys, __ye, __zs);
+                                }
+                                else
+                                {
+                                    __zs = __move_sequence_y(__xs, __xe, __zs);
+                                    __move_sequence_y(__ys, __ye, __zs);
+                                }
                             }
                             return;
                         }
@@ -125,36 +200,43 @@ struct __serial_move_merge
             __ys = __xs;
             __ye = __xe;
         }
-        const auto __i = __zs - __zs_beg;
-        if (__same_move_seq || __i < __nx)
+        if constexpr (__same_move_seq)
+        {
             __move_sequence_x(__ys, __ye, __zs);
+        }
         else
-            __move_sequence_y(__ys, __ye, __zs);
+        {
+            const auto __i = __zs - __zs_beg;
+            if (__i < __nx)
+                __move_sequence_x(__ys, __ye, __zs);
+            else
+                __move_sequence_y(__ys, __ye, __zs);
+        }
     }
 };
 
-template <typename _ForwardIterator1, typename _ForwardIterator2, typename _OutputIterator, typename _Compare,
-          typename _CopyConstructRange>
+template <typename _ForwardIterator1, typename _ForwardIterator2, typename _OutputIterator,
+          typename _CopyConstructRange, typename _Compare, typename _Proj1, typename _Proj2>
 _OutputIterator
 __set_union_construct(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
-                      _ForwardIterator2 __last2, _OutputIterator __result, _Compare __comp,
-                      _CopyConstructRange __cc_range)
+                      _ForwardIterator2 __last2, _OutputIterator __result, _CopyConstructRange __cc_range,
+                      _Compare __comp, _Proj1 __proj1, _Proj2 __proj2)
 {
-    using _Tp = typename std::iterator_traits<_OutputIterator>::value_type;
+    using _Tp = typename ::std::iterator_traits<_OutputIterator>::value_type;
 
     for (; __first1 != __last1; ++__result)
     {
         if (__first2 == __last2)
             return __cc_range(__first1, __last1, __result);
-        if (__comp(*__first2, *__first1))
+        if (std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1)))
         {
-            ::new (std::addressof(*__result)) _Tp(*__first2);
+            ::new (::std::addressof(*__result)) _Tp(*__first2);
             ++__first2;
         }
         else
         {
-            ::new (std::addressof(*__result)) _Tp(*__first1);
-            if (!__comp(*__first1, *__first2))
+            ::new (::std::addressof(*__result)) _Tp(*__first1);
+            if (!std::invoke(__comp, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__first2)))
                 ++__first2;
             ++__first1;
         }
@@ -162,85 +244,86 @@ __set_union_construct(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _Fo
     return __cc_range(__first2, __last2, __result);
 }
 
-template <typename _ForwardIterator1, typename _ForwardIterator2, typename _OutputIterator, typename _Compare>
+template <typename _ForwardIterator1, typename _ForwardIterator2, typename _OutputIterator, typename _CopyFunc,
+          typename _Compare, typename _Proj1, typename _Proj2>
 _OutputIterator
 __set_intersection_construct(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
-                             _ForwardIterator2 __last2, _OutputIterator __result, _Compare __comp)
+                             _ForwardIterator2 __last2, _OutputIterator __result, _CopyFunc _copy, _Compare __comp,
+                             _Proj1 __proj1, _Proj2 __proj2)
 {
-    using _Tp = typename std::iterator_traits<_OutputIterator>::value_type;
-
-    for (; __first1 != __last1 && __first2 != __last2;)
+    while (__first1 != __last1 && __first2 != __last2)
     {
-        if (__comp(*__first1, *__first2))
+        if (std::invoke(__comp, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__first2)))
             ++__first1;
+        else if (std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1)))
+            ++__first2;
         else
         {
-            if (!__comp(*__first2, *__first1))
-            {
-                ::new (std::addressof(*__result)) _Tp(*__first1);
-                ++__result;
-                ++__first1;
-            }
+            _copy(*__first1, *__result);
+
+            ++__first1;
             ++__first2;
+            ++__result;
         }
     }
     return __result;
 }
 
-template <typename _ForwardIterator1, typename _ForwardIterator2, typename _OutputIterator, typename _Compare,
-          typename _CopyConstructRange>
+template <typename _ForwardIterator1, typename _ForwardIterator2, typename _OutputIterator,
+          typename _CopyConstructRange, typename _Compare, typename _Proj1, typename _Proj2>
 _OutputIterator
 __set_difference_construct(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
-                           _ForwardIterator2 __last2, _OutputIterator __result, _Compare __comp,
-                           _CopyConstructRange __cc_range)
+                           _ForwardIterator2 __last2, _OutputIterator __result, _CopyConstructRange __cc_range,
+                           _Compare __comp, _Proj1 __proj1, _Proj2 __proj2)
 {
-    using _Tp = typename std::iterator_traits<_OutputIterator>::value_type;
+    using _Tp = typename ::std::iterator_traits<_OutputIterator>::value_type;
 
     for (; __first1 != __last1;)
     {
         if (__first2 == __last2)
             return __cc_range(__first1, __last1, __result);
 
-        if (__comp(*__first1, *__first2))
+        if (std::invoke(__comp, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__first2)))
         {
-            ::new (std::addressof(*__result)) _Tp(*__first1);
+            ::new (::std::addressof(*__result)) _Tp(*__first1);
             ++__result;
             ++__first1;
         }
         else
         {
-            if (!__comp(*__first2, *__first1))
+            if (!std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1)))
                 ++__first1;
             ++__first2;
         }
     }
     return __result;
 }
-template <typename _ForwardIterator1, typename _ForwardIterator2, typename _OutputIterator, typename _Compare,
-          typename _CopyConstructRange>
+
+template <typename _ForwardIterator1, typename _ForwardIterator2, typename _OutputIterator,
+          typename _CopyConstructRange, typename _Compare, typename _Proj1, typename _Proj2>
 _OutputIterator
 __set_symmetric_difference_construct(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
-                                     _ForwardIterator2 __last2, _OutputIterator __result, _Compare __comp,
-                                     _CopyConstructRange __cc_range)
+                                     _ForwardIterator2 __last2, _OutputIterator __result,
+                                     _CopyConstructRange __cc_range, _Compare __comp, _Proj1 __proj1, _Proj2 __proj2)
 {
-    using _Tp = typename std::iterator_traits<_OutputIterator>::value_type;
+    using _Tp = typename ::std::iterator_traits<_OutputIterator>::value_type;
 
     for (; __first1 != __last1;)
     {
         if (__first2 == __last2)
             return __cc_range(__first1, __last1, __result);
 
-        if (__comp(*__first1, *__first2))
+        if (std::invoke(__comp, std::invoke(__proj1, *__first1), std::invoke(__proj2, *__first2)))
         {
-            ::new (std::addressof(*__result)) _Tp(*__first1);
+            ::new (::std::addressof(*__result)) _Tp(*__first1);
             ++__result;
             ++__first1;
         }
         else
         {
-            if (__comp(*__first2, *__first1))
+            if (std::invoke(__comp, std::invoke(__proj2, *__first2), std::invoke(__proj1, *__first1)))
             {
-                ::new (std::addressof(*__result)) _Tp(*__first2);
+                ::new (::std::addressof(*__result)) _Tp(*__first2);
                 ++__result;
             }
             else
@@ -251,7 +334,73 @@ __set_symmetric_difference_construct(_ForwardIterator1 __first1, _ForwardIterato
     return __cc_range(__first2, __last2, __result);
 }
 
-} // namespace __utils
-} // namespace __pstl
+template <template <typename, typename...> typename _Concrete, typename _ValueType, typename... _Args>
+struct __enumerable_thread_local_storage_base
+{
+    using _Derived = _Concrete<_ValueType, _Args...>;
 
-#endif /* _PSTL_PARALLEL_BACKEND_UTILS_H */
+    __enumerable_thread_local_storage_base(std::tuple<_Args...> __tp)
+        : __thread_specific_storage(_Derived::get_num_threads()), __num_elements(0), __args(__tp)
+    {
+    }
+
+    // Note: size should not be used concurrently with parallel loops which may instantiate storage objects, as it may
+    // not return an accurate count of instantiated storage objects in lockstep with the number allocated and stored.
+    // This is because the count is not atomic with the allocation and storage of the storage objects.
+    std::size_t
+    size() const
+    {
+        // only count storage which has been instantiated
+        return __num_elements.load(std::memory_order_relaxed);
+    }
+
+    // Note: get_with_id should not be used concurrently with parallel loops which may instantiate storage objects,
+    // as its operation may provide an out of date view of the stored objects based on the timing new object creation
+    // and incrementing of the size.
+    // TODO: Consider replacing this access with a visitor pattern.
+    _ValueType&
+    get_with_id(std::size_t __i)
+    {
+        assert(__i < size());
+
+        if (size() == __thread_specific_storage.size())
+        {
+            return *__thread_specific_storage[__i];
+        }
+
+        std::size_t __j = 0;
+        for (std::size_t __count = 0; __j < __thread_specific_storage.size() && __count <= __i; ++__j)
+        {
+            // Only include storage from threads which have instantiated a storage object
+            if (__thread_specific_storage[__j])
+            {
+                ++__count;
+            }
+        }
+        // Need to back up one once we have found a valid storage object
+        return *__thread_specific_storage[__j - 1];
+    }
+
+    _ValueType&
+    get_for_current_thread()
+    {
+        const std::size_t __i = _Derived::get_thread_num();
+        std::optional<_ValueType>& __local = __thread_specific_storage[__i];
+        if (!__local)
+        {
+            // create temporary storage on first usage to avoid extra parallel region and unnecessary instantiation
+            std::apply([&__local](_Args... __arg_pack) { __local.emplace(__arg_pack...); }, __args);
+            __num_elements.fetch_add(1, std::memory_order_relaxed);
+        }
+        return *__local;
+    }
+
+    std::vector<std::optional<_ValueType>> __thread_specific_storage;
+    std::atomic_size_t __num_elements;
+    const std::tuple<_Args...> __args;
+};
+
+} // namespace __utils
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_PARALLEL_BACKEND_UTILS_H
diff --git a/libstdc++-v3/include/pstl/parallel_impl.h b/libstdc++-v3/include/pstl/parallel_impl.h
index 4cf2abde650b..89e451bd5450 100644
--- a/libstdc++-v3/include/pstl/parallel_impl.h
+++ b/libstdc++-v3/include/pstl/parallel_impl.h
@@ -1,20 +1,28 @@
 // -*- C++ -*-
-//===-- parallel_impl.h ---------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_PARALLEL_IMPL_H
-#define _PSTL_PARALLEL_IMPL_H
+#ifndef _ONEDPL_PARALLEL_IMPL_H
+#define _ONEDPL_PARALLEL_IMPL_H
 
 #include <atomic>
+#include <functional> // for std::invoke
+
 // This header defines the minimum set of parallel routines required to support Parallel STL,
 // implemented on top of Intel(R) Threading Building Blocks (Intel(R) TBB) library
 
-namespace __pstl
+namespace std::__onedpl
 {
 namespace __internal
 {
@@ -24,29 +32,33 @@ namespace __internal
 //-----------------------------------------------------------------------
 /** Return extremum value returned by brick f[i,j) for subranges [i,j) of [first,last)
 Each f[i,j) must return a value in [i,j). */
-template <class _BackendTag, class _ExecutionPolicy, class _Index, class _Brick, class _Compare>
+template <class _IsVector, class _ExecutionPolicy, class _Index, class _Brick, class _IsFirst>
 _Index
-__parallel_find(_BackendTag __tag, _ExecutionPolicy&& __exec, _Index __first, _Index __last, _Brick __f,
-                _Compare __comp, bool __b_first)
+__parallel_find(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _Index __first, _Index __last, _Brick __f,
+                _IsFirst)
 {
-    typedef typename std::iterator_traits<_Index>::difference_type _DifferenceType;
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
+
+    using _DifferenceType = typename std::iterator_traits<_Index>::difference_type;
     const _DifferenceType __n = __last - __first;
-    _DifferenceType __initial_dist = __b_first ? __n : -1;
-    std::atomic<_DifferenceType> __extremum(__initial_dist);
+    _DifferenceType __initial_dist = _IsFirst::value ? __n : -1;
+
+    constexpr auto __comp = ::std::conditional_t<_IsFirst::value, __pstl_less, __pstl_greater>{};
+
+    ::std::atomic<_DifferenceType> __extremum(__initial_dist);
     // TODO: find out what is better here: parallel_for or parallel_reduce
-    __par_backend::__parallel_for(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                  [__comp, __f, __first, &__extremum](_Index __i, _Index __j)
-                                  {
+    __par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                  [__comp, __f, __first, &__extremum](_Index __i, _Index __j) {
                                       // See "Reducing Contention Through Priority Updates", PPoPP '13, for discussion of
                                       // why using a shared variable scales fairly well in this situation.
-                                      if (__comp(__i - __first, __extremum))
+                                      if (std::invoke(__comp, __i - __first, __extremum))
                                       {
                                           _Index __res = __f(__i, __j);
                                           // If not '__last' returned then we found what we want so put this to extremum
                                           if (__res != __j)
                                           {
                                               const _DifferenceType __k = __res - __first;
-                                              for (_DifferenceType __old = __extremum; __comp(__k, __old);
+                                              for (_DifferenceType __old = __extremum; std::invoke(__comp, __k, __old);
                                                    __old = __extremum)
                                               {
                                                   __extremum.compare_exchange_weak(__old, __k);
@@ -61,24 +73,25 @@ __parallel_find(_BackendTag __tag, _ExecutionPolicy&& __exec, _Index __first, _I
 // parallel_or
 //------------------------------------------------------------------------
 //! Return true if brick f[i,j) returns true for some subrange [i,j) of [first,last)
-template <class _BackendTag, class _ExecutionPolicy, class _Index, class _Brick>
+template <class _IsVector, class _ExecutionPolicy, class _Index, class _Brick>
 bool
-__parallel_or(_BackendTag __tag, _ExecutionPolicy&& __exec, _Index __first, _Index __last, _Brick __f)
+__parallel_or(__parallel_tag<_IsVector>, _ExecutionPolicy&& __exec, _Index __first, _Index __last, _Brick __f)
 {
-    std::atomic<bool> __found(false);
-    __par_backend::__parallel_for(__tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
-                                  [__f, &__found](_Index __i, _Index __j)
-                                  {
-                                      if (!__found.load(std::memory_order_relaxed) && __f(__i, __j))
+    using __backend_tag = typename __parallel_tag<_IsVector>::__backend_tag;
+
+    ::std::atomic<bool> __found(false);
+    __par_backend::__parallel_for(__backend_tag{}, ::std::forward<_ExecutionPolicy>(__exec), __first, __last,
+                                  [__f, &__found](_Index __i, _Index __j) {
+                                      if (!__found.load(::std::memory_order_relaxed) && __f(__i, __j))
                                       {
-                                          __found.store(true, std::memory_order_relaxed);
-                                          __par_backend::__cancel_execution();
+                                          __found.store(true, ::std::memory_order_relaxed);
+                                          __par_backend::__cancel_execution(__backend_tag{});
                                       }
                                   });
     return __found;
 }
 
 } // namespace __internal
-} // namespace __pstl
+} // namespace std::__onedpl
 
-#endif /* _PSTL_PARALLEL_IMPL_H */
+#endif // _ONEDPL_PARALLEL_IMPL_H
diff --git a/libstdc++-v3/include/pstl/pstl_config.h b/libstdc++-v3/include/pstl/pstl_config.h
index 6fae15460eac..148d305edb0b 100644
--- a/libstdc++-v3/include/pstl/pstl_config.h
+++ b/libstdc++-v3/include/pstl/pstl_config.h
@@ -1,17 +1,24 @@
 // -*- C++ -*-
-//===-- pstl_config.h -----------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
 #ifndef _PSTL_CONFIG_H
 #define _PSTL_CONFIG_H
 
+// The version of the Parallel STL upstream project maintained within LLVM.
 // The version is XYYZ, where X is major, YY is minor, and Z is patch (i.e. X.YY.Z)
-#define _PSTL_VERSION 17000
+#define _PSTL_VERSION 14000
 #define _PSTL_VERSION_MAJOR (_PSTL_VERSION / 1000)
 #define _PSTL_VERSION_MINOR ((_PSTL_VERSION % 1000) / 10)
 #define _PSTL_VERSION_PATCH (_PSTL_VERSION % 10)
@@ -53,16 +60,14 @@
 // the actual GCC version on the system.
 #define _PSTL_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
 
-#if defined(_GLIBCXX_CLANG)
+#if __clang__
 // according to clang documentation, version can be vendor specific
 #    define _PSTL_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
 #endif
 
 // Enable SIMD for compilers that support OpenMP 4.0
-#if (defined(_OPENMP) && _OPENMP >= 201307) || \
-    (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1600) || \
-    (!defined(__INTEL_COMPILER) && _PSTL_GCC_VERSION >= 40900) || \
-    defined(_GLIBCXX_CLANG)
+#if defined(__clang__) || (_OPENMP >= 201307) || __INTEL_LLVM_COMPILER || (__INTEL_COMPILER >= 1600) ||                \
+    (!defined(__INTEL_LLVM_COMPILER) && !defined(__INTEL_COMPILER) && _PSTL_GCC_VERSION >= 40900)
 #    define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd)
 #    define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd)
 #    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM))
@@ -76,14 +81,13 @@
 #    define _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
 #endif //Enable SIMD
 
-#if defined(__INTEL_COMPILER)
+#if (__INTEL_LLVM_COMPILER || __INTEL_COMPILER)
 #    define _PSTL_PRAGMA_FORCEINLINE _PSTL_PRAGMA(forceinline)
 #else
 #    define _PSTL_PRAGMA_FORCEINLINE
 #endif
 
-#if (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1900) || \
-    (!defined(__INTEL_COMPILER) && _PSTL_GCC_VERSION >= 100000)
+#if (__INTEL_LLVM_COMPILER >= 20230100 || __INTEL_COMPILER >= 1900)
 #    define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM))
 #    define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM))
 #    define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM))
@@ -94,51 +98,35 @@
 #endif
 
 // Should be defined to 1 for environments with a vendor implementation of C++17 execution policies
-#define _PSTL_CPP17_EXECUTION_POLICIES_PRESENT (_MSC_VER >= 1912 && _MSVC_LANG >= 201703L) ||                          \
-    (_GLIBCXX_RELEASE >= 9 && __GLIBCXX__ >= 20190503 && __cplusplus >= 201703L)
+#define _PSTL_CPP17_EXECUTION_POLICIES_PRESENT                                                                         \
+    (_MSC_VER >= 1912 && _MSVC_LANG >= 201703L) ||                                                                     \
+        (_GLIBCXX_RELEASE >= 9 && __GLIBCXX__ >= 20190503 && __cplusplus >= 201703L)
 
-#if (defined(_MSC_VER) && _MSC_VER >= 1900) || \
-    __cplusplus >= 201300L || \
-    __cpp_lib_robust_nonmodifying_seq_ops == 201304
-#   define _PSTL_CPP14_2RANGE_MISMATCH_EQUAL_PRESENT
-#endif
-#if (defined(_MSC_VER) && _MSC_VER >= 1900) || \
-    __cplusplus >= 201402L || \
-    __cpp_lib_make_reverse_iterator == 201402
-#   define _PSTL_CPP14_MAKE_REVERSE_ITERATOR_PRESENT
-#endif
-#if (defined(_MSC_VER) && _MSC_VER >= 1900) || __cplusplus >= 201402L
-#   define _PSTL_CPP14_INTEGER_SEQUENCE_PRESENT
-#endif
-#if (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1700) || \
-    (defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023918) || \
-    __cplusplus >= 201402L
-#   define _PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT
+#define _PSTL_EARLYEXIT_PRESENT (__INTEL_COMPILER >= 1800)
+#define _PSTL_MONOTONIC_PRESENT (__INTEL_COMPILER >= 1800)
+
+#if (_OPENMP >= 201307 || __INTEL_LLVM_COMPILER || __INTEL_COMPILER >= 1900 ||                                         \
+     !defined(__INTEL_LLVM_COMPILER) && !defined(__INTEL_COMPILER) && _PSTL_GCC_VERSION >= 40900)
+#    define _PSTL_UDR_PRESENT 1
+#else
+#    define _PSTL_UDR_PRESENT 0
 #endif
 
-#if defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1800
-#   define _PSTL_EARLYEXIT_PRESENT
-#   define _PSTL_MONOTONIC_PRESENT
+// TODO: enable UDS on Windows with Intel LLVM-based compiler when it is fixed
+#if (__INTEL_LLVM_COMPILER >= 20230100 && !defined(_MSC_VER)) ||                                                       \
+    (__INTEL_COMPILER >= 1900 && __INTEL_COMPILER_BUILD_DATE >= 20180626)
+#    define _PSTL_UDS_PRESENT 1
+#else
+#    define _PSTL_UDS_PRESENT 0
 #endif
 
-#if (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1900) || \
-    (!defined(__INTEL_COMPILER) && _PSTL_GCC_VERSION >= 40900) || \
-    (defined(_OPENMP) && _OPENMP >= 201307)
-#    define _PSTL_UDR_PRESENT
-#endif
-
-#if (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1900 && __INTEL_COMPILER_BUILD_DATE >= 20180626) || \
-    (!defined(__INTEL_COMPILER) && _PSTL_GCC_VERSION >= 100000)
-#   define _PSTL_UDS_PRESENT
-#endif
-
-#if defined(_PSTL_EARLYEXIT_PRESENT)
+#if _PSTL_EARLYEXIT_PRESENT
 #    define _PSTL_PRAGMA_SIMD_EARLYEXIT _PSTL_PRAGMA(omp simd early_exit)
 #else
 #    define _PSTL_PRAGMA_SIMD_EARLYEXIT
 #endif
 
-#if defined(_PSTL_MONOTONIC_PRESENT)
+#if _PSTL_MONOTONIC_PRESENT
 #    define _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(PRM) _PSTL_PRAGMA(omp ordered simd monotonic(PRM))
 #    define _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(PRM1, PRM2) _PSTL_PRAGMA(omp ordered simd monotonic(PRM1, PRM2))
 #else
@@ -154,22 +142,22 @@
 // omp_priv - refers to the private copy of the initial value
 // omp_orig - refers to the original variable to be reduced
 #define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)                                                                       \
-    _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
+    _PSTL_PRAGMA(omp declare reduction(NAME : OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
 
-#if defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1600
+#if (__INTEL_COMPILER >= 1600)
 #    define _PSTL_PRAGMA_VECTOR_UNALIGNED _PSTL_PRAGMA(vector unaligned)
 #else
 #    define _PSTL_PRAGMA_VECTOR_UNALIGNED
 #endif
 
 // Check the user-defined macro to use non-temporal stores
-#if defined(PSTL_USE_NONTEMPORAL_STORES) && (__INTEL_COMPILER >= 1600)
+#if defined(PSTL_USE_NONTEMPORAL_STORES) && (__INTEL_LLVM_COMPILER || __INTEL_COMPILER >= 1600)
 #    define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED _PSTL_PRAGMA(vector nontemporal)
 #else
 #    define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
 #endif
 
-#if defined(_MSC_VER) || defined(__INTEL_COMPILER) // the preprocessors don't type a message location
+#if _MSC_VER || __INTEL_COMPILER //the preprocessors don't type a message location
 #    define _PSTL_PRAGMA_LOCATION __FILE__ ":" _PSTL_STRING(__LINE__) ": [Parallel STL message]: "
 #else
 #    define _PSTL_PRAGMA_LOCATION " [Parallel STL message]: "
@@ -186,13 +174,12 @@
 #endif
 
 // broken macros
-#if (defined(__GLIBCXX__) && __GLIBCXX__ < 20150716) || \
-    (defined(_MSC_VER) && _MSC_VER < 1800)
-#   define _PSTL_CPP11_STD_ROTATE_BROKEN
+#define _PSTL_ICC_18_OMP_SIMD_BROKEN (__INTEL_COMPILER == 1800)
+
+#if defined(_MSC_VER) && __INTEL_LLVM_COMPILER < 20240100
+#    define _PSTL_ICPX_OMP_SIMD_DESTROY_WINDOWS_BROKEN 1
+#else
+#    define _PSTL_ICPX_OMP_SIMD_DESTROY_WINDOWS_BROKEN 0
 #endif
 
-#if defined(__INTEL_COMPILER) && __INTEL_COMPILER == 1800
-#   define _PSTL_ICC_18_OMP_SIMD_BROKEN
-#endif
-
-#endif /* _PSTL_CONFIG_H */
+#endif // _PSTL_CONFIG_H
diff --git a/libstdc++-v3/include/pstl/ranges/nanorange.hpp b/libstdc++-v3/include/pstl/ranges/nanorange.hpp
new file mode 100644
index 000000000000..d42d03244ec2
--- /dev/null
+++ b/libstdc++-v3/include/pstl/ranges/nanorange.hpp
@@ -0,0 +1,19384 @@
+// nanorange.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#ifndef NANORANGE_HPP_INCLUDED
+#define NANORANGE_HPP_INCLUDED
+
+// nanorange/algorithm.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#ifndef NANORANGE_ALGORITHM_HPP_INCLUDED
+#    define NANORANGE_ALGORITHM_HPP_INCLUDED
+
+// Algorithms reimplemented in Nanorange
+// nanorange/algorithm/adjacent_find.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_ADJACENT_FIND_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_ADJACENT_FIND_HPP_INCLUDED
+
+// nanorange/range.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_RANGES_HPP_INCLUDED
+#            define NANORANGE_RANGES_HPP_INCLUDED
+
+// nanorange/detail/iterator/algorithm_requirements.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#            ifndef NANORANGE_DETAIL_ITERATOR_ALGORITHM_REQUIREMENTS_HPP_INCLUDED
+#                define NANORANGE_DETAIL_ITERATOR_ALGORITHM_REQUIREMENTS_HPP_INCLUDED
+
+// nanorange/detail/functional/comparisons.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                ifndef NANORANGE_DETAIL_FUNCTIONAL_COMPARISONS_HPP_INCLUDED
+#                    define NANORANGE_DETAIL_FUNCTIONAL_COMPARISONS_HPP_INCLUDED
+
+// nanorange/detail/concepts/comparison.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                    ifndef NANORANGE_DETAIL_CONCEPTS_COMPARISON_HPP_INCLUDED
+#                        define NANORANGE_DETAIL_CONCEPTS_COMPARISON_HPP_INCLUDED
+
+// nanorange/detail/concepts/core.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                        ifndef NANORANGE_DETAIL_CONCEPTS_CORE_HPP_INCLUDED
+#                            define NANORANGE_DETAIL_CONCEPTS_CORE_HPP_INCLUDED
+
+// nanorange/detail/macros.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                            ifndef NANORANGE_DETAIL_MACROS_HPP_INCLUDED
+#                                define NANORANGE_DETAIL_MACROS_HPP_INCLUDED
+
+#                                if __has_include(<version>)
+#                                   include <version>
+#                                else
+#                                    include <ciso646>
+#                                endif
+
+#                                ifdef NANORANGE_NO_DEPRECATION_WARNINGS
+#                                    define NANO_DEPRECATED
+#                                    define NANO_DEPRECATED_FOR(x)
+#                                else
+#                                    define NANO_DEPRECATED [[deprecated]]
+#                                    define NANO_DEPRECATED_FOR(x) [[deprecated(x)]]
+#                                endif
+
+#                                ifdef __has_cpp_attribute
+#                                    if __has_cpp_attribute(no_unique_address) >= 201803L
+#                                        define NANO_NO_UNIQUE_ADDRESS [[no_unique_address]]
+#                                    else
+#                                        define NANO_NO_UNIQUE_ADDRESS
+#                                    endif // __has_cpp_attribute(no_unique_address)
+#                                else
+#                                    define NANO_NO_UNIQUE_ADDRESS
+#                                endif // defined(__has_cpp_attribute)
+
+#                                define NANO_CONCEPT inline constexpr bool
+
+#                                define NANO_BEGIN_NAMESPACE                                                           \
+                                    namespace __nanorange                                                              \
+                                    {                                                                                  \
+                                                                                                                       \
+                                    namespace nano                                                                     \
+                                    {                                                                                  \
+                                                                                                                       \
+                                    inline namespace ranges                                                            \
+                                    {
+
+#                                define NANO_END_NAMESPACE                                                             \
+                                    }                                                                                  \
+                                    }                                                                                  \
+                                    }
+
+#                                define NANO_INLINE_VAR(type, name)                                                    \
+                                    inline namespace function_objects                                                  \
+                                    {                                                                                  \
+                                    inline constexpr type name{};                                                      \
+                                    }
+#                                define NANORANGE_NO_STD_FORWARD_DECLARATIONS
+#                                if defined(_LIBCPP_VERSION)
+#                                    define NANO_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
+#                                    define NANO_END_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
+#                                elif defined(_MSVC_STL_VERSION)
+#                                    define NANO_BEGIN_NAMESPACE_STD _STD_BEGIN
+#                                    define NANO_END_NAMESPACE_STD _STD_END
+#                                elif defined(_GLIBCXX_DEBUG)
+#                                    ifndef NANORANGE_NO_STD_FORWARD_DECLARATIONS
+#                                        define NANORANGE_NO_STD_FORWARD_DECLARATIONS
+#                                    endif
+#                                else
+#                                    define NANO_BEGIN_NAMESPACE_STD                                                   \
+                                        namespace std                                                                  \
+                                        {
+#                                    define NANO_END_NAMESPACE_STD }
+#                                endif
+
+#                                if defined(_MSC_VER)
+#                                    define NANO_MSVC_LAMBDA_PIPE_WORKAROUND 1
+#                                endif
+
+#                            endif
+
+// nanorange/type_traits.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                            ifndef NANORANGE_TYPE_TRAITS_HPP_INCLUDED
+#                                define NANORANGE_TYPE_TRAITS_HPP_INCLUDED
+
+// nanorange/detail/common_reference.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                                ifndef NANORANGE_DETAIL_COMMON_REFERENCE_HPP_INCLUDED
+#                                    define NANORANGE_DETAIL_COMMON_REFERENCE_HPP_INCLUDED
+
+// nanorange/detail/type_traits.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                                    ifndef NANORANGE_DETAIL_TYPE_TRAITS_HPP_INCLUDED
+#                                        define NANORANGE_DETAIL_TYPE_TRAITS_HPP_INCLUDED
+
+#                                        include <type_traits>
+
+NANO_BEGIN_NAMESPACE
+
+template <typename T>
+struct remove_cvref
+{
+    using type = ::std::remove_cv_t<::std::remove_reference_t<T>>;
+};
+
+template <typename T>
+using remove_cvref_t = typename remove_cvref<T>::type;
+
+template <typename T>
+struct type_identity
+{
+    using type = T;
+};
+
+template <typename T>
+using type_identity_t = typename type_identity<T>::type;
+
+namespace detail
+{
+
+template <bool>
+struct conditional
+{
+    template <typename T, typename>
+    using type = T;
+};
+
+template <>
+struct conditional<false>
+{
+    template <typename, typename U>
+    using type = U;
+};
+
+template <bool B, typename T, typename U>
+using conditional_t = typename conditional<B>::template type<T, U>;
+
+template <template <class...> class AliasT, typename... Args>
+auto
+exists_helper(long) -> ::std::false_type;
+
+template <template <class...> class AliasT, typename... Args, typename = AliasT<Args...>>
+auto
+exists_helper(int) -> ::std::true_type;
+
+template <template <class...> class AliasT, typename... Args>
+inline constexpr bool exists_v = decltype(exists_helper<AliasT, Args...>(0))::value;
+
+template <typename, typename...>
+auto
+test_requires_fn(long) -> ::std::false_type;
+
+template <typename R, typename... Args, typename = decltype(&R::template requires_<Args...>)>
+auto
+test_requires_fn(int) -> ::std::true_type;
+
+template <typename R, typename... Args>
+inline constexpr bool requires_ = decltype(test_requires_fn<R, Args...>(0))::value;
+
+template <bool Expr>
+using requires_expr = ::std::enable_if_t<Expr, int>;
+
+template <::std::size_t I>
+struct priority_tag : priority_tag<I - 1>
+{
+};
+
+template <>
+struct priority_tag<0>
+{
+};
+
+} // namespace detail
+
+NANO_END_NAMESPACE
+
+#                                    endif
+
+NANO_BEGIN_NAMESPACE
+
+template <typename...>
+struct common_type;
+
+namespace detail
+{
+
+template <typename T, typename U>
+struct copy_cv
+{
+    using type = U;
+};
+
+template <typename T, typename U>
+struct copy_cv<const T, U>
+{
+    using type = ::std::add_const_t<U>;
+};
+
+template <typename T, typename U>
+struct copy_cv<volatile T, U>
+{
+    using type = ::std::add_volatile_t<U>;
+};
+
+template <typename T, typename U>
+struct copy_cv<const volatile T, U>
+{
+    using type = ::std::add_cv_t<U>;
+};
+
+template <typename T, typename U>
+using copy_cv_t = typename copy_cv<T, U>::type;
+
+template <typename T>
+using cref_t = ::std::add_lvalue_reference_t<const ::std::remove_reference_t<T>>;
+
+// Workaround for "term does not evaluate to a function taking 0 arguments"
+// error in MSVC 19.22 (issue #75)
+#                                    if defined(_MSC_VER) && _MSC_VER >= 1922
+template <typename, typename, typename = void>
+struct cond_res
+{
+};
+
+template <typename T, typename U>
+struct cond_res<T, U, ::std::void_t<decltype(false ? ::std::declval<T (&)()>()() : ::std::declval<U (&)()>()())>>
+{
+    using type = decltype(false ? ::std::declval<T (&)()>()() : ::std::declval<U (&)()>()());
+};
+
+template <typename T, typename U>
+using cond_res_t = typename cond_res<T, U>::type;
+#                                    else
+template <typename T, typename U>
+using cond_res_t = decltype(false ? ::std::declval<T (&)()>()() : ::std::declval<U (&)()>()());
+#                                    endif
+
+// For some value of "simple"
+template <typename A, typename B, typename X = ::std::remove_reference_t<A>, typename Y = ::std::remove_reference_t<B>,
+          typename = void>
+struct common_ref
+{
+};
+
+template <typename A, typename B>
+using common_ref_t = typename common_ref<A, B>::type;
+
+template <typename A, typename B, typename X = ::std::remove_reference_t<A>, typename Y = ::std::remove_reference_t<B>,
+          typename = void>
+struct lval_common_ref
+{
+};
+
+template <typename A, typename B, typename X, typename Y>
+struct lval_common_ref<A, B, X, Y,
+                       ::std::enable_if_t<::std::is_reference_v<cond_res_t<copy_cv_t<X, Y>&, copy_cv_t<Y, X>&>>>>
+{
+    using type = cond_res_t<copy_cv_t<X, Y>&, copy_cv_t<Y, X>&>;
+};
+
+template <typename A, typename B>
+using lval_common_ref_t = typename lval_common_ref<A, B>::type;
+
+template <typename A, typename B, typename X, typename Y>
+struct common_ref<A&, B&, X, Y> : lval_common_ref<A&, B&>
+{
+};
+
+template <typename X, typename Y>
+using rref_cr_helper_t = ::std::remove_reference_t<lval_common_ref_t<X&, Y&>>&&;
+
+template <typename A, typename B, typename X, typename Y>
+struct common_ref<A&&, B&&, X, Y,
+                  ::std::enable_if_t<::std::is_convertible_v<A&&, rref_cr_helper_t<X, Y>>&& ::std::is_convertible_v<
+                      B&&, rref_cr_helper_t<X, Y>>>>
+{
+    using type = rref_cr_helper_t<X, Y>;
+};
+
+template <typename A, typename B, typename X, typename Y>
+struct common_ref<A&&, B&, X, Y, ::std::enable_if_t<::std::is_convertible_v<A&&, lval_common_ref_t<const X&, Y&>>>>
+{
+    using type = lval_common_ref_t<const X&, Y&>;
+};
+
+template <typename A, typename B, typename X, typename Y>
+struct common_ref<A&, B&&, X, Y> : common_ref<B&&, A&>
+{
+};
+
+template <typename>
+struct xref
+{
+    template <typename U>
+    using type = U;
+};
+
+template <typename A>
+struct xref<A&>
+{
+    template <typename U>
+    using type = ::std::add_lvalue_reference_t<typename xref<A>::template type<U>>;
+};
+
+template <typename A>
+struct xref<A&&>
+{
+    template <typename U>
+    using type = ::std::add_rvalue_reference_t<typename xref<A>::template type<U>>;
+};
+
+template <typename A>
+struct xref<const A>
+{
+    template <typename U>
+    using type = ::std::add_const_t<typename xref<A>::template type<U>>;
+};
+
+template <typename A>
+struct xref<volatile A>
+{
+    template <typename U>
+    using type = ::std::add_volatile_t<typename xref<A>::template type<U>>;
+};
+
+template <typename A>
+struct xref<const volatile A>
+{
+    template <typename U>
+    using type = ::std::add_cv_t<typename xref<A>::template type<U>>;
+};
+
+} // namespace detail
+
+template <class T, class U, template <class> class TQual, template <class> class UQual>
+struct basic_common_reference
+{
+};
+
+template <typename...>
+struct common_reference;
+
+template <typename... Ts>
+using common_reference_t = typename common_reference<Ts...>::type;
+
+template <>
+struct common_reference<>
+{
+};
+
+template <typename T0>
+struct common_reference<T0>
+{
+    using type = T0;
+};
+
+namespace detail
+{
+
+template <typename T, typename U>
+inline constexpr bool has_common_ref_v = exists_v<common_ref_t, T, U>;
+
+template <typename T, typename U>
+using basic_common_ref_t =
+    typename basic_common_reference<remove_cvref_t<T>, remove_cvref_t<U>, detail::xref<T>::template type,
+                                    detail::xref<U>::template type>::type;
+
+template <typename T, typename U>
+inline constexpr bool has_basic_common_ref_v = exists_v<basic_common_ref_t, T, U>;
+
+template <typename T, typename U>
+inline constexpr bool has_cond_res_v = exists_v<cond_res_t, T, U>;
+
+template <typename T, typename U, typename = void>
+struct binary_common_ref : common_type<T, U>
+{
+};
+
+template <typename T, typename U>
+struct binary_common_ref<T, U, ::std::enable_if_t<has_common_ref_v<T, U>>> : common_ref<T, U>
+{
+};
+
+template <typename T, typename U>
+struct binary_common_ref<T, U, ::std::enable_if_t<has_basic_common_ref_v<T, U> && !has_common_ref_v<T, U>>>
+{
+    using type = basic_common_ref_t<T, U>;
+};
+
+template <typename T, typename U>
+struct binary_common_ref<
+    T, U, ::std::enable_if_t<has_cond_res_v<T, U> && !has_basic_common_ref_v<T, U> && !has_common_ref_v<T, U>>>
+{
+    using type = cond_res_t<T, U>;
+};
+
+} // namespace detail
+
+template <typename T1, typename T2>
+struct common_reference<T1, T2> : detail::binary_common_ref<T1, T2>
+{
+};
+
+namespace detail
+{
+
+template <typename Void, typename T1, typename T2, typename... Rest>
+struct multiple_common_reference
+{
+};
+
+template <typename T1, typename T2, typename... Rest>
+struct multiple_common_reference<::std::void_t<common_reference_t<T1, T2>>, T1, T2, Rest...>
+    : common_reference<common_reference_t<T1, T2>, Rest...>
+{
+};
+
+} // namespace detail
+
+template <typename T1, typename T2, typename... Rest>
+struct common_reference<T1, T2, Rest...> : detail::multiple_common_reference<void, T1, T2, Rest...>
+{
+};
+
+NANO_END_NAMESPACE
+
+#                                endif
+
+// nanorange/detail/common_reference.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                                ifndef NANORANGE_DETAIL_COMMON_TYPE_HPP_INCLUDED
+#                                    define NANORANGE_DETAIL_COMMON_TYPE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename...>
+struct common_type;
+
+template <typename... Ts>
+using common_type_t = typename common_type<Ts...>::type;
+
+namespace detail
+{
+
+template <typename T, typename U>
+constexpr bool same_decayed_v =
+    ::std::is_same<T, ::std::decay_t<T>>::value && ::std::is_same<U, ::std::decay_t<U>>::value;
+
+template <typename T, typename U>
+using ternary_return_t = ::std::decay_t<decltype(false ? ::std::declval<T>() : ::std::declval<U>())>;
+
+template <typename, typename, typename = void>
+struct binary_common_type
+{
+};
+
+template <typename T, typename U>
+struct binary_common_type<T, U, ::std::enable_if_t<!same_decayed_v<T, U>>>
+    : nano::common_type<::std::decay_t<T>, ::std::decay_t<U>>
+{
+};
+
+template <typename T, typename U>
+struct binary_common_type<T, U, ::std::enable_if_t<same_decayed_v<T, U> && exists_v<ternary_return_t, T, U>>>
+{
+    using type = ternary_return_t<T, U>;
+};
+
+template <typename T, typename U>
+struct binary_common_type<T, U,
+                          ::std::enable_if_t<same_decayed_v<T, U> && !exists_v<ternary_return_t, T, U> &&
+                                             exists_v<cond_res_t, cref_t<T>, cref_t<U>>>>
+{
+    using type = ::std::decay_t<cond_res_t<cref_t<T>, cref_t<U>>>;
+};
+
+} // namespace detail
+
+template <>
+struct common_type<>
+{
+};
+
+template <typename T>
+struct common_type<T> : common_type<T, T>
+{
+};
+
+template <typename T, typename U>
+struct common_type<T, U> : detail::binary_common_type<T, U>
+{
+};
+
+namespace detail
+{
+
+template <typename Void, typename...>
+struct multiple_common_type
+{
+};
+
+template <typename T1, typename T2, typename... R>
+struct multiple_common_type<::std::void_t<common_type_t<T1, T2>>, T1, T2, R...>
+    : common_type<common_type_t<T1, T2>, R...>
+{
+};
+
+} // namespace detail
+
+template <typename T1, typename T2, typename... R>
+struct common_type<T1, T2, R...> : detail::multiple_common_type<void, T1, T2, R...>
+{
+};
+
+NANO_END_NAMESPACE
+
+#                                endif
+
+#                            endif
+
+#                            include <utility>
+
+NANO_BEGIN_NAMESPACE
+
+// [concept.same]
+template <typename T, typename U>
+NANO_CONCEPT same_as = ::std::is_same_v<T, U>;
+
+// [concept.derived]
+namespace detail
+{
+
+struct derived_from_concept
+{
+    template <typename, typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename Derived, typename Base>
+    static auto
+    test(int) -> ::std::enable_if_t<
+        ::std::is_base_of_v<Base, Derived>&& ::std::is_convertible_v<const volatile Derived*, const volatile Base*>,
+        ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename Derived, typename Base>
+NANO_CONCEPT derived_from = decltype(detail::derived_from_concept::test<Derived, Base>(0))::value;
+
+// [concept.convertible]
+namespace detail
+{
+
+struct convertible_to_concept
+{
+    template <typename From, typename To>
+    auto requires_(::std::add_rvalue_reference_t<From> (&f)()) -> decltype(static_cast<To>(f()));
+};
+
+} // namespace detail
+
+template <typename From, typename To>
+NANO_CONCEPT convertible_to =
+    ::std::is_convertible_v<From, To>&& detail::requires_<detail::convertible_to_concept, From, To>;
+
+// [concept.commonref]
+namespace detail
+{
+
+struct common_reference_with_concept
+{
+    template <typename T, typename U>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T, typename U>
+    static auto
+    test(int) -> ::std::enable_if_t<same_as<common_reference_t<T, U>, common_reference_t<U, T>> &&
+                                        convertible_to<T, common_reference_t<T, U>> &&
+                                        convertible_to<U, common_reference_t<T, U>>,
+                                    ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename T, typename U>
+NANO_CONCEPT common_reference_with = decltype(detail::common_reference_with_concept::test<T, U>(0))::value;
+
+// [concepts.common]
+namespace detail
+{
+
+struct common_with_concept
+{
+    template <typename T, typename U>
+    auto
+    requires_() -> decltype(static_cast<common_type_t<T, U>>(::std::declval<T>()),
+                            static_cast<common_type_t<T, U>>(::std::declval<U>()));
+
+    template <typename, typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T, typename U>
+    static auto
+    test(int) -> ::std::enable_if_t<
+        same_as<common_type_t<T, U>, common_type_t<U, T>> && detail::requires_<common_with_concept, T, U> &&
+            common_reference_with<::std::add_lvalue_reference_t<const T>, ::std::add_lvalue_reference_t<const U>> &&
+            common_reference_with<
+                ::std::add_lvalue_reference_t<common_type_t<T, U>>,
+                common_reference_t<::std::add_lvalue_reference_t<const T>, ::std::add_lvalue_reference_t<const U>>>,
+        ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename T, typename U>
+NANO_CONCEPT common_with = decltype(detail::common_with_concept::test<T, U>(0))::value;
+
+// [concept.arithmetic]
+template <typename T>
+NANO_CONCEPT integral = ::std::is_integral_v<T>;
+
+template <typename T>
+NANO_CONCEPT signed_integral = integral<T>&& ::std::is_signed_v<T>;
+
+template <typename T>
+NANO_CONCEPT unsigned_integral = integral<T> && !signed_integral<T>;
+
+template <typename T>
+NANO_CONCEPT floating_point = ::std::is_floating_point_v<T>;
+
+// [concept.assignable]
+
+namespace detail
+{
+
+struct assignable_from_concept
+{
+    template <typename LHS, typename RHS>
+    auto
+    requires_(LHS lhs, RHS&& rhs) -> decltype(requires_expr<same_as<decltype(lhs = ::std::forward<RHS>(rhs)), LHS>>{});
+
+    template <typename, typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename LHS, typename RHS>
+    static auto
+    test(int) -> ::std::enable_if_t<
+        ::std::is_lvalue_reference_v<LHS> &&
+            common_reference_with<const ::std::remove_reference_t<LHS>&, const ::std::remove_reference_t<RHS>&> &&
+            detail::requires_<assignable_from_concept, LHS, RHS>,
+        ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename LHS, typename RHS>
+NANO_CONCEPT assignable_from = decltype(detail::assignable_from_concept::test<LHS, RHS>(0))::value;
+
+// [concept.destructible]
+template <typename T>
+NANO_CONCEPT destructible = ::std::is_nothrow_destructible_v<T>;
+
+// [concept.constructible]
+template <typename T, typename... Args>
+NANO_CONCEPT constructible_from = destructible<T>&& ::std::is_constructible_v<T, Args...>;
+
+// [concept.default.init]
+namespace detail
+{
+
+template <typename, typename = void>
+inline constexpr bool is_default_initializable = false;
+
+// Thanks to Damian Jarek on Slack for this formulation
+template <typename T>
+inline constexpr bool is_default_initializable<T, ::std::void_t<decltype(::new T)>> = true;
+
+struct default_initializable_concept
+{
+    template <typename T, typename = decltype(T{})>
+    auto
+    requires_() -> void;
+};
+
+} // namespace detail
+
+template <typename T>
+NANO_CONCEPT default_initializable = constructible_from<T>&&
+    detail::requires_<detail::default_initializable_concept, T>&& detail::is_default_initializable<T>;
+
+// [concept.moveconstructible]
+template <typename T>
+NANO_CONCEPT move_constructible = constructible_from<T, T>&& convertible_to<T, T>;
+
+// [concept.copyconstructible]
+namespace detail
+{
+
+struct copy_constructible_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T>
+    static auto
+    test(int) -> ::std::enable_if_t<move_constructible<T> && constructible_from<T, T&> && convertible_to<T&, T> &&
+                                        constructible_from<T, const T&> && convertible_to<const T&, T> &&
+                                        constructible_from<T, const T> && convertible_to<const T, T>,
+                                    ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename T>
+NANO_CONCEPT copy_constructible = decltype(detail::copy_constructible_concept::test<T>(0))::value;
+
+NANO_END_NAMESPACE
+
+#                        endif
+
+// nanorange/detail/concepts/swappable.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                        ifndef NANORANGE_DETAIL_CONCEPTS_SWAPPABLE_HPP_INCLUDED
+#                            define NANORANGE_DETAIL_CONCEPTS_SWAPPABLE_HPP_INCLUDED
+
+// nanorange/detail/swap.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                            ifndef NANORANGE_DETAIL_SWAP_HPP_INCLUDED
+#                                define NANORANGE_DETAIL_SWAP_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+// [range.swap]
+
+namespace detail
+{
+namespace swap_
+{
+
+template <typename T>
+void
+swap(T&, T&) = delete;
+
+template <typename T, ::std::size_t N>
+void swap(T (&)[N], T (&)[N]) = delete;
+
+struct fn
+{
+  private:
+    template <typename T, typename U>
+    static constexpr auto
+    impl(T&& t, U&& u, priority_tag<2>) noexcept(noexcept(swap(::std::forward<T>(t), ::std::forward<U>(u))))
+        -> decltype(static_cast<void>(swap(::std::forward<T>(t), ::std::forward<U>(u))))
+    {
+        (void)swap(::std::forward<T>(t), ::std::forward<U>(u));
+    }
+
+    template <typename T, typename U, ::std::size_t N, typename F = fn>
+    static constexpr auto impl(T (&t)[N], U (&u)[N], priority_tag<1>) noexcept(noexcept(::std::declval<F&>()(*t, *u)))
+        -> decltype(::std::declval<F&>()(*t, *u))
+    {
+        for (::std::size_t i = 0; i < N; ++i)
+        {
+            fn::impl(t[i], u[i], priority_tag<2>{});
+        }
+    }
+
+    template <typename T>
+    static constexpr auto
+    impl(T& a, T& b, priority_tag<0>) noexcept(
+        ::std::is_nothrow_move_constructible<T>::value&& ::std::is_nothrow_assignable<T&, T>::value)
+        -> ::std::enable_if_t<move_constructible<T> && assignable_from<T&, T>>
+    {
+        T temp = ::std::move(a);
+        a = ::std::move(b);
+        b = ::std::move(temp);
+    }
+
+  public:
+    template <typename T, typename U>
+    constexpr auto
+    operator()(T&& t, U&& u) const
+        noexcept(noexcept(fn::impl(::std::forward<T>(t), ::std::forward<U>(u), priority_tag<2>{})))
+            -> decltype(fn::impl(::std::forward<T>(t), ::std::forward<U>(u), priority_tag<2>{}))
+    {
+        return fn::impl(::std::forward<T>(t), ::std::forward<U>(u), priority_tag<2>{});
+    }
+};
+
+} // end namespace swap_
+} // end namespace detail
+
+NANO_INLINE_VAR(detail::swap_::fn, swap)
+
+NANO_END_NAMESPACE
+
+#                            endif
+
+NANO_BEGIN_NAMESPACE
+
+// [concept.swappable]
+namespace detail
+{
+
+struct swappable_concept
+{
+    template <typename T>
+    auto
+    requires_(T& a, T& b) -> decltype(ranges::swap(a, b));
+};
+
+} // namespace detail
+
+template <typename T>
+NANO_CONCEPT swappable = detail::requires_<detail::swappable_concept, T>;
+
+namespace detail
+{
+
+struct swappable_with_concept
+{
+    template <typename T, typename U>
+    auto
+    requires_(T&& t, U&& u) -> decltype(ranges::swap(::std::forward<T>(t), ::std::forward<T>(t)),
+                                        ranges::swap(::std::forward<U>(u), ::std::forward<U>(u)),
+                                        ranges::swap(::std::forward<T>(t), ::std::forward<U>(u)),
+                                        ranges::swap(::std::forward<U>(u), ::std::forward<T>(t)));
+
+    template <typename, typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T, typename U>
+    static auto
+    test(int) -> ::std::enable_if_t<
+        common_reference_with<const ::std::remove_reference_t<T>&, const ::std::remove_reference_t<U>&> &&
+            detail::requires_<swappable_with_concept, T, U>,
+        ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename T, typename U>
+NANO_CONCEPT swappable_with = decltype(detail::swappable_with_concept::test<T, U>(0))::value;
+
+NANO_END_NAMESPACE
+
+#                        endif
+
+NANO_BEGIN_NAMESPACE
+
+// [concept.boolean_testable]
+namespace detail
+{
+
+template <typename T>
+NANO_CONCEPT boolean_testable_impl = convertible_to<T, bool>;
+
+struct boolean_testable_concept
+{
+    template <typename T>
+    auto
+    requires_(T&& t) -> requires_expr<boolean_testable_impl<decltype(!::std::forward<T>(t))>>;
+};
+
+template <typename T>
+NANO_CONCEPT boolean_testable = boolean_testable_impl<T>&& detail::requires_<boolean_testable_concept, T>;
+
+} // namespace detail
+
+// [concept.equalitycomparable]
+namespace detail
+{
+
+struct weakly_equality_comparable_with_concept
+{
+    template <typename T, typename U>
+    auto
+    requires_(const ::std::remove_reference_t<T>& t, const ::std::remove_reference_t<U>& u)
+        -> decltype(requires_expr<boolean_testable<decltype(t == u)>>{},
+                    requires_expr<boolean_testable<decltype(t != u)>>{},
+                    requires_expr<boolean_testable<decltype(u == t)>>{},
+                    requires_expr<boolean_testable<decltype(u != t)>>{});
+};
+
+template <typename T, typename U>
+NANO_CONCEPT weakly_equality_comparable_with = requires_<weakly_equality_comparable_with_concept, T, U>;
+
+} // namespace detail
+
+template <typename T>
+NANO_CONCEPT equality_comparable = detail::weakly_equality_comparable_with<T, T>;
+
+namespace detail
+{
+
+struct equality_comparable_with_concept
+{
+    template <typename, typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T, typename U>
+    static auto
+    test(int) -> ::std::enable_if_t<
+        equality_comparable<T> && equality_comparable<U> &&
+            common_reference_with<const ::std::remove_reference_t<T>&, const ::std::remove_reference_t<U>&> &&
+            equality_comparable<
+                common_reference_t<const ::std::remove_reference_t<T>&, const ::std::remove_reference_t<U>&>> &&
+            weakly_equality_comparable_with<T, U>,
+        ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename T, typename U>
+NANO_CONCEPT equality_comparable_with = decltype(detail::equality_comparable_with_concept::test<T, U>(0))::value;
+
+// [concepts.totallyordered]
+namespace detail
+{
+
+struct partially_ordered_with_concept
+{
+    template <typename T, typename U>
+    auto
+    requires_(const ::std::remove_reference_t<T>& t, const ::std::remove_reference_t<U>& u) -> decltype(
+        requires_expr<boolean_testable<decltype(t < u)>>{}, requires_expr<boolean_testable<decltype(t > u)>>{},
+        requires_expr<boolean_testable<decltype(t <= u)>>{}, requires_expr<boolean_testable<decltype(t >= u)>>{},
+        requires_expr<boolean_testable<decltype(u < t)>>{}, requires_expr<boolean_testable<decltype(u > t)>>{},
+        requires_expr<boolean_testable<decltype(u <= t)>>{}, requires_expr<boolean_testable<decltype(u >= t)>>{});
+};
+
+template <typename T, typename U>
+NANO_CONCEPT partially_ordered_with = detail::requires_<detail::partially_ordered_with_concept, T, U>;
+
+} // namespace detail
+
+template <typename T>
+NANO_CONCEPT totally_ordered = equality_comparable<T>&& detail::partially_ordered_with<T, T>;
+
+namespace detail
+{
+
+struct totally_ordered_with_concept
+{
+    template <typename, typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T, typename U>
+    static auto
+    test(int) -> ::std::enable_if_t<totally_ordered<T> && totally_ordered<U> && equality_comparable_with<T, U> &&
+                                        totally_ordered<common_reference_t<const ::std::remove_reference_t<T>&,
+                                                                           const ::std::remove_reference_t<U>&>> &&
+                                        partially_ordered_with<T, U>,
+                                    ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename T, typename U>
+NANO_CONCEPT totally_ordered_with = decltype(detail::totally_ordered_with_concept::test<T, U>(0))::value;
+
+NANO_END_NAMESPACE
+
+#                    endif
+
+#                    include <functional>
+#                    include <utility>
+
+NANO_BEGIN_NAMESPACE
+
+// [range.comparisons]
+
+struct equal_to
+{
+    template <typename T, typename U>
+    constexpr auto
+    operator()(T&& t, U&& u) const -> ::std::enable_if_t<equality_comparable_with<T, U>, bool>
+    {
+        return ::std::equal_to<>{}(::std::forward<T>(t), ::std::forward<U>(u));
+    }
+
+    using is_transparent = ::std::true_type;
+};
+
+struct not_equal_to
+{
+    template <typename T, typename U>
+    constexpr auto
+    operator()(T&& t, U&& u) const -> ::std::enable_if_t<equality_comparable_with<T, U>, bool>
+    {
+        return !ranges::equal_to{}(::std::forward<T>(t), ::std::forward<U>(u));
+    }
+
+    using is_transparent = ::std::true_type;
+};
+
+struct less
+{
+    template <typename T, typename U>
+    constexpr auto
+    operator()(T&& t, U&& u) const -> ::std::enable_if_t<totally_ordered_with<T, U>, bool>
+    {
+        return ::std::less<>{}(::std::forward<T>(t), ::std::forward<U>(u));
+    }
+
+    using is_transparent = ::std::true_type;
+};
+
+struct greater
+{
+    template <typename T, typename U>
+    constexpr auto
+    operator()(T&& t, U&& u) const -> ::std::enable_if_t<totally_ordered_with<T, U>, bool>
+    {
+        return ranges::less{}(::std::forward<U>(u), ::std::forward<T>(t));
+    }
+
+    using is_transparent = ::std::true_type;
+};
+
+struct greater_equal
+{
+    template <typename T, typename U>
+    constexpr auto
+    operator()(T&& t, U&& u) const -> ::std::enable_if_t<totally_ordered_with<T, U>, bool>
+    {
+        return !ranges::less{}(::std::forward<T>(t), ::std::forward<U>(u));
+    }
+
+    using is_transparent = ::std::true_type;
+};
+
+struct less_equal
+{
+    template <typename T, typename U>
+    constexpr auto
+    operator()(T&& t, U&& u) const -> ::std::enable_if_t<totally_ordered_with<T, U>, bool>
+    {
+        return !ranges::less{}(::std::forward<U>(u), ::std::forward<T>(t));
+    }
+
+    using is_transparent = ::std::true_type;
+};
+
+NANO_END_NAMESPACE
+
+#                endif
+// nanorange/detail/functional/identity.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                ifndef NANORANGE_DETAIL_FUNCTIONAL_IDENTITY_HPP_INCLUDED
+#                    define NANORANGE_DETAIL_FUNCTIONAL_IDENTITY_HPP_INCLUDED
+
+#                    include <type_traits>
+#                    include <utility>
+
+NANO_BEGIN_NAMESPACE
+
+struct identity
+{
+    template <typename T>
+    constexpr T&&
+    operator()(T&& t) const noexcept
+    {
+        return ::std::forward<T>(t);
+    }
+
+    using is_transparent = ::std::true_type;
+};
+
+NANO_END_NAMESPACE
+
+#                endif
+
+// nanorange/detail/iterator/indirect_callable_concepts.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                ifndef NANORANGE_DETAIL_ITERATOR_INDIRECT_CALLABLE_CONCEPTS_HPP_INCLUDED
+#                    define NANORANGE_DETAIL_ITERATOR_INDIRECT_CALLABLE_CONCEPTS_HPP_INCLUDED
+
+// nanorange/detail/iterator/concepts.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                    ifndef NANORANGE_DETAIL_ITERATOR_CONCEPTS_HPP_INCLUDED
+#                        define NANORANGE_DETAIL_ITERATOR_CONCEPTS_HPP_INCLUDED
+
+// nanorange/detail/concepts/object.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                        ifndef NANORANGE_DETAIL_CONCEPTS_OBJECT_HPP_INCLUDED
+#                            define NANORANGE_DETAIL_CONCEPTS_OBJECT_HPP_INCLUDED
+
+// nanorange/detail/functional/invoke.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                            ifndef NANORANGE_DETAIL_FUNCTIONAL_INVOKE_HPP_INCLUDED
+#                                define NANORANGE_DETAIL_FUNCTIONAL_INVOKE_HPP_INCLUDED
+
+#                                include <functional>
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+// This is a reimplementation of ::std::invoke, which for some stupid
+// reason is not constexpr in C++17
+inline namespace invoke_
+{
+
+template <typename>
+constexpr bool is_reference_wrapper_v = false;
+
+template <typename T>
+constexpr bool is_reference_wrapper_v<::std::reference_wrapper<T>> = true;
+
+struct fn
+{
+  private:
+    template <class Base, class T, class Derived, class... Args>
+    static constexpr auto
+    impl(T Base::*pmf, Derived&& ref,
+         Args&&... args) noexcept(noexcept((::std::forward<Derived>(ref).*pmf)(::std::forward<Args>(args)...)))
+        -> ::std::enable_if_t<::std::is_function<T>::value&& ::std::is_base_of<Base, ::std::decay_t<Derived>>::value,
+                              decltype((::std::forward<Derived>(ref).*pmf)(::std::forward<Args>(args)...))>
+    {
+        return (::std::forward<Derived>(ref).*pmf)(::std::forward<Args>(args)...);
+    }
+
+    template <class Base, class T, class RefWrap, class... Args>
+    static constexpr auto
+    impl(T Base::*pmf, RefWrap&& ref,
+         Args&&... args) noexcept(noexcept((ref.get().*pmf)(::std::forward<Args>(args)...)))
+        -> ::std::enable_if_t<::std::is_function<T>::value && is_reference_wrapper_v<::std::decay_t<RefWrap>>,
+                              decltype((ref.get().*pmf)(::std::forward<Args>(args)...))>
+    {
+        return (ref.get().*pmf)(::std::forward<Args>(args)...);
+    }
+
+    template <class Base, class T, class Pointer, class... Args>
+    static constexpr auto
+    impl(T Base::*pmf, Pointer&& ptr,
+         Args&&... args) noexcept(noexcept(((*::std::forward<Pointer>(ptr)).*pmf)(::std::forward<Args>(args)...)))
+        -> ::std::enable_if_t<::std::is_function<T>::value && !is_reference_wrapper_v<::std::decay_t<Pointer>> &&
+                                  !::std::is_base_of<Base, ::std::decay_t<Pointer>>::value,
+                              decltype(((*::std::forward<Pointer>(ptr)).*pmf)(::std::forward<Args>(args)...))>
+    {
+        return ((*::std::forward<Pointer>(ptr)).*pmf)(::std::forward<Args>(args)...);
+    }
+
+    template <class Base, class T, class Derived>
+    static constexpr auto
+    impl(T Base::*pmd, Derived&& ref) noexcept(noexcept(::std::forward<Derived>(ref).*pmd))
+        -> ::std::enable_if_t<!::std::is_function<T>::value && ::std::is_base_of<Base, ::std::decay_t<Derived>>::value,
+                              decltype(::std::forward<Derived>(ref).*pmd)>
+    {
+        return ::std::forward<Derived>(ref).*pmd;
+    }
+
+    template <class Base, class T, class RefWrap>
+    static constexpr auto
+    impl(T Base::*pmd, RefWrap&& ref) noexcept(noexcept(ref.get().*pmd))
+        -> ::std::enable_if_t<!::std::is_function<T>::value && is_reference_wrapper_v<::std::decay_t<RefWrap>>,
+                              decltype(ref.get().*pmd)>
+    {
+        return ref.get().*pmd;
+    }
+
+    template <class Base, class T, class Pointer>
+    static constexpr auto
+    impl(T Base::*pmd, Pointer&& ptr) noexcept(noexcept((*::std::forward<Pointer>(ptr)).*pmd))
+        -> ::std::enable_if_t<!::std::is_function<T>::value && !is_reference_wrapper_v<::std::decay_t<Pointer>> &&
+                                  !::std::is_base_of<Base, ::std::decay_t<Pointer>>::value,
+                              decltype((*::std::forward<Pointer>(ptr)).*pmd)>
+    {
+        return (*::std::forward<Pointer>(ptr)).*pmd;
+    }
+
+    template <class F, class... Args>
+    static constexpr auto
+    impl(F&& f, Args&&... args) noexcept(noexcept(::std::forward<F>(f)(::std::forward<Args>(args)...)))
+        -> ::std::enable_if_t<!::std::is_member_pointer<::std::decay_t<F>>::value,
+                              decltype(::std::forward<F>(f)(::std::forward<Args>(args)...))>
+    {
+        return ::std::forward<F>(f)(::std::forward<Args>(args)...);
+    }
+
+  public:
+    template <typename F, typename... Args>
+    constexpr auto
+    operator()(F&& f, Args&&... args) const
+        noexcept(noexcept(fn::impl(::std::forward<F>(f), ::std::forward<Args>(args)...)))
+            -> decltype(fn::impl(::std::forward<F>(f), ::std::forward<Args>(args)...))
+    {
+        return fn::impl(::std::forward<F>(f), ::std::forward<Args>(args)...);
+    }
+};
+
+} // namespace invoke_
+} // namespace detail
+
+NANO_INLINE_VAR(nano::detail::invoke_::fn, invoke)
+
+namespace detail
+{
+
+template <typename Void, typename, typename...>
+struct invoke_result_helper
+{
+};
+
+template <typename F, typename... Args>
+struct invoke_result_helper<::std::void_t<decltype(nano::invoke(::std::declval<F>(), ::std::declval<Args>()...))>, F,
+                            Args...>
+{
+    using type = decltype(nano::invoke(::std::declval<F>(), ::std::declval<Args>()...));
+};
+
+} // namespace detail
+
+template <typename F, typename... Args>
+struct invoke_result : detail::invoke_result_helper<void, F, Args...>
+{
+};
+
+template <typename F, typename... Args>
+using invoke_result_t = typename invoke_result<F, Args...>::type;
+
+NANO_END_NAMESPACE
+
+#                            endif
+
+NANO_BEGIN_NAMESPACE
+
+// [concept.movable]
+namespace detail
+{
+
+struct movable_concept
+{
+    template <typename T>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T>
+    static auto
+    test(int)
+        -> ::std::enable_if_t<::std::is_object_v<T> && move_constructible<T> && assignable_from<T&, T> && swappable<T>,
+                              ::std::true_type>;
+};
+} // namespace detail
+
+template <typename T>
+NANO_CONCEPT movable = decltype(detail::movable_concept::test<T>(0))::value;
+
+// [concept.copyable]
+namespace detail
+{
+
+struct copyable_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T>
+    static auto
+    test(int) -> ::std::enable_if_t<copy_constructible<T> && movable<T> && assignable_from<T&, T&> &&
+                                        assignable_from<T&, const T&> && assignable_from<T&, const T>,
+                                    ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename T>
+NANO_CONCEPT copyable = decltype(detail::copyable_concept::test<T>(0))::value;
+
+// [concept.semiregular]
+template <typename T>
+NANO_CONCEPT semiregular = copyable<T>&& default_initializable<T>;
+
+// [concept.regular]
+template <typename T>
+NANO_CONCEPT regular = semiregular<T>&& equality_comparable<T>;
+
+// [concept.invocable]
+namespace detail
+{
+
+struct invocable_concept
+{
+    // FIXME (Clang): https://bugs.llvm.org/show_bug.cgi?id=21446
+#                            if (defined(__clang_major__) && (defined(__apple_build_version__) || __clang_major__ < 7))
+    template <typename F, typename... Args>
+    auto
+    requires_(F&& f, Args&&... args) -> invoke_result_t<F, Args...>;
+#                            else
+    template <typename F, typename... Args>
+    auto
+    requires_(F&& f, Args&&... args) -> decltype(nano::invoke(::std::forward<F>(f), ::std::forward<Args>(args)...));
+#                            endif
+};
+
+} // namespace detail
+
+template <typename F, typename... Args>
+NANO_CONCEPT invocable = detail::requires_<detail::invocable_concept, F, Args...>;
+
+// [concept.regularinvocable]
+template <typename F, typename... Args>
+NANO_CONCEPT regular_invocable = invocable<F, Args...>;
+
+// [concept.predicate]
+namespace detail
+{
+
+struct predicate_concept
+{
+    template <typename, typename...>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename F, typename... Args>
+    static auto
+    test(int) -> ::std::enable_if_t<regular_invocable<F, Args...> && boolean_testable<invoke_result_t<F, Args...>>,
+                                    ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename F, typename... Args>
+NANO_CONCEPT predicate = decltype(detail::predicate_concept::test<F, Args...>(0))::value;
+
+// [concept.relation]
+template <typename R, typename T, typename U>
+NANO_CONCEPT relation = predicate<R, T, T>&& predicate<R, U, U>&& predicate<R, T, U>&& predicate<R, U, T>;
+
+// [concept.equiv]
+template <typename R, typename T, typename U>
+NANO_CONCEPT equivalence_relation = relation<R, T, U>;
+
+// [concept.strictweakorder]
+template <typename R, typename T, typename U>
+NANO_CONCEPT strict_weak_order = relation<R, T, U>;
+
+NANO_END_NAMESPACE
+
+#                        endif
+
+// nanorange/detail/iterator/associated_types.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                        ifndef NANORANGE_DETAIL_ITERATOR_ASSOCIATED_TYPES_HPP_INCLUDED
+#                            define NANORANGE_DETAIL_ITERATOR_ASSOCIATED_TYPES_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename>
+struct incrementable_traits;
+
+namespace detail
+{
+
+struct empty
+{
+};
+
+template <typename T>
+struct with_difference_type
+{
+    using difference_type = T;
+};
+
+template <typename, typename = void>
+struct incrementable_traits_helper
+{
+};
+
+// Workaround for GCC silliness: void* has no difference_type
+// FIXME: This is required to stop WeaklyIncrementable<void*> being a hard error
+// Can we formulate the concept differently to avoid the need for this hack?
+template <>
+struct incrementable_traits_helper<void*>
+{
+};
+
+template <typename T>
+struct incrementable_traits_helper<T*>
+    : detail::conditional_t<::std::is_object<T>::value, with_difference_type<::std::ptrdiff_t>, empty>
+{
+};
+
+template <class I>
+struct incrementable_traits_helper<const I> : incrementable_traits<::std::decay_t<I>>
+{
+};
+
+template <typename, typename = void>
+struct has_member_difference_type : ::std::false_type
+{
+};
+
+template <typename T>
+struct has_member_difference_type<T, ::std::void_t<typename T::difference_type>> : ::std::true_type
+{
+};
+
+template <typename T>
+constexpr bool has_member_difference_type_v = has_member_difference_type<T>::value;
+
+template <typename T>
+struct incrementable_traits_helper<T, ::std::enable_if_t<has_member_difference_type_v<T>>>
+{
+    using difference_type = typename T::difference_type;
+};
+
+template <typename T>
+struct incrementable_traits_helper<
+    T, ::std::enable_if_t<!::std::is_pointer<T>::value && !has_member_difference_type_v<T> &&
+                          integral<decltype(::std::declval<const T&>() - ::std::declval<const T&>())>>>
+    : with_difference_type<::std::make_signed_t<decltype(::std::declval<T>() - ::std::declval<T>())>>
+{
+};
+
+} // namespace detail
+
+template <typename T>
+struct incrementable_traits : detail::incrementable_traits_helper<T>
+{
+};
+
+template <typename T>
+using iter_difference_t = typename incrementable_traits<T>::difference_type;
+
+// [range.iterator.assoc.types.value_type]
+
+template <typename>
+struct readable_traits;
+
+namespace detail
+{
+
+template <typename T>
+struct with_value_type
+{
+    using value_type = T;
+};
+
+template <typename, typename = void>
+struct readable_traits_helper
+{
+};
+
+template <typename T>
+struct readable_traits_helper<T*>
+    : detail::conditional_t<::std::is_object<T>::value, with_value_type<::std::remove_cv_t<T>>, empty>
+{
+};
+
+template <typename I>
+struct readable_traits_helper<I, ::std::enable_if_t<::std::is_array<I>::value>> : readable_traits<::std::decay_t<I>>
+{
+};
+
+template <typename I>
+struct readable_traits_helper<const I, ::std::enable_if_t<!::std::is_array<I>::value>>
+    : readable_traits<::std::decay_t<I>>
+{
+};
+
+template <typename T, typename V = typename T::value_type>
+struct member_value_type : detail::conditional_t<::std::is_object<V>::value, with_value_type<V>, empty>
+{
+};
+
+template <typename T, typename E = typename T::element_type>
+struct member_element_type
+    : detail::conditional_t<::std::is_object<E>::value, with_value_type<::std::remove_cv_t<E>>, empty>
+{
+};
+
+template <typename T>
+using member_value_type_t = typename T::value_type;
+
+template <typename T>
+constexpr bool has_member_value_type_v = exists_v<member_value_type_t, T>;
+
+template <typename T>
+using member_element_type_t = typename T::element_type;
+
+template <typename T>
+constexpr bool has_member_element_type_v = exists_v<member_element_type_t, T>;
+
+template <typename T>
+struct readable_traits_helper<T, ::std::enable_if_t<has_member_value_type_v<T> && !has_member_element_type_v<T>>>
+    : member_value_type<T>
+{
+};
+
+template <typename T>
+struct readable_traits_helper<T, ::std::enable_if_t<has_member_element_type_v<T> && !has_member_value_type_v<T>>>
+    : member_element_type<T>
+{
+};
+
+// A type which has both value_type and element_type members must specialise
+// readable_traits to tell us which one to prefer -- see
+// https://github.com/ericniebler/stl2/issues/562
+template <typename T>
+struct readable_traits_helper<T, ::std::enable_if_t<has_member_element_type_v<T> && has_member_value_type_v<T>>>
+{
+};
+
+} // namespace detail
+
+template <typename T>
+struct readable_traits : detail::readable_traits_helper<T>
+{
+};
+
+template <typename T>
+using iter_value_t = typename readable_traits<T>::value_type;
+
+NANO_END_NAMESPACE
+
+#                        endif
+
+// nanorange/detail/iterator/traits.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                        ifndef NANORANGE_DETAIL_ITERATOR_TRAITS_HPP_INCLUDED
+#                            define NANORANGE_DETAIL_ITERATOR_TRAITS_HPP_INCLUDED
+
+// nanorange/detail/iterator/dereferenceable.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                            ifndef NANORANGE_DETAIL_ITERATOR_DEREFERENCABLE_HPP_INCLUDED
+#                                define NANORANGE_DETAIL_ITERATOR_DEREFERENCABLE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+template <typename T>
+using with_reference = T&;
+
+struct can_reference_concept
+{
+    template <typename T>
+    auto
+    requires_() -> with_reference<T>;
+};
+
+template <typename T>
+NANO_CONCEPT can_reference = detail::requires_<can_reference_concept, T>;
+
+struct dereferencable_concept
+{
+    template <typename T>
+    auto
+    requires_(T& t) -> decltype(requires_expr<can_reference<decltype(*t)>>{});
+};
+
+template <typename T>
+NANO_CONCEPT dereferenceable = requires_<dereferencable_concept, T>;
+
+// GCC and Clang allow dereferencing void* as an extension.
+// Let's kill that off now.
+
+template <>
+NANO_CONCEPT dereferenceable<void*> = false;
+
+} // namespace detail
+
+NANO_END_NAMESPACE
+
+#                            endif
+
+// nanorange/detail/iterator/iter_move.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                            ifndef NANORANGE_DETAIL_ITERATOR_ITER_MOVE_HPP_INCLUDED
+#                                define NANORANGE_DETAIL_ITERATOR_ITER_MOVE_HPP_INCLUDED
+
+#                                include <utility>
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+namespace iter_move_
+{
+
+void
+iter_move();
+
+struct fn
+{
+  private:
+    template <typename T>
+    static constexpr auto
+    impl(T&& t, priority_tag<2>) noexcept(noexcept(iter_move(t))) -> decltype(iter_move(t))
+    {
+        return iter_move(t);
+    }
+
+    template <typename T>
+    static constexpr auto
+    impl(T&& t, priority_tag<1>) noexcept(noexcept(::std::move(*::std::declval<T&&>())))
+        -> ::std::enable_if_t<::std::is_lvalue_reference<decltype(*::std::forward<T>(t))>::value,
+                              decltype(::std::move(*::std::forward<T>(t)))>
+    {
+        return ::std::move(*::std::forward<T>(t));
+    }
+
+    template <typename T>
+    static constexpr auto
+    impl(T&& t, priority_tag<0>) noexcept(noexcept(*::std::forward<T>(t))) -> decltype(*::std::forward<T>(t))
+    {
+        return *::std::forward<T>(t);
+    }
+
+  public:
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const noexcept(noexcept(fn::impl(::std::forward<T>(t), priority_tag<2>{})))
+        -> decltype(fn::impl(::std::forward<T>(t), priority_tag<2>{}))
+    {
+        return fn::impl(::std::forward<T>(t), priority_tag<2>{});
+    }
+};
+
+} // namespace iter_move_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::iter_move_::fn, iter_move)
+
+NANO_END_NAMESPACE
+
+#                            endif
+
+#                            include <iterator>
+
+NANO_BEGIN_NAMESPACE
+
+// [range.iterator.assoc.types.iterator_category]
+using ::std::bidirectional_iterator_tag;
+using ::std::forward_iterator_tag;
+using ::std::input_iterator_tag;
+using ::std::output_iterator_tag;
+using ::std::random_access_iterator_tag;
+
+struct contiguous_iterator_tag : random_access_iterator_tag
+{
+};
+
+template <typename T>
+struct iterator_category;
+
+namespace detail
+{
+
+template <typename T, typename = void>
+struct iterator_category_
+{
+};
+
+template <typename T>
+struct iterator_category_<T*> : ::std::enable_if<::std::is_object<T>::value, contiguous_iterator_tag>
+{
+};
+
+template <typename T>
+struct iterator_category_<const T> : iterator_category<T>
+{
+};
+
+template <typename T>
+struct iterator_category_<T, ::std::void_t<typename T::iterator_category>>
+{
+    using type = typename T::iterator_category;
+};
+
+} // namespace detail
+
+template <typename T>
+struct iterator_category : detail::iterator_category_<T>
+{
+};
+
+template <typename T>
+using iterator_category_t = typename iterator_category<T>::type;
+
+namespace detail
+{
+
+template <typename T, typename = void>
+struct legacy_iterator_category : iterator_category<T>
+{
+};
+
+template <typename T>
+struct legacy_iterator_category<
+    T, ::std::enable_if_t<::std::is_same<iterator_category_t<T>, contiguous_iterator_tag>::value>>
+{
+    using type = random_access_iterator_tag;
+};
+
+template <typename T>
+using legacy_iterator_category_t = typename legacy_iterator_category<T>::type;
+
+} // namespace detail
+
+template <typename T>
+using iter_reference_t = ::std::enable_if_t<detail::dereferenceable<T>, decltype(*::std::declval<T&>())>;
+
+namespace detail
+{
+
+struct iter_rvalue_reference_req
+{
+    template <typename T>
+    auto
+    requires_(T& t) -> decltype(ranges::iter_move(t), requires_expr<can_reference<decltype(ranges::iter_move(t))>>{});
+};
+
+} // namespace detail
+
+template <typename T>
+using iter_rvalue_reference_t =
+    ::std::enable_if_t<detail::dereferenceable<T> && detail::requires_<detail::iter_rvalue_reference_req, T>,
+                       decltype(ranges::iter_move(::std::declval<T&>()))>;
+
+NANO_END_NAMESPACE
+
+#                        endif
+
+NANO_BEGIN_NAMESPACE
+
+// [iterators.concept.readable]
+namespace detail
+{
+
+struct readable_concept
+{
+    template <typename In>
+    auto
+    requires_() -> decltype(::std::declval<iter_value_t<In>>(), ::std::declval<iter_reference_t<In>>(),
+                            ::std::declval<iter_rvalue_reference_t<In>>());
+
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename In>
+    static auto
+    test(int) -> ::std::enable_if_t<detail::requires_<readable_concept, In> &&
+                                        common_reference_with<iter_reference_t<In>&&, iter_value_t<In>&> &&
+                                        common_reference_with<iter_reference_t<In>&&, iter_rvalue_reference_t<In>&&> &&
+                                        common_reference_with<iter_rvalue_reference_t<In>&&, const iter_value_t<In>&>,
+                                    ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename In>
+NANO_CONCEPT readable = decltype(detail::readable_concept::test<In>(0))::value;
+
+// [iterator.concept.writable]
+namespace detail
+{
+
+struct writable_concept
+{
+    template <typename Out, typename T>
+    auto
+    requires_(Out&& o, T&& t)
+        -> decltype(*o = ::std::forward<T>(t), *::std::forward<Out>(o) = ::std::forward<T>(t),
+                    const_cast<const iter_reference_t<Out>&&>(*o) = ::std::forward<T>(t),
+                    const_cast<const iter_reference_t<Out>&&>(*::std::forward<Out>(o)) = ::std::forward<T>(t));
+};
+
+} // namespace detail
+
+template <typename Out, typename T>
+NANO_CONCEPT writable = detail::requires_<detail::writable_concept, Out, T>;
+
+// [iterator.concept.weaklyincrementable]
+
+namespace detail
+{
+
+template <typename T>
+inline constexpr bool is_integer_like = integral<T>;
+
+template <typename T>
+inline constexpr bool is_signed_integer_like = signed_integral<T>;
+
+struct weakly_incrementable_concept
+{
+    template <typename I>
+    auto
+    requires_(I i) -> decltype(::std::declval<iter_difference_t<I>>(),
+                               requires_expr<is_signed_integer_like<iter_difference_t<I>>>{},
+                               requires_expr<same_as<decltype(++i), I&>>{}, i++);
+};
+
+} // namespace detail
+
+template <typename I>
+NANO_CONCEPT weakly_incrementable =
+    default_initializable<I>&& movable<I>&& detail::requires_<detail::weakly_incrementable_concept, I>;
+
+// [iterator.concept.incrementable]
+namespace detail
+{
+
+struct incrementable_concept
+{
+    template <typename I>
+    auto
+    requires_(I i) -> decltype(requires_expr<same_as<decltype(i++), I>>{});
+};
+
+} // namespace detail
+
+template <typename I>
+NANO_CONCEPT incrementable = regular<I>&& weakly_incrementable<I>&& detail::requires_<detail::incrementable_concept, I>;
+
+// [iterator.concept.iterator]
+
+namespace detail
+{
+
+struct input_or_output_iterator_concept
+{
+    template <typename I>
+    auto
+    requires_(I i) -> decltype(requires_expr<can_reference<decltype(*i)>>{});
+};
+
+} // namespace detail
+
+template <typename I>
+NANO_CONCEPT input_or_output_iterator =
+    detail::requires_<detail::input_or_output_iterator_concept, I>&& weakly_incrementable<I>;
+
+// [iterator.concept.sentinel]
+
+template <typename S, typename I>
+NANO_CONCEPT sentinel_for =
+    semiregular<S>&& input_or_output_iterator<I>&& detail::weakly_equality_comparable_with<S, I>;
+
+// [iterator.concept.sizedsentinel]
+
+template <typename S, typename I>
+inline constexpr bool disable_sized_sentinel = false;
+
+namespace detail
+{
+
+struct sized_sentinel_for_concept
+{
+    template <typename S, typename I>
+    auto
+    requires_(const S& s, const I& i) -> decltype(requires_expr<same_as<decltype(s - i), iter_difference_t<I>>>{},
+                                                  requires_expr<same_as<decltype(i - s), iter_difference_t<I>>>{});
+};
+
+} // namespace detail
+
+template <typename S, typename I>
+NANO_CONCEPT sized_sentinel_for =
+    sentinel_for<S, I> && !disable_sized_sentinel<::std::remove_cv_t<S>, ::std::remove_cv_t<I>> &&
+    detail::requires_<detail::sized_sentinel_for_concept, S, I>;
+
+// This is a hack, but I'm fed up with my tests breaking because GCC
+// has a silly extension
+template <typename S>
+NANO_CONCEPT sized_sentinel_for<S, void*> = false;
+
+template <typename I>
+NANO_CONCEPT sized_sentinel_for<void*, I> = false;
+
+template <>
+NANO_CONCEPT sized_sentinel_for<void*, void*> = false;
+
+// [iterator.concept.input]
+
+namespace detail
+{
+
+// FIXME: Use ITER_CONCEPT, not iterator_category_t
+struct input_iterator_concept
+{
+    template <typename I>
+    auto
+    requires_() -> iterator_category_t<I>;
+
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename I>
+    static auto
+    test(int) -> ::std::enable_if_t<input_or_output_iterator<I> && readable<I> &&
+                                        detail::requires_<input_iterator_concept, I> &&
+                                        derived_from<iterator_category_t<I>, input_iterator_tag>,
+                                    ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename I>
+NANO_CONCEPT input_iterator = decltype(detail::input_iterator_concept::test<I>(0))::value;
+
+// [iterator.concept.output]
+
+namespace detail
+{
+
+struct output_iterator_concept
+{
+    template <typename I, typename T>
+    auto
+    requires_(I i, T&& t) -> decltype(*i++ = ::std::forward<T>(t));
+};
+
+} // namespace detail
+
+template <typename I, typename T>
+NANO_CONCEPT output_iterator =
+    input_or_output_iterator<I>&& writable<I, T>&& detail::requires_<detail::output_iterator_concept, I, T>;
+
+// [ranges.iterators.forward]
+
+namespace detail
+{
+
+struct forward_iterator_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename I>
+    static auto
+    test(int) -> ::std::enable_if_t<input_iterator<I> && derived_from<iterator_category_t<I>, forward_iterator_tag> &&
+                                        incrementable<I> && sentinel_for<I, I>,
+                                    ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename I>
+NANO_CONCEPT forward_iterator = decltype(detail::forward_iterator_concept::test<I>(0))::value;
+
+// [iterator.concept.bidir]
+namespace detail
+{
+
+struct bidirectional_iterator_concept
+{
+    template <typename I>
+    auto
+    requires_(I i) -> decltype(requires_expr<same_as<decltype(--i), I&>>{}, requires_expr<same_as<decltype(i--), I>>{});
+
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename I>
+    static auto
+    test(int)
+        -> ::std::enable_if_t<forward_iterator<I> && derived_from<iterator_category_t<I>, bidirectional_iterator_tag> &&
+                                  detail::requires_<bidirectional_iterator_concept, I>,
+                              ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename I>
+NANO_CONCEPT bidirectional_iterator = decltype(detail::bidirectional_iterator_concept::test<I>(0))::value;
+
+// [iterator.concept.random.access]
+
+namespace detail
+{
+
+struct random_access_iterator_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename I>
+    static auto
+    test(int) -> ::std::enable_if_t<
+        bidirectional_iterator<I> && derived_from<iterator_category_t<I>, random_access_iterator_tag> &&
+            totally_ordered<I> && sized_sentinel_for<I, I> && detail::requires_<random_access_iterator_concept, I>,
+        ::std::true_type>;
+
+    template <typename I>
+    auto
+    requires_(I i, const I j, const iter_difference_t<I> n)
+        -> decltype(requires_expr<same_as<decltype(i += n), I&>>{}, requires_expr<same_as<decltype(j + n), I>>{},
+#                        ifndef _MSC_VER
+                    requires_expr<same_as<decltype(n + j), I>>{}, // FIXME: MSVC doesn't like this when I = int*
+#                        endif
+                    requires_expr<same_as<decltype(i -= n), I&>>{}, requires_expr<same_as<decltype(j - n), I>>{},
+                    requires_expr<same_as<decltype(j[n]), iter_reference_t<I>>>{});
+};
+
+} // namespace detail
+
+template <typename I>
+NANO_CONCEPT random_access_iterator = decltype(detail::random_access_iterator_concept::test<I>(0))::value;
+
+namespace detail
+{
+
+struct contiguous_iterator_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename I>
+    static auto
+    test(int) -> ::std::enable_if_t<random_access_iterator<I> &&
+                                        derived_from<iterator_category_t<I>, contiguous_iterator_tag>&& ::std::
+                                            is_lvalue_reference_v<iter_reference_t<I>> &&
+                                        same_as<iter_value_t<I>, remove_cvref_t<iter_reference_t<I>>>,
+                                    ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename I>
+NANO_CONCEPT contiguous_iterator = decltype(detail::contiguous_iterator_concept::test<I>(0))::value;
+
+NANO_END_NAMESPACE
+
+#                    endif
+
+NANO_BEGIN_NAMESPACE
+
+template <typename T>
+using iter_common_reference_t =
+    ::std::enable_if_t<readable<T>, common_reference_t<iter_reference_t<T>, iter_value_t<T>&>>;
+
+// [iterator.concept.indirectinvocable]
+namespace detail
+{
+
+struct indirect_unary_invocable_concept
+{
+    template <typename, typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename F, typename I>
+    static auto
+    test(int) -> ::std::enable_if_t<
+        readable<I> && copy_constructible<F> && invocable<F&, iter_value_t<I>&> && invocable<F&, iter_reference_t<I>> &&
+            invocable<F&, iter_common_reference_t<I>> &&
+            common_reference_with<invoke_result_t<F&, iter_value_t<I>&>, invoke_result_t<F&, iter_reference_t<I>&>>,
+        ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename F, typename I>
+NANO_CONCEPT indirect_unary_invocable = decltype(detail::indirect_unary_invocable_concept::test<F, I>(0))::value;
+
+namespace detail
+{
+
+struct indirect_regular_unary_invocable_concept
+{
+    template <typename, typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename F, typename I>
+    static auto
+    test(int) -> ::std::enable_if_t<
+        readable<I> && copy_constructible<F> && regular_invocable<F&, iter_value_t<I>&> &&
+            regular_invocable<F&, iter_reference_t<I>> && regular_invocable<F&, iter_common_reference_t<I>> &&
+            common_reference_with<invoke_result_t<F&, iter_value_t<I>&>, invoke_result_t<F&, iter_reference_t<I>&>>,
+        ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename F, typename I>
+NANO_CONCEPT indirect_regular_unary_invocable =
+    decltype(detail::indirect_regular_unary_invocable_concept::test<F, I>(0))::value;
+
+namespace detail
+{
+
+struct indirect_unary_predicate_concept
+{
+    template <typename, typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename F, typename I>
+    static auto
+    test(int) -> ::std::enable_if_t<readable<I> && copy_constructible<F> && predicate<F&, iter_value_t<I>&> &&
+                                        predicate<F&, iter_reference_t<I>> && predicate<F&, iter_common_reference_t<I>>,
+                                    ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename F, typename I>
+NANO_CONCEPT indirect_unary_predicate = decltype(detail::indirect_unary_predicate_concept::test<F, I>(0))::value;
+
+namespace detail
+{
+
+struct indirect_relation_concept
+{
+    template <typename F, typename I1, typename I2>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename F, typename I1, typename I2>
+    static auto
+    test(int) -> ::std::enable_if_t<readable<I1> && readable<I2> && copy_constructible<F> &&
+                                        relation<F&, iter_value_t<I1>&, iter_value_t<I2>&> &&
+                                        relation<F&, iter_value_t<I1>&, iter_reference_t<I2>> &&
+                                        relation<F&, iter_reference_t<I1>, iter_value_t<I2>&> &&
+                                        relation<F&, iter_reference_t<I1>, iter_reference_t<I2>> &&
+                                        relation<F&, iter_common_reference_t<I1>, iter_common_reference_t<I2>>,
+                                    ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename F, typename I1, typename I2 = I1>
+NANO_CONCEPT indirect_relation = decltype(detail::indirect_relation_concept::test<F, I1, I2>(0))::value;
+
+namespace detail
+{
+
+struct indirect_strict_weak_order_concept
+{
+    template <typename, typename, typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename F, typename I1, typename I2>
+    static auto
+    test(int) -> ::std::enable_if_t<readable<I1> && readable<I2> && copy_constructible<F> &&
+                                        strict_weak_order<F&, iter_value_t<I1>&, iter_value_t<I2>&> &&
+                                        strict_weak_order<F&, iter_value_t<I1>&, iter_reference_t<I2>> &&
+                                        strict_weak_order<F&, iter_reference_t<I1>, iter_value_t<I2>&> &&
+                                        strict_weak_order<F&, iter_reference_t<I1>, iter_reference_t<I2>> &&
+                                        strict_weak_order<F&, iter_common_reference_t<I1>, iter_common_reference_t<I2>>,
+                                    ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename F, typename I1, typename I2 = I1>
+NANO_CONCEPT indirect_strict_weak_order =
+    decltype(detail::indirect_strict_weak_order_concept::test<F, I1, I2>(0))::value;
+
+template <typename F, typename... Is>
+using indirect_result_t = ::std::enable_if_t<(readable<Is> && ...) && invocable<F, iter_reference_t<Is>...>,
+                                             invoke_result_t<F, iter_reference_t<Is>...>>;
+
+// [alg.req.ind.move]
+
+namespace detail
+{
+
+struct indirectly_movable_concept
+{
+    template <typename, typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename In, typename Out>
+    static auto
+    test(int) -> ::std::enable_if_t<readable<In> && writable<Out, iter_rvalue_reference_t<In>>, ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename In, typename Out>
+NANO_CONCEPT indirectly_movable = decltype(detail::indirectly_movable_concept::test<In, Out>(0))::value;
+
+namespace detail
+{
+
+struct indirectly_movable_storable_concept
+{
+    template <typename In, typename Out>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename In, typename Out>
+    static auto
+    test(int) -> ::std::enable_if_t<indirectly_movable<In, Out> && writable<Out, iter_value_t<In>> &&
+                                        movable<iter_value_t<In>> &&
+                                        constructible_from<iter_value_t<In>, iter_rvalue_reference_t<In>> &&
+                                        assignable_from<iter_value_t<In>&, iter_rvalue_reference_t<In>>,
+                                    ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename In, typename Out>
+NANO_CONCEPT indirectly_movable_storable =
+    decltype(detail::indirectly_movable_storable_concept::test<In, Out>(0))::value;
+
+// [alg.req.ind.copy]
+namespace detail
+{
+
+struct indirectly_copyable_concept
+{
+    template <typename, typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename In, typename Out>
+    static auto
+    test(int) -> ::std::enable_if_t<readable<In> && writable<Out, iter_reference_t<In>>, ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename In, typename Out>
+NANO_CONCEPT indirectly_copyable = decltype(detail::indirectly_copyable_concept::test<In, Out>(0))::value;
+
+namespace detail
+{
+
+struct indirectly_copyable_storable_concept
+{
+    template <typename, typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename In, typename Out>
+    static auto
+    test(int) -> ::std::enable_if_t<indirectly_copyable<In, Out> && writable<Out, const iter_value_t<In>&> &&
+                                        copyable<iter_value_t<In>> &&
+                                        constructible_from<iter_value_t<In>, iter_reference_t<In>> &&
+                                        assignable_from<iter_value_t<In>&, iter_reference_t<In>>,
+                                    ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename In, typename Out>
+NANO_CONCEPT indirectly_copyable_storable =
+    decltype(detail::indirectly_copyable_storable_concept::test<In, Out>(0))::value;
+
+NANO_END_NAMESPACE
+
+#                endif
+
+// nanorange/detail/iterator/iter_swap.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                ifndef NANORANGE_DETAIL_ITERATOR_ITER_SWAP_HPP_INCLUDED
+#                    define NANORANGE_DETAIL_ITERATOR_ITER_SWAP_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+namespace iter_swap_
+{
+
+// ADL "poison pill"
+template <typename I1, typename I2>
+void iter_swap(I1, I2) = delete;
+
+// FIXME MSVC: add a second (redundant) poison pill
+template <typename I>
+void iter_swap(I, I) = delete;
+
+struct fn
+{
+  private:
+    template <typename X, typename Y>
+    static constexpr iter_value_t<::std::remove_reference_t<X>>
+    iter_exchange_move(X&& x,
+                       Y&& y) noexcept(noexcept(iter_value_t<::std::remove_reference_t<X>>(ranges::iter_move(x))) &&
+                                       noexcept(*x = ranges::iter_move(y)))
+    {
+        iter_value_t<::std::remove_reference_t<X>> old_value(ranges::iter_move(x));
+        *x = ranges::iter_move(y);
+        return old_value;
+    }
+
+    template <typename T, typename U>
+    static constexpr auto
+    impl(T&& t, U&& u,
+         priority_tag<2>) noexcept(noexcept((void)(iter_swap(::std::forward<T>(t), ::std::forward<U>(u)))))
+        -> decltype((void)(iter_swap(::std::forward<T>(t), ::std::forward<U>(u))))
+    {
+        (void)iter_swap(::std::forward<T>(t), ::std::forward<U>(u));
+    }
+
+    template <typename T, typename U>
+    static constexpr auto
+    impl(T&& t, U&& u, priority_tag<1>) noexcept(noexcept(ranges::swap(*::std::forward<T>(t), *::std::forward<U>(u))))
+        -> ::std::enable_if_t<readable<::std::remove_reference_t<T>> && readable<::std::remove_reference_t<U>> &&
+                              swappable_with<iter_reference_t<T>, iter_reference_t<U>>>
+    {
+        ranges::swap(*::std::forward<T>(t), *::std::forward<U>(u));
+    }
+
+    template <typename T, typename U>
+    static constexpr auto
+    impl(T&& t, U&& u,
+         priority_tag<0>) noexcept(noexcept(*t = fn::iter_exchange_move(::std::forward<U>(u), ::std::forward<T>(t))))
+        -> ::std::enable_if_t<indirectly_movable_storable<T, U> && indirectly_movable_storable<U, T>>
+    {
+        return *t = fn::iter_exchange_move(::std::forward<U>(u), ::std::forward<T>(t));
+    }
+
+  public:
+    template <typename T, typename U>
+    constexpr auto
+    operator()(T&& t, U&& u) const
+        noexcept(noexcept(fn::impl(::std::forward<T>(t), ::std::forward<U>(u), priority_tag<2>{})))
+            -> decltype(fn::impl(::std::forward<T>(t), ::std::forward<U>(u), priority_tag<2>{}))
+    {
+        return fn::impl(::std::forward<T>(t), ::std::forward<U>(u), priority_tag<2>{});
+    }
+};
+} // namespace iter_swap_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::iter_swap_::fn, iter_swap)
+
+NANO_END_NAMESPACE
+
+#                endif
+
+// nanorange/detail/iterator/projected.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                ifndef NANORANGE_DETAIL_ITERATOR_PROJECTED_HPP_INCLUDED
+#                    define NANORANGE_DETAIL_ITERATOR_PROJECTED_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+// [range.projected]
+
+//template <typename I, typename Proj>
+//struct projected;
+
+namespace detail
+{
+
+template <typename, typename, typename = void>
+struct projected_helper
+{
+};
+
+template <typename I, typename Proj>
+struct projected_helper<I, Proj, ::std::enable_if_t<readable<I> && indirect_regular_unary_invocable<Proj, I>>>
+{
+    using value_type = remove_cvref_t<indirect_result_t<Proj&, I>>;
+
+    indirect_result_t<Proj&, I> operator*() const;
+};
+
+template <typename, typename, typename = void>
+struct projected_difference_t_helper
+{
+};
+
+template <typename I, typename Proj>
+struct projected_difference_t_helper<I, Proj, ::std::enable_if_t<weakly_incrementable<I>>>
+{
+    using difference_type = iter_difference_t<I>;
+};
+
+} // namespace detail
+
+template <typename I, typename Proj>
+using projected = detail::conditional_t<same_as<Proj, identity>, I, detail::projected_helper<I, Proj>>;
+
+template <typename I, typename Proj>
+struct incrementable_traits<detail::projected_helper<I, Proj>> : detail::projected_difference_t_helper<I, Proj>
+{
+};
+
+NANO_END_NAMESPACE
+
+#                endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct indirectly_swappable_concept
+{
+    template <typename I1, typename I2>
+    auto
+    requires_(I1& i1, I2& i2) -> decltype(ranges::iter_swap(i1, i1), ranges::iter_swap(i2, i2),
+                                          ranges::iter_swap(i1, i2), ranges::iter_swap(i2, i1));
+};
+
+} // namespace detail
+
+template <typename I1, typename I2 = I1>
+NANO_CONCEPT indirectly_swappable =
+    readable<I1>&& readable<I2>&& detail::requires_<detail::indirectly_swappable_concept, I1, I2>;
+
+// [alg.req.ind.cmp]
+
+template <typename I1, typename I2, typename R, typename P1 = identity, typename P2 = identity>
+NANO_CONCEPT indirectly_comparable = indirect_relation<R, projected<I1, P1>, projected<I2, P2>>;
+
+// [alg.req.permutable]
+
+template <typename I>
+NANO_CONCEPT permutable = forward_iterator<I>&& indirectly_movable_storable<I, I>&& indirectly_swappable<I, I>;
+
+// [alg.req.mergeable]
+
+template <typename I1, typename I2, typename Out, typename R = ranges::less, typename P1 = identity,
+          typename P2 = identity>
+NANO_CONCEPT mergeable =
+    input_iterator<I1>&& input_iterator<I2>&& weakly_incrementable<Out>&& indirectly_copyable<I1, Out>&&
+        indirectly_copyable<I2, Out>&& indirect_strict_weak_order<R, projected<I1, P1>, projected<I2, P2>>;
+
+// [alg.req.sortable]
+
+template <typename I, typename R = ranges::less, typename P = identity>
+NANO_CONCEPT sortable = permutable<I>&& indirect_strict_weak_order<R, projected<I, P>>;
+
+NANO_END_NAMESPACE
+
+#            endif
+
+// nanorange/detail/ranges/access.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#            ifndef NANORANGE_DETAIL_RANGES_ACCESS_HPP_INCLUDED
+#                define NANORANGE_DETAIL_RANGES_ACCESS_HPP_INCLUDED
+
+// nanorange/detail/ranges/begin_end.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                ifndef NANORANGE_DETAIL_RANGES_BEGIN_END_HPP_INCLUDED
+#                    define NANORANGE_DETAIL_RANGES_BEGIN_END_HPP_INCLUDED
+
+// nanorange/detail/functional/decay_copy.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                    ifndef NANORANGE_DETAIL_FUNCTIONAL_DECAY_COPY_HPP_INCLUDED
+#                        define NANORANGE_DETAIL_FUNCTIONAL_DECAY_COPY_HPP_INCLUDED
+
+#                        include <type_traits>
+#                        include <utility>
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+template <typename T>
+constexpr ::std::decay_t<T>
+decay_copy(T&& t) noexcept(noexcept(static_cast<::std::decay_t<T>>(::std::forward<T>(t))))
+{
+    return ::std::forward<T>(t);
+}
+
+} // namespace detail
+
+NANO_END_NAMESPACE
+
+#                    endif
+
+// nanorange/detail/ranges/borrowed_range.hpp
+//
+// Copyright (c) 2020 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                    ifndef NANORANGE_DETAIL_RANGES_BORROWED_RANGE_HPP_INCLUDED
+#                        define NANORANGE_DETAIL_RANGES_BORROWED_RANGE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename>
+inline constexpr bool enable_borrowed_range = false;
+
+NANO_END_NAMESPACE
+
+#                    endif
+
+NANO_BEGIN_NAMESPACE
+
+// [range.access.begin]
+
+namespace detail
+{
+namespace begin_
+{
+
+template <typename T>
+void
+begin(T&) = delete;
+
+template <typename T>
+void
+begin(const T&) = delete;
+
+struct fn
+{
+  private:
+    template <
+        typename T,
+        ::std::enable_if_t<!::std::is_lvalue_reference_v<T> && !enable_borrowed_range<::std::remove_cv_t<T>>, int> = 0>
+    static constexpr void
+    impl(T&&, priority_tag<3>) = delete;
+
+    template <typename T, ::std::enable_if_t<::std::is_array_v<remove_cvref_t<T>>, int> = 0>
+    static constexpr auto
+    impl(T&& t, priority_tag<2>) noexcept -> decltype(t + 0)
+    {
+        return t + 0;
+    }
+
+    template <typename T>
+    static constexpr auto
+    impl(T&& t, priority_tag<1>) noexcept(noexcept(decay_copy(::std::forward<T>(t).begin())))
+        -> ::std::enable_if_t<input_or_output_iterator<decltype(decay_copy(::std::forward<T>(t).begin()))>,
+                              decltype(decay_copy(::std::forward<T>(t).begin()))>
+    {
+        return decay_copy(t.begin());
+    }
+
+    template <typename T>
+    static constexpr auto
+    impl(T&& t, priority_tag<0>) noexcept(noexcept(decay_copy(begin(::std::forward<T>(t)))))
+        -> ::std::enable_if_t<input_or_output_iterator<decltype(decay_copy(begin(::std::forward<T>(t))))>,
+                              decltype(decay_copy(begin(::std::forward<T>(t))))>
+    {
+        return decay_copy(begin(::std::forward<T>(t)));
+    }
+
+  public:
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const noexcept(noexcept(fn::impl(::std::forward<T>(t), priority_tag<3>{})))
+        -> decltype(fn::impl(::std::forward<T>(t), priority_tag<3>{}))
+    {
+        return fn::impl(::std::forward<T>(t), priority_tag<3>{});
+    }
+};
+
+} // namespace begin_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::begin_::fn, begin)
+
+namespace detail
+{
+namespace end_
+{
+
+template <typename T>
+void
+end(T&) = delete;
+
+template <typename T>
+void
+end(const T&) = delete;
+
+struct fn
+{
+  private:
+    template <
+        typename T,
+        ::std::enable_if_t<!::std::is_lvalue_reference_v<T> && !enable_borrowed_range<::std::remove_cv_t<T>>, int> = 0>
+    static constexpr void
+    impl(T&&, priority_tag<3>) = delete;
+
+    template <typename T, ::std::enable_if_t<::std::is_array_v<remove_cvref_t<T>>, int> = 0>
+    static constexpr auto
+    impl(T&& t, priority_tag<2>) noexcept -> decltype(t + ::std::extent_v<remove_cvref_t<T>>)
+    {
+        return t + ::std::extent_v<remove_cvref_t<T>>;
+    }
+
+    template <typename T, typename S = decltype(decay_copy(::std::declval<T>().end())),
+              typename I = decltype(ranges::begin(::std::declval<T>()))>
+    static constexpr auto
+    impl(T&& t, priority_tag<1>) noexcept(noexcept(decay_copy(::std::forward<T>(t).end())))
+        -> ::std::enable_if_t<sentinel_for<S, I>, decltype(decay_copy(::std::forward<T>(t).end()))>
+    {
+        return decay_copy(::std::forward<T>(t).end());
+    }
+
+    template <typename T, typename S = decltype(decay_copy(end(::std::declval<T>()))),
+              typename I = decltype(ranges::begin(::std::declval<T>()))>
+    static constexpr auto
+    impl(T&& t, priority_tag<0>) noexcept(noexcept(decay_copy(end(::std::forward<T>(t)))))
+        -> ::std::enable_if_t<sentinel_for<S, I>, S>
+    {
+        return decay_copy(end(::std::forward<T>(t)));
+    }
+
+  public:
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const noexcept(noexcept(fn::impl(::std::forward<T>(t), priority_tag<3>{})))
+        -> decltype(fn::impl(::std::forward<T>(t), priority_tag<3>{}))
+    {
+        return fn::impl(::std::forward<T>(t), priority_tag<3>{});
+    }
+};
+
+} // namespace end_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::end_::fn, end)
+
+// [range.access.cbegin]
+
+namespace detail
+{
+namespace cbegin_
+{
+
+struct fn
+{
+  private:
+    template <typename T, typename U = ::std::remove_reference_t<T>,
+              ::std::enable_if_t<::std::is_lvalue_reference_v<T>, int> = 0>
+    static constexpr auto
+    impl(T&& t) noexcept(noexcept(ranges::begin(static_cast<const U&>(t))))
+        -> decltype(ranges::begin(static_cast<const U&>(t)))
+    {
+        return ranges::begin(static_cast<const U&>(t));
+    }
+
+    template <typename T, ::std::enable_if_t<!::std::is_lvalue_reference_v<T>, int> = 0>
+    static constexpr auto
+    impl(T&& t) noexcept(noexcept(ranges::begin(static_cast<const T&&>(::std::forward<T>(t)))))
+        -> decltype(ranges::begin(static_cast<const T&&>(::std::forward<T>(t))))
+    {
+        return ranges::begin(static_cast<const T&&>(::std::forward<T>(t)));
+    }
+
+  public:
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const noexcept(noexcept(fn::impl(::std::forward<T>(t))))
+        -> decltype(fn::impl(::std::forward<T>(t)))
+    {
+        return fn::impl(::std::forward<T>(t));
+    }
+};
+
+} // namespace cbegin_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::cbegin_::fn, cbegin)
+
+// [ranges.access.cend]
+
+namespace detail
+{
+namespace cend_
+{
+
+struct fn
+{
+  private:
+    template <typename T, typename U = ::std::remove_reference_t<T>,
+              ::std::enable_if_t<::std::is_lvalue_reference_v<T>, int> = 0>
+    static constexpr auto
+    impl(T&& t) noexcept(noexcept(ranges::end(static_cast<const U&>(t))))
+        -> decltype(ranges::end(static_cast<const U&>(t)))
+    {
+        return ranges::end(static_cast<const U&>(t));
+    }
+
+    template <typename T, ::std::enable_if_t<!::std::is_lvalue_reference_v<T>, int> = 0>
+    static constexpr auto
+    impl(T&& t) noexcept(noexcept(ranges::end(static_cast<const T&&>(::std::forward<T>(t)))))
+        -> decltype(ranges::end(static_cast<const T&&>(::std::forward<T>(t))))
+    {
+        return ranges::end(static_cast<const T&&>(::std::forward<T>(t)));
+    }
+
+  public:
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const noexcept(noexcept(fn::impl(::std::forward<T>(t))))
+        -> decltype(fn::impl(::std::forward<T>(t)))
+    {
+        return fn::impl(::std::forward<T>(t));
+    }
+};
+
+} // namespace cend_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::cend_::fn, cend)
+
+NANO_END_NAMESPACE
+
+#                endif
+
+// nanorange/iterator/reverse_iterator.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                ifndef NANORANGE_ITERATOR_REVERSE_ITERATOR_HPP_INCLUDED
+#                    define NANORANGE_ITERATOR_REVERSE_ITERATOR_HPP_INCLUDED
+
+// nanorange/iterator/operations.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                    ifndef NANORANGE_ITERATOR_OPERATIONS_HPP_INCLUDED
+#                        define NANORANGE_ITERATOR_OPERATIONS_HPP_INCLUDED
+
+// nanorange/detail/ranges/concepts.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                        ifndef NANORANGE_DETAIL_RANGES_CONCEPTS_HPP_INCLUDED
+#                            define NANORANGE_DETAIL_RANGES_CONCEPTS_HPP_INCLUDED
+
+// nanorange/detail/ranges/basic_range_types.hpp
+//
+// Copyright (c) 2020 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                            ifndef NANORANGE_DETAIL_RANGES_BASIC_RANGE_TYPES_HPP_INCLUDED
+#                                define NANORANGE_DETAIL_RANGES_BASIC_RANGE_TYPES_HPP_INCLUDED
+
+// nanorange/detail/ranges/range_concept.hpp
+//
+// Copyright (c) 2020 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                                ifndef NANORANGE_DETAIL_RANGES_RANGE_CONCEPT_HPP_INCLUDED
+#                                    define NANORANGE_DETAIL_RANGES_RANGE_CONCEPT_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct range_concept
+{
+    template <typename T>
+    auto
+    requires_(T& t) -> decltype(ranges::begin(t), ranges::end(t));
+};
+
+} // namespace detail
+
+template <typename T>
+NANO_CONCEPT range = detail::requires_<detail::range_concept, T>;
+
+NANO_END_NAMESPACE
+
+#                                endif
+
+NANO_BEGIN_NAMESPACE
+
+template <typename T>
+using iterator_t = decltype(ranges::begin(::std::declval<T&>()));
+
+template <typename R>
+using sentinel_t = ::std::enable_if_t<range<R>, decltype(ranges::end(::std::declval<R&>()))>;
+
+template <typename R>
+using range_difference_t = ::std::enable_if_t<range<R>, iter_difference_t<iterator_t<R>>>;
+
+template <typename R>
+using range_value_t = ::std::enable_if_t<range<R>, iter_value_t<iterator_t<R>>>;
+
+template <typename R>
+using range_reference_t = ::std::enable_if_t<range<R>, iter_reference_t<iterator_t<R>>>;
+
+template <typename R>
+using range_rvalue_reference_t = ::std::enable_if_t<range<R>, iter_rvalue_reference_t<iterator_t<R>>>;
+
+NANO_END_NAMESPACE
+
+#                            endif
+
+// nanorange/detail/ranges/primitives.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                            ifndef NANORANGE_DETAIL_RANGES_PRIMITIVES_HPP_INCLUDED
+#                                define NANORANGE_DETAIL_RANGES_PRIMITIVES_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+// [range.prim.size]
+
+template <typename>
+inline constexpr bool disable_sized_range = false;
+
+namespace detail
+{
+namespace size_
+{
+
+template <typename T>
+void
+size(T&&) = delete;
+
+// For some reason MSVC doesn't mind poison pills,
+// as long as there are two
+template <typename T>
+void
+size(T&) = delete;
+
+struct fn
+{
+  private:
+    template <typename T, ::std::size_t N>
+    static constexpr ::std::size_t
+    impl(const T(&&)[N], priority_tag<3>) noexcept
+    {
+        return N;
+    }
+
+    template <typename T, ::std::size_t N>
+    static constexpr ::std::size_t
+    impl(const T (&)[N], priority_tag<3>) noexcept
+    {
+        return N;
+    }
+
+    template <typename T, typename I = decltype(decay_copy(::std::declval<T>().size()))>
+    static constexpr auto
+    impl(T&& t, priority_tag<2>) noexcept(noexcept(decay_copy(::std::forward<T>(t).size())))
+        -> ::std::enable_if_t<integral<I> && !disable_sized_range<remove_cvref_t<T>>, I>
+    {
+        return decay_copy(::std::forward<T>(t).size());
+    }
+
+    template <typename T, typename I = decltype(decay_copy(size(::std::declval<T>())))>
+    static constexpr auto
+    impl(T&& t, priority_tag<1>) noexcept(noexcept(decay_copy(size(::std::forward<T>(t)))))
+        -> ::std::enable_if_t<integral<I> && !disable_sized_range<remove_cvref_t<T>>, I>
+    {
+        return decay_copy(size(::std::forward<T>(t)));
+    }
+
+    template <typename T, typename I = decltype(ranges::begin(::std::declval<T>())),
+              typename S = decltype(ranges::end(::std::declval<T>())),
+              typename D = decltype(decay_copy(::std::declval<S>() - ::std::declval<I>()))>
+    static constexpr auto
+    impl(T&& t, priority_tag<0>) noexcept(noexcept(decay_copy(ranges::end(t) - ranges::begin(t))))
+        -> ::std::enable_if_t<!::std::is_array<remove_cvref_t<T>>::value && // MSVC sillyness?
+                                  sized_sentinel_for<S, I> && forward_iterator<I>,
+                              D>
+    {
+        return decay_copy(ranges::end(t) - ranges::begin(t));
+    }
+
+  public:
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const noexcept(noexcept(fn::impl(::std::forward<T>(t), priority_tag<3>{})))
+        -> decltype(fn::impl(::std::forward<T>(t), priority_tag<3>{}))
+    {
+        return fn::impl(::std::forward<T>(t), priority_tag<3>{});
+    }
+};
+
+} // namespace size_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::size_::fn, size)
+
+// [range.prim.ssize]
+
+namespace detail
+{
+namespace ssize_
+{
+
+struct fn
+{
+  private:
+    template <typename T>
+    using ssize_return_t = ::std::conditional_t<sizeof(range_difference_t<T>) < sizeof(::std::ptrdiff_t),
+                                                ::std::ptrdiff_t, range_difference_t<T>>;
+
+    template <typename T>
+    static constexpr auto
+    impl(T&& t) noexcept(noexcept(ranges::size(::std::forward<T>(t))))
+        -> decltype(ranges::size(::std::forward<T>(t)), ssize_return_t<T>())
+    {
+        return static_cast<ssize_return_t<T>>(ranges::size(::std::forward<T>(t)));
+    }
+
+  public:
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const noexcept(noexcept(fn::impl(::std::forward<T>(t))))
+        -> decltype(fn::impl(::std::forward<T>(t)))
+    {
+        return fn::impl(::std::forward<T>(t));
+    }
+};
+
+} // namespace ssize_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::ssize_::fn, ssize)
+
+// [range.prim.empty]
+
+namespace detail
+{
+namespace empty_
+{
+
+struct fn
+{
+  private:
+    template <typename T>
+    static constexpr auto
+    impl(T&& t, priority_tag<2>) noexcept(noexcept((bool(::std::forward<T>(t).empty()))))
+        -> decltype((bool(::std::forward<T>(t).empty())))
+    {
+        return bool((::std::forward<T>(t).empty()));
+    }
+
+    template <typename T>
+    static constexpr auto
+    impl(T&& t, priority_tag<1>) noexcept(noexcept(ranges::size(::std::forward<T>(t)) == 0))
+        -> decltype(ranges::size(::std::forward<T>(t)) == 0)
+    {
+        return ranges::size(::std::forward<T>(t)) == 0;
+    }
+
+    template <typename T, typename I = decltype(ranges::begin(::std::declval<T>()))>
+    static constexpr auto
+    impl(T&& t, priority_tag<0>) noexcept(noexcept(ranges::begin(t) == ranges::end(t)))
+        -> ::std::enable_if_t<forward_iterator<I>, decltype(ranges::begin(t) == ranges::end(t))>
+    {
+        return ranges::begin(t) == ranges::end(t);
+    }
+
+  public:
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const noexcept(noexcept(fn::impl(::std::forward<T>(t), priority_tag<2>{})))
+        -> decltype(fn::impl(::std::forward<T>(t), priority_tag<2>{}))
+    {
+        return fn::impl(::std::forward<T>(t), priority_tag<2>{});
+    }
+};
+
+} // namespace empty_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::empty_::fn, empty)
+
+namespace detail
+{
+
+template <typename, typename = void>
+inline constexpr bool is_object_pointer_v = false;
+
+template <typename P>
+inline constexpr bool
+    is_object_pointer_v<P, ::std::enable_if_t<::std::is_pointer_v<P>&& ::std::is_object_v<iter_value_t<P>>>> = true;
+
+namespace data_
+{
+
+struct fn
+{
+  private:
+    template <typename T, typename D = decltype(decay_copy(::std::declval<T&>().data()))>
+    static constexpr auto
+    impl(T& t, priority_tag<1>) noexcept(noexcept(decay_copy(t.data())))
+        -> ::std::enable_if_t<is_object_pointer_v<D>, D>
+    {
+        return t.data();
+    }
+
+    template <typename T>
+    static constexpr auto
+    impl(T&& t, priority_tag<0>) noexcept(noexcept(ranges::begin(::std::forward<T>(t))))
+        -> ::std::enable_if_t<is_object_pointer_v<decltype(ranges::begin(::std::forward<T>(t)))>,
+                              decltype(ranges::begin(::std::forward<T>(t)))>
+    {
+        return ranges::begin(::std::forward<T>(t));
+    }
+
+  public:
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const noexcept(noexcept(fn::impl(::std::forward<T>(t), priority_tag<1>{})))
+        -> decltype(fn::impl(::std::forward<T>(t), priority_tag<1>{}))
+    {
+        return fn::impl(::std::forward<T>(t), priority_tag<1>{});
+    }
+};
+
+} // namespace data_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::data_::fn, data)
+
+namespace detail
+{
+namespace cdata_
+{
+
+struct fn
+{
+  private:
+    template <typename T, typename U = ::std::remove_reference_t<T>,
+              ::std::enable_if_t<::std::is_lvalue_reference_v<T>, int> = 0>
+    static constexpr auto
+    impl(T&& t) noexcept(noexcept(ranges::data(static_cast<const U&>(t))))
+        -> decltype(ranges::data(static_cast<const U&>(t)))
+    {
+        return ranges::data(static_cast<const U&>(t));
+    }
+
+    template <typename T, ::std::enable_if_t<!::std::is_lvalue_reference_v<T>, int> = 0>
+    static constexpr auto
+    impl(T&& t) noexcept(noexcept(ranges::data(static_cast<const T&&>(t))))
+        -> decltype(ranges::data(static_cast<const T&&>(t)))
+    {
+        return ranges::data(static_cast<const T&&>(t));
+    }
+
+  public:
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const noexcept(noexcept(fn::impl(::std::forward<T>(t))))
+        -> decltype(fn::impl(::std::forward<T>(t)))
+    {
+        return fn::impl(::std::forward<T>(t));
+    }
+};
+
+} // namespace cdata_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::cdata_::fn, cdata)
+
+NANO_END_NAMESPACE
+
+#                            endif
+
+#                            include <initializer_list>
+
+// Avoid dragging in the large <set> and <unordered_set> headers
+// This is technically undefined behaviour: define the symbol
+// NANORANGE_NO_STD_FORWARD_DECLARATIONS
+// to enforce standard-compliant mode
+#                            ifndef NANORANGE_NO_STD_FORWARD_DECLARATIONS
+NANO_BEGIN_NAMESPACE_STD
+template <typename, typename>
+class basic_string_view;
+template <typename, typename, typename>
+class set;
+template <typename, typename, typename>
+class multiset;
+template <typename, typename, typename, typename>
+class unordered_set;
+template <typename, typename, typename, typename>
+class unordered_multiset;
+template <typename, typename>
+class match_results;
+NANO_END_NAMESPACE_STD
+#                            else
+#                                include <string_view>
+#                                include <regex>
+#                                include <set>
+#                                include <unordered_set>
+#                            endif
+
+NANO_BEGIN_NAMESPACE
+
+template <typename T>
+NANO_CONCEPT borrowed_range = range<T> && (::std::is_lvalue_reference_v<T> || enable_borrowed_range<remove_cvref_t<T>>);
+
+// Special-case ::std::string_view
+template <typename CharT, typename Traits>
+inline constexpr bool enable_borrowed_range<::std::basic_string_view<CharT, Traits>> = true;
+
+// [range.sized]
+namespace detail
+{
+
+struct sized_range_concept
+{
+    template <typename T>
+    auto
+    requires_(T& t) -> decltype(ranges::size(t));
+};
+
+} // namespace detail
+
+template <typename T>
+NANO_CONCEPT sized_range =
+    range<T> && !disable_sized_range<remove_cvref_t<T>> && detail::requires_<detail::sized_range_concept, T>;
+
+// [range.views]
+struct view_base
+{
+};
+
+namespace detail
+{
+
+template <typename>
+inline constexpr bool is_std_non_view = false;
+
+template <typename T>
+inline constexpr bool is_std_non_view<::std::initializer_list<T>> = true;
+
+template <typename K, typename C, typename A>
+inline constexpr bool is_std_non_view<::std::set<K, C, A>> = true;
+
+template <typename K, typename C, typename A>
+inline constexpr bool is_std_non_view<::std::multiset<K, C, A>> = true;
+
+template <typename K, typename H, typename E, typename A>
+inline constexpr bool is_std_non_view<::std::unordered_set<K, H, E, A>> = true;
+
+template <typename K, typename H, typename E, typename A>
+inline constexpr bool is_std_non_view<::std::unordered_multiset<K, H, E, A>> = true;
+
+template <typename B, typename A>
+inline constexpr bool is_std_non_view<::std::match_results<B, A>> = true;
+
+template <typename T>
+constexpr bool
+enable_view_helper()
+{
+    if constexpr (derived_from<T, view_base>)
+    {
+        return true;
+    }
+    else if constexpr (is_std_non_view<T>)
+    {
+        return false;
+    }
+    else if constexpr (range<T> && range<const T>)
+    {
+        return same_as<range_reference_t<T>, range_reference_t<const T>>;
+    }
+    else
+    {
+        return true;
+    }
+}
+
+} // namespace detail
+
+template <typename T>
+inline constexpr bool enable_view = detail::enable_view_helper<T>();
+
+template <typename T>
+NANO_CONCEPT view = range<T>&& semiregular<T>&& enable_view<T>;
+
+// [range.refinements]
+namespace detail
+{
+
+struct output_range_concept
+{
+    template <typename, typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename R, typename T>
+    static auto
+    test(int) -> ::std::enable_if_t<range<R> && output_iterator<iterator_t<R>, T>, ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename R, typename T>
+NANO_CONCEPT output_range = decltype(detail::output_range_concept::test<R, T>(0))::value;
+
+namespace detail
+{
+
+struct input_range_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T>
+    static auto
+    test(int) -> ::std::enable_if_t<range<T> && input_iterator<iterator_t<T>>, ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename T>
+NANO_CONCEPT input_range = decltype(detail::input_range_concept::test<T>(0))::value;
+
+namespace detail
+{
+
+struct forward_range_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T>
+    static auto
+    test(int) -> ::std::enable_if_t<input_range<T> && forward_iterator<iterator_t<T>>, ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename T>
+NANO_CONCEPT forward_range = decltype(detail::forward_range_concept::test<T>(0))::value;
+
+namespace detail
+{
+
+struct bidirectional_range_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T>
+    static auto
+    test(int) -> ::std::enable_if_t<forward_range<T> && bidirectional_iterator<iterator_t<T>>, ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename T>
+NANO_CONCEPT bidirectional_range = decltype(detail::bidirectional_range_concept::test<T>(0))::value;
+
+namespace detail
+{
+
+struct random_access_range_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T>
+    static auto
+    test(int) -> ::std::enable_if_t<bidirectional_range<T> && random_access_iterator<iterator_t<T>>, ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename T>
+NANO_CONCEPT random_access_range = decltype(detail::random_access_range_concept::test<T>(0))::value;
+
+namespace detail
+{
+
+// FIXME: Not to spec
+// We only require random_access_iterator, not contiguous_iterator
+// This is so that vector::iterator, string::iterator etc can model
+// contiguous_range.
+// If we do range-v3-style deep integration with iterator_traits then
+// this could be fixed
+struct contiguous_range_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T>
+    static auto
+    test(int) -> ::std::enable_if_t<random_access_range<T> && /* contiguous_iterator<iterator_t<T>> && */
+                                        detail::requires_<contiguous_range_concept, T>,
+                                    ::std::true_type>;
+
+    template <typename T>
+    auto
+    requires_(T& t)
+        -> decltype(requires_expr<same_as<decltype(ranges::data(t)), ::std::add_pointer_t<range_reference_t<T>>>>{});
+};
+
+} // namespace detail
+
+template <typename R>
+NANO_CONCEPT contiguous_range = decltype(detail::contiguous_range_concept::test<R>(0))::value;
+
+namespace detail
+{
+
+struct common_range_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T>
+    static auto
+    test(int) -> ::std::enable_if_t<range<T> && same_as<iterator_t<T>, sentinel_t<T>>, ::std::true_type>;
+};
+
+} // namespace detail
+
+template <typename T>
+NANO_CONCEPT common_range = decltype(detail::common_range_concept::test<T>(0))::value;
+
+template <typename T>
+NANO_CONCEPT viewable_range = range<T> && (borrowed_range<T> || view<remove_cvref_t<T>>);
+
+// [range.dangling]
+
+struct dangling
+{
+    constexpr dangling() noexcept = default;
+
+    template <typename... Args>
+    constexpr dangling(Args&&...) noexcept
+    {
+    }
+};
+
+template <typename R>
+using borrowed_iterator_t = detail::conditional_t<borrowed_range<R>, iterator_t<R>, dangling>;
+
+// Helper concepts
+
+namespace detail
+{
+
+struct simple_view_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename R>
+    static auto
+    test(int) -> ::std::enable_if_t<view<R> && range<const R> && same_as<iterator_t<R>, iterator_t<const R>> &&
+                                        same_as<sentinel_t<R>, sentinel_t<const R>>,
+                                    ::std::true_type>;
+};
+
+template <typename R>
+NANO_CONCEPT simple_view = decltype(simple_view_concept::test<R>(0))::value;
+
+struct has_arrow_concept
+{
+    template <typename I>
+    auto
+    requires_(I i) -> decltype(i.operator->());
+};
+
+template <typename I>
+NANO_CONCEPT has_arrow = input_iterator<I> && (::std::is_pointer_v<I> || detail::requires_<has_arrow_concept, I>);
+
+template <typename T, typename U>
+NANO_CONCEPT not_same_as = !same_as<remove_cvref_t<T>, remove_cvref_t<U>>;
+
+} // namespace detail
+
+NANO_END_NAMESPACE
+
+#                        endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+namespace advance_
+{
+
+struct fn
+{
+  private:
+    template <typename T>
+    static constexpr T
+    abs(T t)
+    {
+        if (t < T{0})
+        {
+            return -t;
+        }
+        return t;
+    }
+
+    template <typename R>
+    static constexpr auto
+    impl(R& r, iter_difference_t<R> n) -> ::std::enable_if_t<random_access_iterator<R>>
+    {
+        r += n;
+    }
+
+    template <typename I>
+    static constexpr auto
+    impl(I& i, iter_difference_t<I> n) -> ::std::enable_if_t<bidirectional_iterator<I> && !random_access_iterator<I>>
+    {
+        constexpr auto zero = iter_difference_t<I>{0};
+
+        if (n > zero)
+        {
+            while (n-- > zero)
+            {
+                ++i;
+            }
+        }
+        else
+        {
+            while (n++ < zero)
+            {
+                --i;
+            }
+        }
+    }
+
+    template <typename I>
+    static constexpr auto
+    impl(I& i, iter_difference_t<I> n) -> ::std::enable_if_t<!bidirectional_iterator<I>>
+    {
+        while (n-- > iter_difference_t<I>{0})
+        {
+            ++i;
+        }
+    }
+
+    template <typename I, typename S>
+    static constexpr auto
+    impl(I& i, S bound, priority_tag<2>) -> ::std::enable_if_t<assignable_from<I&, S>>
+    {
+        i = ::std::move(bound);
+    }
+
+    template <typename I, typename S>
+    static constexpr auto
+    impl(I& i, S bound, priority_tag<1>) -> ::std::enable_if_t<sized_sentinel_for<S, I>>
+    {
+        fn::impl(i, bound - i);
+    }
+
+    template <typename I, typename S>
+    static constexpr void
+    impl(I& i, S bound, priority_tag<0>)
+    {
+        while (i != bound)
+        {
+            ++i;
+        }
+    }
+
+    template <typename I, typename S>
+    static constexpr auto
+    impl(I& i, iter_difference_t<I> n, S bound) -> ::std::enable_if_t<sized_sentinel_for<S, I>, iter_difference_t<I>>
+    {
+        if (fn::abs(n) >= fn::abs(bound - i))
+        {
+            auto dist = bound - i;
+            fn::impl(i, bound, priority_tag<2>{});
+            return dist;
+        }
+        else
+        {
+            fn::impl(i, n);
+            return n;
+        }
+    }
+
+    template <typename I, typename S>
+    static constexpr auto
+    impl(I& i, iter_difference_t<I> n, S bound)
+        -> ::std::enable_if_t<bidirectional_iterator<I> && !sized_sentinel_for<S, I>, iter_difference_t<I>>
+    {
+        constexpr iter_difference_t<I> zero{0};
+        iter_difference_t<I> counter{0};
+
+        if (n < zero)
+        {
+            do
+            {
+                --i;
+                --counter; // Yes, really
+            } while (++n < zero && i != bound);
+        }
+        else
+        {
+            while (n-- > zero && i != bound)
+            {
+                ++i;
+                ++counter;
+            }
+        }
+
+        return counter;
+    }
+
+    template <typename I, typename S>
+    static constexpr auto
+    impl(I& i, iter_difference_t<I> n, S bound)
+        -> ::std::enable_if_t<!bidirectional_iterator<I> && !sized_sentinel_for<S, I>, iter_difference_t<I>>
+    {
+        constexpr iter_difference_t<I> zero{0};
+        iter_difference_t<I> counter{0};
+
+        while (n-- > zero && i != bound)
+        {
+            ++i;
+            ++counter;
+        }
+
+        return counter;
+    }
+
+  public:
+    template <typename I>
+    constexpr auto
+    operator()(I& i, iter_difference_t<I> n) const -> ::std::enable_if_t<input_or_output_iterator<I>>
+    {
+        fn::impl(i, n);
+    }
+
+    template <typename I, typename S>
+    constexpr auto
+    operator()(I& i, S bound) const -> ::std::enable_if_t<input_or_output_iterator<I> && sentinel_for<S, I>>
+    {
+        fn::impl(i, bound, priority_tag<2>{});
+    }
+
+    template <typename I, typename S>
+    constexpr auto
+    operator()(I& i, iter_difference_t<I> n, S bound) const
+        -> ::std::enable_if_t<input_or_output_iterator<I> && sentinel_for<S, I>, iter_difference_t<I>>
+    {
+        return n - fn::impl(i, n, bound);
+    }
+};
+
+} // namespace advance_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::advance_::fn, advance)
+
+namespace detail
+{
+namespace distance_
+{
+
+struct fn
+{
+  private:
+    template <typename I, typename S>
+    static constexpr auto
+    impl(I i, S s) -> ::std::enable_if_t<sized_sentinel_for<S, I>, iter_difference_t<I>>
+    {
+        return s - i;
+    }
+
+    template <typename I, typename S>
+    static constexpr auto
+    impl(I i, S s) -> ::std::enable_if_t<!sized_sentinel_for<S, I>, iter_difference_t<I>>
+    {
+        iter_difference_t<I> counter{0};
+        while (i != s)
+        {
+            ++i;
+            ++counter;
+        }
+        return counter;
+    }
+
+    template <typename R>
+    static constexpr auto
+    impl(R&& r) -> ::std::enable_if_t<sized_range<R>, iter_difference_t<iterator_t<R>>>
+    {
+        return static_cast<iter_difference_t<iterator_t<R>>>(ranges::size(r));
+    }
+
+    template <typename R>
+    static constexpr auto
+    impl(R&& r) -> ::std::enable_if_t<!sized_range<R>, iter_difference_t<iterator_t<R>>>
+    {
+        return fn::impl(ranges::begin(r), ranges::end(r));
+    }
+
+  public:
+    template <typename I, typename S>
+    constexpr auto
+    operator()(I first, S last) const
+        -> ::std::enable_if_t<input_or_output_iterator<I> && sentinel_for<S, I>, iter_difference_t<I>>
+    {
+        return fn::impl(::std::move(first), ::std::move(last));
+    }
+
+    template <typename R>
+    constexpr auto
+    operator()(R&& r) const -> ::std::enable_if_t<range<R>, iter_difference_t<iterator_t<R>>>
+    {
+        return fn::impl(::std::forward<R>(r));
+    }
+};
+
+} // namespace distance_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::distance_::fn, distance)
+
+namespace detail
+{
+namespace next_
+{
+
+struct fn
+{
+    template <typename I>
+    constexpr auto
+    operator()(I x) const -> ::std::enable_if_t<input_or_output_iterator<I>, I>
+    {
+        ++x;
+        return x;
+    }
+
+    template <typename I>
+    constexpr auto
+    operator()(I x, iter_difference_t<I> n) const -> ::std::enable_if_t<input_or_output_iterator<I>, I>
+    {
+        ranges::advance(x, n);
+        return x;
+    }
+
+    template <typename I, typename S>
+    constexpr auto
+    operator()(I x, S bound) const -> ::std::enable_if_t<input_or_output_iterator<I> && sentinel_for<S, I>, I>
+    {
+        ranges::advance(x, bound);
+        return x;
+    }
+
+    template <typename I, typename S>
+    constexpr auto
+    operator()(I x, iter_difference_t<I> n, S bound) const
+        -> ::std::enable_if_t<input_or_output_iterator<I> && sentinel_for<S, I>, I>
+    {
+        ranges::advance(x, n, bound);
+        return x;
+    }
+};
+
+} // namespace next_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::next_::fn, next)
+
+namespace detail
+{
+namespace prev_
+{
+
+struct fn
+{
+    template <typename I>
+    constexpr auto
+    operator()(I x) const -> ::std::enable_if_t<bidirectional_iterator<I>, I>
+    {
+        --x;
+        return x;
+    }
+
+    template <typename I>
+    constexpr auto
+    operator()(I x, iter_difference_t<I> n) const -> ::std::enable_if_t<bidirectional_iterator<I>, I>
+    {
+        ranges::advance(x, -n);
+        return x;
+    }
+
+    template <typename I, typename S>
+    constexpr auto
+    operator()(I x, iter_difference_t<I> n, S bound) const
+        -> ::std::enable_if_t<bidirectional_iterator<I> && sentinel_for<S, I>, I>
+    {
+        ranges::advance(x, -n, bound);
+        return x;
+    }
+};
+
+} // namespace prev_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::prev_::fn, prev)
+
+NANO_END_NAMESPACE
+
+#                    endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace reverse_iterator_
+{
+
+template <typename I>
+class reverse_iterator
+{
+
+    static_assert(bidirectional_iterator<I>, "Template argument to reverse_iterator must model "
+                                             "BidirectionalIterator");
+
+  public:
+    using iterator_type = I;
+    using difference_type = iter_difference_t<I>;
+    using value_type = iter_value_t<I>;
+    using iterator_category = detail::legacy_iterator_category_t<I>;
+    using reference = iter_reference_t<I>;
+    using pointer = I;
+
+    constexpr reverse_iterator() = default;
+
+    explicit constexpr reverse_iterator(I x) : current_(::std::move(x)) {}
+
+    template <typename U, ::std::enable_if_t<convertible_to<U, I>, int> = 0>
+
+    constexpr reverse_iterator(const reverse_iterator<U>& i) : current_(i.base())
+    {
+    }
+
+    template <typename U, ::std::enable_if_t<convertible_to<U, I>, int> = 0>
+
+    constexpr reverse_iterator&
+    operator=(const reverse_iterator<U>& i)
+    {
+        current_ = i.base();
+        return *this;
+    }
+
+    constexpr I
+    base() const
+    {
+        return current_;
+    }
+
+    constexpr reference operator*() const { return *prev(current_); }
+
+    constexpr pointer operator->() const { return prev(current_); }
+
+    constexpr reverse_iterator&
+    operator++()
+    {
+        --current_;
+        return *this;
+    }
+
+    constexpr reverse_iterator
+    operator++(int)
+    {
+        reverse_iterator tmp = *this;
+        --current_;
+        return tmp;
+    }
+
+    constexpr reverse_iterator&
+    operator--()
+    {
+        ++current_;
+        return *this;
+    }
+
+    constexpr reverse_iterator
+    operator--(int)
+    {
+        reverse_iterator tmp = *this;
+        ++current_;
+        return tmp;
+    }
+
+    template <typename II = I>
+    constexpr ::std::enable_if_t<random_access_iterator<II>, reverse_iterator>
+    operator+(difference_type n) const
+    {
+        return reverse_iterator(current_ - n);
+    }
+
+    template <typename II = I>
+    constexpr ::std::enable_if_t<random_access_iterator<II>, reverse_iterator&>
+    operator+=(difference_type n)
+    {
+        current_ -= n;
+        return *this;
+    }
+
+    template <typename II = I>
+    constexpr ::std::enable_if_t<random_access_iterator<II>, reverse_iterator>
+    operator-(difference_type n) const
+    {
+        return reverse_iterator(current_ + n);
+    }
+
+    template <typename II = I>
+    constexpr ::std::enable_if_t<random_access_iterator<II>, reverse_iterator&>
+    operator-=(difference_type n)
+    {
+        current_ += n;
+        return *this;
+    }
+
+    template <typename II = I>
+    constexpr ::std::enable_if_t<random_access_iterator<II>, reference> operator[](difference_type n) const
+    {
+        return current_[-n - 1];
+    }
+
+    friend constexpr iter_rvalue_reference_t<I>
+    iter_move(const reverse_iterator& i) noexcept(noexcept(ranges::iter_move(::std::declval<I&>())) &&
+                                                  noexcept(--::std::declval<I&>()) &&
+                                                  ::std::is_nothrow_copy_constructible<I>::value)
+    {
+        return ranges::iter_move(prev(i.current_));
+    }
+
+    template <typename I2>
+    friend constexpr auto
+    iter_swap(const reverse_iterator& x, const reverse_iterator<I2>& y) noexcept(
+        noexcept(ranges::iter_swap(::std::declval<I>(), ::std::declval<I>())) && noexcept(--::std::declval<I&>()))
+        -> ::std::enable_if_t<indirectly_swappable<I2, I>>
+
+    {
+        ranges::iter_swap(prev(x.current_), prev(y.base()));
+    }
+
+  private:
+    I current_{};
+};
+
+template <typename I1, typename I2>
+constexpr ::std::enable_if_t<equality_comparable_with<I1, I2>, bool>
+operator==(const reverse_iterator<I1>& x, const reverse_iterator<I2>& y)
+{
+    return x.base() == y.base();
+}
+
+template <typename I1, typename I2>
+constexpr ::std::enable_if_t<equality_comparable_with<I1, I2>, bool>
+operator!=(const reverse_iterator<I1>& x, const reverse_iterator<I2>& y)
+{
+    return x.base() != y.base();
+}
+
+template <typename I1, typename I2>
+constexpr ::std::enable_if_t<totally_ordered_with<I1, I2>, bool>
+operator<(const reverse_iterator<I1>& x, const reverse_iterator<I2>& y)
+{
+    return x.base() > y.base();
+}
+
+template <typename I1, typename I2>
+constexpr ::std::enable_if_t<totally_ordered_with<I1, I2>, bool>
+operator>(const reverse_iterator<I1>& x, const reverse_iterator<I2>& y)
+{
+    return x.base() < y.base();
+}
+
+template <typename I1, typename I2>
+constexpr ::std::enable_if_t<totally_ordered_with<I1, I2>, bool>
+operator>=(const reverse_iterator<I1>& x, const reverse_iterator<I2>& y)
+{
+    return x.base() <= y.base();
+}
+
+template <typename I1, typename I2>
+constexpr ::std::enable_if_t<totally_ordered_with<I1, I2>, bool>
+operator<=(const reverse_iterator<I1>& x, const reverse_iterator<I2>& y)
+{
+    return x.base() >= y.base();
+}
+
+template <typename I1, typename I2>
+constexpr ::std::enable_if_t<sized_sentinel_for<I1, I2>, iter_difference_t<I2>>
+operator-(const reverse_iterator<I1>& x, const reverse_iterator<I2>& y)
+{
+    return y.base() - x.base();
+}
+
+template <typename I>
+constexpr ::std::enable_if_t<random_access_iterator<I>, reverse_iterator<I>>
+operator+(iter_difference_t<I> n, const reverse_iterator<I>& x)
+{
+    return reverse_iterator<I>(x.base() - n);
+}
+
+} // namespace reverse_iterator_
+
+using reverse_iterator_::reverse_iterator;
+
+template <typename I>
+constexpr ::std::enable_if_t<bidirectional_iterator<I>, reverse_iterator<I>>
+make_reverse_iterator(I i)
+{
+    return reverse_iterator<I>(::std::move(i));
+}
+
+NANO_END_NAMESPACE
+
+#                endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+namespace rbegin_
+{
+
+template <typename T>
+void
+rbegin(T&) = delete;
+
+template <typename T>
+void
+rbegin(const T&) = delete;
+
+struct fn
+{
+  private:
+    template <
+        typename T,
+        ::std::enable_if_t<!::std::is_lvalue_reference_v<T> && !enable_borrowed_range<::std::remove_cv_t<T>>, int> = 0>
+    static constexpr void
+    impl(T&&, priority_tag<3>) = delete;
+
+    template <typename T, typename I = decltype(decay_copy(::std::declval<T>().rbegin()))>
+    static constexpr auto
+    impl(T&& t, priority_tag<2>) noexcept(noexcept(decay_copy(::std::forward<T>(t).rbegin())))
+        -> ::std::enable_if_t<input_or_output_iterator<I>, I>
+    {
+        return ::std::forward<T>(t).rbegin();
+    }
+
+    template <typename T, typename I = decltype(decay_copy(rbegin(::std::declval<T>())))>
+    static constexpr auto
+    impl(T&& t, priority_tag<1>) noexcept(noexcept(decay_copy(rbegin(::std::forward<T>(t)))))
+        -> ::std::enable_if_t<input_or_output_iterator<I>, I>
+    {
+        return rbegin(::std::forward<T>(t));
+    }
+
+    template <typename T, typename I = decltype(ranges::begin(::std::declval<T>())),
+              typename S = decltype(ranges::end(::std::declval<T>()))>
+    static constexpr auto
+    impl(T&& t, priority_tag<0>) noexcept(noexcept(ranges::make_reverse_iterator(ranges::end(::std::forward<T>(t)))))
+        -> ::std::enable_if_t<same_as<I, S> && bidirectional_iterator<I>,
+                              decltype(ranges::make_reverse_iterator(ranges::end(::std::forward<T>(t))))>
+    {
+        return ranges::make_reverse_iterator(ranges::end(::std::forward<T>(t)));
+    }
+
+  public:
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const noexcept(noexcept(fn::impl(::std::forward<T>(t), priority_tag<3>{})))
+        -> decltype(fn::impl(::std::forward<T>(t), priority_tag<3>{}))
+    {
+        return fn::impl(::std::forward<T>(t), priority_tag<3>{});
+    }
+};
+
+} // namespace rbegin_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::rbegin_::fn, rbegin)
+
+namespace detail
+{
+namespace rend_
+{
+
+template <typename T>
+void
+rend(T&) = delete;
+
+template <typename T>
+void
+rend(const T&) = delete;
+
+struct fn
+{
+  private:
+    template <
+        typename T,
+        ::std::enable_if_t<!::std::is_lvalue_reference_v<T> && !enable_borrowed_range<::std::remove_cv_t<T>>, int> = 0>
+    static constexpr void
+    impl(T&&, priority_tag<3>) = delete;
+
+    template <typename T, typename I = decltype(ranges::rbegin(::std::declval<T>())),
+              typename S = decltype(decay_copy(::std::declval<T>().rend()))>
+    static constexpr auto
+    impl(T&& t, priority_tag<2>) noexcept(noexcept(decay_copy(::std::forward<T>(t).rend())))
+        -> ::std::enable_if_t<sentinel_for<S, I>, S>
+    {
+        return ::std::forward<T>(t).rend();
+    }
+
+    template <typename T, typename I = decltype(ranges::rbegin(::std::declval<T>())),
+              typename S = decltype(decay_copy(rend(::std::declval<T>())))>
+    static constexpr auto
+    impl(T&& t, priority_tag<1>) noexcept(noexcept(decay_copy(rend(::std::forward<T>(t)))))
+        -> ::std::enable_if_t<sentinel_for<S, I>, S>
+    {
+        return rend(::std::forward<T>(t));
+    }
+
+    template <typename T, typename I = decltype(ranges::begin(::std::declval<T>())),
+              typename S = decltype(ranges::end(::std::declval<T>()))>
+    static constexpr auto
+    impl(T&& t, priority_tag<0>) noexcept(noexcept(ranges::make_reverse_iterator(ranges::begin(::std::forward<T>(t)))))
+        -> ::std::enable_if_t<same_as<I, S> && bidirectional_iterator<I>,
+                              decltype(ranges::make_reverse_iterator(ranges::begin(::std::forward<T>(t))))>
+    {
+        return ranges::make_reverse_iterator(ranges::begin(::std::forward<T>(t)));
+    }
+
+  public:
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const noexcept(noexcept(fn::impl(::std::forward<T>(t), priority_tag<3>{})))
+        -> decltype(fn::impl(::std::forward<T>(t), priority_tag<3>{}))
+    {
+        return fn::impl(::std::forward<T>(t), priority_tag<3>{});
+    }
+};
+
+} // namespace rend_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::rend_::fn, rend)
+
+namespace detail
+{
+namespace crbegin_
+{
+
+struct fn
+{
+  private:
+    template <typename T, typename U = ::std::remove_reference_t<T>,
+              ::std::enable_if_t<::std::is_lvalue_reference_v<T>, int> = 0>
+    static constexpr auto
+    impl(T&& t) noexcept(noexcept(ranges::rbegin(static_cast<const U&>(t))))
+        -> decltype(ranges::rbegin(static_cast<const U&>(t)))
+    {
+        return ranges::rbegin(static_cast<const U&>(t));
+    }
+
+    template <typename T, ::std::enable_if_t<!::std::is_lvalue_reference_v<T>, int> = 0>
+    static constexpr auto
+    impl(T&& t) noexcept(noexcept(ranges::rbegin(static_cast<const T&&>(t))))
+        -> decltype(ranges::rbegin(static_cast<const T&&>(t)))
+    {
+        return ranges::rbegin(static_cast<const T&&>(t));
+    }
+
+  public:
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const noexcept(noexcept(fn::impl(::std::forward<T>(t))))
+        -> decltype(fn::impl(::std::forward<T>(t)))
+    {
+        return fn::impl(::std::forward<T>(t));
+    }
+};
+
+} // namespace crbegin_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::crbegin_::fn, crbegin)
+
+namespace detail
+{
+namespace crend_
+{
+
+struct fn
+{
+  private:
+    template <typename T, typename U = ::std::remove_reference_t<T>,
+              ::std::enable_if_t<::std::is_lvalue_reference_v<T>, int> = 0>
+    static constexpr auto
+    impl(T&& t) noexcept(noexcept(ranges::rend(static_cast<const U&>(t))))
+        -> decltype(ranges::rend(static_cast<const U&>(t)))
+    {
+        return ranges::rend(static_cast<const U&>(t));
+    }
+
+    template <typename T, ::std::enable_if_t<!::std::is_lvalue_reference_v<T>, int> = 0>
+    static constexpr auto
+    impl(T&& t) noexcept(noexcept(ranges::rend(static_cast<const T&&>(t))))
+        -> decltype(ranges::rend(static_cast<const T&&>(t)))
+    {
+        return ranges::rend(static_cast<const T&&>(t));
+    }
+
+  public:
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const noexcept(noexcept(fn::impl(::std::forward<T>(t))))
+        -> decltype(fn::impl(::std::forward<T>(t)))
+    {
+        return fn::impl(::std::forward<T>(t));
+    }
+};
+
+} // namespace crend_
+} // namespace detail
+
+NANO_INLINE_VAR(detail::crend_::fn, crend)
+
+NANO_END_NAMESPACE
+
+#            endif
+
+// nanorange/functional.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#            ifndef NANORANGE_FUNCTIONAL_HPP_INCLUDED
+#                define NANORANGE_FUNCTIONAL_HPP_INCLUDED
+
+#            endif
+
+#        endif
+
+NANO_BEGIN_NAMESPACE
+
+// [range.alg.adjacent.find]
+
+namespace detail
+{
+
+struct adjacent_find_fn
+{
+  private:
+    friend struct unique_fn;
+
+    template <typename I, typename S, typename Proj, typename Pred>
+    static constexpr I
+    impl(I first, S last, Pred& pred, Proj& proj)
+    {
+        if (first == last)
+        {
+            return first;
+        }
+
+        I next = first;
+        ++next;
+
+        while (next != last)
+        {
+            if (nano::invoke(pred, nano::invoke(proj, *first), nano::invoke(proj, *next)))
+            {
+                return first;
+            }
+            ++first;
+            ++next;
+        }
+
+        return next;
+    }
+
+  public:
+    template <typename I, typename S, typename Proj = identity, typename Pred = ranges::equal_to>
+    constexpr ::std::enable_if_t<
+        forward_iterator<I> && sentinel_for<S, I> && indirect_relation<Pred, projected<I, Proj>>, I>
+    operator()(I first, S last, Pred pred = Pred{}, Proj proj = Proj{}) const
+    {
+        return adjacent_find_fn::impl(::std::move(first), ::std::move(last), pred, proj);
+    }
+
+    template <typename Rng, typename Proj = identity, typename Pred = ranges::equal_to>
+    constexpr ::std::enable_if_t<forward_range<Rng> && indirect_relation<Pred, projected<iterator_t<Rng>, Proj>>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, Pred pred = Pred{}, Proj proj = Proj{}) const
+    {
+        return adjacent_find_fn::impl(nano::begin(rng), nano::end(rng), pred, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::adjacent_find_fn, adjacent_find)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/all_of.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_ALL_OF_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_ALL_OF_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+// [range.alg.all_of]
+
+namespace detail
+{
+
+struct all_of_fn
+{
+  private:
+    template <typename I, typename S, typename Proj, typename Pred>
+    static constexpr bool
+    impl(I first, S last, Pred& pred, Proj& proj)
+    {
+        while (first != last)
+        {
+            if (!nano::invoke(pred, nano::invoke(proj, *first)))
+            {
+                return false;
+            }
+            ++first;
+        }
+        return true;
+    }
+
+  public:
+    template <typename I, typename S, typename Proj = identity, typename Pred>
+    constexpr ::std::enable_if_t<
+        input_iterator<I> && sentinel_for<S, I> && indirect_unary_predicate<Pred, projected<I, Proj>>, bool>
+    operator()(I first, S last, Pred pred, Proj proj = Proj{}) const
+    {
+        return all_of_fn::impl(::std::move(first), ::std::move(last), pred, proj);
+    }
+
+    template <typename Rng, typename Proj = identity, typename Pred>
+    constexpr ::std::enable_if_t<input_range<Rng> && indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>>,
+                                 bool>
+    operator()(Rng&& rng, Pred pred, Proj proj = Proj{}) const
+    {
+        return all_of_fn::impl(nano::begin(rng), nano::end(rng), pred, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::all_of_fn, all_of)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/any_of.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_ANY_OF_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_ANY_OF_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+// [ranges.alg.any_of]
+
+namespace detail
+{
+
+struct any_of_fn
+{
+  private:
+    friend struct is_permutation_fn;
+    friend struct none_of_fn;
+
+    template <typename I, typename S, typename Proj, typename Pred>
+    static constexpr bool
+    impl(I first, S last, Pred& pred, Proj& proj)
+    {
+        while (first != last)
+        {
+            if (nano::invoke(pred, nano::invoke(proj, *first)) == true)
+            {
+                return true;
+            }
+            ++first;
+        }
+        return false;
+    }
+
+  public:
+    template <typename I, typename S, typename Proj = identity, typename Pred>
+    constexpr ::std::enable_if_t<
+        input_iterator<I> && sentinel_for<S, I> && indirect_unary_predicate<Pred, projected<I, Proj>>, bool>
+    operator()(I first, S last, Pred pred, Proj proj = Proj{}) const
+    {
+        return any_of_fn::impl(::std::move(first), ::std::move(last), pred, proj);
+    }
+
+    template <typename Rng, typename Proj = identity, typename Pred>
+    constexpr ::std::enable_if_t<input_range<Rng> && indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>>,
+                                 bool>
+    operator()(Rng&& rng, Pred pred, Proj proj = Proj{}) const
+    {
+        return any_of_fn::impl(nano::begin(rng), nano::end(rng), pred, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::any_of_fn, any_of)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/binary_search.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_BINARY_SEARCH_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_BINARY_SEARCH_HPP_INCLUDED
+
+// nanorange/algorithm/lower_bound.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_ALGORITHM_LOWER_BOUND_HPP_INCLUDED
+#            define NANORANGE_ALGORITHM_LOWER_BOUND_HPP_INCLUDED
+
+// nanorange/algorithm/partition_point.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+// Uses code from CMCSTL2
+
+//  Copyright Eric Niebler 2014
+//  Copyright Casey Carter 2015
+
+//===-------------------------- algorithm ---------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+
+#            ifndef NANORANGE_ALGORITHM_PARTITION_POINT_HPP_INCLUDED
+#                define NANORANGE_ALGORITHM_PARTITION_POINT_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct partition_point_fn
+{
+  private:
+    friend struct lower_bound_fn;
+    friend struct upper_bound_fn;
+
+    template <typename I, typename Pred, typename Proj>
+    static constexpr I
+    impl_n(I first, iter_difference_t<I> n, Pred& pred, Proj& proj)
+    {
+        while (n != 0)
+        {
+            const auto half = n / 2;
+
+            auto middle = nano::next(first, half);
+
+            if (nano::invoke(pred, nano::invoke(proj, *middle)))
+            {
+                first = ::std::move(++middle);
+                n -= half + 1;
+            }
+            else
+            {
+                n = half;
+            }
+        }
+
+        return first;
+    }
+
+    template <typename I, typename S, typename Pred, typename Proj>
+    static constexpr ::std::enable_if_t<sized_sentinel_for<S, I>, I>
+    impl(I first, S last, Pred& pred, Proj& proj)
+    {
+        const auto n = nano::distance(first, ::std::move(last));
+        return partition_point_fn::impl_n(::std::move(first), n, pred, proj);
+    }
+
+    template <typename I, typename S, typename Pred, typename Proj>
+    static constexpr ::std::enable_if_t<!sized_sentinel_for<S, I>, I>
+    impl(I first, S last, Pred& pred, Proj& proj)
+    {
+        // Probe exponentially for either end-of-range or an iterator
+        // that is past the partition point (i.e., does not satisfy pred).
+        iter_difference_t<I> n{1};
+
+        while (true)
+        {
+            auto m = first;
+            auto d = nano::advance(m, n, last);
+            if (m == last || !nano::invoke(pred, nano::invoke(proj, *m)))
+            {
+                n -= d;
+                return partition_point_fn::impl_n(::std::move(first), n, pred, proj);
+            }
+            first = ::std::move(m);
+            n *= 2;
+        }
+    }
+
+  public:
+    template <typename I, typename S, typename Pred, typename Proj = identity>
+    ::std::enable_if_t<forward_iterator<I> && sentinel_for<S, I> && indirect_unary_predicate<Pred, projected<I, Proj>>,
+                       I> constexpr
+    operator()(I first, S last, Pred pred, Proj proj = Proj{}) const
+    {
+        return partition_point_fn::impl(::std::move(first), ::std::move(last), pred, proj);
+    }
+
+    template <typename Rng, typename Pred, typename Proj = identity>
+    ::std::enable_if_t<forward_range<Rng> && indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>>,
+                       borrowed_iterator_t<Rng>> constexpr
+    operator()(Rng&& rng, Pred pred, Proj proj = Proj{}) const
+    {
+        return partition_point_fn::impl(nano::begin(rng), nano::end(rng), pred, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::partition_point_fn, partition_point)
+
+NANO_END_NAMESPACE
+
+#            endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct lower_bound_fn
+{
+  private:
+    friend struct binary_search_fn;
+    friend struct equal_range_fn;
+
+    template <typename Comp, typename T>
+    struct compare
+    {
+        Comp& comp;
+        const T& val;
+
+        template <typename U>
+        constexpr bool
+        operator()(U&& u) const
+        {
+            return nano::invoke(comp, ::std::forward<U>(u), val);
+        }
+    };
+
+    template <typename I, typename S, typename T, typename Comp, typename Proj>
+    static constexpr I
+    impl(I first, S last, const T& value, Comp& comp, Proj& proj)
+    {
+        const auto comparator = compare<Comp, T>{comp, value};
+        return partition_point_fn::impl(::std::move(first), ::std::move(last), comparator, proj);
+    }
+
+  public:
+    template <typename I, typename S, typename T, typename Comp = ranges::less, typename Proj = identity>
+    ::std::enable_if_t<forward_iterator<I> && sentinel_for<S, I> &&
+                           indirect_strict_weak_order<Comp, const T*, projected<I, Proj>>,
+                       I> constexpr
+    operator()(I first, S last, const T& value, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return lower_bound_fn::impl(::std::move(first), ::std::move(last), value, comp, proj);
+    }
+
+    template <typename Rng, typename T, typename Comp = ranges::less, typename Proj = identity>
+    ::std::enable_if_t<forward_range<Rng> &&
+                           indirect_strict_weak_order<Comp, const T*, projected<iterator_t<Rng>, Proj>>,
+                       borrowed_iterator_t<Rng>> constexpr
+    operator()(Rng&& rng, const T& value, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return lower_bound_fn::impl(nano::begin(rng), nano::end(rng), value, comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::lower_bound_fn, lower_bound)
+
+NANO_END_NAMESPACE
+
+#        endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct binary_search_fn
+{
+  private:
+    template <typename I, typename S, typename T, typename Comp, typename Proj>
+    static constexpr bool
+    impl(I first, S last, const T& value, Comp& comp, Proj& proj)
+    {
+        first = lower_bound_fn::impl(::std::move(first), last, value, comp, proj);
+        return (first != last && !nano::invoke(comp, value, nano::invoke(proj, *first)));
+    }
+
+  public:
+    template <typename I, typename S, typename T, typename Comp = ranges::less, typename Proj = identity>
+    ::std::enable_if_t<forward_iterator<I> && sentinel_for<S, I> &&
+                           indirect_strict_weak_order<Comp, const T*, projected<I, Proj>>,
+                       bool> constexpr
+    operator()(I first, S last, const T& value, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return binary_search_fn::impl(::std::move(first), ::std::move(last), value, comp, proj);
+    }
+
+    template <typename Rng, typename T, typename Comp = ranges::less, typename Proj = identity>
+    ::std::enable_if_t<forward_range<Rng> &&
+                           indirect_strict_weak_order<Comp, const T*, projected<iterator_t<Rng>, Proj>>,
+                       bool> constexpr
+    operator()(Rng&& rng, const T& value, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return binary_search_fn::impl(nano::begin(rng), nano::end(rng), value, comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::binary_search_fn, binary_search)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/clamp.hpp
+//
+// Copyright (c) 2020 Boris Staletic (boris dot staletic at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_CLAMP_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_CLAMP_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct clamp_fn
+{
+    template <typename T, typename Proj = identity, typename Comp = nano::less>
+    constexpr ::std::enable_if_t<indirect_strict_weak_order<Comp, projected<const T*, Proj>>, const T&>
+    operator()(const T& value, const T& low, const T& high, Comp comp = {}, Proj proj = Proj{}) const
+    {
+        auto&& projected_value = nano::invoke(proj, value);
+        if (nano::invoke(comp, projected_value, nano::invoke(proj, low)))
+        {
+            return low;
+        }
+        else if (nano::invoke(comp, nano::invoke(proj, high), projected_value))
+        {
+            return high;
+        }
+        else
+        {
+            return value;
+        }
+    }
+};
+} // namespace detail
+
+NANO_INLINE_VAR(detail::clamp_fn, clamp)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/copy.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_COPY_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_COPY_HPP_INCLUDED
+
+// nanorange/detail/algorithm/result_types.hpp
+//
+// Copyright (c) 2020 Boris Staletic (boris dot staletic at gmail dot com)
+// Copyright (c) 2020 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_DETAIL_ALGORITHM_RETURN_TYPES
+#            define NANORANGE_DETAIL_ALGORITHM_RETURN_TYPES
+
+#            include <type_traits>
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I, typename F>
+struct in_fun_result
+{
+    NANO_NO_UNIQUE_ADDRESS I in;
+    NANO_NO_UNIQUE_ADDRESS F fun;
+
+    template <typename I2, typename F2,
+              ::std::enable_if_t<convertible_to<const I&, I2> && convertible_to<const F&, F2>, int> = 0>
+    constexpr operator in_fun_result<I2, F2>() const&
+    {
+        return {in, fun};
+    }
+
+    template <typename I2, typename F2, ::std::enable_if_t<convertible_to<I, I2> && convertible_to<F, F2>, int> = 0>
+    constexpr operator in_fun_result<I2, F2>() &&
+    {
+        return {::std::move(in), ::std::move(fun)};
+    }
+};
+
+template <typename I1, typename I2>
+struct in_in_result
+{
+    NANO_NO_UNIQUE_ADDRESS I1 in1;
+    NANO_NO_UNIQUE_ADDRESS I2 in2;
+
+    template <typename II1, typename II2,
+              ::std::enable_if_t<convertible_to<const I1&, II1> && convertible_to<const I2&, II2>, int> = 0>
+    constexpr operator in_in_result<II1, II2>() const&
+    {
+        return {in1, in2};
+    }
+
+    template <typename II1, typename II2,
+              ::std::enable_if_t<convertible_to<I1, II1> && convertible_to<I2, II2>, int> = 0>
+    constexpr operator in_in_result<II1, II2>() &&
+    {
+        return {::std::move(in1), ::std::move(in2)};
+    }
+};
+
+template <typename I, typename O>
+struct in_out_result
+{
+    NANO_NO_UNIQUE_ADDRESS I in;
+    NANO_NO_UNIQUE_ADDRESS O out;
+
+    template <typename I2, typename O2,
+              ::std::enable_if_t<convertible_to<const I&, I2> && convertible_to<const O&, O2>, int> = 0>
+    constexpr operator in_out_result<I2, O2>() const&
+    {
+        return {in, out};
+    }
+
+    template <typename I2, typename O2, ::std::enable_if_t<convertible_to<I, I2> && convertible_to<O, O2>, int> = 0>
+    constexpr operator in_out_result<I2, O2>() &&
+    {
+        return {::std::move(in), ::std::move(out)};
+    }
+};
+
+template <typename I1, typename I2, typename O>
+struct in_in_out_result
+{
+    NANO_NO_UNIQUE_ADDRESS I1 in1;
+    NANO_NO_UNIQUE_ADDRESS I2 in2;
+    NANO_NO_UNIQUE_ADDRESS O out;
+
+    template <
+        typename II1, typename II2, typename O2,
+        ::std::enable_if_t<
+            convertible_to<const I1&, II1> && convertible_to<const I2&, II2> && convertible_to<const O&, O2>, int> = 0>
+    constexpr operator in_in_out_result<II1, II2, O2>() const&
+    {
+        return {in1, in2, out};
+    }
+
+    template <typename II1, typename II2, typename O2,
+              ::std::enable_if_t<convertible_to<I1, II1> && convertible_to<I2, II2> && convertible_to<O, O2>, int> = 0>
+    constexpr operator in_in_out_result<II1, II2, O2>() &&
+    {
+        return {::std::move(in1), ::std::move(in2), ::std::move(out)};
+    }
+};
+
+template <typename I, typename O1, typename O2>
+struct in_out_out_result
+{
+    NANO_NO_UNIQUE_ADDRESS I in;
+    NANO_NO_UNIQUE_ADDRESS O1 out1;
+    NANO_NO_UNIQUE_ADDRESS O2 out2;
+
+    template <
+        typename II, typename OO1, typename OO2,
+        ::std::enable_if_t<
+            convertible_to<const I&, II> && convertible_to<const O1&, OO1> && convertible_to<const O2&, OO2>, int> = 0>
+    constexpr operator in_out_out_result<II, OO1, OO2>() const&
+    {
+        return {in, out1, out2};
+    }
+
+    template <typename II, typename OO1, typename OO2,
+              ::std::enable_if_t<convertible_to<I, II> && convertible_to<O1, OO1> && convertible_to<O2, OO2>, int> = 0>
+    constexpr operator in_out_out_result<II, OO1, OO2>() &&
+    {
+        return {::std::move(in), ::std::move(out1), ::std::move(out2)};
+    }
+};
+
+template <typename T>
+struct min_max_result
+{
+    NANO_NO_UNIQUE_ADDRESS T min;
+    NANO_NO_UNIQUE_ADDRESS T max;
+
+    template <typename T2, ::std::enable_if_t<convertible_to<const T&, T2>, int> = 0>
+    constexpr operator min_max_result<T2>() const&
+    {
+        return {min, max};
+    }
+
+    template <typename T2, ::std::enable_if_t<convertible_to<T, T2>, int> = 0>
+    constexpr operator min_max_result<T2>() &&
+    {
+        return {::std::move(min), ::std::move(max)};
+    }
+};
+
+template <typename I>
+struct in_found_result
+{
+    NANO_NO_UNIQUE_ADDRESS I in;
+    bool found;
+    template <class I2, ::std::enable_if_t<convertible_to<const I&, I2>, int> = 0>
+    constexpr operator in_found_result<I2>() const&
+    {
+        return {in, found};
+    }
+    template <class I2, ::std::enable_if_t<convertible_to<const I&, I2>, int> = 0>
+    constexpr operator in_found_result<I2>() &&
+    {
+        return {::std::move(in), found};
+    }
+};
+
+NANO_END_NAMESPACE
+
+#        endif
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I, typename O>
+using copy_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct copy_fn
+{
+  private:
+    // If we know the distance between first and last, we can use that
+    // information to (potentially) allow better codegen
+    template <typename I, typename S, typename O>
+    static constexpr ::std::enable_if_t<sized_sentinel_for<S, I>, copy_result<I, O>>
+    impl(I first, S last, O result, priority_tag<1>)
+    {
+        const auto dist = last - first;
+
+        for (iter_difference_t<I> i = 0; i < dist; ++i)
+        {
+            *result = *first;
+            ++first;
+            ++result;
+        }
+
+        return {::std::move(first), ::std::move(result)};
+    }
+
+    template <typename I, typename S, typename O>
+    static constexpr copy_result<I, O>
+    impl(I first, S last, O result, priority_tag<0>)
+    {
+        while (first != last)
+        {
+            *result = *first;
+            ++first;
+            ++result;
+        }
+
+        return {::std::move(first), ::std::move(result)};
+    }
+
+  public:
+    template <typename I, typename S, typename O>
+    constexpr ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> && weakly_incrementable<O> &&
+                                     indirectly_copyable<I, O>,
+                                 copy_result<I, O>>
+    operator()(I first, S last, O result) const
+    {
+        return copy_fn::impl(::std::move(first), ::std::move(last), ::std::move(result), priority_tag<1>{});
+    }
+
+    template <typename Rng, typename O>
+    constexpr ::std::enable_if_t<input_range<Rng> && weakly_incrementable<O> && indirectly_copyable<iterator_t<Rng>, O>,
+                                 copy_result<borrowed_iterator_t<Rng>, O>>
+    operator()(Rng&& rng, O result) const
+    {
+        return copy_fn::impl(nano::begin(rng), nano::end(rng), ::std::move(result), priority_tag<1>{});
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::copy_fn, copy)
+
+template <typename I, typename O>
+using copy_n_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct copy_n_fn
+{
+    template <typename I, typename O>
+    constexpr ::std::enable_if_t<input_iterator<I> && weakly_incrementable<O> && indirectly_copyable<I, O>,
+                                 copy_n_result<I, O>>
+    operator()(I first, iter_difference_t<I> n, O result) const
+    {
+        for (iter_difference_t<I> i{}; i < n; i++)
+        {
+            *result = *first;
+            ++first;
+            ++result;
+        }
+
+        return {::std::move(first), ::std::move(result)};
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::copy_n_fn, copy_n)
+
+template <typename I, typename O>
+using copy_if_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct copy_if_fn
+{
+  private:
+    template <typename I, typename S, typename O, typename Pred, typename Proj>
+    static constexpr copy_if_result<I, O>
+    impl(I first, S last, O result, Pred pred, Proj proj)
+    {
+        while (first != last)
+        {
+            if (nano::invoke(pred, nano::invoke(proj, *first)))
+            {
+                *result = *first;
+                ++result;
+            }
+            ++first;
+        }
+
+        return {::std::move(first), ::std::move(result)};
+    }
+
+  public:
+    template <typename I, typename S, typename O, typename Proj = identity, typename Pred>
+    constexpr ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> && weakly_incrementable<O> &&
+                                     indirect_unary_predicate<Pred, projected<I, Proj>> && indirectly_copyable<I, O>,
+                                 copy_if_result<I, O>>
+    operator()(I first, S last, O result, Pred pred, Proj proj = Proj{}) const
+    {
+        return copy_if_fn::impl(::std::move(first), ::std::move(last), ::std::move(result), ::std::move(pred),
+                                ::std::move(proj));
+    }
+
+    template <typename Rng, typename O, typename Proj = identity, typename Pred>
+    constexpr ::std::enable_if_t<input_range<Rng> && weakly_incrementable<O> &&
+                                     indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>>,
+                                 copy_if_result<borrowed_iterator_t<Rng>, O>>
+    operator()(Rng&& rng, O result, Pred pred, Proj proj = Proj{}) const
+    {
+        return copy_if_fn::impl(nano::begin(rng), nano::end(rng), ::std::move(result), ::std::move(pred),
+                                ::std::move(proj));
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::copy_if_fn, copy_if)
+
+template <typename I, typename O>
+using copy_backward_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct copy_backward_fn
+{
+  private:
+    template <typename I1, typename S1, typename I2>
+    static constexpr copy_backward_result<I1, I2>
+    impl(I1 first, S1 last, I2 result)
+    {
+        I1 last_it = nano::next(first, ::std::move(last));
+        I1 it = last_it;
+
+        while (it != first)
+        {
+            *--result = *--it;
+        }
+
+        return {::std::move(last_it), ::std::move(result)};
+    }
+
+  public:
+    template <typename I1, typename S1, typename I2>
+    constexpr ::std::enable_if_t<bidirectional_iterator<I1> && sentinel_for<S1, I1> && bidirectional_iterator<I2> &&
+                                     indirectly_copyable<I1, I2>,
+                                 copy_backward_result<I1, I2>>
+    operator()(I1 first, S1 last, I2 result) const
+    {
+        return copy_backward_fn::impl(::std::move(first), ::std::move(last), ::std::move(result));
+    }
+
+    template <typename Rng, typename I>
+    constexpr ::std::enable_if_t<bidirectional_range<Rng> && bidirectional_iterator<I> &&
+                                     indirectly_copyable<iterator_t<Rng>, I>,
+                                 copy_backward_result<borrowed_iterator_t<Rng>, I>>
+    operator()(Rng&& rng, I result) const
+    {
+        return copy_backward_fn::impl(nano::begin(rng), nano::end(rng), ::std::move(result));
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::copy_backward_fn, copy_backward)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/count.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_COUNT_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_COUNT_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+// [rng.alg.count]
+
+namespace detail
+{
+
+struct count_if_fn
+{
+  private:
+    friend struct count_fn;
+    friend struct is_permutation_fn;
+
+    template <typename I, typename S, typename Proj, typename Pred>
+    static constexpr iter_difference_t<I>
+    impl(I first, S last, Pred& pred, Proj& proj)
+    {
+        iter_difference_t<I> counter = 0;
+
+        for (; first != last; ++first)
+        {
+            if (nano::invoke(pred, nano::invoke(proj, *first)))
+            {
+                ++counter;
+            }
+        }
+
+        return counter;
+    }
+
+  public:
+    template <typename I, typename S, typename Proj = identity, typename Pred>
+    constexpr ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> &&
+                                     indirect_unary_predicate<Pred, projected<I, Proj>>,
+                                 iter_difference_t<I>>
+    operator()(I first, S last, Pred pred, Proj proj = Proj{}) const
+    {
+        return count_if_fn::impl(::std::move(first), ::std::move(last), pred, proj);
+    }
+
+    template <typename Rng, typename Proj = identity, typename Pred>
+    constexpr ::std::enable_if_t<input_range<Rng> && indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>>,
+                                 range_difference_t<Rng>>
+    operator()(Rng&& rng, Pred pred, Proj proj = Proj{}) const
+    {
+        return count_if_fn::impl(nano::begin(rng), nano::end(rng), pred, proj);
+    }
+};
+} // namespace detail
+
+NANO_INLINE_VAR(detail::count_if_fn, count_if)
+
+namespace detail
+{
+
+struct count_fn
+{
+    template <typename I, typename S, typename T, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> &&
+                                     indirect_relation<ranges::equal_to, projected<I, Proj>, const T*>,
+                                 iter_difference_t<I>>
+    operator()(I first, S last, const T& value, Proj proj = Proj{}) const
+    {
+        const auto pred = [&value](const auto& t) { return t == value; };
+        return count_if_fn::impl(::std::move(first), ::std::move(last), pred, proj);
+    }
+
+    template <typename Rng, typename T, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_range<Rng> &&
+                                     indirect_relation<ranges::equal_to, projected<iterator_t<Rng>, Proj>, const T*>,
+                                 range_difference_t<Rng>>
+    operator()(Rng&& rng, const T& value, Proj proj = Proj{}) const
+    {
+        const auto pred = [&value](const auto& t) { return t == value; };
+        return count_if_fn::impl(nano::begin(rng), nano::end(rng), pred, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::count_fn, count)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/equal.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_EQUAL_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_EQUAL_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct equal_fn
+{
+  private:
+    template <typename I1, typename S1, typename I2, typename S2, typename Pred, typename Proj1, typename Proj2>
+    static constexpr bool
+    impl4(I1 first1, S1 last1, I2 first2, S2 last2, Pred& pred, Proj1& proj1, Proj2& proj2)
+    {
+        while (first1 != last1 && first2 != last2)
+        {
+            if (!nano::invoke(pred, nano::invoke(proj1, *first1), nano::invoke(proj2, *first2)))
+            {
+                return false;
+            }
+            ++first1;
+            ++first2;
+        }
+
+        return first1 == last1 && first2 == last2;
+    }
+
+    template <typename I1, typename S1, typename I2, typename Pred, typename Proj1, typename Proj2>
+    static constexpr bool
+    impl3(I1 first1, S1 last1, I2 first2, Pred pred, Proj1& proj1, Proj2& proj2)
+    {
+        while (first1 != last1)
+        {
+            if (!nano::invoke(pred, nano::invoke(proj1, *first1), nano::invoke(proj2, *first2)))
+            {
+                return false;
+            }
+            ++first1;
+            ++first2;
+        }
+
+        return true;
+    }
+
+  public:
+    // Four-legged, sized sentinels
+    template <typename I1, typename S1, typename I2, typename S2, typename Pred = ranges::equal_to,
+              typename Proj1 = identity, typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_iterator<I1> && sentinel_for<S1, I1> && input_iterator<I2> &&
+                                     sentinel_for<S2, I2> && indirectly_comparable<I1, I2, Pred, Proj1, Proj2> &&
+                                     sized_sentinel_for<S1, I1> && sized_sentinel_for<S2, I2>,
+                                 bool>
+    operator()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = Pred{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        if (last1 - first1 != last2 - first2)
+        {
+            return false;
+        }
+
+        // Ranges are the same size, so call the 3-legged version
+        // and save ourselves a comparison
+        return equal_fn::impl3(::std::move(first1), ::std::move(last1), ::std::move(first2), pred, proj1, proj2);
+    }
+
+    // Four-legged, unsized sentinels
+    template <typename I1, typename S1, typename I2, typename S2, typename Pred = ranges::equal_to,
+              typename Proj1 = identity, typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_iterator<I1> && sentinel_for<S1, I1> && input_iterator<I2> &&
+                                     sentinel_for<S2, I2> && indirectly_comparable<I1, I2, Pred, Proj1, Proj2> &&
+                                     !(sized_sentinel_for<S1, I1> && sized_sentinel_for<S2, I2>),
+                                 bool>
+    operator()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = Pred{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return equal_fn::impl4(::std::move(first1), ::std::move(last1), ::std::move(first2), ::std::move(last2), pred,
+                               proj1, proj2);
+    }
+
+    // Three legged
+    template <typename I1, typename S1, typename I2, typename Pred = ranges::equal_to, typename Proj1 = identity,
+              typename Proj2 = identity>
+    NANO_DEPRECATED constexpr ::std::enable_if_t<input_iterator<I1> && sentinel_for<S1, I1> &&
+                                                     input_iterator<::std::decay_t<I2>> && !input_range<I2> &&
+                                                     indirectly_comparable<I1, ::std::decay_t<I2>, Pred, Proj1, Proj2>,
+                                                 bool>
+    operator()(I1 first1, S1 last1, I2 first2, Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return equal_fn::impl3(::std::move(first1), ::std::move(last1), ::std::forward<I2>(first2), pred, proj1, proj2);
+    }
+
+    // Two ranges, both sized
+    template <typename Rng1, typename Rng2, typename Pred = ranges::equal_to, typename Proj1 = identity,
+              typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_range<Rng1> && input_range<Rng2> &&
+                                     indirectly_comparable<iterator_t<Rng1>, iterator_t<Rng2>, Pred, Proj1, Proj2> &&
+                                     sized_range<Rng1> && sized_range<Rng2>,
+                                 bool>
+    operator()(Rng1&& rng1, Rng2&& rng2, Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        if (nano::distance(rng1) != nano::distance(rng2))
+        {
+            return false;
+        }
+
+        return equal_fn::impl3(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), pred, proj1, proj2);
+    }
+
+    // Two ranges, not both sized
+    template <typename Rng1, typename Rng2, typename Pred = ranges::equal_to, typename Proj1 = identity,
+              typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_range<Rng1> && input_range<Rng2> &&
+                                     indirectly_comparable<iterator_t<Rng1>, iterator_t<Rng2>, Pred, Proj1, Proj2> &&
+                                     !(sized_range<Rng1> && sized_range<Rng2>),
+                                 bool>
+    operator()(Rng1&& rng1, Rng2&& rng2, Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return equal_fn::impl4(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), nano::end(rng2), pred, proj1,
+                               proj2);
+    }
+
+    // Range and a half
+    template <typename Rng1, typename I2, typename Pred = ranges::equal_to, typename Proj1 = identity,
+              typename Proj2 = identity>
+    NANO_DEPRECATED constexpr ::std::enable_if_t<
+        input_range<Rng1> && input_iterator<::std::decay_t<I2>> && !input_range<I2> &&
+            indirectly_comparable<iterator_t<Rng1>, ::std::decay_t<I2>, Pred, Proj1, Proj2>,
+        bool>
+    operator()(Rng1&& rng1, I2&& first2, Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return equal_fn::impl3(nano::begin(rng1), nano::end(rng1), ::std::forward<I2>(first2), pred, proj1, proj2);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::equal_fn, equal)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/equal_range.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_EQUAL_RANGE_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_EQUAL_RANGE_HPP_INCLUDED
+
+// nanorange/algorithm/upper_bound.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_ALGORITHM_UPPER_BOUND_HPP_INCLUDED
+#            define NANORANGE_ALGORITHM_UPPER_BOUND_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct upper_bound_fn
+{
+  private:
+    friend struct equal_range_fn;
+
+    template <typename Comp, typename T>
+    struct compare
+    {
+        Comp& comp;
+        const T& val;
+
+        template <typename U>
+        constexpr bool
+        operator()(U&& u) const
+        {
+            return !nano::invoke(comp, val, ::std::forward<U>(u));
+        }
+    };
+
+    template <typename I, typename S, typename T, typename Comp, typename Proj>
+    static constexpr I
+    impl(I first, S last, const T& value, Comp& comp, Proj& proj)
+    {
+        const auto comparator = compare<Comp, T>{comp, value};
+        return partition_point_fn::impl(::std::move(first), ::std::move(last), comparator, proj);
+    }
+
+  public:
+    template <typename I, typename S, typename T, typename Comp = ranges::less, typename Proj = identity>
+    ::std::enable_if_t<forward_iterator<I> && sentinel_for<S, I> &&
+                           indirect_strict_weak_order<Comp, const T*, projected<I, Proj>>,
+                       I> constexpr
+    operator()(I first, S last, const T& value, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return upper_bound_fn::impl(::std::move(first), ::std::move(last), value, comp, proj);
+    }
+
+    template <typename Rng, typename T, typename Comp = ranges::less, typename Proj = identity>
+    ::std::enable_if_t<forward_range<Rng> &&
+                           indirect_strict_weak_order<Comp, const T*, projected<iterator_t<Rng>, Proj>>,
+                       borrowed_iterator_t<Rng>> constexpr
+    operator()(Rng&& rng, const T& value, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return upper_bound_fn::impl(nano::begin(rng), nano::end(rng), value, comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::upper_bound_fn, upper_bound)
+
+NANO_END_NAMESPACE
+
+#        endif
+
+// nanorange/views/subrange.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_VIEWS_SUBRANGE_HPP_INCLUDED
+#            define NANORANGE_VIEWS_SUBRANGE_HPP_INCLUDED
+
+// nanorange/views/interface.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#            ifndef NANORANGE_VIEWS_INTERFACE_HPP_INCLUDED
+#                define NANORANGE_VIEWS_INTERFACE_HPP_INCLUDED
+
+// nanorange/iterator/common_iterator.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                ifndef NANORANGE_ITERATOR_COMMON_ITERATOR_HPP_INCLUDED
+#                    define NANORANGE_ITERATOR_COMMON_ITERATOR_HPP_INCLUDED
+
+// nanorange/iterator/concepts.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                    ifndef NANORANGE_ITERATOR_CONCEPTS_HPP_INCLUDED
+#                        define NANORANGE_ITERATOR_CONCEPTS_HPP_INCLUDED
+
+#                    endif
+
+NANO_BEGIN_NAMESPACE
+
+// [range.iterators.common]
+
+namespace common_iterator_
+{
+
+template <typename I, typename S>
+class common_iterator
+{
+    static_assert(input_or_output_iterator<I>, "");
+    static_assert(sentinel_for<S, I>, "");
+    static_assert(!same_as<I, S>, "");
+
+    template <typename II, typename SS>
+    friend class common_iterator;
+
+    class op_arrow_proxy
+    {
+        iter_value_t<I> keep_;
+
+        constexpr op_arrow_proxy(iter_reference_t<I>&& x) : keep_(::std::move(x)) {}
+
+      public:
+        constexpr const iter_value_t<I>* operator->() const { return ::std::addressof(keep_); }
+    };
+
+    template <typename II>
+    using op_arrow_t = decltype(::std::declval<const II&>().operator->());
+
+    template <typename II>
+    static constexpr auto
+    do_op_arrow(const II& i, detail::priority_tag<2>)
+        -> ::std::enable_if_t<::std::is_pointer<II>::value || detail::exists_v<op_arrow_t, II>, I>
+    {
+        return i;
+    }
+
+    template <typename II>
+    static constexpr auto
+    do_op_arrow(const II& i, detail::priority_tag<1>)
+        -> ::std::enable_if_t<::std::is_reference<iter_reference_t<const II>>::value,
+                              ::std::add_pointer_t<iter_reference_t<const II>>>
+    {
+        auto&& tmp = *i;
+        return ::std::addressof(tmp);
+    }
+
+    template <typename II>
+    static constexpr auto
+    do_op_arrow(const II& i, detail::priority_tag<0>) -> op_arrow_proxy
+    {
+        return {i};
+    }
+
+  public:
+    using difference_type = iter_difference_t<I>;
+
+    constexpr common_iterator() : is_sentinel_{false}, iter_{} {}
+
+    constexpr common_iterator(I i) : is_sentinel_{false}, iter_(i) {}
+
+    constexpr common_iterator(S s) : is_sentinel_{true}, sentinel_{s} {}
+
+    template <typename II, typename SS, ::std::enable_if_t<convertible_to<II, I> && convertible_to<SS, S>, int> = 0>
+    constexpr common_iterator(const common_iterator<II, SS>& other)
+        : is_sentinel_{other.is_sentinel_}, iter_(other.iter_), sentinel_(other.sentinel_)
+    {
+    }
+
+    template <typename II, typename SS>
+    constexpr ::std::enable_if_t<convertible_to<II, I> && convertible_to<SS, S>, common_iterator&>
+    operator=(const common_iterator<II, SS>& other)
+    {
+        is_sentinel_ = other.is_sentinel_;
+        iter_ = other.iter_;
+        sentinel_ = other.sentinel_;
+        return *this;
+    }
+
+    constexpr decltype(auto) operator*() { return *iter_; }
+
+    template <typename II = I, ::std::enable_if_t<detail::dereferenceable<const I>, int> = 0>
+    constexpr decltype(auto) operator*() const
+    {
+        return *iter_;
+    }
+
+    template <typename II = I>
+    constexpr auto operator-> () const
+        -> decltype(common_iterator::do_op_arrow(::std::declval<const II&>(), detail::priority_tag<2>{}))
+    {
+        return do_op_arrow(iter_, detail::priority_tag<2>{});
+    }
+
+    constexpr common_iterator&
+    operator++()
+    {
+        ++iter_;
+        return *this;
+    }
+
+    template <typename II = I, ::std::enable_if_t<!forward_iterator<II>, int> = 0>
+    constexpr decltype(auto)
+    operator++(int)
+    {
+        return iter_++;
+    }
+
+    template <typename II = I, ::std::enable_if_t<forward_iterator<II>, int> = 0>
+    constexpr common_iterator
+    operator++(int)
+    {
+        common_iterator tmp = *this;
+        ++iter_;
+        return tmp;
+    }
+
+    template <typename I2, typename S2>
+    friend constexpr auto
+    operator==(const common_iterator& x, const common_iterator<I2, S2>& y)
+        -> ::std::enable_if_t<sentinel_for<S2, I> && sentinel_for<S, I2> && !equality_comparable_with<I, I2>, bool>
+    {
+        return x.is_sentinel_ ? (y.is_sentinel_ || y.iter_ == x.sentinel_)
+                              : (!y.is_sentinel_ || x.iter_ == y.sentinel_);
+    }
+
+    template <typename I2, typename S2>
+    friend constexpr auto
+    operator==(const common_iterator& x, const common_iterator<I2, S2>& y)
+        -> ::std::enable_if_t<sentinel_for<S2, I> && sentinel_for<S, I2> && equality_comparable_with<I, I2>, bool>
+    {
+        return x.is_sentinel_ ? (y.is_sentinel_ || y.iter_ == x.sentinel_)
+                              : (y.is_sentinel_ ? x.iter_ == y.sentinel_ : x.iter_ == y.iter_);
+    }
+
+    template <typename I2, typename S2>
+    friend constexpr auto
+    operator!=(const common_iterator& x, const common_iterator<I2, S2>& y)
+        -> ::std::enable_if_t<sentinel_for<S2, I> && sentinel_for<S, I2>, bool>
+    {
+        return !(x == y);
+    }
+
+    template <typename I2, typename S2>
+    friend constexpr auto
+    operator-(const common_iterator& x, const common_iterator<I2, S2>& y)
+        -> ::std::enable_if_t<sized_sentinel_for<I, I2> && sized_sentinel_for<S, I2> && sized_sentinel_for<S, I2>,
+                              iter_difference_t<I2>>
+    {
+        return x.is_sentinel_ ? (y.is_sentinel_ ? 0 : x.sentinel_ - y.iter_)
+                              : (y.is_sentinel_ ? x.iter_ - y.sentinel_ : x.iter_ - y.iter_);
+    }
+
+    friend constexpr iter_rvalue_reference_t<I>
+    iter_move(const common_iterator& i)
+    {
+        return ranges::iter_move(i.iter_);
+    }
+
+    template <typename I2, typename S2>
+    friend constexpr ::std::enable_if_t<indirectly_swappable<I2, I>>
+    iter_swap(const common_iterator& x, const common_iterator<I2, S2>& y)
+    {
+        return ranges::iter_swap(x.iter_, y.iter_);
+    }
+
+    // private:
+    // TODO: Some sort of variant-like union
+    bool is_sentinel_{};
+    I iter_{};
+    S sentinel_{};
+};
+
+} // namespace common_iterator_
+
+using common_iterator_::common_iterator;
+
+template <typename I, typename S>
+struct readable_traits<common_iterator<I, S>>
+{
+    using value_type = iter_value_t<I>;
+};
+
+template <typename I, typename S>
+struct iterator_category<common_iterator<I, S>>
+    : ::std::conditional<forward_iterator<I>, forward_iterator_tag, input_iterator_tag>
+{
+};
+
+NANO_END_NAMESPACE
+
+namespace std
+{
+
+template <typename I, typename S>
+struct iterator_traits<__nanorange::nano::common_iterator<I, S>>
+{
+    using difference_type = __nanorange::nano::iter_difference_t<__nanorange::nano::common_iterator<I, S>>;
+    using value_type = __nanorange::nano::iter_value_t<__nanorange::nano::common_iterator<I, S>>;
+    using pointer = ::std::add_pointer_t<__nanorange::nano::iter_reference_t<__nanorange::nano::common_iterator<I, S>>>;
+    using reference = __nanorange::nano::iter_reference_t<__nanorange::nano::common_iterator<I, S>>;
+    using iterator_category = __nanorange::nano::detail::conditional_t<__nanorange::nano::forward_iterator<I>, ::std::forward_iterator_tag,
+                                                            ::std::input_iterator_tag>;
+};
+
+} // namespace std
+
+#                endif
+
+NANO_BEGIN_NAMESPACE
+
+// [ranges.view_interface]
+
+namespace detail
+{
+
+template <typename, typename = void>
+struct range_common_iterator_impl;
+
+template <typename R>
+struct range_common_iterator_impl<R, ::std::enable_if_t<range<R> && !common_range<R>>>
+{
+    using type = common_iterator<iterator_t<R>, sentinel_t<R>>;
+};
+
+template <typename R>
+struct range_common_iterator_impl<R, ::std::enable_if_t<common_range<R>>>
+{
+    using type = iterator_t<R>;
+};
+
+template <typename R>
+using range_common_iterator_t = typename range_common_iterator_impl<R>::type;
+
+} // namespace detail
+
+template <typename D>
+class view_interface : public view_base
+{
+
+    static_assert(::std::is_class<D>::value, "");
+    static_assert(same_as<D, ::std::remove_cv_t<D>>, "");
+
+  private:
+    constexpr D&
+    derived() noexcept
+    {
+        return static_cast<D&>(*this);
+    }
+
+    constexpr const D&
+    derived() const noexcept
+    {
+        return static_cast<const D&>(*this);
+    }
+
+  public:
+    template <typename R = D>
+    [[nodiscard]] constexpr auto
+    empty() -> ::std::enable_if_t<forward_range<R>, bool>
+    {
+        return ranges::begin(derived()) == ranges::end(derived());
+    }
+
+    template <typename R = D>
+    [[nodiscard]] constexpr auto
+    empty() const -> ::std::enable_if_t<forward_range<const R>, bool>
+    {
+        return ranges::begin(derived()) == ranges::end(derived());
+    }
+
+    template <typename R = D, typename = decltype(ranges::empty(::std::declval<R&>()))>
+    constexpr explicit operator bool()
+    {
+        return !ranges::empty(derived());
+    }
+
+    template <typename R = D, typename = decltype(ranges::empty(::std::declval<const R&>()))>
+    constexpr explicit operator bool() const
+    {
+        return !ranges::empty(derived());
+    }
+
+    template <typename R = D, typename = ::std::enable_if_t<contiguous_iterator<iterator_t<R>>>>
+    constexpr auto
+    data()
+    {
+        return ranges::empty(derived()) ? nullptr : ::std::addressof(*ranges::begin(derived()));
+    }
+
+    template <typename R = D, typename = ::std::enable_if_t<range<const R> && contiguous_iterator<iterator_t<const R>>>>
+    constexpr auto
+    data() const
+    {
+        return ranges::empty(derived()) ? nullptr : ::std::addressof(*ranges::begin(derived()));
+    }
+
+    template <typename R = D,
+              typename = ::std::enable_if_t<forward_range<R> && sized_sentinel_for<sentinel_t<R>, iterator_t<R>>>>
+    constexpr auto
+    size()
+    {
+        return ranges::end(derived()) - ranges::begin(derived());
+    }
+
+    template <typename R = D,
+              typename = ::std::enable_if_t<forward_range<const R> &&
+                                            sized_sentinel_for<sentinel_t<const R>, iterator_t<const R>>>>
+    constexpr auto
+    size() const
+    {
+        return ranges::end(derived()) - ranges::begin(derived());
+    }
+
+    template <typename R = D, typename = ::std::enable_if_t<forward_range<R>>>
+    constexpr decltype(auto)
+    front()
+    {
+        return *ranges::begin(derived());
+    }
+
+    template <typename R = D, typename = ::std::enable_if_t<forward_range<const R>>>
+    constexpr decltype(auto)
+    front() const
+    {
+        return *ranges::begin(derived());
+    }
+
+    template <typename R = D, typename = ::std::enable_if_t<bidirectional_range<R> && common_range<R>>>
+    constexpr decltype(auto)
+    back()
+    {
+        return *ranges::prev(ranges::end(derived()));
+    }
+
+    template <typename R = D, typename = ::std::enable_if_t<bidirectional_range<const R> && common_range<const R>>>
+    constexpr decltype(auto)
+    back() const
+    {
+        return *ranges::prev(ranges::end(derived()));
+    }
+
+    template <typename R = D, typename = ::std::enable_if_t<random_access_range<R>>>
+    constexpr decltype(auto) operator[](iter_difference_t<iterator_t<R>> n)
+    {
+        return ranges::begin(derived())[n];
+    }
+
+    template <typename R = D, typename = ::std::enable_if_t<random_access_range<const R>>>
+    constexpr decltype(auto) operator[](iter_difference_t<iterator_t<const R>> n) const
+    {
+        return ranges::begin(derived())[n];
+    }
+};
+
+NANO_END_NAMESPACE
+
+#            endif
+
+NANO_BEGIN_NAMESPACE
+
+// [ranges.subrange]
+
+enum class subrange_kind : bool
+{
+    unsized,
+    sized
+};
+
+namespace detail
+{
+
+template <typename I, typename S, bool = sized_sentinel_for<S, I>>
+struct default_subrange_kind
+{
+    static constexpr subrange_kind kind = subrange_kind::unsized;
+};
+
+template <typename I, typename S>
+struct default_subrange_kind<I, S, true>
+{
+    static constexpr subrange_kind kind = subrange_kind::sized;
+};
+
+} // namespace detail
+
+namespace subrange_
+{
+
+template <typename I, typename S = I, subrange_kind = detail::default_subrange_kind<I, S>::kind>
+class subrange;
+}
+
+using subrange_::subrange;
+
+namespace detail
+{
+
+struct convertible_to_non_slicing_concept
+{
+    template <typename, typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename From, typename To>
+    static auto
+    test(int) -> ::std::enable_if_t<
+        convertible_to<From, To> &&
+            !(::std::is_pointer_v<::std::decay_t<From>> && ::std::is_pointer_v<::std::decay_t<To>> &&
+              not_same_as<::std::remove_pointer_t<::std::decay_t<From>>, ::std::remove_pointer_t<::std::decay_t<To>>>),
+        ::std::true_type>;
+};
+
+template <typename From, typename To>
+NANO_CONCEPT convertible_to_non_slicing = decltype(convertible_to_non_slicing_concept::test<From, To>(0))::value;
+
+struct pair_like_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T, typename = typename ::std::tuple_size<T>::type,
+              typename = ::std::enable_if_t<detail::requires_<pair_like_concept, T>>>
+    static auto
+    test(int) -> ::std::true_type;
+
+    template <typename T>
+    auto
+    requires_(T t)
+        -> decltype(requires_expr<derived_from<::std::tuple_size<T>, ::std::integral_constant<::std::size_t, 2>>>{},
+                    ::std::declval<::std::tuple_element_t<0, ::std::remove_const_t<T>>>(),
+                    ::std::declval<::std::tuple_element_t<1, ::std::remove_const_t<T>>>(),
+                    requires_expr<convertible_to<decltype(::std::get<0>(t)), const ::std::tuple_element<0, T>&>>{},
+                    requires_expr<convertible_to<decltype(::std::get<1>(t)), const ::std::tuple_element<1, T>&>>{});
+};
+
+template <typename T>
+NANO_CONCEPT pair_like = !::std::is_reference_v<T> && decltype(pair_like_concept::test<T>(0))::value;
+
+struct pair_like_convertible_from_concept
+{
+    template <typename, typename, typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T, typename U, typename V, ::std::enable_if_t<!range<T>, int> = 0,
+              ::std::enable_if_t<pair_like<T>, int> = 0, ::std::enable_if_t<constructible_from<T, U, V>, int> = 0,
+              ::std::enable_if_t<convertible_to_non_slicing<U, ::std::tuple_element<0, T>>, int> = 0,
+              ::std::enable_if_t<convertible_to<V, ::std::tuple_element<1, T>>, int> = 0>
+    static auto
+    test(int) -> ::std::true_type;
+};
+
+template <typename T, typename U, typename V>
+NANO_CONCEPT pair_like_convertible_from = decltype(pair_like_convertible_from_concept::test<T, U, V>(0))::value;
+
+struct iterator_sentinel_pair_concept
+{
+    template <typename T>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename T>
+    static auto
+    test(int) -> ::std::enable_if_t<!range<T> && pair_like<T> &&
+                                        sentinel_for<::std::tuple_element_t<1, T>, ::std::tuple_element_t<0, T>>,
+                                    ::std::true_type>;
+};
+
+template <typename T>
+NANO_CONCEPT iterator_sentinel_pair = decltype(iterator_sentinel_pair_concept::test<T>(0))::value;
+
+template <typename I, typename S, bool StoreSize = false>
+struct subrange_data
+{
+    constexpr subrange_data() = default;
+
+    constexpr subrange_data(I&& begin, S&& end) : begin_(::std::move(begin)), end_(::std::move(end)) {}
+
+    constexpr subrange_data(I&& begin, S&& end, iter_difference_t<I> /*unused*/)
+        : begin_(::std::move(begin)), end_(::std::move(end))
+    {
+    }
+
+    I begin_{};
+    S end_{};
+};
+
+template <typename I, typename S>
+struct subrange_data<I, S, true>
+{
+    constexpr subrange_data() = default;
+
+    constexpr subrange_data(I&& begin, S&& end, iter_difference_t<I> size)
+        : begin_(::std::move(begin)), end_(::std::move(end)), size_(size)
+    {
+    }
+
+    I begin_{};
+    S end_{};
+    iter_difference_t<I> size_ = 0;
+};
+
+// MSVC gets confused if enable_if conditions in template param lists are too
+// complex, so give it some help by calculating the constraints in a helper
+// variable
+template <typename R, typename I, typename S, subrange_kind K>
+auto
+subrange_range_constructor_constraint_helper_fn(long) -> ::std::false_type;
+
+template <typename R, typename I, typename S, subrange_kind K>
+auto
+subrange_range_constructor_constraint_helper_fn(int)
+    -> ::std::enable_if_t<borrowed_range<R> && convertible_to_non_slicing<iterator_t<R>, I> &&
+                              convertible_to<sentinel_t<R>, S>,
+                          ::std::true_type>;
+
+template <typename R, typename I, typename S, subrange_kind K>
+constexpr bool subrange_range_constructor_constraint_helper =
+    decltype(subrange_range_constructor_constraint_helper_fn<R, I, S, K>(0))::value;
+
+template <typename R>
+constexpr subrange_kind
+subrange_deduction_guide_helper()
+{
+    return (sized_range<R> || sized_sentinel_for<sentinel_t<R>, iterator_t<R>>) ? subrange_kind::sized
+                                                                                : subrange_kind::unsized;
+}
+
+} // namespace detail
+
+namespace subrange_
+{
+
+template <typename I, typename S, subrange_kind K>
+class subrange : public view_interface<subrange<I, S, K>>
+{
+    static_assert(input_or_output_iterator<I>);
+    static_assert(sentinel_for<S, I>);
+    static_assert(K == subrange_kind::sized || !sized_sentinel_for<S, I>, "");
+
+  private:
+    static constexpr bool StoreSize = K == subrange_kind::sized && !sized_sentinel_for<S, I>;
+
+    detail::subrange_data<I, S, StoreSize> data_{};
+
+  public:
+    subrange() = default;
+
+    template <typename II, bool SS = StoreSize,
+              typename = ::std::enable_if_t<detail::convertible_to_non_slicing<II, I> && !SS>>
+    constexpr subrange(II i, S s) : data_{::std::move(i), ::std::move(s)}
+    {
+    }
+
+    template <typename II, subrange_kind KK = K,
+              typename = ::std::enable_if_t<detail::convertible_to_non_slicing<II, I> && KK == subrange_kind::sized>>
+    constexpr subrange(II i, S s, iter_difference_t<I> n) : data_{::std::move(i), ::std::move(s), n}
+    {
+    }
+
+    template <typename R, bool SS = StoreSize, ::std::enable_if_t<detail::not_same_as<R, subrange>, int> = 0,
+              ::std::enable_if_t<
+                  detail::subrange_range_constructor_constraint_helper<R, I, S, K> && SS && sized_range<R>, int> = 0>
+    constexpr subrange(R&& r) : subrange(ranges::begin(r), ranges::end(r), ranges::size(r))
+    {
+    }
+
+    template <typename R, bool SS = StoreSize, ::std::enable_if_t<detail::not_same_as<R, subrange>, int> = 0,
+              ::std::enable_if_t<detail::subrange_range_constructor_constraint_helper<R, I, S, K> && !SS, int> = 0>
+    constexpr subrange(R&& r) : subrange(ranges::begin(r), ranges::end(r))
+    {
+    }
+
+    template <typename R, subrange_kind KK = K,
+              ::std::enable_if_t<borrowed_range<R> && detail::convertible_to_non_slicing<iterator_t<R>, I> &&
+                                     convertible_to<sentinel_t<R>, S> && KK == subrange_kind::sized,
+                                 int> = 0>
+    constexpr subrange(R&& r, iter_difference_t<I> n) : subrange(ranges::begin(r), ranges::end(r), n)
+    {
+    }
+
+    template <typename PairLike_, ::std::enable_if_t<detail::not_same_as<PairLike_, subrange>, int> = 0,
+              ::std::enable_if_t<detail::pair_like_convertible_from<PairLike_, const I&, const S&>, int> = 0>
+    constexpr operator PairLike_() const
+    {
+        return PairLike_(begin(), end());
+    }
+
+    constexpr I
+    begin() const
+    {
+        return data_.begin_;
+    }
+
+    constexpr S
+    end() const
+    {
+        return data_.end_;
+    }
+
+    [[nodiscard]] constexpr bool
+    empty() const
+    {
+        return data_.begin_ == data_.end_;
+    }
+
+    template <subrange_kind KK = K>
+    constexpr auto
+    size() const -> ::std::enable_if_t<KK == subrange_kind::sized, iter_difference_t<I>>
+    {
+        if constexpr (StoreSize)
+        {
+            return data_.size_;
+        }
+        else
+        {
+            return data_.end_ - data_.begin_;
+        }
+    }
+
+    [[nodiscard]] constexpr subrange
+    next(iter_difference_t<I> n = 1) const
+    {
+        auto tmp = *this;
+        tmp.advance(n);
+        return tmp;
+    }
+
+    template <typename II = I>
+    [[nodiscard]] constexpr auto
+    prev(iter_difference_t<I> n = 1) const -> ::std::enable_if_t<bidirectional_iterator<II>, subrange>
+    {
+        auto tmp = *this;
+        tmp.advance(-n);
+        return tmp;
+    }
+
+    constexpr subrange&
+    advance(iter_difference_t<I> n)
+    {
+        if constexpr (StoreSize)
+        {
+            data_.size_ -= n - ranges::advance(data_.begin_, n, data_.end_);
+        }
+        else
+        {
+            ranges::advance(data_.begin_, n, data_.end_);
+        }
+        return *this;
+    }
+};
+
+template <typename I, typename S, ::std::enable_if_t<input_or_output_iterator<I> && sentinel_for<S, I>, int> = 0>
+subrange(I, S)->subrange<I, S>;
+
+template <typename I, typename S, ::std::enable_if_t<input_or_output_iterator<I> && sentinel_for<S, I>, int> = 0>
+subrange(I, S, iter_difference_t<I>)->subrange<I, S, subrange_kind::sized>;
+
+template <typename P, ::std::enable_if_t<detail::iterator_sentinel_pair<P>, int> = 0>
+subrange(P)->subrange<::std::tuple_element_t<0, P>, ::std::tuple_element_t<1, P>>;
+
+template <typename P, ::std::enable_if_t<detail::iterator_sentinel_pair<P>, int> = 0>
+subrange(P, iter_difference_t<::std::tuple_element_t<0, P>>)
+    ->subrange<::std::tuple_element_t<0, P>, ::std::tuple_element_t<1, P>, subrange_kind::sized>;
+
+template <typename R, ::std::enable_if_t<borrowed_range<R>, int> = 0>
+subrange(R &&)->subrange<iterator_t<R>, sentinel_t<R>, detail::subrange_deduction_guide_helper<R>()>;
+
+template <typename R, ::std::enable_if_t<borrowed_range<R>, int> = 0>
+subrange(R&&, iter_difference_t<iterator_t<R>>)->subrange<iterator_t<R>, sentinel_t<R>, subrange_kind::sized>;
+
+} // namespace subrange_
+
+template <typename I, typename S, subrange_kind K>
+inline constexpr bool enable_borrowed_range<subrange<I, S, K>> = true;
+
+template <::std::size_t N, typename I, typename S, subrange_kind K, ::std::enable_if_t<(N < 2), int> = 0>
+constexpr auto
+get(const subrange<I, S, K>& r)
+{
+    if constexpr (N == 0)
+    {
+        return r.begin();
+    }
+    else
+    {
+        return r.end();
+    }
+}
+
+template <typename R>
+using borrowed_subrange_t = detail::conditional_t<borrowed_range<R>, subrange<iterator_t<R>>, dangling>;
+
+NANO_END_NAMESPACE
+
+namespace std
+{
+
+template <typename I, typename S, __nanorange::nano::subrange_kind K>
+class tuple_size<__nanorange::nano::subrange<I, S, K>> : public integral_constant<size_t, 2>
+{
+};
+
+template <typename I, typename S, __nanorange::nano::subrange_kind K>
+class tuple_element<0, __nanorange::nano::subrange<I, S, K>>
+{
+  public:
+    using type = I;
+};
+
+template <typename I, typename S, __nanorange::nano::subrange_kind K>
+class tuple_element<1, __nanorange::nano::subrange<I, S, K>>
+{
+  public:
+    using type = S;
+};
+
+using __nanorange::nano::ranges::get;
+
+} // namespace std
+
+#        endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct equal_range_fn
+{
+  private:
+    template <typename I, typename S, typename T, typename Comp, typename Proj>
+    static constexpr subrange<I>
+    impl(I first, S last, const T& value, Comp& comp, Proj& proj)
+    {
+        return {lower_bound_fn::impl(first, last, value, comp, proj),
+                upper_bound_fn::impl(first, last, value, comp, proj)};
+    }
+
+  public:
+    template <typename I, typename S, typename T, typename Comp = ranges::less, typename Proj = identity>
+    ::std::enable_if_t<forward_iterator<I> && sentinel_for<S, I> &&
+                           indirect_strict_weak_order<Comp, const T*, projected<I, Proj>>,
+                       subrange<I>> constexpr
+    operator()(I first, S last, const T& value, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return equal_range_fn::impl(::std::move(first), ::std::move(last), value, comp, proj);
+    }
+
+    template <typename Rng, typename T, typename Comp = ranges::less, typename Proj = identity>
+    ::std::enable_if_t<forward_range<Rng> &&
+                           indirect_strict_weak_order<Comp, const T*, projected<iterator_t<Rng>, Proj>>,
+                       borrowed_subrange_t<Rng>> constexpr
+    operator()(Rng&& rng, const T& value, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return equal_range_fn::impl(nano::begin(rng), nano::end(rng), value, comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::equal_range_fn, equal_range)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/fill.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_FILL_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_FILL_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct fill_fn
+{
+  private:
+    template <typename T, typename O, typename S>
+    static constexpr O
+    impl(O first, S last, const T& value)
+    {
+        while (first != last)
+        {
+            *first = value;
+            ++first;
+        }
+
+        return first;
+    }
+
+  public:
+    template <typename T, typename O, typename S>
+    constexpr ::std::enable_if_t<output_iterator<O, const T&> && sentinel_for<S, O>, O>
+    operator()(O first, S last, const T& value) const
+    {
+        return fill_fn::impl(::std::move(first), ::std::move(last), value);
+    }
+
+    template <typename T, typename Rng>
+    constexpr ::std::enable_if_t<output_range<Rng, const T&>, borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, const T& value) const
+    {
+        return fill_fn::impl(nano::begin(rng), nano::end(rng), value);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::fill_fn, fill)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/fill_n.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_FILL_N_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_FILL_N_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct fill_n_fn
+{
+    template <typename T, typename O>
+    constexpr ::std::enable_if_t<output_iterator<O, const T&>, O>
+    operator()(O first, iter_difference_t<O> n, const T& value) const
+    {
+        for (iter_difference_t<O> i{0}; i < n; ++i, ++first)
+        {
+            *first = value;
+        }
+        return first;
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::fill_n_fn, fill_n)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/find.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_FIND_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_FIND_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+// [ranges.alg.find]
+
+namespace detail
+{
+
+struct find_if_fn
+{
+  private:
+    friend struct find_fn;
+    friend struct find_if_not_fn;
+
+    template <typename I, typename S, typename Pred, typename Proj>
+    static constexpr I
+    impl(I first, S last, Pred& pred, Proj& proj)
+    {
+        while (first != last)
+        {
+            if (nano::invoke(pred, nano::invoke(proj, *first)))
+            {
+                return first;
+            }
+            ++first;
+        }
+        return first;
+    }
+
+  public:
+    template <typename I, typename S, typename Proj = identity, typename Pred>
+    constexpr ::std::enable_if_t<
+        input_iterator<I> && sentinel_for<S, I> && indirect_unary_predicate<Pred, projected<I, Proj>>, I>
+    operator()(I first, S last, Pred pred, Proj proj = Proj{}) const
+    {
+        return find_if_fn::impl(::std::move(first), ::std::move(last), pred, proj);
+    }
+
+    template <typename Rng, typename Proj = identity, typename Pred>
+    constexpr ::std::enable_if_t<input_range<Rng> && indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, Pred pred, Proj proj = Proj{}) const
+    {
+        return find_if_fn::impl(nano::begin(rng), nano::end(rng), pred, proj);
+    }
+};
+} // namespace detail
+
+NANO_INLINE_VAR(detail::find_if_fn, find_if)
+
+namespace detail
+{
+
+struct find_fn
+{
+    template <typename I, typename S, typename T, typename Proj = identity>
+    constexpr ::std::enable_if_t<
+        input_iterator<I> && sentinel_for<S, I> && indirect_relation<ranges::equal_to, projected<I, Proj>, const T*>, I>
+    operator()(I first, S last, const T& value, Proj proj = Proj{}) const
+    {
+        const auto pred = [&value](const auto& t) { return t == value; };
+        return find_if_fn::impl(::std::move(first), ::std::move(last), pred, proj);
+    }
+
+    template <typename Rng, typename T, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_range<Rng> &&
+                                     indirect_relation<ranges::equal_to, projected<iterator_t<Rng>, Proj>, const T*>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, const T& value, Proj proj = Proj{}) const
+    {
+        const auto pred = [&value](const auto& t) { return t == value; };
+        return find_if_fn::impl(nano::begin(rng), nano::end(rng), pred, proj);
+    }
+};
+} // namespace detail
+
+NANO_INLINE_VAR(detail::find_fn, find)
+
+namespace detail
+{
+
+struct find_if_not_fn
+{
+  private:
+    template <typename Pred>
+    struct not_pred
+    {
+        Pred& p;
+
+        template <typename T>
+        constexpr bool
+        operator()(T&& t) const
+        {
+            return !nano::invoke(p, ::std::forward<T>(t));
+        }
+    };
+
+  public:
+    template <typename I, typename S, typename Proj = identity, typename Pred>
+    constexpr ::std::enable_if_t<
+        input_iterator<I> && sentinel_for<S, I> && indirect_unary_predicate<Pred, projected<I, Proj>>, I>
+    operator()(I first, S last, Pred pred, Proj proj = Proj{}) const
+    {
+        const auto find_if_pred = not_pred<Pred>{pred};
+        return find_if_fn::impl(::std::move(first), ::std::move(last), find_if_pred, proj);
+    }
+
+    template <typename Rng, typename Proj = identity, typename Pred>
+    constexpr ::std::enable_if_t<input_range<Rng> && indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, Pred pred, Proj proj = Proj{}) const
+    {
+        const auto find_if_pred = not_pred<Pred>{pred};
+        return find_if_fn::impl(nano::begin(rng), nano::end(rng), find_if_pred, proj);
+    }
+};
+} // namespace detail
+
+NANO_INLINE_VAR(detail::find_if_not_fn, find_if_not)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/find_end.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_FIND_END_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_FIND_END_HPP_INCLUDED
+
+// nanorange/algorithm/search.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_ALGORITHM_SEARCH_HPP_INCLUDED
+#            define NANORANGE_ALGORITHM_SEARCH_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct search_fn
+{
+  private:
+    friend struct find_end_fn;
+
+    template <typename I1, typename S1, typename I2, typename S2, typename Pred, typename Proj1,
+              typename Proj2 = identity>
+    static constexpr subrange<I1>
+    impl(I1 first1, S1 last1, I2 first2, S2 last2, Pred& pred, Proj1& proj1, Proj2& proj2)
+    {
+        while (true)
+        {
+            auto it1 = first1;
+            auto it2 = first2;
+
+            while (true)
+            {
+                if (it2 == last2)
+                {
+                    return {first1, it1};
+                }
+                if (it1 == last1)
+                {
+                    return {it1, it1};
+                }
+                if (!nano::invoke(pred, nano::invoke(proj1, *it1), nano::invoke(proj2, *it2)))
+                {
+                    break;
+                }
+                ++it1;
+                ++it2;
+            }
+
+            ++first1;
+        }
+    }
+
+  public:
+    template <typename I1, typename S1, typename I2, typename S2, typename Pred = ranges::equal_to,
+              typename Proj1 = identity, typename Proj2 = identity>
+    constexpr ::std::enable_if_t<forward_iterator<I1> && sentinel_for<S1, I1> && forward_iterator<I2> &&
+                                     sentinel_for<S2, I2> && indirectly_comparable<I1, I2, Pred, Proj1, Proj2>,
+                                 subrange<I1>>
+    operator()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = Pred{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return search_fn::impl(::std::move(first1), ::std::move(last1), ::std::move(first2), ::std::move(last2), pred,
+                               proj1, proj2);
+    }
+
+    template <typename Rng1, typename Rng2, typename Pred = ranges::equal_to, typename Proj1 = identity,
+              typename Proj2 = identity>
+    constexpr ::std::enable_if_t<forward_range<Rng1> && forward_range<Rng2> &&
+                                     indirectly_comparable<iterator_t<Rng1>, iterator_t<Rng2>, Pred, Proj1, Proj2>,
+                                 borrowed_subrange_t<Rng1>>
+    operator()(Rng1&& rng1, Rng2&& rng2, Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return search_fn::impl(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), nano::end(rng2), pred, proj1,
+                               proj2);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::search_fn, search)
+
+NANO_END_NAMESPACE
+
+#        endif
+
+NANO_BEGIN_NAMESPACE
+
+// [ranges.alg.find.end]
+namespace detail
+{
+
+// TODO: For BiDir iterators, we can be smarter and search backwards
+struct find_end_fn
+{
+  private:
+    template <typename I1, typename S1, typename I2, typename S2, typename Pred, typename Proj1, typename Proj2>
+    static constexpr subrange<I1>
+    impl(I1 first1, S1 last1, I2 first2, S2 last2, Pred& pred, Proj1& proj1, Proj2& proj2)
+    {
+        if (first2 == last2)
+        {
+            auto last_it = nano::next(first1, last1);
+            return {last_it, last_it};
+        }
+
+        auto result = search_fn::impl(::std::move(first1), last1, first2, last2, pred, proj1, proj2);
+
+        if (result.empty())
+        {
+            return result;
+        }
+
+        while (true)
+        {
+            auto new_result = search_fn::impl(next(result.begin()), last1, first2, last2, pred, proj1, proj2);
+            if (new_result.empty())
+            {
+                return result;
+            }
+            else
+            {
+                result = ::std::move(new_result);
+            }
+        }
+    }
+
+  public:
+    template <typename I1, typename S1, typename I2, typename S2, typename Pred = ranges::equal_to,
+              typename Proj1 = identity, typename Proj2 = identity>
+    constexpr ::std::enable_if_t<forward_iterator<I1> && sentinel_for<S1, I1> && forward_iterator<I2> &&
+                                     sentinel_for<S2, I2> && indirectly_comparable<I1, I2, Pred, Proj1, Proj2>,
+                                 subrange<I1>>
+    operator()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = Pred{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return find_end_fn::impl(::std::move(first1), ::std::move(last1), ::std::move(first2), ::std::move(last2), pred,
+                                 proj1, proj2);
+    }
+
+    template <typename Rng1, typename Rng2, typename Pred = ranges::equal_to, typename Proj1 = identity,
+              typename Proj2 = identity>
+    constexpr ::std::enable_if_t<forward_range<Rng1> && forward_range<Rng2> &&
+                                     indirectly_comparable<iterator_t<Rng1>, iterator_t<Rng2>, Pred, Proj1, Proj2>,
+                                 borrowed_subrange_t<Rng1>>
+    operator()(Rng1&& rng1, Rng2&& rng2, Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return find_end_fn::impl(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), nano::end(rng2), pred, proj1,
+                                 proj2);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::find_end_fn, find_end)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/find_first_of.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_FIND_FIRST_OF_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_FIND_FIRST_OF_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+// [range.alg.find.first.of]
+
+namespace detail
+{
+
+struct find_first_of_fn
+{
+  private:
+    template <typename I1, typename S1, typename I2, typename S2, typename Pred, typename Proj1, typename Proj2>
+    static constexpr I1
+    impl(I1 first1, S1 last1, I2 first2, S2 last2, Pred& pred, Proj1& proj1, Proj2& proj2)
+    {
+        for (; first1 != last1; ++first1)
+        {
+            for (I2 it = first2; it != last2; ++it)
+            {
+                if (nano::invoke(pred, nano::invoke(proj1, *first1), nano::invoke(proj2, *it)))
+                {
+                    return first1;
+                }
+            }
+        }
+
+        return first1;
+    }
+
+  public:
+    template <typename I1, typename S1, typename I2, typename S2, typename Proj1 = identity, typename Proj2 = identity,
+              typename Pred = ranges::equal_to>
+    constexpr ::std::enable_if_t<input_iterator<I1> && sentinel_for<S1, I1> && forward_iterator<I2> &&
+                                     sentinel_for<S2, I2> &&
+                                     indirect_relation<Pred, projected<I1, Proj1>, projected<I2, Proj2>>,
+                                 I1>
+    operator()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = Pred{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return find_first_of_fn::impl(::std::move(first1), ::std::move(last1), ::std::move(first2), ::std::move(last2),
+                                      pred, proj1, proj2);
+    }
+
+    template <typename Rng1, typename Rng2, typename Proj1 = identity, typename Proj2 = identity,
+              typename Pred = ranges::equal_to>
+    constexpr ::std::enable_if_t<
+        input_range<Rng1> && forward_range<Rng2> &&
+            indirect_relation<Pred, projected<iterator_t<Rng1>, Proj1>, projected<iterator_t<Rng2>, Proj2>>,
+        borrowed_iterator_t<Rng1>>
+    operator()(Rng1&& rng1, Rng2&& rng2, Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return find_first_of_fn::impl(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), nano::end(rng2), pred,
+                                      proj1, proj2);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::find_first_of_fn, find_first_of)
+
+NANO_END_NAMESPACE
+
+#    endif
+// nanorange/algorithm/for_each.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_FOR_EACH_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_FOR_EACH_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+// [range.alg.foreach]
+
+template <typename I, typename F>
+using for_each_result = in_fun_result<I, F>;
+
+namespace detail
+{
+
+struct for_each_fn
+{
+  private:
+    template <typename I, typename S, typename Proj, typename Fun>
+    static constexpr for_each_result<I, Fun>
+    impl(I first, S last, Fun& fun, Proj& proj)
+    {
+        while (first != last)
+        {
+            nano::invoke(fun, nano::invoke(proj, *first));
+            ++first;
+        }
+        return {first, ::std::move(fun)};
+    }
+
+  public:
+    template <typename I, typename S, typename Proj = identity, typename Fun>
+    constexpr ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> &&
+                                     indirect_unary_invocable<Fun, projected<I, Proj>>,
+                                 for_each_result<I, Fun>>
+    operator()(I first, S last, Fun fun, Proj proj = Proj{}) const
+    {
+        return for_each_fn::impl(::std::move(first), ::std::move(last), fun, proj);
+    }
+
+    template <typename Rng, typename Proj = identity, typename Fun>
+    constexpr ::std::enable_if_t<input_range<Rng> && indirect_unary_invocable<Fun, projected<iterator_t<Rng>, Proj>>,
+                                 for_each_result<borrowed_iterator_t<Rng>, Fun>>
+    operator()(Rng&& rng, Fun fun, Proj proj = Proj{}) const
+    {
+        return for_each_fn::impl(nano::begin(rng), nano::end(rng), fun, proj);
+    }
+};
+} // namespace detail
+
+NANO_INLINE_VAR(detail::for_each_fn, for_each)
+
+template <typename I, typename F>
+using for_each_n_result = in_fun_result<I, F>;
+
+namespace detail
+{
+
+struct for_each_n_fn
+{
+    template <typename I, typename Proj = identity, typename Fun>
+    constexpr ::std::enable_if_t<input_iterator<I> && indirect_unary_invocable<Fun, projected<I, Proj>>,
+                                 for_each_n_result<I, Fun>>
+    operator()(I first, iter_difference_t<I> n, Fun fun, Proj proj = Proj{}) const
+    {
+        while (n-- > 0)
+        {
+            nano::invoke(fun, nano::invoke(proj, *first));
+            ++first;
+        }
+        return {::std::move(first), ::std::move(fun)};
+    }
+};
+} // namespace detail
+
+NANO_INLINE_VAR(detail::for_each_n_fn, for_each_n)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/generate.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_GENERATE_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_GENERATE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct generate_fn
+{
+  private:
+    template <typename O, typename S, typename F>
+    static constexpr O
+    impl(O first, S last, F& gen)
+    {
+        while (first != last)
+        {
+            *first = gen();
+            ++first;
+        }
+
+        return first;
+    }
+
+  public:
+    template <typename O, typename S, typename F>
+    constexpr ::std::enable_if_t<input_or_output_iterator<O> && sentinel_for<S, O> && copy_constructible<F> &&
+                                     invocable<F&> && writable<O, invoke_result_t<F&>>,
+                                 O>
+    operator()(O first, S last, F gen) const
+    {
+        return generate_fn::impl(::std::move(first), ::std::move(last), gen);
+    }
+
+    template <typename Rng, typename F>
+    constexpr ::std::enable_if_t<invocable<F&> && output_range<Rng, invoke_result_t<F&>>, borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, F gen) const
+    {
+        return generate_fn::impl(nano::begin(rng), nano::end(rng), gen);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::generate_fn, generate)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/generate_n.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_GENERATE_N_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_GENERATE_N_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct generate_n_fn
+{
+    template <typename O, typename F>
+    constexpr ::std::enable_if_t<
+        input_or_output_iterator<O> && copy_constructible<F> && invocable<F&> && writable<O, invoke_result_t<F&>>, O>
+    operator()(O first, iter_difference_t<O> n, F gen) const
+    {
+        for (iter_difference_t<O> i{0}; i < n; ++i, ++first)
+        {
+            *first = gen();
+        }
+
+        return first;
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::generate_n_fn, generate_n)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/includes.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_INCLUDES_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_INCLUDES_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct includes_fn
+{
+  private:
+    template <typename I1, typename S1, typename I2, typename S2, typename Comp, typename Proj1, typename Proj2>
+    static constexpr bool
+    impl(I1 first1, S1 last1, I2 first2, S2 last2, Comp& comp, Proj1& proj1, Proj2& proj2)
+    {
+        while (first2 != last2)
+        {
+            // If range1 is done but we still have elements in range2, then
+            // it is not a subset
+            if (first1 == last1)
+            {
+                return false;
+            }
+
+            // If the current element of r2 is less than the current
+            // element of r1, then it is not in r1 => not a subset
+            if (nano::invoke(comp, nano::invoke(proj2, *first2), nano::invoke(proj1, *first1)))
+            {
+                return false;
+            }
+
+            // Now we know that that !(r2 < r1). If we also have !(r1 < r2),
+            // then it must be equal, so in range1 -- so move onto the next
+            // element
+            if (!nano::invoke(comp, nano::invoke(proj1, *first1), nano::invoke(proj2, *first2)))
+            {
+                ++first2;
+            }
+
+            ++first1;
+        }
+
+        return true;
+    }
+
+  public:
+    template <typename I1, typename S1, typename I2, typename S2, typename Comp = ranges::less,
+              typename Proj1 = identity, typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_iterator<I1> && sentinel_for<S1, I1> && input_iterator<I2> &&
+                                     sentinel_for<S2, I2> &&
+                                     indirect_strict_weak_order<Comp, projected<I1, Proj1>, projected<I2, Proj2>>,
+                                 bool>
+    operator()(I1 first1, S1 last1, I2 first2, S2 last2, Comp comp = Comp{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return includes_fn::impl(::std::move(first1), ::std::move(last1), ::std::move(first2), ::std::move(last2), comp,
+                                 proj1, proj2);
+    }
+
+    template <typename Rng1, typename Rng2, typename Comp = ranges::less, typename Proj1 = identity,
+              typename Proj2 = identity>
+    constexpr ::std::enable_if_t<
+        input_range<Rng1> && input_range<Rng2> &&
+            indirect_strict_weak_order<Comp, projected<iterator_t<Rng1>, Proj1>, projected<iterator_t<Rng2>, Proj2>>,
+        bool>
+    operator()(Rng1&& rng1, Rng2&& rng2, Comp comp = Comp{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return includes_fn::impl(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), nano::end(rng2), comp, proj1,
+                                 proj2);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::includes_fn, includes)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/inplace_merge.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+// Uses code from cmcstl2 - A concept-enabled C++ standard library
+//
+//  Copyright Eric Niebler 2014
+//  Copyright Casey Carter 2015
+//
+
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#    ifndef NANORANGE_ALGORITHM_INPLACE_MERGE_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_INPLACE_MERGE_HPP_INCLUDED
+
+// nanorange/algorithm/merge.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_ALGORITHM_MERGE_HPP_INCLUDED
+#            define NANORANGE_ALGORITHM_MERGE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I1, typename I2, typename O>
+using merge_result = in_in_out_result<I1, I2, O>;
+
+namespace detail
+{
+
+struct merge_fn
+{
+  private:
+    template <typename I1, typename S1, typename I2, typename S2, typename O, typename Comp, typename Proj1,
+              typename Proj2>
+    static constexpr merge_result<I1, I2, O>
+    impl(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp& comp, Proj1& proj1, Proj2& proj2)
+    {
+        while (first1 != last1)
+        {
+            // If we've reached the end of the second range, copy any remaining
+            // elements from the first range directly
+            if (first2 == last2)
+            {
+                auto res = nano::copy(::std::move(first1), ::std::move(last1), ::std::move(result));
+                first1 = ::std::move(res.in);
+                result = ::std::move(res.out);
+                break;
+            }
+
+            // (Only) if the element from range2 compares less than the element
+            // from range1, copy it. Otherwise copy the element from the first
+            if (nano::invoke(comp, nano::invoke(proj2, *first2), nano::invoke(proj1, *first1)))
+            {
+                *result = *first2;
+                ++first2;
+            }
+            else
+            {
+                *result = *first1;
+                ++first1;
+            }
+            ++result;
+        }
+
+        // We've reached the end of range1, so copy any remaining elements
+        // from range2
+        auto res = nano::copy(::std::move(first2), ::std::move(last2), ::std::move(result));
+        first2 = ::std::move(res.in);
+        result = ::std::move(res.out);
+
+        return {::std::move(first1), ::std::move(first2), ::std::move(result)};
+    }
+
+  public:
+    template <typename I1, typename S1, typename I2, typename S2, typename O, typename Comp = ranges::less,
+              typename Proj1 = identity, typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_iterator<I1> && sentinel_for<S1, I1> && input_iterator<I2> &&
+                                     sentinel_for<S2, I2> && weakly_incrementable<O> &&
+                                     mergeable<I1, I2, O, Comp, Proj1, Proj1>,
+                                 merge_result<I1, I2, O>>
+    operator()(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp comp = Comp{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return merge_fn::impl(::std::move(first1), ::std::move(last1), ::std::move(first2), ::std::move(last2),
+                              ::std::move(result), comp, proj1, proj2);
+    }
+
+    template <typename Rng1, typename Rng2, typename O, typename Comp = ranges::less, typename Proj1 = identity,
+              typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_range<Rng1> && input_range<Rng2> && weakly_incrementable<O> &&
+                                     mergeable<iterator_t<Rng1>, iterator_t<Rng2>, O, Comp, Proj1, Proj2>,
+                                 merge_result<borrowed_iterator_t<Rng1>, borrowed_iterator_t<Rng2>, O>>
+    operator()(Rng1&& rng1, Rng2&& rng2, O result, Comp comp = Comp{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return merge_fn::impl(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), nano::end(rng2),
+                              ::std::move(result), comp, proj1, proj2);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::merge_fn, merge)
+
+NANO_END_NAMESPACE
+
+#        endif
+
+// nanorange/algorithm/min.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_ALGORITHM_MIN_HPP_INCLUDED
+#            define NANORANGE_ALGORITHM_MIN_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct min_fn
+{
+  private:
+    template <typename Rng, typename Comp, typename Proj>
+    static constexpr iter_value_t<iterator_t<Rng>>
+    impl(Rng&& rng, Comp& comp, Proj& proj)
+    {
+        auto first = nano::begin(rng);
+        const auto last = nano::end(rng);
+
+        // Empty ranges not allowed
+        auto result = *first;
+
+        while (++first != last)
+        {
+            auto&& val = *first;
+            if (nano::invoke(comp, nano::invoke(proj, val), nano::invoke(proj, result)))
+            {
+                result = ::std::forward<decltype(val)>(val);
+            }
+        }
+
+        return result;
+    }
+
+  public:
+    template <typename T, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<indirect_strict_weak_order<Comp, projected<const T*, Proj>>, const T&>
+    operator()(const T& a, const T& b, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return nano::invoke(comp, nano::invoke(proj, b), nano::invoke(proj, a)) ? b : a;
+    }
+
+    template <typename T, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<copyable<T> && indirect_strict_weak_order<Comp, projected<const T*, Proj>>, T>
+    operator()(::std::initializer_list<T> rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return min_fn::impl(rng, comp, proj);
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_range<Rng> && copyable<iter_value_t<iterator_t<Rng>>> &&
+                                     indirect_strict_weak_order<Comp, projected<iterator_t<Rng>, Proj>>,
+                                 range_value_t<Rng>>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return min_fn::impl(::std::forward<Rng>(rng), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::min_fn, min)
+
+NANO_END_NAMESPACE
+
+#        endif
+
+// nanorange/algorithm/move.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_ALGORITHM_MOVE_HPP_INCLUDED
+#            define NANORANGE_ALGORITHM_MOVE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I, typename O>
+using move_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct move_fn
+{
+  private:
+    template <typename I, typename S, typename O>
+    static constexpr ::std::enable_if_t<sized_sentinel_for<S, I>, move_result<I, O>>
+    impl(I first, S last, O result, priority_tag<1>)
+    {
+        const auto dist = last - first;
+
+        for (iter_difference_t<I> i{0}; i < dist; i++)
+        {
+            *result = nano::iter_move(first);
+            ++first;
+            ++result;
+        }
+
+        return {::std::move(first), ::std::move(result)};
+    }
+
+    template <typename I, typename S, typename O>
+    static constexpr move_result<I, O>
+    impl(I first, S last, O result, priority_tag<0>)
+    {
+        while (first != last)
+        {
+            *result = nano::iter_move(first);
+            ++first;
+            ++result;
+        }
+
+        return {::std::move(first), ::std::move(result)};
+    }
+
+  public:
+    template <typename I, typename S, typename O>
+    constexpr ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> && weakly_incrementable<O> &&
+                                     indirectly_movable<I, O>,
+                                 move_result<I, O>>
+    operator()(I first, S last, O result) const
+    {
+        return move_fn::impl(::std::move(first), ::std::move(last), ::std::move(result), priority_tag<1>{});
+    }
+
+    template <typename Rng, typename O>
+    constexpr ::std::enable_if_t<input_range<Rng> && weakly_incrementable<O> && indirectly_movable<iterator_t<Rng>, O>,
+                                 move_result<borrowed_iterator_t<Rng>, O>>
+    operator()(Rng&& rng, O result) const
+    {
+        return move_fn::impl(nano::begin(rng), nano::end(rng), ::std::move(result), priority_tag<1>{});
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::move_fn, move)
+
+template <typename I, typename O>
+using move_backward_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct move_backward_fn
+{
+  private:
+    template <typename I, typename O>
+    static constexpr move_backward_result<I, O>
+    impl(I first, I last, O result)
+    {
+        auto it = last;
+
+        while (it != first)
+        {
+            *--result = nano::iter_move(--it);
+        }
+
+        return {::std::move(last), ::std::move(result)};
+    }
+
+    template <typename I, typename S, typename O>
+    static constexpr ::std::enable_if_t<!same_as<I, S>, move_backward_result<I, O>>
+    impl(I first, S sent, O result)
+    {
+        I last = nano::next(first, sent);
+        return impl(::std::move(first), ::std::move(last), ::std::move(result));
+    }
+
+  public:
+    template <typename I, typename S, typename O>
+    constexpr ::std::enable_if_t<bidirectional_iterator<I> && sentinel_for<S, I> && bidirectional_iterator<O> &&
+                                     indirectly_movable<I, O>,
+                                 move_backward_result<I, O>>
+    operator()(I first, S last, O result) const
+    {
+        return move_backward_fn::impl(::std::move(first), ::std::move(last), ::std::move(result));
+    }
+
+    template <typename Rng, typename O>
+    constexpr ::std::enable_if_t<bidirectional_range<Rng> && bidirectional_iterator<O> &&
+                                     indirectly_movable<iterator_t<Rng>, O>,
+                                 move_backward_result<borrowed_iterator_t<Rng>, O>>
+    operator()(Rng&& rng, O result) const
+    {
+        return move_backward_fn::impl(nano::begin(rng), nano::end(rng), ::std::move(result));
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::move_backward_fn, move_backward)
+
+NANO_END_NAMESPACE
+
+#        endif
+
+// nanorange/algorithm/rotate.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_ALGORITHM_ROTATE_HPP_INCLUDED
+#            define NANORANGE_ALGORITHM_ROTATE_HPP_INCLUDED
+
+// nanorange/algorithm/swap_ranges.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#            ifndef NANORANGE_ALGORITHM_SWAP_RANGES_HPP_INCLUDED
+#                define NANORANGE_ALGORITHM_SWAP_RANGES_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I1, typename I2>
+using swap_ranges_result = in_in_result<I1, I2>;
+
+namespace detail
+{
+
+struct swap_ranges_fn
+{
+    template <typename I1, typename S1, typename I2, typename S2>
+    static constexpr swap_ranges_result<I1, I2>
+    impl4(I1 first1, S1 last1, I2 first2, S2 last2)
+    {
+        while (first1 != last1 && first2 != last2)
+        {
+            nano::iter_swap(first1, first2);
+            ++first1;
+            ++first2;
+        }
+        return {::std::move(first1), ::std::move(first2)};
+    }
+
+    template <typename I1, typename S1, typename I2>
+    static constexpr swap_ranges_result<I1, I2>
+    impl3(I1 first1, S1 last1, I2 first2)
+    {
+        while (first1 != last1)
+        {
+            nano::iter_swap(first1, first2);
+            ++first1;
+            ++first2;
+        }
+        return {::std::move(first1), ::std::move(first2)};
+    }
+
+  public:
+    template <typename I1, typename S1, typename I2, typename S2>
+    constexpr ::std::enable_if_t<forward_iterator<I1> && sentinel_for<S1, I1> && forward_iterator<I2> &&
+                                     sentinel_for<S2, I2> && indirectly_swappable<I1, I2>,
+                                 swap_ranges_result<I1, I2>>
+    operator()(I1 first1, S1 last1, I2 first2, S2 last2) const
+    {
+        return swap_ranges_fn::impl4(::std::move(first1), ::std::move(last1), ::std::move(first2), ::std::move(last2));
+    }
+
+    template <typename I1, typename S1, typename I2>
+    NANO_DEPRECATED constexpr ::std::enable_if_t<forward_iterator<I1> && sentinel_for<S1, I1> && forward_iterator<I2> &&
+                                                     indirectly_swappable<I1, I2>,
+                                                 swap_ranges_result<I1, I2>>
+    operator()(I1 first1, S1 last1, I2 first2) const
+    {
+        return swap_ranges_fn::impl3(::std::move(first1), ::std::move(last1), ::std::move(first2));
+    }
+
+    template <typename Rng1, typename Rng2>
+    constexpr ::std::enable_if_t<forward_range<Rng1> && forward_range<Rng2> &&
+                                     indirectly_swappable<iterator_t<Rng1>, iterator_t<Rng2>>,
+                                 swap_ranges_result<borrowed_iterator_t<Rng1>, borrowed_iterator_t<Rng2>>>
+    operator()(Rng1&& rng1, Rng2&& rng2) const
+    {
+        return swap_ranges_fn::impl4(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), nano::end(rng2));
+    }
+
+    template <typename Rng1, typename I2>
+    NANO_DEPRECATED constexpr ::std::enable_if_t<forward_range<Rng1> && forward_iterator<I2> &&
+                                                     indirectly_swappable<iterator_t<Rng1>, I2>,
+                                                 swap_ranges_result<borrowed_iterator_t<Rng1>, I2>>
+    operator()(Rng1&& rng1, I2 first2) const
+    {
+        return swap_ranges_fn::impl3(nano::begin(rng1), nano::end(rng1), ::std::move(first2));
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::swap_ranges_fn, swap_ranges)
+
+NANO_END_NAMESPACE
+
+#            endif
+
+// nanorange/iterator/unreachable.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#            ifndef NANORANGE_ITERATOR_UNREACHABLE_HPP_INCLUDED
+#                define NANORANGE_ITERATOR_UNREACHABLE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+// [range.unreachable.sentinels]
+
+struct unreachable_sentinel_t
+{
+    template <typename I>
+    friend constexpr ::std::enable_if_t<weakly_incrementable<I>, bool>
+    operator==(const I&, unreachable_sentinel_t) noexcept
+    {
+        return false;
+    }
+
+    template <typename I>
+    friend constexpr ::std::enable_if_t<weakly_incrementable<I>, bool>
+    operator==(unreachable_sentinel_t, const I&) noexcept
+    {
+        return false;
+    }
+
+    template <typename I>
+    friend constexpr ::std::enable_if_t<weakly_incrementable<I>, bool>
+    operator!=(const I&, unreachable_sentinel_t) noexcept
+    {
+        return true;
+    }
+
+    template <typename I>
+    friend constexpr ::std::enable_if_t<weakly_incrementable<I>, bool>
+    operator!=(unreachable_sentinel_t, const I&) noexcept
+    {
+        return true;
+    }
+};
+
+inline constexpr unreachable_sentinel_t unreachable_sentinel{};
+
+NANO_END_NAMESPACE
+
+#            endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct rotate_fn
+{
+  private:
+    template <typename I, typename S>
+    static constexpr subrange<I>
+    do_rotate_one_left(I first, S last)
+    {
+        // Stash the first element and move everything one place
+        iter_value_t<I> val = nano::iter_move(first);
+        auto ret = nano::move(nano::next(first), ::std::move(last), first);
+        *ret.out = ::std::move(val);
+        return {::std::move(ret.out), ::std::move(ret.in)};
+    }
+
+    template <typename I>
+    static constexpr subrange<I>
+    do_rotate_one_right(I first, I middle)
+    {
+        I last = nano::next(middle);
+        iter_value_t<I> val = nano::iter_move(middle);
+        nano::move_backward(first, middle, last);
+        *first = ::std::move(val);
+        return {::std::move(++first), ::std::move(last)};
+    }
+
+    template <typename I, typename S>
+    static constexpr ::std::enable_if_t<random_access_iterator<I> && sized_sentinel_for<S, I>, subrange<I>>
+    do_rotate(I first, I middle, S last, priority_tag<2>)
+    {
+        constexpr bool is_tma = ::std::is_trivially_move_assignable<iter_value_t<I>>::value;
+
+        auto i = nano::distance(first, middle);
+        auto j = nano::distance(first, last) - i;
+        I out = first + (last - middle);
+
+        while (i != j)
+        {
+            if (i > j)
+            {
+                if (is_tma && j == 1)
+                {
+                    do_rotate_one_right(middle - i, middle);
+                    return {::std::move(out), nano::next(first, last)};
+                }
+                nano::swap_ranges(middle - i, unreachable_sentinel, middle, middle + j);
+                i -= j;
+            }
+            else
+            {
+                if (is_tma && i == 1)
+                {
+                    do_rotate_one_left(middle - i, middle + j);
+                    return {::std::move(out), nano::next(first, last)};
+                }
+                nano::swap_ranges(middle - i, middle, middle + j - i, unreachable_sentinel);
+                j -= i;
+            }
+        }
+        nano::swap_ranges(middle - i, middle, middle, unreachable_sentinel);
+
+        return {::std::move(out), nano::next(first, last)};
+    }
+
+    template <typename I, typename S>
+    static constexpr ::std::enable_if_t<bidirectional_iterator<I>, subrange<I>>
+    do_rotate(I first, I middle, S last, priority_tag<1>)
+    {
+        if (::std::is_trivially_move_assignable<iter_value_t<I>>::value && nano::next(middle) == last)
+        {
+            return do_rotate_one_right(::std::move(first), ::std::move(middle));
+        }
+
+        return do_rotate(::std::move(first), ::std::move(middle), ::std::move(last), priority_tag<0>{});
+    }
+
+    template <typename I, typename S>
+    static constexpr subrange<I>
+    do_rotate(I first, I middle, S last, priority_tag<0>)
+    {
+        if (::std::is_trivially_move_assignable<iter_value_t<I>>::value && nano::next(first) == middle)
+        {
+            return do_rotate_one_left(::std::move(first), ::std::move(last));
+        }
+
+        if (sized_sentinel_for<I, I> && sized_sentinel_for<S, I> &&
+            nano::distance(first, middle) == nano::distance(middle, last))
+        {
+            auto ret = nano::swap_ranges(first, middle, middle, unreachable_sentinel);
+            return {::std::move(ret.in1), ::std::move(ret.in2)};
+        }
+
+        I next = middle;
+
+        do
+        {
+            nano::iter_swap(first++, next++);
+            if (first == middle)
+            {
+                middle = next;
+            }
+        } while (next != last);
+
+        I ret = first;
+        next = middle;
+
+        while (next != last)
+        {
+            nano::iter_swap(first++, next++);
+            if (first == middle)
+            {
+                middle = next;
+            }
+            else if (next == last)
+            {
+                next = middle;
+            }
+        }
+
+        return {::std::move(ret), ::std::move(next)};
+    }
+
+    template <typename I, typename S>
+    static constexpr subrange<I>
+    impl(I first, I middle, S last)
+    {
+        if (first == middle)
+        {
+            auto ret = nano::next(first, last);
+            return {ret, ret};
+        }
+        if (middle == last)
+        {
+            return {first, middle};
+        }
+
+        return do_rotate(::std::move(first), ::std::move(middle), ::std::move(last), priority_tag<2>{});
+    }
+
+  public:
+    template <typename I, typename S>
+    constexpr ::std::enable_if_t<forward_iterator<I> && sentinel_for<S, I> && permutable<I>, subrange<I>>
+    operator()(I first, I middle, S last) const
+    {
+        return rotate_fn::impl(::std::move(first), ::std::move(middle), ::std::move(last));
+    }
+
+    template <typename Rng>
+    constexpr ::std::enable_if_t<forward_range<Rng> && permutable<iterator_t<Rng>>, borrowed_subrange_t<Rng>>
+    operator()(Rng&& rng, iterator_t<Rng> middle) const
+    {
+        return rotate_fn::impl(nano::begin(rng), ::std::move(middle), nano::end(rng));
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::rotate_fn, rotate)
+
+NANO_END_NAMESPACE
+
+#        endif
+
+// nanorange/detail/memory/temporary_vector.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_DETAIL_MEMORY_TEMPORARY_VECTOR_HPP_INCLUDED
+#            define NANORANGE_DETAIL_MEMORY_TEMPORARY_VECTOR_HPP_INCLUDED
+
+// nanorange/memory/destroy.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#            ifndef NANORANGE_MEMORY_DESTROY_HPP_INCLUDED
+#                define NANORANGE_MEMORY_DESTROY_HPP_INCLUDED
+
+// nanorange/detail/memory/concepts.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                ifndef NANORANGE_DETAIL_MEMORY_CONCEPTS_HPP_INCLUDED
+#                    define NANORANGE_DETAIL_MEMORY_CONCEPTS_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct no_throw_input_iterator_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename I>
+    static auto
+    test(int) -> ::std::enable_if_t<input_iterator<I>&& ::std::is_lvalue_reference<iter_reference_t<I>>::value &&
+                                        same_as<remove_cvref_t<iter_reference_t<I>>, iter_value_t<I>>,
+                                    ::std::true_type>;
+};
+
+template <typename I>
+NANO_CONCEPT no_throw_input_iterator = decltype(no_throw_input_iterator_concept::test<I>(0))::value;
+
+template <typename S, typename I>
+NANO_CONCEPT no_throw_sentinel = sentinel_for<S, I>;
+
+struct no_throw_input_range_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename R>
+    static auto
+    test(int) -> ::std::enable_if_t<range<R> && no_throw_input_iterator<iterator_t<R>> &&
+                                        no_throw_sentinel<sentinel_t<R>, iterator_t<R>>,
+                                    ::std::true_type>;
+};
+
+template <typename R>
+NANO_CONCEPT no_throw_input_range = decltype(no_throw_input_range_concept::test<R>(0))::value;
+
+template <typename I>
+NANO_CONCEPT no_throw_forward_iterator = no_throw_input_iterator<I>&& forward_iterator<I>&& no_throw_sentinel<I, I>;
+
+struct no_throw_forward_range_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename R>
+    static auto
+    test(int)
+        -> ::std::enable_if_t<no_throw_input_range<R> && no_throw_forward_iterator<iterator_t<R>>, ::std::true_type>;
+};
+
+template <typename R>
+NANO_CONCEPT no_throw_forward_range = decltype(no_throw_forward_range_concept::test<R>(0))::value;
+
+template <typename T>
+void*
+voidify(T& ptr) noexcept
+{
+    return const_cast<void*>(static_cast<const volatile void*>(::std::addressof(ptr)));
+}
+
+} // namespace detail
+
+NANO_END_NAMESPACE
+
+#                endif
+
+// nanorange/iterator/counted_iterator.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                ifndef NANORANGE_ITERATOR_COUNTED_ITERATOR_HPP_INCLUDED
+#                    define NANORANGE_ITERATOR_COUNTED_ITERATOR_HPP_INCLUDED
+
+// nanorange/iterator/default_sentinel.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#                    ifndef NANORANGE_ITERATOR_DEFAULT_SENTINEL_HPP_INCLUDED
+#                        define NANORANGE_ITERATOR_DEFAULT_SENTINEL_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+struct default_sentinel_t
+{
+};
+
+inline constexpr default_sentinel_t default_sentinel{};
+
+NANO_END_NAMESPACE
+
+#                    endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace counted_iterator_
+{
+
+template <typename I>
+class counted_iterator
+{
+  public:
+    using iterator = I;
+    using difference_type = iter_difference_t<I>;
+
+  private:
+    I current_{};
+    iter_difference_t<I> cnt_{0};
+
+    static_assert(input_or_output_iterator<I>, "");
+
+    template <typename I2>
+    friend class counted_iterator;
+
+  public:
+    constexpr counted_iterator() = default;
+
+    constexpr counted_iterator(I x, iter_difference_t<I> n) : current_(x), cnt_(n) {}
+
+    template <typename I2, ::std::enable_if_t<convertible_to<I2, I>, int> = 0>
+    constexpr counted_iterator(const counted_iterator<I2>& i) : current_(i.current_), cnt_(i.cnt_)
+    {
+    }
+
+    template <typename I2>
+    constexpr auto
+    operator=(const counted_iterator<I2>& i) -> ::std::enable_if_t<convertible_to<I2, I>, counted_iterator&>
+    {
+        current_ = i.current_;
+        cnt_ = i.cnt_;
+        return *this;
+    }
+
+    constexpr I
+    base() const
+    {
+        return current_;
+    }
+
+    constexpr iter_difference_t<I>
+    count() const
+    {
+        return cnt_;
+    }
+
+    constexpr decltype(auto) operator*() { return *current_; }
+
+    template <typename II = I, ::std::enable_if_t<detail::dereferenceable<const II>, int> = 0>
+    constexpr decltype(auto) operator*() const
+    {
+        return *current_;
+    }
+
+    constexpr counted_iterator&
+    operator++()
+    {
+        ++current_;
+        --cnt_;
+        return *this;
+    }
+
+    template <typename II = I, ::std::enable_if_t<!forward_iterator<II>, int> = 0>
+    decltype(auto)
+    operator++(int)
+    {
+        --cnt_;
+        try
+        {
+            return current_++;
+        }
+        catch (...)
+        {
+            ++cnt_;
+            throw;
+        }
+    }
+
+    template <typename II = I>
+    constexpr auto
+    operator++(int) -> ::std::enable_if_t<forward_iterator<II>, counted_iterator>
+    {
+        auto tmp = *this;
+        ++*this;
+        return tmp;
+    }
+
+    template <typename II = I>
+    constexpr auto
+    operator--() -> ::std::enable_if_t<bidirectional_iterator<II>, counted_iterator&>
+    {
+        --current_;
+        ++cnt_;
+        return *this;
+    }
+
+    template <typename II = I>
+    constexpr auto
+    operator--(int) -> ::std::enable_if_t<bidirectional_iterator<II>, counted_iterator>
+    {
+        auto tmp = *this;
+        --*this;
+        return tmp;
+    }
+
+    template <typename II = I>
+    constexpr auto
+    operator+(difference_type n) const -> ::std::enable_if_t<random_access_iterator<II>, counted_iterator>
+    {
+        return counted_iterator(current_ + n, cnt_ - n);
+    }
+
+    template <typename II = I, ::std::enable_if_t<random_access_iterator<II>, int> = 0>
+    friend constexpr counted_iterator
+    operator+(iter_difference_t<II> n, const counted_iterator<II>& x)
+    {
+        return x + n;
+    }
+
+    template <typename II = I>
+    constexpr auto
+    operator+=(difference_type n) -> ::std::enable_if_t<random_access_iterator<II>, counted_iterator&>
+    {
+        current_ += n;
+        cnt_ -= n;
+        return *this;
+    }
+
+    template <typename II = I>
+    constexpr auto
+    operator-(difference_type n) const -> ::std::enable_if_t<random_access_iterator<II>, counted_iterator>
+    {
+        return counted_iterator(current_ - n, cnt_ + n);
+    }
+
+    template <typename II = I, ::std::enable_if_t<random_access_iterator<II>, int> = 0>
+    constexpr decltype(auto) operator[](difference_type n) const
+    {
+        return current_[n];
+    }
+
+    template <typename I2>
+    friend constexpr auto
+    operator==(const counted_iterator& x, const counted_iterator<I2>& y) -> ::std::enable_if_t<common_with<I2, I>, bool>
+    {
+        return x.count() == y.count();
+    }
+
+    friend constexpr bool
+    operator==(const counted_iterator& x, default_sentinel_t)
+    {
+        return x.count() == 0;
+    }
+
+    friend constexpr bool
+    operator==(default_sentinel_t, const counted_iterator& x)
+    {
+        return x.count() == 0;
+    }
+
+    template <typename I2>
+    friend constexpr auto
+    operator!=(const counted_iterator& x, const counted_iterator<I2>& y) -> ::std::enable_if_t<common_with<I2, I>, bool>
+    {
+        return !(x == y);
+    }
+
+    friend constexpr bool
+    operator!=(const counted_iterator& x, default_sentinel_t y)
+    {
+        return !(x == y);
+    }
+
+    friend constexpr bool
+    operator!=(default_sentinel_t x, const counted_iterator& y)
+    {
+        return !(x == y);
+    }
+
+    template <typename I2>
+    friend constexpr auto
+    operator<(const counted_iterator& x, const counted_iterator<I2>& y) -> ::std::enable_if_t<common_with<I2, I>, bool>
+    {
+        return y.count() < x.count();
+    }
+
+    template <typename I2>
+    friend constexpr auto
+    operator>(const counted_iterator& x, const counted_iterator<I2>& y) -> ::std::enable_if_t<common_with<I2, I>, bool>
+    {
+        return y < x;
+    }
+
+    template <typename I2>
+    friend constexpr auto
+    operator<=(const counted_iterator& x, const counted_iterator<I2>& y) -> ::std::enable_if_t<common_with<I2, I>, bool>
+    {
+        return !(y < x);
+    }
+
+    template <typename I2>
+    friend constexpr auto
+    operator>=(const counted_iterator& x, const counted_iterator<I2>& y) -> ::std::enable_if_t<common_with<I2, I>, bool>
+    {
+        return !(x < y);
+    }
+
+    template <typename I2>
+    friend constexpr auto
+    operator-(const counted_iterator& x, const counted_iterator<I2>& y)
+        -> ::std::enable_if_t<common_with<I2, I>, iter_difference_t<I2>>
+    {
+        return y.count() - x.count();
+    }
+
+    friend constexpr iter_difference_t<I>
+    operator-(const counted_iterator& x, default_sentinel_t)
+    {
+        return -x.cnt_;
+    }
+
+    friend constexpr iter_difference_t<I>
+    operator-(default_sentinel_t, const counted_iterator& y)
+    {
+        return y.cnt_;
+    }
+
+    template <typename II = I>
+    constexpr auto
+    operator-=(difference_type n) -> ::std::enable_if_t<random_access_iterator<II>, counted_iterator&>
+    {
+        current_ -= n;
+        cnt_ += n;
+        return *this;
+    }
+
+#                    ifndef _MSC_VER
+    // FIXME MSVC: If this is a template, MSVC can't find it via ADL for some reason
+    // Making it a non-template doesn't lose much other than the InputIterator guard
+    template <typename II = I, ::std::enable_if_t<input_iterator<II>, int> = 0>
+#                    endif
+    friend constexpr iter_rvalue_reference_t<I>
+    iter_move(const counted_iterator& i) noexcept(noexcept(ranges::iter_move(i.current_)))
+    {
+        return ranges::iter_move(i.current_);
+    }
+
+    template <typename I2>
+    friend constexpr auto
+    iter_swap(const counted_iterator<I>& x,
+              const counted_iterator<I2>& y) noexcept(noexcept(ranges::iter_swap(x.current_, y.current_)))
+        -> ::std::enable_if_t<indirectly_swappable<I2, I>>
+    {
+        ranges::iter_swap(x.current_, y.current_);
+    }
+};
+
+} // namespace counted_iterator_
+
+using counted_iterator_::counted_iterator;
+
+namespace detail
+{
+
+template <typename I, typename = void>
+struct counted_iterator_readable_traits_helper
+{
+};
+
+template <typename I>
+struct counted_iterator_readable_traits_helper<I, ::std::enable_if_t<readable<I>>>
+{
+    using value_type = iter_value_t<I>;
+};
+
+template <typename I, typename = void>
+struct counted_iterator_category_helper
+{
+};
+
+template <typename I>
+struct counted_iterator_category_helper<I, ::std::enable_if_t<input_iterator<I>>>
+{
+    using type = iterator_category_t<I>;
+};
+
+} // namespace detail
+
+template <typename I>
+struct readable_traits<counted_iterator<I>> : detail::counted_iterator_readable_traits_helper<I>
+{
+};
+
+template <typename I>
+struct iterator_category<counted_iterator<I>> : detail::counted_iterator_category_helper<I>
+{
+};
+
+template <typename I>
+constexpr auto
+make_counted_iterator(I i, iter_difference_t<I> n)
+    -> ::std::enable_if_t<input_or_output_iterator<I>, counted_iterator<I>>
+{
+    return counted_iterator<I>(::std::move(i), n);
+}
+
+NANO_END_NAMESPACE
+
+#                endif
+
+NANO_BEGIN_NAMESPACE
+
+template <typename T>
+::std::enable_if_t<destructible<T>>
+destroy_at(T* location) noexcept
+{
+    location->~T();
+}
+
+namespace detail
+{
+
+struct destroy_fn
+{
+  private:
+    template <typename I, typename S>
+    static I
+    impl(I first, S last) noexcept
+    {
+        for (; first != last; ++first)
+        {
+            nano::destroy_at(::std::addressof(*first));
+        }
+        return first;
+    }
+
+  public:
+    template <typename I, typename S>
+    ::std::enable_if_t<no_throw_input_iterator<I> && no_throw_sentinel<S, I> && destructible<iter_value_t<I>>, I>
+    operator()(I first, S last) const noexcept
+    {
+        return destroy_fn::impl(::std::move(first), ::std::move(last));
+    }
+
+    template <typename Rng>
+    ::std::enable_if_t<no_throw_input_range<Rng> && destructible<iter_value_t<iterator_t<Rng>>>,
+                       borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng) const noexcept
+    {
+        return destroy_fn::impl(nano::begin(rng), nano::end(rng));
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::destroy_fn, destroy)
+
+namespace detail
+{
+
+struct destroy_n_fn
+{
+    template <typename I>
+    ::std::enable_if_t<no_throw_input_iterator<I> && destructible<iter_value_t<I>>, I>
+    operator()(I first, iter_difference_t<I> n) const noexcept
+    {
+        return nano::destroy(make_counted_iterator(::std::move(first), n), default_sentinel).base();
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::destroy_n_fn, destroy_n)
+
+NANO_END_NAMESPACE
+
+#            endif
+
+#            include <cassert>
+#            include <memory>
+#            include <new>
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+template <typename T>
+struct temporary_vector
+{
+  private:
+    struct deleter
+    {
+        void
+        operator()(T* ptr) const
+        {
+            ::operator delete[](ptr);
+        }
+    };
+
+  public:
+    temporary_vector() = default;
+
+    explicit temporary_vector(::std::size_t capacity)
+        : start_(static_cast<T*>(::operator new[](capacity * sizeof(T), ::std::nothrow))),
+          end_cap_(start_ ? start_.get() + capacity : nullptr)
+    {
+    }
+
+    temporary_vector(temporary_vector&& other) noexcept
+        : start_(::std::move(other.start_)), end_(other.end_), end_cap_(other.end_cap_)
+    {
+        other.end_ = nullptr;
+        other.end_cap_ = nullptr;
+    }
+
+    temporary_vector&
+    operator=(temporary_vector&& other) noexcept
+    {
+        nano::swap(start_, other.start_);
+        nano::swap(end_, other.end_);
+        nano::swap(end_cap_, other.end_cap_);
+        return *this;
+    }
+
+    ~temporary_vector() { nano::destroy(begin(), end()); }
+
+    ::std::size_t
+    size() const
+    {
+        return end_ - start_.get();
+    }
+    ::std::size_t
+    capacity() const
+    {
+        return end_cap_ - start_.get();
+    }
+    [[nodiscard]] bool
+    empty() const { return size() == 0; }
+
+    void push_back(const T& elem)
+    {
+        emplace_back(elem);
+    }
+    void
+    push_back(T&& elem)
+    {
+        emplace_back(::std::move(elem));
+    }
+
+    template <typename... Args>
+    void
+    emplace_back(Args&&... args)
+    {
+        assert(end_ < end_cap_);
+        ::new (end_) T(::std::forward<Args>(args)...);
+        ++end_;
+    }
+
+    T*
+    begin()
+    {
+        return start_.get();
+    }
+    const T*
+    begin() const
+    {
+        return start_.get();
+    }
+    T*
+    end()
+    {
+        return end_;
+    }
+    const T*
+    end() const
+    {
+        return end_;
+    }
+
+    void
+    clear()
+    {
+        nano::destroy(begin(), end());
+        end_ = start_.get();
+    }
+
+  private:
+    ::std::unique_ptr<T, deleter> start_{nullptr};
+    T* end_ = start_.get();
+    T* end_cap_ = nullptr;
+};
+
+} // namespace detail
+
+NANO_END_NAMESPACE
+
+#        endif
+
+// nanorange/iterator/back_insert_iterator.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_ITERATOR_BACK_INSERT_ITERATOR_HPP_INCLUDED
+#            define NANORANGE_ITERATOR_BACK_INSERT_ITERATOR_HPP_INCLUDED
+
+#            include <iterator>
+
+NANO_BEGIN_NAMESPACE
+
+template <typename Container>
+struct back_insert_iterator
+{
+    using container_type = Container;
+    using difference_type = ::std::ptrdiff_t;
+
+    constexpr back_insert_iterator() = default;
+
+    explicit back_insert_iterator(Container& x) : cont_(::std::addressof(x)) {}
+
+    back_insert_iterator&
+    operator=(const iter_value_t<iterator_t<Container>>& value)
+    {
+        cont_->push_back(value);
+        return *this;
+    }
+
+    back_insert_iterator&
+    operator=(iter_value_t<iterator_t<Container>>&& value)
+    {
+        cont_->push_back(::std::move(value));
+        return *this;
+    }
+
+    back_insert_iterator& operator*() { return *this; }
+    back_insert_iterator&
+    operator++()
+    {
+        return *this;
+    }
+    back_insert_iterator&
+    operator++(int)
+    {
+        return *this;
+    }
+
+  private:
+    container_type* cont_ = nullptr;
+};
+
+template <typename Container>
+back_insert_iterator<Container>
+back_inserter(Container& x)
+{
+    return back_insert_iterator<Container>(x);
+}
+
+NANO_END_NAMESPACE
+
+namespace std
+{
+
+template <typename Cont>
+struct iterator_traits<__nanorange::nano::back_insert_iterator<Cont>>
+{
+    using value_type = void;
+    using difference_type = ptrdiff_t;
+    using reference = void;
+    using pointer = void;
+    using iterator_category = ::std::output_iterator_tag;
+};
+
+} // namespace std
+
+#        endif
+
+// nanorange/iterator/move_iterator.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_ITERATOR_MOVE_ITERATOR_HPP_INCLUDED
+#            define NANORANGE_ITERATOR_MOVE_ITERATOR_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace move_iterator_
+{
+
+template <typename I>
+class move_iterator
+{
+  public:
+    using iterator_type = I;
+    using difference_type = iter_difference_t<I>;
+    using value_type = iter_value_t<I>;
+    using iterator_category = input_iterator_tag;
+    using reference = iter_rvalue_reference_t<I>;
+
+  private:
+    I current_{};
+
+    static_assert(input_iterator<I>, "Template argument to move_iterator must model InputIterator");
+
+    template <typename I2>
+    friend class move_iterator;
+
+  public:
+    constexpr move_iterator() = default;
+
+    explicit constexpr move_iterator(I i) : current_(::std::move(i)) {}
+
+    template <typename U, ::std::enable_if_t<convertible_to<U, I>, int> = 0>
+    constexpr move_iterator(const move_iterator<U>& i) : current_(i.current_)
+    {
+    }
+
+    template <typename U>
+    constexpr ::std::enable_if_t<convertible_to<U, I>, move_iterator&>
+    operator=(const move_iterator<U>& i)
+    {
+        current_ = i.current_;
+        return *this;
+    }
+
+    constexpr I
+    base() const
+    {
+        return current_;
+    }
+
+    constexpr reference operator*() const { return iter_move(current_); }
+
+    constexpr move_iterator&
+    operator++()
+    {
+        ++current_;
+        return *this;
+    }
+
+    template <typename II = I>
+    constexpr auto
+    operator++(int) -> ::std::enable_if_t<!forward_iterator<II>>
+    {
+        ++current_;
+    }
+
+    template <typename II = I>
+    constexpr auto
+    operator++(int) -> ::std::enable_if_t<forward_iterator<II>, move_iterator>
+    {
+        move_iterator tmp = *this;
+        ++current_;
+        return tmp;
+    }
+
+    template <typename II = I>
+    constexpr auto
+    operator--() -> ::std::enable_if_t<bidirectional_iterator<II>, move_iterator&>
+    {
+        --current_;
+        return *this;
+    }
+
+    template <typename II = I>
+    constexpr auto
+    operator--(int) -> ::std::enable_if_t<bidirectional_iterator<II>, move_iterator>
+    {
+        move_iterator tmp = *this;
+        --current_;
+        return tmp;
+    }
+
+    template <typename II = I>
+    constexpr auto
+    operator+(difference_type n) const -> ::std::enable_if_t<random_access_iterator<II>, move_iterator>
+    {
+        return move_iterator(current_ + n);
+    }
+
+    template <typename II = I>
+    constexpr auto
+    operator+=(difference_type n) -> ::std::enable_if_t<random_access_iterator<II>, move_iterator&>
+    {
+        current_ += n;
+        return *this;
+    }
+
+    template <typename II = I>
+    constexpr auto
+    operator-(difference_type n) const -> ::std::enable_if_t<random_access_iterator<II>, move_iterator>
+    {
+        return move_iterator(current_ - n);
+    }
+
+    template <typename II = I>
+    constexpr auto
+    operator-=(difference_type n) -> ::std::enable_if_t<random_access_iterator<II>, move_iterator&>
+    {
+        current_ -= n;
+        return *this;
+    }
+
+    template <typename II = I>
+    constexpr auto operator[](difference_type n) const -> ::std::enable_if_t<random_access_iterator<II>, reference>
+    //   -> decltype(auto)
+    {
+        return iter_move(current_ + n);
+    }
+
+    friend constexpr iter_rvalue_reference_t<I>
+    iter_move(const move_iterator& i) noexcept(noexcept(ranges::iter_move(i.current_)))
+    {
+        return ranges::iter_move(i.current_);
+    }
+
+    template <typename I2>
+    friend constexpr auto
+    iter_swap(const move_iterator& x,
+              const move_iterator<I2>& y) noexcept(noexcept(ranges::iter_swap(x.current_, y.current_)))
+        -> ::std::enable_if_t<indirectly_swappable<I2, I>>
+    {
+        ranges::iter_swap(x.current_, y.current_);
+    }
+};
+
+template <typename I1, typename I2>
+constexpr auto
+operator==(const move_iterator<I1>& x, const move_iterator<I2>& y)
+    -> ::std::enable_if_t<equality_comparable_with<I1, I2>, bool>
+{
+    return x.base() == y.base();
+}
+
+template <typename I1, typename I2>
+constexpr auto
+operator!=(const move_iterator<I1>& x, const move_iterator<I2>& y)
+    -> ::std::enable_if_t<equality_comparable_with<I1, I2>, bool>
+{
+    return !(x == y);
+}
+
+template <typename I1, typename I2>
+constexpr auto
+operator<(const move_iterator<I1>& x, const move_iterator<I2>& y)
+    -> ::std::enable_if_t<totally_ordered_with<I1, I2>, bool>
+{
+    return x.base() < y.base();
+}
+
+template <typename I1, typename I2>
+constexpr auto
+operator<=(const move_iterator<I1>& x, const move_iterator<I2>& y)
+    -> ::std::enable_if_t<totally_ordered_with<I1, I2>, bool>
+{
+    return !(y < x);
+}
+
+template <typename I1, typename I2>
+constexpr auto
+operator>(const move_iterator<I1>& x, const move_iterator<I2>& y)
+    -> ::std::enable_if_t<totally_ordered_with<I1, I2>, bool>
+{
+    return y < x;
+}
+
+template <typename I1, typename I2>
+constexpr auto
+operator>=(const move_iterator<I1>& x, const move_iterator<I2>& y)
+    -> ::std::enable_if_t<totally_ordered_with<I1, I2>, bool>
+{
+    return !(x < y);
+}
+
+template <typename I1, typename I2>
+constexpr auto
+operator-(const move_iterator<I1>& x, const move_iterator<I2>& y)
+    -> ::std::enable_if_t<sized_sentinel_for<I1, I2>, iter_difference_t<I2>>
+{
+    return x.base() - y.base();
+}
+
+template <typename I>
+constexpr auto
+operator+(iter_difference_t<I> n, const move_iterator<I>& x)
+    -> ::std::enable_if_t<random_access_iterator<I>, move_iterator<I>>
+{
+    return x + n;
+}
+
+} // namespace move_iterator_
+
+using move_iterator_::move_iterator;
+
+template <typename I>
+constexpr auto
+make_move_iterator(I i) -> ::std::enable_if_t<input_iterator<I>, move_iterator<I>>
+{
+    return move_iterator<I>(::std::move(i));
+}
+
+template <typename S>
+class move_sentinel
+{
+    static_assert(semiregular<S>, "Template argument to move_sentinel must model Semiregular");
+
+  public:
+    constexpr move_sentinel() = default;
+
+    constexpr explicit move_sentinel(S s) : last_(::std::move(s)) {}
+
+    template <typename U, ::std::enable_if_t<convertible_to<U, S>, int> = 0>
+    constexpr move_sentinel(const move_sentinel<U>& s) : last_(s.base())
+    {
+    }
+
+    template <typename U>
+    constexpr auto
+    operator=(const move_sentinel<U>& s) -> ::std::enable_if_t<convertible_to<U, S>, move_sentinel&>
+    {
+        last_ = s.base();
+        return *this;
+    }
+
+    constexpr S
+    base() const
+    {
+        return last_;
+    }
+
+  private:
+    S last_{};
+};
+
+template <typename I, typename S>
+constexpr auto
+operator==(const move_iterator<I>& i, const move_sentinel<S>& s) -> ::std::enable_if_t<sentinel_for<S, I>, bool>
+{
+    return i.base() == s.base();
+}
+
+template <typename I, typename S>
+constexpr auto
+operator==(const move_sentinel<S>& s, const move_iterator<I>& i) -> ::std::enable_if_t<sentinel_for<S, I>, bool>
+{
+    return i.base() == s.base();
+}
+
+template <typename I, typename S>
+constexpr auto
+operator!=(const move_iterator<I>& i, const move_sentinel<S>& s) -> ::std::enable_if_t<sentinel_for<S, I>, bool>
+{
+    return !(i == s);
+}
+
+template <typename I, typename S>
+constexpr auto
+operator!=(const move_sentinel<S>& s, const move_iterator<I>& i) -> ::std::enable_if_t<sentinel_for<S, I>, bool>
+{
+    return !(i == s);
+}
+
+template <typename I, typename S>
+constexpr auto
+operator-(const move_sentinel<S>& s, const move_iterator<I>& i)
+    -> ::std::enable_if_t<sized_sentinel_for<S, I>, iter_difference_t<I>>
+{
+    return s.base() - i.base();
+}
+
+template <typename I, typename S>
+constexpr auto
+operator-(const move_iterator<I>& i, const move_sentinel<S>& s)
+    -> ::std::enable_if_t<sized_sentinel_for<S, I>, iter_difference_t<I>>
+{
+    return i.base() - s.base();
+}
+
+template <typename S>
+constexpr auto
+make_move_sentinel(S s) -> ::std::enable_if_t<semiregular<S>, move_sentinel<S>>
+{
+    return move_sentinel<S>(::std::move(s));
+}
+
+NANO_END_NAMESPACE
+
+namespace std
+{
+
+template <typename I>
+struct iterator_traits<__nanorange::nano::move_iterator_::move_iterator<I>>
+{
+    using value_type = typename __nanorange::nano::move_iterator_::move_iterator<I>::value_type;
+    using reference = typename __nanorange::nano::move_iterator_::move_iterator<I>::reference;
+    using pointer = value_type*;
+    using difference_type = typename __nanorange::nano::move_iterator_::move_iterator<I>::difference_type;
+    using iterator_category = typename __nanorange::nano::move_iterator_::move_iterator<I>::iterator_category;
+};
+
+} // namespace std
+
+#        endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct inplace_merge_fn
+{
+  private:
+    friend struct stable_sort_fn;
+
+    template <typename I, typename Pred, typename Proj>
+    static void
+    impl_slow(I first, I middle, I last, iter_difference_t<I> len1, iter_difference_t<I> len2, Pred& pred, Proj& proj)
+    {
+        using dist_t = iter_difference_t<I>;
+
+        while (true)
+        {
+            // if middle == end, we're done
+            if (len2 == 0)
+            {
+                return;
+            }
+
+            // shrink [first, middle) as much as possible (with no moves),
+            // returning if it shrinks to 0
+            for (; true; ++first, (void)--len1)
+            {
+                if (len1 == 0)
+                {
+                    return;
+                }
+                if (nano::invoke(pred, nano::invoke(proj, *middle), nano::invoke(proj, *first)))
+                {
+                    break;
+                }
+            }
+
+            /*if (len1 <= buf.size() || len2 <= buf.size()) {
+                impl(::std::move(begin), ::std::move(middle),
+                     ::std::move(end), len1, len2, buf, pred, proj);
+                return;
+            }*/
+
+            // first < middle < end
+            // *first > *middle
+            // partition [first, m1) [m1, middle) [middle, m2) [m2, end) such that
+            //     all elements in:
+            //         [first, m1)  <= [middle, m2)
+            //         [middle, m2) <  [m1, middle)
+            //         [m1, middle) <= [m2, end)
+            //     and m1 or m2 is in the middle of its range
+            I m1;         // "median" of [first, middle)
+            I m2;         // "median" of [middle, end)
+            dist_t len11; // distance(first, m1)
+            dist_t len21; // distance(middle, m2)
+            // binary search smaller range
+            if (len1 < len2)
+            {
+                // len >= 1, len2 >= 2
+                len21 = len2 / 2;
+                m2 = nano::next(middle, len21);
+                m1 = nano::upper_bound(first, middle, nano::invoke(proj, *m2), ::std::ref(pred), ::std::ref(proj));
+                len11 = nano::distance(first, m1);
+            }
+            else
+            {
+                if (len1 == 1)
+                {
+                    // len1 >= len2 && len2 > 0, therefore len2 == 1
+                    // It is known *first > *middle
+                    nano::iter_swap(first, middle);
+                    return;
+                }
+                // len1 >= 2, len2 >= 1
+                len11 = len1 / 2;
+                m1 = nano::next(first, len11);
+                m2 = nano::lower_bound(middle, last, nano::invoke(proj, *m1), ::std::ref(pred), ::std::ref(proj));
+                len21 = nano::distance(middle, m2);
+            }
+            dist_t len12 = len1 - len11; // distance(m1, middle)
+            dist_t len22 = len2 - len21; // distance(m2, end)
+            // [first, m1) [m1, middle) [middle, m2) [m2, end)
+            // swap middle two partitions
+            middle = nano::rotate(m1, ::std::move(middle), m2).begin();
+            // len12 and len21 now have swapped meanings
+            // merge smaller range with recursive call and larger with tail recursion elimination
+            if (len11 + len21 < len12 + len22)
+            {
+                impl_slow(::std::move(first), ::std::move(m1), middle, len11, len21, pred, proj);
+                first = ::std::move(middle);
+                middle = ::std::move(m2);
+                len1 = len12;
+                len2 = len22;
+            }
+            else
+            {
+                impl_slow(middle, ::std::move(m2), ::std::move(last), len12, len22, pred, proj);
+                last = ::std::move(middle);
+                middle = ::std::move(m1);
+                len1 = len11;
+                len2 = len21;
+            }
+        }
+    }
+
+    template <typename I, typename Buf, typename Comp, typename Proj>
+    static void
+    impl_buffered(I first, I middle, I last, iter_difference_t<I> len1, iter_difference_t<I> len2, Buf& buf, Comp& comp,
+                  Proj& proj)
+    {
+        if (len1 <= len2)
+        {
+            nano::move(first, middle, nano::back_inserter(buf));
+            nano::merge(nano::make_move_iterator(buf.begin()), nano::make_move_sentinel(buf.end()),
+                        nano::make_move_iterator(::std::move(middle)), nano::make_move_sentinel(::std::move(last)),
+                        ::std::move(first), ::std::ref(comp), ::std::ref(proj), ::std::ref(proj));
+        }
+        else
+        {
+            nano::move(middle, last, nano::back_inserter(buf));
+            using ri_t = nano::reverse_iterator<I>;
+            // TODO: C++17's not_fn would be useful
+            auto not_comp = [&comp](auto&& a, auto&& b) {
+                return !nano::invoke(comp, ::std::forward<decltype(a)>(a), ::std::forward<decltype(b)>(b));
+            };
+            nano::merge(nano::make_move_iterator(ri_t{::std::move(middle)}),
+                        nano::make_move_sentinel(ri_t{::std::move(first)}), nano::make_move_iterator(nano::rbegin(buf)),
+                        nano::make_move_sentinel(nano::rend(buf)), nano::make_reverse_iterator(::std::move(last)),
+                        not_comp, ::std::ref(proj), ::std::ref(proj));
+        }
+    }
+
+    template <typename I, typename S, typename Comp, typename Proj>
+    static I
+    impl(I first, I middle, S last, Comp& comp, Proj& proj)
+    {
+        auto dist1 = nano::distance(first, middle);
+        I ilast = middle;
+        iter_difference_t<I> dist2 = 0;
+        while (ilast != last)
+        {
+            ++ilast;
+            ++dist2;
+        }
+
+        const auto sz = nano::min(dist1, dist2);
+        auto buf = detail::temporary_vector<iter_value_t<I>>(sz);
+
+        if (buf.capacity() >= static_cast<::std::size_t>(sz))
+        {
+            impl_buffered(::std::move(first), ::std::move(middle), ::std::move(ilast), dist1, dist2, buf, comp, proj);
+        }
+        else
+        {
+            impl_slow(::std::move(first), ::std::move(middle), ::std::move(ilast), dist1, dist2, comp, proj);
+        }
+
+        return ilast;
+    }
+
+  public:
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    ::std::enable_if_t<bidirectional_iterator<I> && sentinel_for<S, I> && sortable<I, Comp, Proj>, I>
+    operator()(I first, I middle, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return inplace_merge_fn::impl(::std::move(first), ::std::move(middle), ::std::move(last), comp, proj);
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    ::std::enable_if_t<bidirectional_range<Rng> && sortable<iterator_t<Rng>, Comp, Proj>, borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, iterator_t<Rng> middle, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return inplace_merge_fn::impl(nano::begin(rng), ::std::move(middle), nano::end(rng), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::inplace_merge_fn, inplace_merge)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/is_heap.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_IS_HEAP_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_IS_HEAP_HPP_INCLUDED
+
+// nanorange/algorithm/is_heap_until.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+// Uses code from CMCSTL2
+//
+// Copyright Eric Niebler 2014
+// Copyright Casey Carter 2015
+
+#        ifndef NANORANGE_ALGORITHM_IS_HEAP_UNTIL_HPP_INCLUDED
+#            define NANORANGE_ALGORITHM_IS_HEAP_UNTIL_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct is_heap_until_fn
+{
+  private:
+    friend struct is_heap_fn;
+
+    template <typename I, typename Comp, typename Proj>
+    static constexpr I
+    impl(I first, const iter_difference_t<I> n, Comp& comp, Proj& proj)
+    {
+        iter_difference_t<I> p = 0, c = 1;
+
+        I pp = first;
+
+        while (c < n)
+        {
+            I cp = first + c;
+
+            if (nano::invoke(comp, nano::invoke(proj, *pp), nano::invoke(proj, *cp)))
+            {
+                return cp;
+            }
+
+            ++c;
+            ++cp;
+
+            if (c == n || nano::invoke(comp, nano::invoke(proj, *pp), nano::invoke(proj, *cp)))
+            {
+                return cp;
+            }
+
+            ++p;
+            ++pp;
+
+            c = 2 * p + 1;
+        }
+
+        return first + n;
+    }
+
+  public:
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<
+        random_access_iterator<I> && sentinel_for<S, I> && indirect_strict_weak_order<Comp, projected<I, Proj>>, I>
+    operator()(I first, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        auto n = nano::distance(first, last);
+        return is_heap_until_fn::impl(::std::move(first), n, comp, proj);
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<random_access_range<Rng> &&
+                                     indirect_strict_weak_order<Comp, projected<iterator_t<Rng>, Proj>>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return is_heap_until_fn::impl(nano::begin(rng), nano::distance(rng), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::is_heap_until_fn, is_heap_until)
+
+NANO_END_NAMESPACE
+
+#        endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct is_heap_fn
+{
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    ::std::enable_if_t<
+        random_access_iterator<I> && sentinel_for<S, I> && indirect_strict_weak_order<Comp, projected<I, Proj>>, bool>
+    operator()(I first, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        const auto n = nano::distance(first, last);
+        return is_heap_until_fn::impl(::std::move(first), n, comp, proj) == last;
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    ::std::enable_if_t<random_access_range<Rng> && indirect_strict_weak_order<Comp, projected<iterator_t<Rng>, Proj>>,
+                       bool>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return is_heap_until_fn::impl(nano::begin(rng), nano::distance(rng), comp, proj) == nano::end(rng);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::is_heap_fn, is_heap)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/is_partitioned.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_IS_PARTITIONED_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_IS_PARTITIONED_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct is_partitioned_fn
+{
+  private:
+    template <typename I, typename S, typename Pred, typename Proj>
+    static constexpr bool
+    impl(I first, S last, Pred& pred, Proj& proj)
+    {
+        first = nano::find_if_not(::std::move(first), last, pred, proj);
+        return nano::find_if(::std::move(first), last, pred, proj) == last;
+    }
+
+  public:
+    template <typename I, typename S, typename Pred, typename Proj = identity>
+    constexpr ::std::enable_if_t<
+        input_iterator<I> && sentinel_for<S, I> && indirect_unary_predicate<Pred, projected<I, Proj>>, bool>
+    operator()(I first, S last, Pred pred = Pred{}, Proj proj = Proj{}) const
+    {
+        return is_partitioned_fn::impl(::std::move(first), ::std::move(last), pred, proj);
+    }
+
+    template <typename Rng, typename Pred, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_range<Rng> && indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>>,
+                                 bool>
+    operator()(Rng&& rng, Pred pred = Pred{}, Proj proj = Proj{}) const
+    {
+        return is_partitioned_fn::impl(nano::begin(rng), nano::end(rng), pred, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::is_partitioned_fn, is_partitioned)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/is_permutation.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_IS_PERMUTATION_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_IS_PERMUTATION_HPP_INCLUDED
+
+// nanorange/algorithm/mismatch.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_ALGORITHM_MISMATCH_HPP_INCLUDED
+#            define NANORANGE_ALGORITHM_MISMATCH_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+// [range.mismatch]
+
+template <typename I1, typename I2>
+using mismatch_result = in_in_result<I1, I2>;
+
+namespace detail
+{
+
+struct mismatch_fn
+{
+  private:
+    friend struct is_permutation_fn;
+
+    template <typename I1, typename S1, typename I2, typename Proj1, typename Proj2, typename Pred>
+    static constexpr mismatch_result<I1, I2>
+    impl3(I1 first1, S1 last1, I2 first2, Pred& pred, Proj1& proj1, Proj2& proj2)
+    {
+        while (first1 != last1 && nano::invoke(pred, nano::invoke(proj1, *first1), nano::invoke(proj2, *first2)))
+        {
+            ++first1;
+            ++first2;
+        }
+
+        return {first1, first2};
+    }
+
+    template <typename I1, typename S1, typename I2, typename S2, typename Proj1, typename Proj2, typename Pred>
+    static constexpr mismatch_result<I1, I2>
+    impl4(I1 first1, S1 last1, I2 first2, S2 last2, Pred& pred, Proj1& proj1, Proj2& proj2)
+    {
+        while (first1 != last1 && first2 != last2 &&
+               nano::invoke(pred, nano::invoke(proj1, *first1), nano::invoke(proj2, *first2)))
+        {
+            ++first1;
+            ++first2;
+        }
+
+        return {first1, first2};
+    }
+
+  public:
+    // three legged
+    template <typename I1, typename S1, typename I2, typename Proj1 = identity, typename Proj2 = identity,
+              typename Pred = ranges::equal_to>
+    NANO_DEPRECATED constexpr ::std::enable_if_t<
+        input_iterator<I1> && sentinel_for<S1, I1> && input_iterator<::std::decay_t<I2>> && !input_range<I1> &&
+            indirect_relation<Pred, projected<I1, Proj1>, projected<::std::decay_t<I2>, Proj2>>,
+        mismatch_result<I1, ::std::decay_t<I2>>>
+    operator()(I1 first1, S1 last1, I2&& first2, Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return mismatch_fn::impl3(::std::move(first1), ::std::move(last1), ::std::forward<I2>(first2), pred, proj1,
+                                  proj2);
+    }
+
+    // range and a half
+    template <typename Rng1, typename I2, typename Proj1 = identity, typename Proj2 = identity,
+              typename Pred = ranges::equal_to>
+    NANO_DEPRECATED constexpr ::std::enable_if_t<
+        input_range<Rng1> && input_iterator<::std::decay_t<I2>> && !input_range<I2> &&
+            indirect_relation<Pred, projected<iterator_t<Rng1>, Proj1>, projected<::std::decay_t<I2>, Proj2>>,
+        mismatch_result<borrowed_iterator_t<Rng1>, ::std::decay_t<I2>>>
+    operator()(Rng1&& rng1, I2&& first2, Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return mismatch_fn::impl3(nano::begin(rng1), nano::end(rng1), ::std::forward<I2>(first2), pred, proj1, proj2);
+    }
+
+    // four legged
+    template <typename I1, typename S1, typename I2, typename S2, typename Proj1 = identity, typename Proj2 = identity,
+              typename Pred = ranges::equal_to>
+    constexpr ::std::enable_if_t<input_iterator<I1> && sentinel_for<S1, I1> && input_iterator<I2> &&
+                                     sentinel_for<S2, I2> &&
+                                     indirect_relation<Pred, projected<I1, Proj1>, projected<I2, Proj2>>,
+                                 mismatch_result<I1, I2>>
+    operator()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = Pred{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return mismatch_fn::impl4(::std::move(first1), ::std::move(last1), ::std::move(first2), ::std::move(last2),
+                                  pred, proj1, proj2);
+    }
+
+    // two ranges
+    template <typename Rng1, typename Rng2, typename Proj1 = identity, typename Proj2 = identity,
+              typename Pred = ranges::equal_to>
+    constexpr ::std::enable_if_t<
+        input_range<Rng1> && input_range<Rng2> &&
+            indirect_relation<Pred, projected<iterator_t<Rng1>, Proj1>, projected<iterator_t<Rng2>, Proj2>>,
+        mismatch_result<borrowed_iterator_t<Rng1>, borrowed_iterator_t<Rng2>>>
+    operator()(Rng1&& rng1, Rng2&& rng2, Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return mismatch_fn::impl4(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), nano::end(rng2), pred, proj1,
+                                  proj2);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::mismatch_fn, mismatch)
+
+NANO_END_NAMESPACE
+
+#        endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct is_permutation_fn
+{
+  private:
+    template <typename I1, typename S1, typename I2, typename S2, typename Pred, typename Proj1, typename Proj2>
+    static constexpr bool
+    process_tail(I1 first1, S1 last1, I2 first2, S2 last2, Pred& pred, Proj1& proj1, Proj2& proj2)
+    {
+        for (auto it = first1; it != last1; ++it)
+        {
+            const auto comp = [&pred, val = nano::invoke(proj1, *it)](const auto& t) {
+                return nano::invoke(pred, t, val);
+            };
+
+            // Check whether we have already seen this value
+            if (any_of_fn::impl(first1, it, comp, proj1))
+            {
+                continue;
+            }
+
+            // Count how many times *it appears in range2
+            const auto count1 = count_if_fn::impl(first2, last2, comp, proj2);
+
+            // If we have a count of zero, we know the ranges are different
+            if (count1 == 0)
+            {
+                return false;
+            }
+
+            // Count how many times *it appears in the remainder of range1
+            // (we can start from one)
+            const auto count2 = iter_difference_t<I1>{1} + count_if_fn::impl(nano::next(it), last1, comp, proj1);
+
+            if (count1 != count2)
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    template <typename I1, typename S1, typename I2, typename Pred, typename Proj1, typename Proj2>
+    static constexpr bool
+    impl3(I1 first1, S1 last1, I2 first2, Pred& pred, Proj1& proj1, Proj2& proj2)
+    {
+        // Strip equal prefixes from both ranges
+        auto result = mismatch_fn::impl3(::std::move(first1), last1, ::std::move(first2), pred, proj1, proj2);
+        first1 = ::std::move(result).in1;
+        first2 = ::std::move(result).in2;
+
+        if (first1 == last1)
+        {
+            return true;
+        }
+
+        // If we have only one value left in range1, it can't be in range2
+        const auto d = nano::distance(first1, last1);
+        if (d == 1)
+        {
+            return false;
+        }
+
+        auto last2 = nano::next(first2, d);
+
+        return is_permutation_fn::process_tail(::std::move(first1), ::std::move(last1), ::std::move(first2),
+                                               ::std::move(last2), pred, proj1, proj2);
+    }
+
+    template <typename I1, typename S1, typename I2, typename S2, typename Pred, typename Proj1, typename Proj2>
+    static constexpr bool
+    impl4(I1 first1, S1 last1, I2 first2, S2 last2, Pred& pred, Proj1& proj1, Proj2& proj2)
+    {
+        // Strip equal prefixes from both ranges
+        auto result = mismatch_fn::impl4(::std::move(first1), last1, ::std::move(first2), last2, pred, proj1, proj2);
+        first1 = ::std::move(result).in1;
+        first2 = ::std::move(result).in2;
+
+        // If we have reached the end of both ranges, they were the same
+        if (first1 == last1 && first2 == last2)
+        {
+            return true;
+        }
+
+        // If we have different numbers of elements left in the ranges,
+        // they are not permutations of one another
+        if (nano::distance(first1, last1) != nano::distance(first2, last2))
+        {
+            return false;
+        }
+
+        return is_permutation_fn::process_tail(::std::move(first1), ::std::move(last1), ::std::move(first2),
+                                               ::std::move(last2), pred, proj1, proj2);
+    }
+
+  public:
+    // Four-legged
+    template <typename I1, typename S1, typename I2, typename S2, typename Pred = ranges::equal_to,
+              typename Proj1 = identity, typename Proj2 = identity>
+    constexpr ::std::enable_if_t<forward_iterator<I1> && sentinel_for<S1, I1> && forward_iterator<I2> &&
+                                     sentinel_for<S2, I2> && indirectly_comparable<I1, I2, Pred, Proj1, Proj2>,
+                                 bool>
+    operator()(I1 first1, S1 last1, I2 first2, S2 last2, Pred pred = Pred{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        if constexpr (sized_sentinel_for<S1, I1> && sized_sentinel_for<S2, I2>)
+        {
+            if (nano::distance(first1, last1) != nano::distance(first2, last2))
+            {
+                return false;
+            }
+            return is_permutation_fn::impl3(::std::move(first1), ::std::move(last1), ::std::move(first2), pred, proj1,
+                                            proj2);
+        }
+
+        return is_permutation_fn::impl4(::std::move(first1), ::std::move(last1), ::std::move(first2),
+                                        ::std::move(last2), pred, proj1, proj2);
+    }
+
+    // Three-legged
+    template <typename I1, typename S1, typename I2, typename Pred = ranges::equal_to, typename Proj1 = identity,
+              typename Proj2 = identity>
+    NANO_DEPRECATED constexpr ::std::enable_if_t<forward_iterator<I1> && sentinel_for<S1, I1> && forward_iterator<I2> &&
+                                                     indirectly_comparable<I1, I2, Pred, Proj1, Proj2>,
+                                                 bool>
+    operator()(I1 first1, S1 last1, I2 first2, Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return is_permutation_fn::impl3(::std::move(first1), ::std::move(last1), ::std::move(first2), pred, proj1,
+                                        proj2);
+    }
+
+    // Two ranges
+    template <typename Rng1, typename Rng2, typename Pred = ranges::equal_to, typename Proj1 = identity,
+              typename Proj2 = identity>
+    constexpr ::std::enable_if_t<forward_range<Rng1> && forward_range<Rng2> &&
+                                     indirectly_comparable<iterator_t<Rng1>, iterator_t<Rng2>, Pred, Proj1, Proj2>,
+                                 bool>
+    operator()(Rng1&& rng1, Rng2&& rng2, Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        if (sized_range<Rng1> && sized_range<Rng2>)
+        {
+            if (nano::distance(rng1) != nano::distance(rng2))
+            {
+                return false;
+            }
+
+            return is_permutation_fn::impl3(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), pred, proj1, proj2);
+        }
+
+        return is_permutation_fn::impl4(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), nano::end(rng2), pred,
+                                        proj1, proj2);
+    }
+
+    // Range and a half
+    template <typename Rng1, typename I2, typename Pred = ranges::equal_to, typename Proj1 = identity,
+              typename Proj2 = identity>
+    NANO_DEPRECATED constexpr ::std::enable_if_t<forward_range<Rng1> && forward_iterator<::std::decay_t<I2>> &&
+                                                     !range<I2> &&
+                                                     indirectly_comparable<iterator_t<Rng1>, I2, Pred, Proj1, Proj2>,
+                                                 bool>
+    operator()(Rng1&& rng1, I2&& first2, Pred pred = Pred{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return is_permutation_fn::impl3(nano::begin(rng1), nano::end(rng1), ::std::forward<I2>(first2), pred, proj1,
+                                        proj2);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::is_permutation_fn, is_permutation)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/is_sorted.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_IS_SORTED_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_IS_SORTED_HPP_INCLUDED
+
+// nanorange/algorithm/is_sorted_until.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_ALGORITHM_IS_SORTED_UNTIL_HPP_INCLUDED
+#            define NANORANGE_ALGORITHM_IS_SORTED_UNTIL_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct is_sorted_until_fn
+{
+  private:
+    friend struct is_sorted_fn;
+
+    template <typename I, typename S, typename Comp, typename Proj>
+    static constexpr I
+    impl(I first, S last, Comp& comp, Proj& proj)
+    {
+        if (first == last)
+        {
+            return first;
+        }
+
+        I n = next(first);
+
+        while (n != last)
+        {
+            if (nano::invoke(comp, nano::invoke(proj, *n), nano::invoke(proj, *first)))
+            {
+                return n;
+            }
+            ++first;
+            ++n;
+        }
+
+        return n;
+    }
+
+  public:
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<
+        forward_iterator<I> && sentinel_for<S, I> && indirect_strict_weak_order<Comp, projected<I, Proj>>, I>
+    operator()(I first, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return is_sorted_until_fn::impl(::std::move(first), ::std::move(last), comp, proj);
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<forward_range<Rng> &&
+                                     indirect_strict_weak_order<Comp, projected<iterator_t<Rng>, Proj>>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return is_sorted_until_fn::impl(nano::begin(rng), nano::end(rng), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::is_sorted_until_fn, is_sorted_until)
+
+NANO_END_NAMESPACE
+
+#        endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct is_sorted_fn
+{
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<
+        forward_iterator<I> && sentinel_for<S, I> && indirect_strict_weak_order<Comp, projected<I, Proj>>, bool>
+    operator()(I first, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return is_sorted_until_fn::impl(::std::move(first), last, comp, proj) == last;
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<
+        forward_range<Rng> && indirect_strict_weak_order<Comp, projected<iterator_t<Rng>, Proj>>, bool>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return is_sorted_until_fn::impl(nano::begin(rng), nano::end(rng), comp, proj) == nano::end(rng);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::is_sorted_fn, is_sorted)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/stl/lexicographical_compare.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct lexicographical_compare_fn
+{
+  private:
+    template <typename I1, typename S1, typename I2, typename S2, typename Comp, typename Proj1, typename Proj2>
+    static constexpr bool
+    impl(I1 first1, S1 last1, I2 first2, S2 last2, Comp& comp, Proj1& proj1, Proj2& proj2)
+    {
+        while (first1 != last1 && first2 != last2)
+        {
+            if (nano::invoke(comp, nano::invoke(proj1, *first1), nano::invoke(proj2, *first2)))
+            {
+                return true;
+            }
+            if (nano::invoke(comp, nano::invoke(proj2, *first2), nano::invoke(proj1, *first1)))
+            {
+                return false;
+            }
+            ++first1;
+            ++first2;
+        }
+
+        return first1 == last1 && first2 != last2;
+    }
+
+  public:
+    template <typename I1, typename S1, typename I2, typename S2, typename Comp = ranges::less,
+              typename Proj1 = identity, typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_iterator<I1> && sentinel_for<S1, I1> && input_iterator<I2> &&
+                                     sentinel_for<S2, I2> &&
+                                     indirect_strict_weak_order<Comp, projected<I1, Proj1>, projected<I2, Proj2>>,
+                                 bool>
+    operator()(I1 first1, S1 last1, I2 first2, S2 last2, Comp comp = Comp{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return lexicographical_compare_fn::impl(::std::move(first1), ::std::move(last1), ::std::move(first2),
+                                                ::std::move(last2), comp, proj1, proj2);
+    }
+
+    template <typename Rng1, typename Rng2, typename Comp = ranges::less, typename Proj1 = identity,
+              typename Proj2 = identity>
+    constexpr ::std::enable_if_t<
+        input_range<Rng1> && input_range<Rng2> &&
+            indirect_strict_weak_order<Comp, projected<iterator_t<Rng1>, Proj1>, projected<iterator_t<Rng2>, Proj2>>,
+        bool>
+    operator()(Rng1&& rng1, Rng2&& rng2, Comp comp = Comp{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return lexicographical_compare_fn::impl(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), nano::end(rng2),
+                                                comp, proj1, proj2);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::lexicographical_compare_fn, lexicographical_compare)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/make_heap.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+// Uses code from CMCSTL2
+//  Copyright Eric Niebler 2014
+//  Copyright Casey Carter 2015
+
+#    ifndef NANORANGE_ALGORITHM_MAKE_HEAP_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_MAKE_HEAP_HPP_INCLUDED
+
+// nanorange/detail/algorithm/heap_sift.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+// cmcstl2 - A concept-enabled C++ standard library
+//
+//  Copyright Eric Niebler 2014
+//  Copyright Casey Carter 2015
+//
+//  Use, modification and distribution is subject to 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)
+//
+// Project home: https://github.com/caseycarter/cmcstl2
+//
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+#        ifndef NANORANGE_DETAIL_ALGORITHM_HEAP_SIFT_HPP
+#            define NANORANGE_DETAIL_ALGORITHM_HEAP_SIFT_HPP
+
+///////////////////////////////////////////////////////////////////////////
+// detail::sift_up_n and detail::sift_down_n
+// (heap implementation details)
+//
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+template <typename I, typename Comp, typename Proj>
+constexpr void
+sift_up_n(I first, iter_difference_t<I> n, Comp& comp, Proj& proj)
+{
+    if (n > 1)
+    {
+        I last = first + n;
+        n = (n - 2) / 2;
+        I i = first + n;
+        if (nano::invoke(comp, nano::invoke(proj, *i), nano::invoke(proj, *--last)))
+        {
+            iter_value_t<I> v = nano::iter_move(last);
+            do
+            {
+                *last = nano::iter_move(i);
+                last = i;
+                if (n == 0)
+                {
+                    break;
+                }
+                n = (n - 1) / 2;
+                i = first + n;
+            } while (nano::invoke(comp, nano::invoke(proj, *i), nano::invoke(proj, v)));
+            *last = ::std::move(v);
+        }
+    }
+}
+
+template <typename I, typename Comp, typename Proj>
+constexpr void
+sift_down_n(I first, iter_difference_t<I> n, I start, Comp& comp, Proj& proj)
+{
+    // left-child of start is at 2 * start + 1
+    // right-child of start is at 2 * start + 2
+    auto child = start - first;
+
+    if (n < 2 || (n - 2) / 2 < child)
+    {
+        return;
+    }
+
+    child = 2 * child + 1;
+    I child_i = first + child;
+
+    if ((child + 1) < n && nano::invoke(comp, nano::invoke(proj, *child_i), nano::invoke(proj, *(child_i + 1))))
+    {
+        // right-child exists and is greater than left-child
+        ++child_i;
+        ++child;
+    }
+
+    // check if we are in heap-order
+    if (nano::invoke(comp, nano::invoke(proj, *child_i), nano::invoke(proj, *start)))
+    {
+        // we are, start is larger than its largest child
+        return;
+    }
+
+    iter_value_t<I> top = nano::iter_move(start);
+    do
+    {
+        // we are not in heap-order, swap the parent with it's largest child
+        *start = nano::iter_move(child_i);
+        start = child_i;
+
+        if ((n - 2) / 2 < child)
+        {
+            break;
+        }
+
+        // recompute the child based off of the updated parent
+        child = 2 * child + 1;
+        child_i = first + child;
+
+        if ((child + 1) < n && nano::invoke(comp, nano::invoke(proj, *child_i), nano::invoke(proj, *(child_i + 1))))
+        {
+            // right-child exists and is greater than left-child
+            ++child_i;
+            ++child;
+        }
+
+        // check if we are in heap-order
+    } while (!nano::invoke(comp, nano::invoke(proj, *child_i), nano::invoke(proj, top)));
+    *start = ::std::move(top);
+}
+
+} // namespace detail
+
+NANO_END_NAMESPACE
+
+#        endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct make_heap_fn
+{
+  private:
+    template <typename I, typename Comp, typename Proj>
+    static constexpr I
+    impl(I first, iter_difference_t<I> n, Comp& comp, Proj& proj)
+    {
+        if (n > 1)
+        {
+            // start from the first parent, there is no need to consider
+            // children
+            for (auto start = (n - 2) / 2; start >= 0; --start)
+            {
+                detail::sift_down_n(first, n, first + start, comp, proj);
+            }
+        }
+
+        return first + n;
+    }
+
+  public:
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<random_access_iterator<I> && sentinel_for<S, I> && sortable<I, Comp, Proj>, I>
+    operator()(I first, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        const auto n = nano::distance(first, last);
+        return make_heap_fn::impl(::std::move(first), n, comp, proj);
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<random_access_range<Rng> && sortable<iterator_t<Rng>, Comp>, borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return make_heap_fn::impl(nano::begin(rng), nano::distance(rng), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::make_heap_fn, make_heap)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/max.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_MAX_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_MAX_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct max_fn
+{
+  private:
+    template <typename Rng, typename Comp, typename Proj>
+    static constexpr iter_value_t<iterator_t<Rng>>
+    impl(Rng&& rng, Comp& comp, Proj& proj)
+    {
+        auto first = nano::begin(rng);
+        const auto last = nano::end(rng);
+
+        // Empty ranges not allowed
+        auto result = *first;
+
+        while (++first != last)
+        {
+            auto&& val = *first;
+            if (nano::invoke(comp, nano::invoke(proj, result), nano::invoke(proj, val)))
+            {
+                result = ::std::forward<decltype(val)>(val);
+            }
+        }
+
+        return result;
+    }
+
+  public:
+    template <typename T, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<indirect_strict_weak_order<Comp, projected<const T*, Proj>>, const T&>
+    operator()(const T& a, const T& b, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        // *sigh*, this should be fixed in STL2
+        return !nano::invoke(comp, nano::invoke(proj, a), nano::invoke(proj, b)) ? a : b;
+    }
+
+    template <typename T, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<copyable<T> && indirect_strict_weak_order<Comp, projected<const T*, Proj>>, T>
+    operator()(::std::initializer_list<T> rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return max_fn::impl(rng, comp, proj);
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_range<Rng> && copyable<iter_value_t<iterator_t<Rng>>> &&
+                                     indirect_strict_weak_order<Comp, projected<iterator_t<Rng>, Proj>>,
+                                 range_value_t<Rng>>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return max_fn::impl(::std::forward<Rng>(rng), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::max_fn, max)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/max_element.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_MAX_ELEMENT_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_MAX_ELEMENT_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct max_element_fn
+{
+    template <typename I, typename S, typename Comp, typename Proj>
+    static constexpr I
+    impl(I first, S last, Comp& comp, Proj& proj)
+    {
+        if (first == last)
+        {
+            return first;
+        }
+
+        I i = nano::next(first);
+        while (i != last)
+        {
+            if (!nano::invoke(comp, nano::invoke(proj, *i), nano::invoke(proj, *first)))
+            {
+                first = i;
+            }
+            ++i;
+        }
+
+        return first;
+    }
+
+  public:
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<
+        forward_iterator<I> && sentinel_for<S, I> && indirect_strict_weak_order<Comp, projected<I, Proj>>, I>
+    operator()(I first, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return max_element_fn::impl(::std::move(first), ::std::move(last), comp, proj);
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<forward_range<Rng> &&
+                                     indirect_strict_weak_order<Comp, projected<iterator_t<Rng>, Proj>>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return max_element_fn::impl(nano::begin(rng), nano::end(rng), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::max_element_fn, max_element)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/min_element.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_MIN_ELEMENT_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_MIN_ELEMENT_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct min_element_fn
+{
+  private:
+    friend struct nth_element_fn;
+
+    template <typename I, typename S, typename Comp, typename Proj>
+    static constexpr I
+    impl(I first, S last, Comp& comp, Proj& proj)
+    {
+        if (first == last)
+        {
+            return first;
+        }
+
+        I i = nano::next(first);
+        while (i != last)
+        {
+            if (nano::invoke(comp, nano::invoke(proj, *i), nano::invoke(proj, *first)))
+            {
+                first = i;
+            }
+            ++i;
+        }
+
+        return first;
+    }
+
+  public:
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<
+        forward_iterator<I> && sentinel_for<S, I> && indirect_strict_weak_order<Comp, projected<I, Proj>>, I>
+    operator()(I first, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return min_element_fn::impl(::std::move(first), ::std::move(last), comp, proj);
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<forward_range<Rng> &&
+                                     indirect_strict_weak_order<Comp, projected<iterator_t<Rng>, Proj>>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return min_element_fn::impl(nano::begin(rng), nano::end(rng), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::min_element_fn, min_element)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/minmax.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+// Uses code from CMCSTL2
+// Copyright Casey Carter 2015
+
+#    ifndef NANORANGE_ALGORITHM_MINMAX_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_MINMAX_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename T>
+using minmax_result = min_max_result<T>;
+
+namespace detail
+{
+
+struct minmax_fn
+{
+  private:
+    template <typename Rng, typename Comp, typename Proj, typename T = iter_value_t<iterator_t<Rng>>>
+    static constexpr minmax_result<T>
+    impl(Rng&& rng, Comp& comp, Proj& proj)
+    {
+        auto first = nano::begin(rng);
+        const auto last = nano::end(rng);
+
+        // Empty ranges not allowed
+        auto temp = *first;
+        minmax_result<T> result{temp, ::std::move(temp)};
+
+        if (++first != last)
+        {
+            {
+                auto&& val = *first;
+                if (nano::invoke(comp, nano::invoke(proj, val), nano::invoke(proj, result.min)))
+                {
+                    result.min = ::std::forward<decltype(val)>(val);
+                }
+                else if (!nano::invoke(comp, nano::invoke(proj, val), nano::invoke(proj, result.max)))
+                {
+                    result.max = ::std::forward<decltype(val)>(val);
+                }
+            }
+
+            while (++first != last)
+            {
+                T val1 = *first;
+
+                // Last iteration
+                if (++first == last)
+                {
+                    if (nano::invoke(comp, nano::invoke(proj, val1), nano::invoke(proj, result.min)))
+                    {
+                        result.min = ::std::move(val1);
+                    }
+                    else if (!nano::invoke(comp, nano::invoke(proj, val1), nano::invoke(proj, result.max)))
+                    {
+                        result.max = ::std::move(val1);
+                    }
+                    break;
+                }
+
+                auto&& val2 = *first;
+                if (nano::invoke(comp, nano::invoke(proj, val2), nano::invoke(proj, val1)))
+                {
+                    if (nano::invoke(comp, nano::invoke(proj, val2), nano::invoke(proj, result.min)))
+                    {
+                        result.min = ::std::forward<decltype(val2)>(val2);
+                    }
+                    if (!nano::invoke(comp, nano::invoke(proj, val1), nano::invoke(proj, result.max)))
+                    {
+                        result.max = ::std::move(val1);
+                    }
+                }
+                else
+                {
+                    if (nano::invoke(comp, nano::invoke(proj, val1), nano::invoke(proj, result.min)))
+                    {
+                        result.min = ::std::move(val1);
+                    }
+                    if (!nano::invoke(comp, nano::invoke(proj, val2), nano::invoke(proj, result.max)))
+                    {
+                        result.max = ::std::forward<decltype(val2)>(val2);
+                    }
+                }
+            }
+        }
+
+        return result;
+    }
+
+  public:
+    template <typename T, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<indirect_strict_weak_order<Comp, projected<const T*, Proj>>, minmax_result<const T&>>
+    operator()(const T& a, const T& b, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        if (nano::invoke(comp, nano::invoke(proj, b), nano::invoke(proj, a)))
+        {
+            return {b, a};
+        }
+        else
+        {
+            return {a, b};
+        }
+    }
+
+    template <typename T, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<copyable<T> && indirect_strict_weak_order<Comp, projected<const T*, Proj>>,
+                                 minmax_result<T>>
+    operator()(::std::initializer_list<T> rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return minmax_fn::impl(rng, comp, proj);
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_range<Rng> && copyable<iter_value_t<iterator_t<Rng>>> &&
+                                     indirect_strict_weak_order<Comp, projected<iterator_t<Rng>, Proj>>,
+                                 minmax_result<range_value_t<Rng>>>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return minmax_fn::impl(::std::forward<Rng>(rng), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::minmax_fn, minmax)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/minmax_element.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+// Uses code from CMCSTL2
+// Copyright Casey Carter 2015
+
+#    ifndef NANORANGE_ALGORITHM_MINMAX_ELEMENT_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_MINMAX_ELEMENT_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename T>
+using minmax_element_result = min_max_result<T>;
+
+namespace detail
+{
+
+struct minmax_element_fn
+{
+  private:
+    template <typename I, typename S, typename Comp, typename Proj>
+    static constexpr minmax_element_result<I>
+    impl(I first, S last, Comp& comp, Proj& proj)
+    {
+        minmax_element_result<I> result{first, first};
+
+        if (first == last || ++first == last)
+        {
+            return result;
+        }
+
+        if (nano::invoke(comp, nano::invoke(proj, *first), nano::invoke(proj, *result.min)))
+        {
+            result.min = first;
+        }
+        else if (!nano::invoke(comp, nano::invoke(proj, *first), nano::invoke(proj, *result.max)))
+        {
+            result.max = first;
+        }
+
+        while (++first != last)
+        {
+            I it = first;
+
+            // Last iteration
+            if (++first == last)
+            {
+                if (nano::invoke(comp, nano::invoke(proj, *it), nano::invoke(proj, *result.min)))
+                {
+                    result.min = ::std::move(it);
+                }
+                else if (!nano::invoke(comp, nano::invoke(proj, *it), nano::invoke(proj, *result.max)))
+                {
+                    result.max = ::std::move(it);
+                }
+                break;
+            }
+
+            if (nano::invoke(comp, nano::invoke(proj, *first), nano::invoke(proj, *it)))
+            {
+                if (nano::invoke(comp, nano::invoke(proj, *first), nano::invoke(proj, *result.min)))
+                {
+                    result.min = first;
+                }
+                if (!nano::invoke(comp, nano::invoke(proj, *it), nano::invoke(proj, *result.max)))
+                {
+                    result.max = it;
+                }
+            }
+            else
+            {
+                if (nano::invoke(comp, nano::invoke(proj, *it), nano::invoke(proj, *result.min)))
+                {
+                    result.min = it;
+                }
+                if (!nano::invoke(comp, nano::invoke(proj, *first), nano::invoke(proj, *result.max)))
+                {
+                    result.max = first;
+                }
+            }
+        }
+
+        return result;
+    }
+
+  public:
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<forward_iterator<I> && sentinel_for<S, I> &&
+                                     indirect_strict_weak_order<Comp, projected<I, Proj>>,
+                                 minmax_element_result<I>>
+    operator()(I first, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return minmax_element_fn::impl(::std::move(first), ::std::move(last), comp, proj);
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<forward_range<Rng> &&
+                                     indirect_strict_weak_order<Comp, projected<iterator_t<Rng>, Proj>>,
+                                 minmax_element_result<borrowed_iterator_t<Rng>>>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return minmax_element_fn::impl(nano::begin(rng), nano::end(rng), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::minmax_element_fn, minmax_element)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/next_permutation.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+// Taken from Range-V3
+//
+// Copyright Eric Niebler 2014-2018
+//
+//===-------------------------- algorithm ---------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#    ifndef NANORANGE_ALGORITHM_NEXT_PERMUTATION_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_NEXT_PERMUTATION_HPP_INCLUDED
+
+// nanorange/algorithm/reverse.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_ALGORITHM_REVERSE_HPP_INCLUDED
+#            define NANORANGE_ALGORITHM_REVERSE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct reverse_fn
+{
+  private:
+    template <typename I>
+    static constexpr I
+    impl(I first, I last)
+    {
+        I ret = last;
+        while (first != last && first != --last)
+        {
+            nano::iter_swap(first, last);
+            ++first;
+        }
+
+        return ret;
+    }
+
+    template <typename I, typename S>
+    static constexpr ::std::enable_if_t<!same_as<I, S>, I>
+    impl(I first, S bound)
+    {
+        I last = next(first, bound);
+        return reverse_fn::impl(::std::move(first), ::std::move(last));
+    }
+
+  public:
+    template <typename I, typename S>
+    constexpr ::std::enable_if_t<bidirectional_iterator<I> && sentinel_for<S, I>, I>
+    operator()(I first, S last) const
+    {
+        return reverse_fn::impl(::std::move(first), ::std::move(last));
+    }
+
+    template <typename Rng>
+    constexpr ::std::enable_if_t<bidirectional_range<Rng>, borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng) const
+    {
+        return reverse_fn::impl(nano::begin(rng), nano::end(rng));
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::reverse_fn, reverse)
+
+NANO_END_NAMESPACE
+
+#        endif
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I>
+using next_permutation_result = in_found_result<I>;
+
+namespace detail
+{
+
+struct next_permutation_fn
+{
+  private:
+    template <typename I, typename S, typename Comp, typename Proj>
+    static constexpr next_permutation_result<I>
+    impl(I first, S last, Comp& comp, Proj& proj)
+    {
+        if (first == last)
+        {
+            return {::std::move(first), false};
+        }
+
+        I last_it = nano::next(first, last);
+        I i = last_it;
+
+        if (first == --i)
+        {
+            return {::std::move(last_it), false};
+        }
+
+        while (true)
+        {
+            I ip1 = i;
+
+            if (nano::invoke(comp, nano::invoke(proj, *--i), nano::invoke(proj, *ip1)))
+            {
+                I j = last_it;
+                while (!nano::invoke(comp, nano::invoke(proj, *i), nano::invoke(proj, *--j)))
+                    ;
+
+                nano::iter_swap(i, j);
+                nano::reverse(ip1, last_it);
+                return {::std::move(last_it), true};
+            }
+
+            if (i == first)
+            {
+                nano::reverse(first, last_it);
+                return {::std::move(last_it), false};
+            }
+        }
+    }
+
+  public:
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<bidirectional_iterator<I> && sentinel_for<S, I> && sortable<I, Comp, Proj>,
+                                 next_permutation_result<I>>
+    operator()(I first, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return next_permutation_fn::impl(::std::move(first), ::std::move(last), comp, proj);
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<bidirectional_range<Rng> && sortable<iterator_t<Rng>, Comp, Proj>,
+                                 next_permutation_result<borrowed_iterator_t<Rng>>>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return next_permutation_fn::impl(nano::begin(rng), nano::end(rng), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::next_permutation_fn, next_permutation)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/none_of.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_NONE_OF_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_NONE_OF_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+// [ranges.alg.none_of]
+
+namespace detail
+{
+
+struct none_of_fn
+{
+
+    template <typename I, typename S, typename Proj = identity, typename Pred>
+    constexpr ::std::enable_if_t<
+        input_iterator<I> && sentinel_for<S, I> && indirect_unary_predicate<Pred, projected<I, Proj>>, bool>
+    operator()(I first, S last, Pred pred, Proj proj = Proj{}) const
+    {
+        return !any_of_fn::impl(first, last, pred, proj);
+    }
+
+    template <typename Rng, typename Proj = identity, typename Pred>
+    constexpr ::std::enable_if_t<input_range<Rng> && indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>>,
+                                 bool>
+    operator()(Rng&& rng, Pred pred, Proj proj = Proj{}) const
+    {
+        return !any_of_fn::impl(nano::begin(rng), nano::end(rng), pred, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::none_of_fn, none_of)
+
+NANO_END_NAMESPACE
+
+#    endif
+// nanorange/algorithm/nth_element.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+// Uses code from cmcstl2 - A concept-enabled C++ standard library
+//
+//  Copyright Eric Niebler 2014
+//  Copyright Casey Carter 2015
+//
+
+//
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#    ifndef NANORANGE_ALGORITHM_NTH_ELEMENT_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_NTH_ELEMENT_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct nth_element_fn
+{
+  private:
+    template <typename I, typename Comp, typename Proj>
+    static constexpr void
+    impl(I first, I nth, I last, Comp& comp, Proj& proj)
+    {
+        constexpr iter_difference_t<I> limit = 7;
+
+        const auto pred = [&comp, &proj](auto&& t, auto&& u) {
+            return nano::invoke(comp, nano::invoke(proj, ::std::forward<decltype(t)>(t)),
+                                nano::invoke(proj, ::std::forward<decltype(u)>(u)));
+        };
+
+        I end = last;
+
+        while (true)
+        {
+            if (nth == end)
+                return;
+
+            iter_difference_t<I> len = end - first;
+
+            switch (len)
+            {
+            case 0:
+            case 1:
+                return;
+            case 2:
+                if (pred(*--end, *first))
+                    iter_swap(first, end);
+                return;
+            case 3:
+            {
+                I m = first;
+                sort3(first, ++m, --end, comp, proj);
+                return;
+            }
+            default:
+                break;
+            }
+            if (len <= limit)
+            {
+                selection_sort(first, end, comp, proj);
+                return;
+            }
+            // Post: len > limit
+
+            I m = first + len / 2;
+            I lm1 = end;
+            unsigned n_swaps = sort3(first, m, --lm1, comp, proj);
+            // Post: *m is median
+
+            // partition [first, m) < *m and *m <= [m, end)
+            //(this inhibits tossing elements equivalent to m around unnecessarily)
+            I i = first;
+            I j = lm1;
+            // j points beyond range to be tested, *lm1 is known to be <= *m
+            // The search going up is known to be guarded but the search coming down isn't.
+            // Prime the downward search with a guard.
+            if (!pred(*i, *m))
+            { // if *first == *m
+                // *first == *m, *first doesn't go in first part
+                // manually guard downward moving j against i
+                bool restart = false;
+                while (true)
+                {
+                    if (i == --j)
+                    {
+                        // *first == *m, *m <= all other elements
+                        // Partition instead into [first, i) == *first and *first < [i, end)
+                        ++i; // first + 1
+                        j = end;
+                        if (!pred(*first, *--j))
+                        { // we need a guard if *first == *(end-1)
+                            while (true)
+                            {
+                                if (i == j)
+                                {
+                                    return; // [first, end) all equivalent elements
+                                }
+                                if (pred(*first, *i))
+                                {
+                                    iter_swap(i, j);
+                                    ++n_swaps;
+                                    ++i;
+                                    break;
+                                }
+                                ++i;
+                            }
+                        }
+                        // [first, i) == *first and *first < [j, end) and j == end - 1
+                        if (i == j)
+                            return;
+
+                        while (true)
+                        {
+                            while (!pred(*first, *i))
+                            {
+                                ++i;
+                            }
+                            while (pred(*first, *--j))
+                            {
+                            }
+                            if (i >= j)
+                                break;
+                            iter_swap(i, j);
+                            ++n_swaps;
+                            ++i;
+                        }
+                        // [first, i) == *first and *first < [i, end)
+                        // The first part is sorted,
+                        if (nth < i)
+                            return;
+
+                        // nth_element the second part
+                        // nth_element<C>(i, nth, end, comp);
+                        restart = true;
+                        break;
+                    }
+                    if (pred(*j, *m))
+                    {
+                        iter_swap(i, j);
+                        ++n_swaps;
+                        break; // found guard for downward moving j, now use unguarded partition
+                    }
+                }
+                if (restart)
+                {
+                    first = i;
+                    continue;
+                }
+            }
+            ++i;
+            // j points beyond range to be tested, *lm1 is known to be <= *m
+            // if not yet partitioned...
+            if (i < j)
+            {
+                // known that *(i - 1) < *m
+                while (true)
+                {
+                    // m still guards upward moving i
+                    while (pred(*i, *m))
+                    {
+                        ++i;
+                    }
+                    // It is now known that a guard exists for downward moving j
+                    while (!pred(*--j, *m))
+                    {
+                    }
+                    if (i >= j)
+                        break;
+                    iter_swap(i, j);
+                    ++n_swaps;
+                    // It is known that m != j
+                    // If m just moved, follow it
+                    if (m == i)
+                        m = j;
+                    ++i;
+                }
+            }
+            // [first, i) < *m and *m <= [i, end)
+            if (i != m && pred(*m, *i))
+            {
+                iter_swap(i, m);
+                ++n_swaps;
+            }
+            // [first, i) < *i and *i <= [i+1, end)
+            if (nth == i)
+                return;
+
+            if (n_swaps == 0)
+            {
+                // We were given a perfectly partitioned sequence.  Coincidence?
+                if (nth < i)
+                {
+                    // Check for [first, i) already sorted
+                    j = m = first;
+                    while (true)
+                    {
+                        if (++j == i)
+                        {
+                            // [first, i) sorted
+                            return;
+                        }
+                        if (pred(*j, *m))
+                        {
+                            // not yet sorted, so sort
+                            break;
+                        }
+                        m = j;
+                    }
+                }
+                else
+                {
+                    // Check for [i, end) already sorted
+                    j = m = i;
+                    while (true)
+                    {
+                        if (++j == end)
+                        {
+                            // [i, end) sorted
+                            return;
+                        }
+                        if (pred(*j, *m))
+                        {
+                            // not yet sorted, so sort
+                            break;
+                        }
+                        m = j;
+                    }
+                }
+            }
+
+            // nth_element on range containing nth
+            if (nth < i)
+            {
+                // nth_element<C>(first, nth, i, comp);
+                end = i;
+            }
+            else
+            {
+                // nth_element<C>(i+1, nth, end, comp);
+                first = ++i;
+            }
+        }
+    }
+
+    template <typename I, typename Comp, typename Proj>
+    static constexpr unsigned
+    sort3(I x, I y, I z, Comp& comp, Proj& proj)
+    {
+        const auto pred = [&comp, &proj](auto&& t, auto&& u) {
+            return nano::invoke(comp, nano::invoke(proj, ::std::forward<decltype(t)>(t)),
+                                nano::invoke(proj, ::std::forward<decltype(u)>(u)));
+        };
+
+        if (!pred(*y, *x))
+        { // if x <= y
+            if (!pred(*z, *y))
+            {             // if y <= z
+                return 0; // x <= y && y <= z
+            }
+            // x <= y && y > z
+            iter_swap(y, z); // x <= z && y < z
+            if (pred(*y, *x))
+            {                    // if x > y
+                iter_swap(x, y); // x < y && y <= z
+                return 2;
+            }
+            return 1; // x <= y && y < z
+        }
+        if (pred(*z, *y))
+        {                    // x > y, if y > z
+            iter_swap(x, z); // x < y && y < z
+            return 1;
+        }
+        iter_swap(x, y); // x > y && y <= z
+        // x < y && x <= z
+        if (pred(*z, *y))
+        {                    // if y > z
+            iter_swap(y, z); // x <= y && y < z
+            return 2;
+        }
+        return 1;
+    }
+
+    template <typename I, typename Comp, typename Proj>
+    static constexpr void
+    selection_sort(I first, I last, Comp& comp, Proj& proj)
+    {
+        for (I lm1 = prev(last); first != lm1; ++first)
+        {
+            I i = min_element_fn::impl(first, last, comp, proj);
+            if (i != first)
+            {
+                iter_swap(first, i);
+            }
+        }
+    }
+
+  public:
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    ::std::enable_if_t<random_access_iterator<I> && sentinel_for<S, I> && sortable<I, Comp, Proj>, I> constexpr
+    operator()(I first, I nth, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        const I ilast = nano::next(nth, last);
+        impl(::std::move(first), nth, ::std::move(ilast), comp, proj);
+        return ilast;
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    ::std::enable_if_t<random_access_range<Rng> && sortable<iterator_t<Rng>, Comp, Proj>,
+                       borrowed_iterator_t<Rng>> constexpr
+    operator()(Rng&& rng, iterator_t<Rng> nth, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        const auto last = nano::next(nth, nano::end(rng));
+        impl(nano::begin(rng), ::std::move(nth), last, comp, proj);
+        return last;
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::nth_element_fn, nth_element)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/partial_sort.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// Copyright Eric Niebler 2014
+// Copyright Casey Carter 2015
+//
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_PARTIAL_SORT_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_PARTIAL_SORT_HPP_INCLUDED
+
+// nanorange/algorithm/sort_heap.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_ALGORITHM_SORT_HEAP_HPP_INCLUDED
+#            define NANORANGE_ALGORITHM_SORT_HEAP_HPP_INCLUDED
+
+// nanorange/algorithm/pop_heap.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#            ifndef NANORANGE_ALGORITHM_POP_HEAP_HPP_INCLUDED
+#                define NANORANGE_ALGORITHM_POP_HEAP_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct pop_heap_fn
+{
+  private:
+    friend struct sort_heap_fn;
+
+    template <typename I, typename Comp, typename Proj>
+    static constexpr I
+    impl(I first, iter_difference_t<I> n, Comp& comp, Proj& proj)
+    {
+        if (n > 1)
+        {
+            nano::iter_swap(first, first + (n - 1));
+            detail::sift_down_n(first, n - 1, first, comp, proj);
+        }
+
+        return first + n;
+    }
+
+  public:
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<random_access_iterator<I> && sentinel_for<S, I> && sortable<I, Comp, Proj>, I>
+    operator()(I first, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        const auto n = nano::distance(first, last);
+        return pop_heap_fn::impl(::std::move(first), n, comp, proj);
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<random_access_range<Rng> && sortable<iterator_t<Rng>, Comp, Proj>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return pop_heap_fn::impl(nano::begin(rng), nano::distance(rng), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::pop_heap_fn, pop_heap)
+
+NANO_END_NAMESPACE
+
+#            endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct sort_heap_fn
+{
+  private:
+    template <typename I, typename Comp, typename Proj>
+    static constexpr I
+    impl(I first, iter_difference_t<I> n, Comp& comp, Proj& proj)
+    {
+        if (n < 2)
+        {
+            return first + n;
+        }
+
+        for (auto i = n; i > 1; --i)
+        {
+            pop_heap_fn::impl(first, i, comp, proj);
+        }
+
+        return first + n;
+    }
+
+  public:
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<random_access_iterator<I> && sentinel_for<S, I> && sortable<I, Comp, Proj>, I>
+    operator()(I first, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        const auto n = nano::distance(first, last);
+        return sort_heap_fn::impl(::std::move(first), n, comp, proj);
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<random_access_range<Rng> && sortable<iterator_t<Rng>, Comp, Proj>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return sort_heap_fn::impl(nano::begin(rng), nano::distance(rng), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::sort_heap_fn, sort_heap)
+
+NANO_END_NAMESPACE
+
+#        endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct partial_sort_fn
+{
+  private:
+    template <typename I, typename S, typename Comp, typename Proj>
+    static constexpr I
+    impl(I first, I middle, S last, Comp& comp, Proj& proj)
+    {
+        nano::make_heap(first, middle, comp, proj);
+        const auto len = nano::distance(first, middle);
+        I i = middle;
+
+        while (i != last)
+        {
+            if (nano::invoke(comp, nano::invoke(proj, *i), nano::invoke(proj, *first)))
+            {
+                nano::iter_swap(i, first);
+                detail::sift_down_n(first, len, first, comp, proj);
+            }
+            ++i;
+        }
+        nano::sort_heap(first, middle, comp, proj);
+        return i;
+    }
+
+  public:
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<random_access_iterator<I> && sentinel_for<S, I> && sortable<I, Comp, Proj>, I>
+    operator()(I first, I middle, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return partial_sort_fn::impl(::std::move(first), ::std::move(middle), ::std::move(last), comp, proj);
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<random_access_range<Rng> && sortable<iterator_t<Rng>, Comp, Proj>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, iterator_t<Rng> middle, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return partial_sort_fn::impl(nano::begin(rng), ::std::move(middle), nano::end(rng), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::partial_sort_fn, partial_sort)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/partial_sort_copy.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_PARTIAL_SORT_COPY_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_PARTIAL_SORT_COPY_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I, typename O>
+using partial_sort_copy_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct partial_sort_copy_fn
+{
+  private:
+    template <typename I1, typename S1, typename I2, typename S2, typename Comp, typename Proj1, typename Proj2>
+    static constexpr partial_sort_copy_result<I1, I2>
+    impl(I1 first, S1 last, I2 result_first, S2 result_last, Comp& comp, Proj1& proj1, Proj2& proj2)
+    {
+        I2 r = result_first;
+        if (r == result_last)
+        {
+            // ::std::move(nano::next()) is needed to avoid GCC ICE.
+            return {::std::move(nano::next(first, last)), ::std::move(result_first)};
+        }
+
+        while (r != result_last && first != last)
+        {
+            *r = *first;
+            ++r;
+            ++first;
+        }
+
+        nano::make_heap(result_first, r, comp, proj2);
+        const auto len = nano::distance(result_first, r);
+
+        while (first != last)
+        {
+            iter_reference_t<I1>&& x = *first;
+            if (nano::invoke(comp, nano::invoke(proj1, x), nano::invoke(proj2, *result_first)))
+            {
+                *result_first = ::std::forward<iter_reference_t<I1>>(x);
+                detail::sift_down_n(result_first, len, result_first, comp, proj2);
+            }
+            ++first;
+        }
+
+        nano::sort_heap(result_first, r, comp, proj2);
+
+        return {::std::move(first), ::std::move(r)};
+    }
+
+  public:
+    template <typename I1, typename S1, typename I2, typename S2, typename Comp = ranges::less,
+              typename Proj1 = identity, typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_iterator<I1> && sentinel_for<S1, I1> && random_access_iterator<I2> &&
+                                     sentinel_for<S2, I2> && indirectly_copyable<I1, I2> && sortable<I2, Comp, Proj2> &&
+                                     indirect_strict_weak_order<Comp, projected<I1, Proj1>, projected<I2, Proj2>>,
+                                 partial_sort_copy_result<I1, I2>>
+    operator()(I1 first, S1 last, I2 result_first, S2 result_last, Comp comp = Comp{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return partial_sort_copy_fn::impl(::std::move(first), ::std::move(last), ::std::move(result_first),
+                                          ::std::move(result_last), comp, proj1, proj2);
+    }
+
+    template <typename Rng1, typename Rng2, typename Comp = ranges::less, typename Proj1 = identity,
+              typename Proj2 = identity>
+    constexpr ::std::enable_if_t<
+        input_range<Rng1> && random_access_range<Rng2> && indirectly_copyable<iterator_t<Rng1>, iterator_t<Rng2>> &&
+            sortable<iterator_t<Rng2>, Comp, Proj2> &&
+            indirect_strict_weak_order<Comp, projected<iterator_t<Rng1>, Proj1>, projected<iterator_t<Rng2>, Proj2>>,
+        partial_sort_copy_result<borrowed_iterator_t<Rng1>, borrowed_iterator_t<Rng2>>>
+    operator()(Rng1&& rng, Rng2&& result_rng, Comp comp = Comp{}, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return partial_sort_copy_fn::impl(nano::begin(rng), nano::end(rng), nano::begin(result_rng),
+                                          nano::end(result_rng), comp, proj1, proj2);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::partial_sort_copy_fn, partial_sort_copy)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/partition.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_PARTITION_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_PARTITION_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct partition_fn
+{
+  private:
+    template <typename I, typename S, typename Pred, typename Proj>
+    static constexpr subrange<I>
+    impl(I first, S last, Pred& pred, Proj& proj)
+    {
+        I it = nano::find_if_not(first, last, pred, proj);
+
+        if (it == last)
+        {
+            return {::std::move(it), ::std::move(nano::next(first, last))};
+        }
+
+        auto n = nano::next(it);
+
+        while (n != last)
+        {
+            if (nano::invoke(pred, nano::invoke(proj, *n)))
+            {
+                nano::iter_swap(n, it);
+                ++it;
+            }
+            ++n;
+        }
+
+        return {::std::move(it), ::std::move(n)};
+    }
+
+  public:
+    template <typename I, typename S, typename Pred, typename Proj = identity>
+    constexpr ::std::enable_if_t<
+        forward_iterator<I> && sentinel_for<S, I> && indirect_unary_predicate<Pred, projected<I, Proj>>, subrange<I>>
+    operator()(I first, S last, Pred pred, Proj proj = Proj{}) const
+    {
+        return partition_fn::impl(::std::move(first), ::std::move(last), pred, proj);
+    }
+
+    template <typename Rng, typename Pred, typename Proj = identity>
+    constexpr ::std::enable_if_t<forward_range<Rng> && indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>>,
+                                 borrowed_subrange_t<Rng>>
+    operator()(Rng&& rng, Pred pred, Proj proj = Proj{}) const
+    {
+        return partition_fn::impl(nano::begin(rng), nano::end(rng), pred, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::partition_fn, partition)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/partition_copy.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_PARTITION_COPY_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_PARTITION_COPY_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I, typename O1, typename O2>
+using partition_copy_result = in_out_out_result<I, O1, O2>;
+
+namespace detail
+{
+
+struct partition_copy_fn
+{
+  private:
+    template <typename I, typename S, typename O1, typename O2, typename Pred, typename Proj>
+    static constexpr partition_copy_result<I, O1, O2>
+    impl(I first, S last, O1 out_true, O2 out_false, Pred& pred, Proj& proj)
+    {
+        while (first != last)
+        {
+            auto&& val = *first;
+            if (nano::invoke(pred, nano::invoke(proj, val)))
+            {
+                *out_true = ::std::forward<decltype(val)>(val);
+                ++out_true;
+            }
+            else
+            {
+                *out_false = ::std::forward<decltype(val)>(val);
+                ++out_false;
+            }
+            ++first;
+        }
+
+        return {::std::move(first), ::std::move(out_true), ::std::move(out_false)};
+    }
+
+  public:
+    template <typename I, typename S, typename O1, typename O2, typename Pred, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> && weakly_incrementable<O1> &&
+                                     weakly_incrementable<O2> && indirect_unary_predicate<Pred, projected<I, Proj>> &&
+                                     indirectly_copyable<I, O1> && indirectly_copyable<I, O2>,
+                                 partition_copy_result<I, O1, O2>>
+    operator()(I first, S last, O1 out_true, O2 out_false, Pred pred, Proj proj = Proj{}) const
+    {
+        return partition_copy_fn::impl(::std::move(first), ::std::move(last), ::std::move(out_true),
+                                       ::std::move(out_false), pred, proj);
+    }
+
+    template <typename Rng, typename O1, typename O2, typename Pred, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_range<Rng> && weakly_incrementable<O1> && weakly_incrementable<O2> &&
+                                     indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>> &&
+                                     indirectly_copyable<iterator_t<Rng>, O1> &&
+                                     indirectly_copyable<iterator_t<Rng>, O2>,
+                                 partition_copy_result<borrowed_iterator_t<Rng>, O1, O2>>
+    operator()(Rng&& rng, O1 out_true, O2 out_false, Pred pred, Proj proj = Proj{}) const
+    {
+        return partition_copy_fn::impl(nano::begin(rng), nano::end(rng), ::std::move(out_true), ::std::move(out_false),
+                                       pred, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::partition_copy_fn, partition_copy)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/prev_permutation.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+// Taken from Range-V3
+//
+// Copyright Eric Niebler 2014-2018
+//
+//===-------------------------- algorithm ---------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#    ifndef NANORANGE_ALGORITHM_PREV_PERMUTATION_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_PREV_PERMUTATION_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I>
+using prev_permutation_result = in_found_result<I>;
+
+namespace detail
+{
+
+struct prev_permutation_fn
+{
+  private:
+    template <typename I, typename S, typename Comp, typename Proj>
+    static constexpr prev_permutation_result<I>
+    impl(I first, S last, Comp& comp, Proj& proj)
+    {
+        if (first == last)
+        {
+            return {::std::move(first), false};
+        }
+
+        I last_it = nano::next(first, last);
+        I i = last_it;
+
+        if (first == --i)
+        {
+            return {::std::move(last_it), false};
+        }
+
+        while (true)
+        {
+            I ip1 = i;
+
+            if (nano::invoke(comp, nano::invoke(proj, *ip1), nano::invoke(proj, *--i)))
+            {
+                I j = last_it;
+
+                while (!nano::invoke(comp, nano::invoke(proj, *--j), nano::invoke(proj, *i)))
+                    ;
+
+                nano::iter_swap(i, j);
+                nano::reverse(ip1, last_it);
+                return {::std::move(last_it), true};
+            }
+
+            if (i == first)
+            {
+                nano::reverse(first, last_it);
+                return {::std::move(last_it), false};
+            }
+        }
+    }
+
+  public:
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<bidirectional_iterator<I> && sentinel_for<S, I> && sortable<I, Comp, Proj>,
+                                 prev_permutation_result<I>>
+    operator()(I first, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return prev_permutation_fn::impl(::std::move(first), ::std::move(last), comp, proj);
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<bidirectional_range<Rng> && sortable<iterator_t<Rng>, Comp, Proj>,
+                                 prev_permutation_result<borrowed_iterator_t<Rng>>>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        return prev_permutation_fn::impl(nano::begin(rng), nano::end(rng), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::prev_permutation_fn, prev_permutation)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/push_heap.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_PUSH_HEAP_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_PUSH_HEAP_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct push_heap_fn
+{
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<random_access_iterator<I> && sentinel_for<S, I> && sortable<I, Comp, Proj>, I>
+    operator()(I first, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        const auto n = nano::distance(first, last);
+        detail::sift_up_n(first, n, comp, proj);
+        return first + n;
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<random_access_range<Rng> && sortable<iterator_t<Rng>, Comp, Proj>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        const auto n = nano::distance(rng);
+        detail::sift_up_n(nano::begin(rng), n, comp, proj);
+        return nano::begin(rng) + n;
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::push_heap_fn, push_heap)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/remove.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_REMOVE_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_REMOVE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct remove_fn
+{
+  private:
+    template <typename I, typename S, typename T, typename Proj>
+    static constexpr I
+    impl(I first, S last, const T& value, Proj& proj)
+    {
+        first = nano::find(::std::move(first), last, value, proj);
+
+        if (first == last)
+        {
+            return first;
+        }
+
+        for (auto i = next(first); i != last; ++i)
+        {
+            if (!(nano::invoke(proj, *i) == value))
+            {
+                *first = nano::iter_move(i);
+                ++first;
+            }
+        }
+
+        return first;
+    }
+
+  public:
+    template <typename I, typename S, typename T, typename Proj = identity>
+    constexpr ::std::enable_if_t<forward_iterator<I> && sentinel_for<S, I> && permutable<I> &&
+                                     indirect_relation<ranges::equal_to, projected<I, Proj>, const T*>,
+                                 I>
+    operator()(I first, S last, const T& value, Proj proj = Proj{}) const
+    {
+        return remove_fn::impl(::std::move(first), ::std::move(last), value, proj);
+    }
+
+    template <typename Rng, typename T, typename Proj = identity>
+    constexpr ::std::enable_if_t<forward_range<Rng> && permutable<iterator_t<Rng>> &&
+                                     indirect_relation<ranges::equal_to, projected<iterator_t<Rng>, Proj>, const T*>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, const T& value, Proj proj = Proj{}) const
+    {
+        return remove_fn::impl(nano::begin(rng), nano::end(rng), value, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::remove_fn, remove)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/remove_copy.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_REMOVE_COPY_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_REMOVE_COPY_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I, typename O>
+using remove_copy_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct remove_copy_fn
+{
+  private:
+    template <typename I, typename S, typename O, typename T, typename Proj>
+    static constexpr remove_copy_result<I, O>
+    impl(I first, S last, O result, const T& value, Proj& proj)
+    {
+        while (first != last)
+        {
+            auto&& ref = *first;
+            if (!(nano::invoke(proj, ref) == value))
+            {
+                *result = ::std::forward<decltype(ref)>(ref);
+                ++result;
+            }
+            ++first;
+        }
+        return {::std::move(first), ::std::move(result)};
+    }
+
+  public:
+    template <typename I, typename S, typename O, typename T, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> && weakly_incrementable<O> &&
+                                     indirectly_copyable<I, O> &&
+                                     indirect_relation<ranges::equal_to, projected<I, Proj>, const T*>,
+                                 remove_copy_result<I, O>>
+    operator()(I first, S last, O result, const T& value, Proj proj = Proj{}) const
+    {
+        return remove_copy_fn::impl(::std::move(first), ::std::move(last), ::std::move(result), value, proj);
+    }
+
+    template <typename Rng, typename O, typename T, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_range<Rng> && weakly_incrementable<O> &&
+                                     indirectly_copyable<iterator_t<Rng>, O> &&
+                                     indirect_relation<ranges::equal_to, projected<iterator_t<Rng>, Proj>, const T*>,
+                                 remove_copy_result<borrowed_iterator_t<Rng>, O>>
+    operator()(Rng&& rng, O result, const T& value, Proj proj = Proj{}) const
+    {
+        return remove_copy_fn::impl(nano::begin(rng), nano::end(rng), ::std::move(result), value, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::remove_copy_fn, remove_copy)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/remove_copy_if.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_REMOVE_COPY_IF_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_REMOVE_COPY_IF_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I, typename O>
+using remove_copy_if_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct remove_copy_if_fn
+{
+  private:
+    template <typename I, typename S, typename O, typename Pred, typename Proj>
+    static constexpr remove_copy_if_result<I, O>
+    impl(I first, S last, O result, Pred& pred, Proj& proj)
+    {
+        while (first != last)
+        {
+            auto&& ref = *first;
+            if (!nano::invoke(pred, nano::invoke(proj, ref)))
+            {
+                *result = ::std::forward<decltype(ref)>(ref);
+                ++result;
+            }
+            ++first;
+        }
+        return {::std::move(first), ::std::move(result)};
+    }
+
+  public:
+    template <typename I, typename S, typename O, typename Pred, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> && weakly_incrementable<O> &&
+                                     indirectly_copyable<I, O> && indirect_unary_predicate<Pred, projected<I, Proj>>,
+                                 remove_copy_if_result<I, O>>
+    operator()(I first, S last, O result, Pred pred, Proj proj = Proj{}) const
+    {
+        return remove_copy_if_fn::impl(::std::move(first), ::std::move(last), ::std::move(result), pred, proj);
+    }
+
+    template <typename Rng, typename O, typename Pred, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_range<Rng> && weakly_incrementable<O> &&
+                                     indirectly_copyable<iterator_t<Rng>, O> &&
+                                     indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>>,
+                                 remove_copy_if_result<borrowed_iterator_t<Rng>, O>>
+    operator()(Rng&& rng, O result, Pred pred, Proj proj = Proj{}) const
+    {
+        return remove_copy_if_fn::impl(nano::begin(rng), nano::end(rng), ::std::move(result), pred, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::remove_copy_if_fn, remove_copy_if)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/remove_if.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_REMOVE_IF_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_REMOVE_IF_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct remove_if_fn
+{
+  private:
+    template <typename I, typename S, typename Pred, typename Proj>
+    static constexpr I
+    impl(I first, S last, Pred& pred, Proj& proj)
+    {
+        first = nano::find_if(::std::move(first), last, pred, proj);
+
+        if (first == last)
+        {
+            return first;
+        }
+
+        for (auto i = next(first); i != last; ++i)
+        {
+            if (!nano::invoke(pred, nano::invoke(proj, *i)))
+            {
+                *first = nano::iter_move(i);
+                ++first;
+            }
+        }
+
+        return first;
+    }
+
+  public:
+    template <typename I, typename S, typename Pred, typename Proj = identity>
+    constexpr ::std::enable_if_t<forward_iterator<I> && sentinel_for<S, I> && permutable<I> &&
+                                     indirect_unary_predicate<Pred, projected<I, Proj>>,
+                                 I>
+    operator()(I first, S last, Pred pred, Proj proj = Proj{}) const
+    {
+        return remove_if_fn::impl(::std::move(first), ::std::move(last), pred, proj);
+    }
+
+    template <typename Rng, typename Pred, typename Proj = identity>
+    constexpr ::std::enable_if_t<forward_range<Rng> && permutable<iterator_t<Rng>> &&
+                                     indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, Pred pred, Proj proj = Proj{}) const
+    {
+        return remove_if_fn::impl(nano::begin(rng), nano::end(rng), pred, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::remove_if_fn, remove_if)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/replace.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_REPLACE_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_REPLACE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct replace_fn
+{
+  private:
+    template <typename I, typename S, typename T1, typename T2, typename Proj>
+    static constexpr I
+    impl(I first, S last, const T1& old_value, const T2& new_value, Proj& proj)
+    {
+        while (first != last)
+        {
+            if (nano::invoke(proj, *first) == old_value)
+            {
+                *first = new_value;
+            }
+            ++first;
+        }
+
+        return first;
+    }
+
+  public:
+    template <typename I, typename S, typename T1, typename T2, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> && writable<I, const T2&> &&
+                                     indirect_relation<ranges::equal_to, projected<I, Proj>, const T1*>,
+                                 I>
+    operator()(I first, S last, const T1& old_value, const T2& new_value, Proj proj = Proj{}) const
+    {
+        return replace_fn::impl(::std::move(first), ::std::move(last), old_value, new_value, proj);
+    }
+
+    template <typename Rng, typename T1, typename T2, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_range<Rng> && writable<iterator_t<Rng>, const T2&> &&
+                                     indirect_relation<ranges::equal_to, projected<iterator_t<Rng>, Proj>, const T1*>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, const T1& old_value, const T2& new_value, Proj proj = Proj{}) const
+    {
+        return replace_fn::impl(nano::begin(rng), nano::end(rng), old_value, new_value, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::replace_fn, replace)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/replace_copy.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_REPLACE_COPY_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_REPLACE_COPY_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I, typename O>
+using replace_copy_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct replace_copy_fn
+{
+  private:
+    template <typename I, typename S, typename O, typename T1, typename T2, typename Proj>
+    static constexpr replace_copy_result<I, O>
+    impl(I first, S last, O result, const T1& old_value, const T2& new_value, Proj& proj)
+    {
+        while (first != last)
+        {
+            if (nano::invoke(proj, *first) == old_value)
+            {
+                *result = new_value;
+            }
+            else
+            {
+                *result = *first;
+            }
+            ++first;
+            ++result;
+        }
+
+        return {::std::move(first), ::std::move(result)};
+    }
+
+  public:
+    template <typename I, typename S, typename O, typename T1, typename T2, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> && output_iterator<O, const T2&> &&
+                                     indirectly_copyable<I, O> &&
+                                     indirect_relation<ranges::equal_to, projected<I, Proj>, const T1*>,
+                                 replace_copy_result<I, O>>
+    operator()(I first, S last, O result, const T1& old_value, const T2& new_value, Proj proj = Proj{}) const
+    {
+        return replace_copy_fn::impl(::std::move(first), ::std::move(last), ::std::move(result), old_value, new_value,
+                                     proj);
+    }
+
+    template <typename Rng, typename O, typename T1, typename T2, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_range<Rng> && output_iterator<O, const T2&> &&
+                                     indirectly_copyable<iterator_t<Rng>, O> &&
+                                     indirect_relation<ranges::equal_to, projected<iterator_t<Rng>, Proj>, const T1*>,
+                                 replace_copy_result<borrowed_iterator_t<Rng>, O>>
+    operator()(Rng&& rng, O result, const T1& old_value, const T2& new_value, Proj proj = Proj{}) const
+    {
+        return replace_copy_fn::impl(nano::begin(rng), nano::end(rng), ::std::move(result), old_value, new_value, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::replace_copy_fn, replace_copy)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/replace_copy_if.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_REPLACE_COPY_IF_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_REPLACE_COPY_IF_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I, typename O>
+using replace_copy_if_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct replace_copy_if_fn
+{
+  private:
+    template <typename I, typename S, typename O, typename Pred, typename T, typename Proj>
+    static constexpr replace_copy_if_result<I, O>
+    impl(I first, S last, O result, Pred& pred, const T& new_value, Proj& proj)
+    {
+        while (first != last)
+        {
+            if (nano::invoke(pred, nano::invoke(proj, *first)))
+            {
+                *result = new_value;
+            }
+            else
+            {
+                *result = *first;
+            }
+            ++first;
+            ++result;
+        }
+
+        return {::std::move(first), ::std::move(result)};
+    }
+
+  public:
+    template <typename I, typename S, typename O, typename Pred, typename T, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> && output_iterator<O, const T&> &&
+                                     indirectly_copyable<I, O> && indirect_unary_predicate<Pred, projected<I, Proj>>,
+                                 replace_copy_if_result<I, O>>
+    operator()(I first, S last, O result, Pred pred, const T& new_value, Proj proj = Proj{}) const
+    {
+        return replace_copy_if_fn::impl(::std::move(first), ::std::move(last), ::std::move(result), pred, new_value,
+                                        proj);
+    }
+
+    template <typename Rng, typename O, typename Pred, typename T, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_range<Rng> && output_iterator<O, const T&> &&
+                                     indirectly_copyable<iterator_t<Rng>, O> &&
+                                     indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>>,
+                                 replace_copy_if_result<borrowed_iterator_t<Rng>, O>>
+    operator()(Rng&& rng, O result, Pred pred, const T& new_value, Proj proj = Proj{}) const
+    {
+        return replace_copy_if_fn::impl(nano::begin(rng), nano::end(rng), ::std::move(result), pred, new_value, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::replace_copy_if_fn, replace_copy_if)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/replace_if.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_REPLACE_IF_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_REPLACE_IF_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct replace_if_fn
+{
+  private:
+    template <typename I, typename S, typename Pred, typename T, typename Proj>
+    static constexpr I
+    impl(I first, S last, Pred& pred, const T& new_value, Proj& proj)
+    {
+        while (first != last)
+        {
+            if (nano::invoke(pred, nano::invoke(proj, *first)))
+            {
+                *first = new_value;
+            }
+            ++first;
+        }
+
+        return first;
+    }
+
+  public:
+    template <typename I, typename S, typename T, typename Pred, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> && writable<I, const T&> &&
+                                     indirect_unary_predicate<Pred, projected<I, Proj>>,
+                                 I>
+    operator()(I first, S last, Pred pred, const T& new_value, Proj proj = Proj{}) const
+    {
+        return replace_if_fn::impl(::std::move(first), ::std::move(last), pred, new_value, proj);
+    }
+
+    template <typename Rng, typename Pred, typename T2, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_range<Rng> && writable<iterator_t<Rng>, const T2&> &&
+                                     indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, Pred pred, const T2& new_value, Proj proj = Proj{}) const
+    {
+        return replace_if_fn::impl(nano::begin(rng), nano::end(rng), pred, new_value, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::replace_if_fn, replace_if)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/reverse_copy.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_REVERSE_COPY_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_REVERSE_COPY_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I, typename O>
+using reverse_copy_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct reverse_copy_fn
+{
+  private:
+    template <typename I, typename O>
+    static constexpr reverse_copy_result<I, O>
+    impl(I first, I last, O result)
+    {
+        auto ret = last;
+        while (last != first)
+        {
+            *result = *--last;
+            ++result;
+        }
+
+        return {::std::move(ret), ::std::move(result)};
+    }
+
+    template <typename I, typename S, typename O>
+    static constexpr ::std::enable_if_t<!same_as<I, S>, reverse_copy_result<I, O>>
+    impl(I first, S bound, O result)
+    {
+        return reverse_copy_fn::impl(::std::move(first), nano::next(first, bound), ::std::move(result));
+    }
+
+  public:
+    template <typename I, typename S, typename O>
+    constexpr ::std::enable_if_t<bidirectional_iterator<I> && sentinel_for<S, I> && weakly_incrementable<O> &&
+                                     indirectly_copyable<I, O>,
+                                 reverse_copy_result<I, O>>
+    operator()(I first, S last, O result) const
+    {
+        return reverse_copy_fn::impl(::std::move(first), ::std::move(last), ::std::move(result));
+    }
+
+    template <typename Rng, typename O>
+    constexpr ::std::enable_if_t<bidirectional_range<Rng> && weakly_incrementable<O> &&
+                                     indirectly_copyable<iterator_t<Rng>, O>,
+                                 reverse_copy_result<borrowed_iterator_t<Rng>, O>>
+    operator()(Rng&& rng, O result) const
+    {
+        return reverse_copy_fn::impl(nano::begin(rng), nano::end(rng), ::std::move(result));
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::reverse_copy_fn, reverse_copy)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/rotate_copy.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_ROTATE_COPY_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_ROTATE_COPY_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I, typename O>
+using rotate_copy_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct rotate_copy_fn
+{
+  private:
+    template <typename I, typename S, typename O>
+    static constexpr rotate_copy_result<I, O>
+    impl(I first, I middle, S last, O result)
+    {
+        auto ret = nano::copy(middle, ::std::move(last), ::std::move(result));
+        ret.out = nano::copy(::std::move(first), ::std::move(middle), ret.out).out;
+        return ret;
+    }
+
+  public:
+    template <typename I, typename S, typename O>
+    constexpr ::std::enable_if_t<forward_iterator<I> && sentinel_for<S, I> && weakly_incrementable<O> &&
+                                     indirectly_copyable<I, O>,
+                                 rotate_copy_result<I, O>>
+    operator()(I first, I middle, S last, O result) const
+    {
+        return rotate_copy_fn::impl(::std::move(first), ::std::move(middle), ::std::move(last), ::std::move(result));
+    }
+
+    template <typename Rng, typename O>
+    constexpr ::std::enable_if_t<forward_range<Rng> && weakly_incrementable<O> &&
+                                     indirectly_copyable<iterator_t<Rng>, O>,
+                                 rotate_copy_result<borrowed_iterator_t<Rng>, O>>
+    operator()(Rng&& rng, iterator_t<Rng> middle, O result) const
+    {
+        return rotate_copy_fn::impl(nano::begin(rng), ::std::move(middle), nano::end(rng), ::std::move(result));
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::rotate_copy_fn, rotate_copy)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/search_n.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_SEARCH_N_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_SEARCH_N_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct search_n_fn
+{
+  private:
+    template <typename I, typename S, typename T, typename Pred, typename Proj>
+    static constexpr subrange<I>
+    impl(I first, S last, iter_difference_t<I> count, const T& value, Pred pred, Proj& proj)
+    {
+        if (count == iter_difference_t<I>{0})
+        {
+            return {first, first};
+        }
+
+        for (; first != last; ++first)
+        {
+            if (!nano::invoke(pred, nano::invoke(proj, *first), value))
+            {
+                continue;
+            }
+
+            I save = first;
+            iter_difference_t<I> running_count{1};
+
+            while (true)
+            {
+                if (running_count++ == count)
+                {
+                    // Success
+                    return {save, nano::next(first)};
+                }
+
+                if (++first == last)
+                {
+                    // We have run out of elements
+                    return {first, first};
+                }
+
+                if (!nano::invoke(pred, nano::invoke(proj, *first), value))
+                {
+                    break;
+                }
+            }
+        }
+
+        return {first, first};
+    }
+
+  public:
+    template <typename I, typename S, typename T, typename Pred = ranges::equal_to, typename Proj = identity>
+    constexpr auto operator()(I first, S last, iter_difference_t<I> count, const T& value, Pred pred = Pred{},
+                              Proj proj = Proj{}) const
+        -> ::std::enable_if_t<
+            forward_iterator<I> && sentinel_for<S, I> && indirectly_comparable<I, const T*, Pred, Proj>, subrange<I>>
+    {
+        return search_n_fn::impl(::std::move(first), ::std::move(last), count, value, pred, proj);
+    }
+
+    template <typename Rng, typename T, typename Pred = ranges::equal_to, typename Proj = identity>
+    constexpr auto operator()(Rng&& rng, iter_difference_t<iterator_t<Rng>> count, const T& value, Pred pred = Pred{},
+                              Proj proj = Proj{}) const
+        -> ::std::enable_if_t<forward_range<Rng> && indirectly_comparable<iterator_t<Rng>, const T*, Pred, Proj>,
+                              borrowed_subrange_t<Rng>>
+    {
+        return search_n_fn::impl(nano::begin(rng), nano::end(rng), count, value, pred, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::search_n_fn, search_n)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/set_difference.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_SET_DIFFERENCE_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_SET_DIFFERENCE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I, typename O>
+using set_difference_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct set_difference_fn
+{
+  private:
+    template <typename I1, typename S1, typename I2, typename S2, typename O, typename Comp, typename Proj1,
+              typename Proj2>
+    static constexpr set_difference_result<I1, O>
+    impl(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp& comp, Proj1& proj1, Proj2& proj2)
+    {
+        while (first1 != last1)
+        {
+            if (first2 == last2)
+            {
+                // We've reached the end of range2, so copy all the remaining
+                // elements from range1 and exit
+                auto res = nano::copy(::std::move(first1), ::std::move(last1), ::std::move(result));
+                first1 = ::std::move(res.in);
+                result = ::std::move(res.out);
+
+                break;
+            }
+
+            // If the element from r1 compares less than the one from r2, then
+            // copy it
+            if (nano::invoke(comp, nano::invoke(proj1, *first1), nano::invoke(proj2, *first2)))
+            {
+                *result = *first1;
+                ++first1;
+                ++result;
+            }
+            else
+            {
+                // We now know that !(r1 < r2). If !(r2 < r1) as well, then
+                // elements are equal and we can skip
+                if (!nano::invoke(comp, nano::invoke(proj2, *first2), nano::invoke(proj1, *first1)))
+                {
+                    ++first1;
+                }
+                ++first2;
+            }
+        }
+
+        return {::std::move(first1), ::std::move(result)};
+    }
+
+  public:
+    template <typename I1, typename S1, typename I2, typename S2, typename O, typename Comp = ranges::less,
+              typename Proj1 = identity, typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_iterator<I1> && sentinel_for<S1, I1> && input_iterator<I2> &&
+                                     sentinel_for<S2, I2> && weakly_incrementable<O> &&
+                                     mergeable<I1, I2, O, Comp, Proj1, Proj2>,
+                                 set_difference_result<I1, O>>
+    operator()(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp comp = Comp{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return set_difference_fn::impl(::std::move(first1), ::std::move(last1), ::std::move(first2), ::std::move(last2),
+                                       ::std::move(result), comp, proj1, proj2);
+    }
+
+    template <typename Rng1, typename Rng2, typename O, typename Comp = ranges::less, typename Proj1 = identity,
+              typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_range<Rng1> && input_range<Rng2> && weakly_incrementable<O> &&
+                                     mergeable<iterator_t<Rng1>, iterator_t<Rng2>, O, Comp, Proj1, Proj2>,
+                                 set_difference_result<borrowed_iterator_t<Rng1>, O>>
+    operator()(Rng1&& rng1, Rng2&& rng2, O result, Comp comp = Comp{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return set_difference_fn::impl(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), nano::end(rng2),
+                                       ::std::move(result), comp, proj1, proj2);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::set_difference_fn, set_difference)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/set_intersection.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_SET_INTERSECTION_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_SET_INTERSECTION_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct set_intersection_fn
+{
+  private:
+    template <typename I1, typename S1, typename I2, typename S2, typename O, typename Comp, typename Proj1,
+              typename Proj2>
+    static constexpr O
+    impl(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp& comp, Proj1& proj1, Proj2& proj2)
+    {
+        while (first1 != last1 && first2 != last2)
+        {
+            if (nano::invoke(comp, nano::invoke(proj1, *first1), nano::invoke(proj2, *first2)))
+            {
+                ++first1;
+            }
+            else
+            {
+                if (!nano::invoke(comp, nano::invoke(proj2, *first2), nano::invoke(proj1, *first1)))
+                {
+                    *result = *first1;
+                    ++result;
+                    ++first1;
+                }
+                ++first2;
+            }
+        }
+
+        return result;
+    }
+
+  public:
+    template <typename I1, typename S1, typename I2, typename S2, typename O, typename Comp = ranges::less,
+              typename Proj1 = identity, typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_iterator<I1> && sentinel_for<S1, I1> && input_iterator<I2> &&
+                                     sentinel_for<S2, I2> && weakly_incrementable<O> &&
+                                     mergeable<I1, I2, O, Comp, Proj1, Proj2>,
+                                 O>
+    operator()(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp comp = Comp{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return set_intersection_fn::impl(::std::move(first1), ::std::move(last1), ::std::move(first2),
+                                         ::std::move(last2), ::std::move(result), comp, proj1, proj2);
+    }
+
+    template <typename Rng1, typename Rng2, typename O, typename Comp = ranges::less, typename Proj1 = identity,
+              typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_range<Rng1> && input_range<Rng2> && weakly_incrementable<O> &&
+                                     mergeable<iterator_t<Rng1>, iterator_t<Rng2>, O, Comp, Proj1, Proj2>,
+                                 O>
+    operator()(Rng1&& rng1, Rng2&& rng2, O result, Comp comp = Comp{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return set_intersection_fn::impl(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), nano::end(rng2),
+                                         ::std::move(result), comp, proj1, proj2);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::set_intersection_fn, set_intersection)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/set_symmetric_difference.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_SET_SYMMETRIC_DIFFERENCE_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_SET_SYMMETRIC_DIFFERENCE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I1, typename I2, typename O>
+using set_symmetric_difference_result = in_in_out_result<I1, I2, O>;
+
+namespace detail
+{
+
+struct set_symmetric_difference_fn
+{
+  private:
+    template <typename I1, typename S1, typename I2, typename S2, typename O, typename Comp, typename Proj1,
+              typename Proj2>
+    static constexpr set_symmetric_difference_result<I1, I2, O>
+    impl(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp& comp, Proj1& proj1, Proj2& proj2)
+    {
+        while (true)
+        {
+            if (first1 == last1)
+            {
+                auto copy_res = nano::copy(::std::move(first2), ::std::move(last2), ::std::move(result));
+
+                return {::std::move(first1), ::std::move(copy_res.in), ::std::move(copy_res.out)};
+            }
+
+            if (first2 == last2)
+            {
+                auto copy_res = nano::copy(::std::move(first1), ::std::move(last1), ::std::move(result));
+                return {::std::move(copy_res.in), ::std::move(first2), ::std::move(copy_res.out)};
+            }
+
+            // If r1 is less than r2, copy it to the output
+            if (nano::invoke(comp, nano::invoke(proj1, *first1), nano::invoke(proj2, *first2)))
+            {
+                *result = *first1;
+                ++result;
+                ++first1;
+            }
+            else
+            {
+                // We now know that !(r1 < r2). If !(r2 < r1) as well then
+                // the elements are equal -- so skip
+                if (!nano::invoke(comp, nano::invoke(proj2, *first2), nano::invoke(proj1, *first1)))
+                {
+                    ++first1;
+                }
+                else
+                {
+                    // Otherwise copy first2
+                    *result = *first2;
+                    ++result;
+                }
+                ++first2;
+            }
+        }
+    }
+
+  public:
+    template <typename I1, typename S1, typename I2, typename S2, typename O, typename Comp = ranges::less,
+              typename Proj1 = identity, typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_iterator<I1> && sentinel_for<S1, I1> && input_iterator<I2> &&
+                                     sentinel_for<S2, I2> && weakly_incrementable<O> &&
+                                     mergeable<I1, I2, O, Comp, Proj1, Proj2>,
+                                 set_symmetric_difference_result<I1, I2, O>>
+    operator()(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp comp = Comp{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return set_symmetric_difference_fn::impl(::std::move(first1), ::std::move(last1), ::std::move(first2),
+                                                 ::std::move(last2), ::std::move(result), comp, proj1, proj2);
+    }
+
+    template <typename Rng1, typename Rng2, typename O, typename Comp = ranges::less, typename Proj1 = identity,
+              typename Proj2 = identity>
+    ::std::enable_if_t<input_range<Rng1> && input_range<Rng2> && weakly_incrementable<O> &&
+                           mergeable<iterator_t<Rng1>, iterator_t<Rng2>, O, Comp, Proj1, Proj2>,
+                       set_symmetric_difference_result<borrowed_iterator_t<Rng1>, borrowed_iterator_t<Rng2>, O>>
+    operator()(Rng1&& rng1, Rng2&& rng2, O result, Comp comp = Comp{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return set_symmetric_difference_fn::impl(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), nano::end(rng2),
+                                                 ::std::move(result), comp, proj1, proj2);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::set_symmetric_difference_fn, set_symmetric_difference)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/set_union.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_SET_UNION_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_SET_UNION_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I1, typename I2, typename O>
+using set_union_result = in_in_out_result<I1, I2, O>;
+
+namespace detail
+{
+
+struct set_union_fn
+{
+  private:
+    template <typename I1, typename S1, typename I2, typename S2, typename O, typename Comp, typename Proj1,
+              typename Proj2>
+    static constexpr set_union_result<I1, I2, O>
+    impl(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp& comp, Proj1& proj1, Proj2& proj2)
+    {
+        while (first1 != last1)
+        {
+            // If we've reached the end of the second range, copy any remaining
+            // elements from the first range and quit
+            if (first2 == last2)
+            {
+                auto copy_res = nano::copy(::std::move(first1), ::std::move(last1), ::std::move(result));
+
+                first1 = ::std::move(copy_res.in);
+                result = ::std::move(copy_res.out);
+
+                break;
+            }
+
+            // If this element from r1 is less than the current element from r2,
+            // copy it and move on
+            if (nano::invoke(comp, nano::invoke(proj1, *first1), nano::invoke(proj2, *first2)))
+            {
+                *result = *first1;
+                ++first1;
+            }
+            else
+            {
+                // Now, we know that !(r1 < r2). If we also have !(r2 < r1) then
+                // the elements compare equal, so skip it
+                if (!nano::invoke(comp, nano::invoke(proj2, *first2), nano::invoke(proj1, *first1)))
+                {
+                    ++first1;
+                }
+                *result = *first2;
+                ++first2;
+            }
+            ++result;
+        }
+
+        // We've run out of elements of range1, so copy all the remaining
+        // elements of range2
+        auto copy_res = nano::copy(::std::move(first2), ::std::move(last2), ::std::move(result));
+
+        return {::std::move(first1), ::std::move(copy_res.in), ::std::move(copy_res.out)};
+    }
+
+  public:
+    template <typename I1, typename S1, typename I2, typename S2, typename O, typename Comp = ranges::less,
+              typename Proj1 = identity, typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_iterator<I1> && sentinel_for<S1, I1> && input_iterator<I2> &&
+                                     sentinel_for<S2, I2> && weakly_incrementable<O> &&
+                                     mergeable<I1, I2, O, Comp, Proj1, Proj2>,
+                                 set_union_result<I1, I2, O>>
+    operator()(I1 first1, S1 last1, I2 first2, S2 last2, O result, Comp comp = Comp{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return set_union_fn::impl(::std::move(first1), ::std::move(last1), ::std::move(first2), ::std::move(last2),
+                                  ::std::move(result), comp, proj1, proj2);
+    }
+
+    template <typename Rng1, typename Rng2, typename O, typename Comp = ranges::less, typename Proj1 = identity,
+              typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_range<Rng1> && input_range<Rng2> && weakly_incrementable<O> &&
+                                     mergeable<iterator_t<Rng1>, iterator_t<Rng2>, O, Comp, Proj1, Proj2>,
+                                 set_union_result<borrowed_iterator_t<Rng1>, borrowed_iterator_t<Rng2>, O>>
+    operator()(Rng1&& rng1, Rng2&& rng2, O result, Comp comp = Comp{}, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return set_union_fn::impl(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), nano::end(rng2),
+                                  ::std::move(result), comp, proj1, proj2);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::set_union_fn, set_union)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/sample.hpp
+//
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#    ifndef NANORANGE_ALGORITHM_SAMPLE_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_SAMPLE_HPP_INCLUDED
+
+// nanorange/random.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_RANDOM_HPP_INCLUDED
+#            define NANORANGE_RANDOM_HPP_INCLUDED
+
+// nanorange/concepts.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#            ifndef NANORANGE_CONCEPTS_HPP_INCLUDED
+#                define NANORANGE_CONCEPTS_HPP_INCLUDED
+
+#            endif
+
+NANO_BEGIN_NAMESPACE
+
+//  [rand.req.urng]
+
+namespace detail
+{
+
+struct uniform_random_bit_generator_concept
+{
+    template <typename>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename G>
+    static auto
+    test(int) -> ::std::enable_if_t<invocable<G&> && unsigned_integral<invoke_result_t<G&>> &&
+                                        detail::requires_<uniform_random_bit_generator_concept, G>,
+                                    ::std::true_type>;
+
+    template <typename G>
+    auto
+    requires_() -> decltype(requires_expr<same_as<decltype(G::min()), invoke_result_t<G&>>>{},
+                            requires_expr<same_as<decltype(G::max()), invoke_result_t<G&>>>{});
+};
+
+} // namespace detail
+
+template <typename G>
+NANO_CONCEPT uniform_random_bit_generator = decltype(detail::uniform_random_bit_generator_concept::test<G>(0))::value;
+
+NANO_END_NAMESPACE
+
+#        endif
+
+#        include <random>
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct sample_fn
+{
+  private:
+    template <typename I, typename S, typename O, typename Gen>
+    static O
+    impl_fwd(I first, S last, O out, iter_difference_t<I> n, Gen& g)
+    {
+        using diff_t = iter_difference_t<I>;
+        using distr_t = ::std::uniform_int_distribution<diff_t>;
+        using param_t = typename distr_t::param_type;
+
+        distr_t D;
+
+        auto unsampled_size = nano::distance(first, last);
+
+        for (n = nano::min(n, unsampled_size); n != 0; ++first)
+        {
+            if (D(g, param_t(0, --unsampled_size)) < n)
+            {
+                *out++ = *first;
+                --n;
+            }
+        }
+
+        return out;
+    }
+    template <typename I, typename S, typename O, typename Gen>
+    static O
+    impl_ra(I first, S last, O out, iter_difference_t<I> n, Gen& g)
+    {
+        using diff_t = iter_difference_t<I>;
+        using distr_t = ::std::uniform_int_distribution<diff_t>;
+        using param_t = typename distr_t::param_type;
+
+        distr_t D;
+        diff_t k = 0;
+
+        for (; first != last && k < n; ++first, (void)++k)
+        {
+            out[k] = *first;
+        }
+
+        diff_t size = k;
+        for (; first != last; ++first, (void)++k)
+        {
+            diff_t r = distr_t(0, k)(g);
+            if (D(g, param_t(0, k)) < size)
+            {
+                out[r] = *first;
+            }
+        }
+
+        return out + nano::min(n, k);
+    }
+
+    template <typename I, typename S, typename O, typename Gen>
+    static O
+    impl(I first, S last, O out, iter_difference_t<I> n, Gen& g)
+    {
+        if constexpr (nano::forward_iterator<I>)
+        {
+            return impl_fwd(::std::move(first), ::std::move(last), ::std::move(out), n, g);
+        }
+        else
+        {
+            return impl_ra(::std::move(first), ::std::move(last), ::std::move(out), n, g);
+        }
+    }
+
+  public:
+    template <typename I, typename S, typename O, typename Gen>
+    ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> && weakly_incrementable<O> &&
+                           (forward_iterator<I> || random_access_iterator<O>)&&indirectly_copyable<I, O> &&
+                           uniform_random_bit_generator<::std::remove_reference_t<Gen>>,
+                       O>
+    operator()(I first, S last, O out, iter_difference_t<I> n, Gen&& gen) const
+    {
+        return sample_fn::impl(::std::move(first), ::std::move(last), ::std::move(out), ::std::move(n),
+                               ::std::forward<Gen>(gen));
+    }
+
+    template <typename Rng, typename O, typename Gen>
+    ::std::enable_if_t<input_range<Rng> && weakly_incrementable<O> &&
+                           (forward_range<Rng> || random_access_iterator<O>)&&indirectly_copyable<iterator_t<Rng>, O> &&
+                           uniform_random_bit_generator<::std::remove_reference_t<Gen>>,
+                       O>
+    operator()(Rng&& rng, O out, range_difference_t<Rng> n, Gen&& gen) const
+    {
+        return sample_fn::impl(nano::begin(rng), nano::end(rng), ::std::move(out), ::std::move(n),
+                               ::std::forward<Gen>(gen));
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::sample_fn, sample)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/shuffle.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_SHUFFLE_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_SHUFFLE_HPP_INCLUDED
+
+#        include <random>
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct shuffle_fn
+{
+  private:
+    template <typename I, typename S, typename Gen>
+    static constexpr I
+    impl(I first, S last, Gen&& g)
+    {
+        using diff_t = iter_difference_t<I>;
+        using distr_t = ::std::uniform_int_distribution<diff_t>;
+        using param_t = typename distr_t::param_type;
+
+        distr_t D;
+        const auto n = last - first; // OK, we have SizedSentinel
+
+        for (diff_t i = 0; i < n; i++)
+        {
+            nano::iter_swap(first + i, first + D(g, param_t(0, i)));
+        }
+
+        return next(first, last);
+    }
+
+  public:
+    template <typename I, typename S, typename Gen>
+    constexpr ::std::enable_if_t<random_access_iterator<I> && sentinel_for<S, I> &&
+                                     uniform_random_bit_generator<::std::remove_reference_t<Gen>> &&
+                                     convertible_to<invoke_result_t<Gen&>, iter_difference_t<I>>,
+                                 I>
+    operator()(I first, S last, Gen&& gen) const
+    {
+        return shuffle_fn::impl(::std::move(first), ::std::move(last), ::std::forward<Gen>(gen));
+    }
+
+    template <typename Rng, typename Gen>
+    constexpr ::std::enable_if_t<random_access_range<Rng> &&
+                                     uniform_random_bit_generator<::std::remove_reference_t<Gen>> &&
+                                     convertible_to<invoke_result_t<Gen&>, iter_difference_t<iterator_t<Rng>>>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, Gen&& gen) const
+    {
+        return shuffle_fn::impl(nano::begin(rng), nano::end(rng), ::std::forward<Gen>(gen));
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::shuffle_fn, shuffle)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/sort.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_SORT_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_SORT_HPP_INCLUDED
+
+// nanorange/detail/algorithm/pqdsort.hpp
+//
+// Copyright Orson Peters 2017.
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+// Modified from Boost.Sort by Orson Peters
+// https://github.com/boostorg/sort/blob/develop/include/boost/sort/pdqsort/pdqsort.hpp
+
+#        ifndef NANORANGE_DETAIL_ALGORITHM_PDQSORT_HPP_INCLUDED
+#            define NANORANGE_DETAIL_ALGORITHM_PDQSORT_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+// Partitions below this size are sorted using insertion sort.
+constexpr int pdqsort_insertion_sort_threshold = 24;
+
+// Partitions above this size use Tukey's ninther to select the pivot.
+constexpr int pdqsort_ninther_threshold = 128;
+
+// When we detect an already sorted partition, attempt an insertion sort that
+// allows this amount of element moves before giving up.
+constexpr int pqdsort_partial_insertion_sort_limit = 8;
+
+// Must be multiple of 8 due to loop unrolling, and < 256 to fit in unsigned
+// char.
+constexpr int pdqsort_block_size = 64;
+
+// Cacheline size, assumes power of two.
+constexpr int pdqsort_cacheline_size = 64;
+
+template <typename>
+struct is_default_compare : ::std::false_type
+{
+};
+template <>
+struct is_default_compare<nano::less> : ::std::true_type
+{
+};
+template <>
+struct is_default_compare<nano::greater> : ::std::true_type
+{
+};
+template <typename T>
+struct is_default_compare<::std::less<T>> : ::std::true_type
+{
+};
+template <typename T>
+struct is_default_compare<::std::greater<T>> : ::std::true_type
+{
+};
+
+template <typename T>
+constexpr bool is_default_compare_v = is_default_compare<T>::value;
+
+// Returns floor(log2(n)), assumes n > 0.
+template <class T>
+constexpr int
+log2(T n)
+{
+    int log = 0;
+    while (n >>= 1)
+        ++log;
+    return log;
+}
+
+// Sorts [begin, end) using insertion sort with the given comparison function.
+template <typename I, typename Comp, typename Proj>
+constexpr void
+insertion_sort(I begin, I end, Comp& comp, Proj& proj)
+{
+    using T = iter_value_t<I>;
+
+    if (begin == end)
+    {
+        return;
+    }
+
+    for (I cur = begin + 1; cur != end; ++cur)
+    {
+        I sift = cur;
+        I sift_1 = cur - 1;
+
+        // Compare first so we can avoid 2 moves for an element already
+        // positioned correctly.
+        if (nano::invoke(comp, nano::invoke(proj, *sift), nano::invoke(proj, *sift_1)))
+        {
+            T tmp = nano::iter_move(sift);
+
+            do
+            {
+                *sift-- = nano::iter_move(sift_1);
+            } while (sift != begin && nano::invoke(comp, nano::invoke(proj, tmp), nano::invoke(proj, *--sift_1)));
+
+            *sift = ::std::move(tmp);
+        }
+    }
+}
+
+// Sorts [begin, end) using insertion sort with the given comparison function.
+// Assumes
+// *(begin - 1) is an element smaller than or equal to any element in [begin,
+// end).
+template <typename I, typename Comp, typename Proj>
+constexpr void
+unguarded_insertion_sort(I begin, I end, Comp& comp, Proj& proj)
+{
+    using T = iter_value_t<I>;
+
+    if (begin == end)
+    {
+        return;
+    }
+
+    for (I cur = begin + 1; cur != end; ++cur)
+    {
+        I sift = cur;
+        I sift_1 = cur - 1;
+
+        // Compare first so we can avoid 2 moves for an element already
+        // positioned correctly.
+        if (nano::invoke(comp, nano::invoke(proj, *sift), nano::invoke(proj, *sift_1)))
+        {
+            T tmp = nano::iter_move(sift);
+
+            do
+            {
+                *sift-- = nano::iter_move(sift_1);
+            } while (nano::invoke(comp, nano::invoke(proj, tmp), nano::invoke(proj, *--sift_1)));
+
+            *sift = ::std::move(tmp);
+        }
+    }
+}
+
+// Attempts to use insertion sort on [begin, end). Will return false if more
+// than partial_insertion_sort_limit elements were moved, and abort sorting.
+// Otherwise it will successfully sort and return true.
+template <typename I, typename Comp, typename Proj>
+constexpr bool
+partial_insertion_sort(I begin, I end, Comp& comp, Proj& proj)
+{
+    using T = iter_value_t<I>;
+
+    if (begin == end)
+    {
+        return true;
+    }
+
+    iter_difference_t<I> limit = 0;
+    for (I cur = begin + 1; cur != end; ++cur)
+    {
+        if (limit > pqdsort_partial_insertion_sort_limit)
+        {
+            return false;
+        }
+
+        I sift = cur;
+        I sift_1 = cur - 1;
+
+        // Compare first so we can avoid 2 moves for an element already
+        // positioned correctly.
+        if (nano::invoke(comp, nano::invoke(proj, *sift), nano::invoke(proj, *sift_1)))
+        {
+            T tmp = nano::iter_move(sift);
+
+            do
+            {
+                *sift-- = nano::iter_move(sift_1);
+            } while (sift != begin && nano::invoke(comp, nano::invoke(proj, tmp), nano::invoke(proj, *--sift_1)));
+
+            *sift = ::std::move(tmp);
+            limit += cur - sift;
+        }
+    }
+
+    return true;
+}
+
+template <typename I, typename Comp, typename Proj>
+constexpr void
+sort2(I a, I b, Comp& comp, Proj& proj)
+{
+    if (nano::invoke(comp, nano::invoke(proj, *b), nano::invoke(proj, *a)))
+    {
+        nano::iter_swap(a, b);
+    }
+}
+
+// Sorts the elements *a, *b and *c using comparison function comp.
+template <typename I, typename Comp, typename Proj>
+constexpr void
+sort3(I a, I b, I c, Comp& comp, Proj& proj)
+{
+    sort2(a, b, comp, proj);
+    sort2(b, c, comp, proj);
+    sort2(a, b, comp, proj);
+}
+
+template <typename I>
+constexpr void
+swap_offsets(I first, I last, unsigned char* offsets_l, unsigned char* offsets_r, int num, bool use_swaps)
+{
+    using T = iter_value_t<I>;
+    if (use_swaps)
+    {
+        // This case is needed for the descending distribution, where we need
+        // to have proper swapping for pdqsort to remain O(n).
+        for (int i = 0; i < num; ++i)
+        {
+            nano::iter_swap(first + offsets_l[i], last - offsets_r[i]);
+        }
+    }
+    else if (num > 0)
+    {
+        I l = first + offsets_l[0];
+        I r = last - offsets_r[0];
+        T tmp(nano::iter_move(l));
+        *l = nano::iter_move(r);
+
+        for (int i = 1; i < num; ++i)
+        {
+            l = first + offsets_l[i];
+            *r = nano::iter_move(l);
+            r = last - offsets_r[i];
+            *l = nano::iter_move(r);
+        }
+        *r = ::std::move(tmp);
+    }
+}
+
+// Partitions [begin, end) around pivot *begin using comparison function comp.
+// Elements equal to the pivot are put in the right-hand partition. Returns the
+// position of the pivot after partitioning and whether the passed sequence
+// already was correctly partitioned. Assumes the pivot is a median of at least
+// 3 elements and that [begin, end) is at least insertion_sort_threshold long.
+// Uses branchless partitioning.
+template <typename I, typename Comp, typename Pred>
+constexpr ::std::pair<I, bool>
+partition_right_branchless(I begin, I end, Comp& comp, Pred& pred)
+{
+    using T = iter_value_t<I>;
+
+    // Move pivot into local for speed.
+    T pivot(nano::iter_move(begin));
+    I first = begin;
+    I last = end;
+
+    // Find the first element greater than or equal than the pivot (the median
+    // of 3 guarantees this exists).
+    while (nano::invoke(comp, nano::invoke(pred, *++first), nano::invoke(pred, pivot)))
+        ;
+
+    // Find the first element strictly smaller than the pivot. We have to guard
+    // this search if there was no element before *first.
+    if (first - 1 == begin)
+    {
+        while (first < last && !nano::invoke(comp, nano::invoke(pred, *--last), nano::invoke(pred, pivot)))
+            ;
+    }
+    else
+    {
+        while (!nano::invoke(comp, nano::invoke(pred, *--last), nano::invoke(pred, pivot)))
+            ;
+    }
+
+    // If the first pair of elements that should be swapped to partition are the
+    // same element, the passed in sequence already was correctly partitioned.
+    bool already_partitioned = first >= last;
+    if (!already_partitioned)
+    {
+        nano::iter_swap(first, last);
+        ++first;
+    }
+
+    // The following branchless partitioning is derived from "BlockQuicksort:
+    // How Branch Mispredictions don't affect Quicksort" by Stefan Edelkamp and
+    // Armin Weiss.
+    alignas(pdqsort_cacheline_size) unsigned char offsets_l_storage[pdqsort_block_size] = {};
+    alignas(pdqsort_cacheline_size) unsigned char offsets_r_storage[pdqsort_block_size] = {};
+    unsigned char* offsets_l = offsets_l_storage;
+    unsigned char* offsets_r = offsets_r_storage;
+    int num_l = 0, num_r = 0, start_l = 0, start_r = 0;
+
+    while (last - first > 2 * pdqsort_block_size)
+    {
+        // Fill up offset blocks with elements that are on the wrong side.
+        if (num_l == 0)
+        {
+            start_l = 0;
+            I it = first;
+            for (unsigned char i = 0; i < pdqsort_block_size;)
+            {
+                offsets_l[num_l] = i++;
+                num_l += !nano::invoke(comp, nano::invoke(pred, *it), nano::invoke(pred, pivot));
+                ++it;
+                offsets_l[num_l] = i++;
+                num_l += !nano::invoke(comp, nano::invoke(pred, *it), nano::invoke(pred, pivot));
+                ++it;
+                offsets_l[num_l] = i++;
+                num_l += !nano::invoke(comp, nano::invoke(pred, *it), nano::invoke(pred, pivot));
+                ++it;
+                offsets_l[num_l] = i++;
+                num_l += !nano::invoke(comp, nano::invoke(pred, *it), nano::invoke(pred, pivot));
+                ++it;
+                offsets_l[num_l] = i++;
+                num_l += !nano::invoke(comp, nano::invoke(pred, *it), nano::invoke(pred, pivot));
+                ++it;
+                offsets_l[num_l] = i++;
+                num_l += !nano::invoke(comp, nano::invoke(pred, *it), nano::invoke(pred, pivot));
+                ++it;
+                offsets_l[num_l] = i++;
+                num_l += !nano::invoke(comp, nano::invoke(pred, *it), nano::invoke(pred, pivot));
+                ++it;
+                offsets_l[num_l] = i++;
+                num_l += !nano::invoke(comp, nano::invoke(pred, *it), nano::invoke(pred, pivot));
+                ++it;
+            }
+        }
+        if (num_r == 0)
+        {
+            start_r = 0;
+            I it = last;
+            for (unsigned char i = 0; i < pdqsort_block_size;)
+            {
+                offsets_r[num_r] = ++i;
+                num_r += nano::invoke(comp, nano::invoke(pred, *--it), nano::invoke(pred, pivot));
+                offsets_r[num_r] = ++i;
+                num_r += nano::invoke(comp, nano::invoke(pred, *--it), nano::invoke(pred, pivot));
+                offsets_r[num_r] = ++i;
+                num_r += nano::invoke(comp, nano::invoke(pred, *--it), nano::invoke(pred, pivot));
+                offsets_r[num_r] = ++i;
+                num_r += nano::invoke(comp, nano::invoke(pred, *--it), nano::invoke(pred, pivot));
+                offsets_r[num_r] = ++i;
+                num_r += nano::invoke(comp, nano::invoke(pred, *--it), nano::invoke(pred, pivot));
+                offsets_r[num_r] = ++i;
+                num_r += nano::invoke(comp, nano::invoke(pred, *--it), nano::invoke(pred, pivot));
+                offsets_r[num_r] = ++i;
+                num_r += nano::invoke(comp, nano::invoke(pred, *--it), nano::invoke(pred, pivot));
+                offsets_r[num_r] = ++i;
+                num_r += nano::invoke(comp, nano::invoke(pred, *--it), nano::invoke(pred, pivot));
+            }
+        }
+
+        // Swap elements and update block sizes and first/last boundaries.
+        int num = (nano::min)(num_l, num_r);
+        swap_offsets(first, last, offsets_l + start_l, offsets_r + start_r, num, num_l == num_r);
+        num_l -= num;
+        num_r -= num;
+        start_l += num;
+        start_r += num;
+        if (num_l == 0)
+            first += pdqsort_block_size;
+        if (num_r == 0)
+            last -= pdqsort_block_size;
+    }
+
+    iter_difference_t<I> l_size = 0, r_size = 0;
+    iter_difference_t<I> unknown_left = (last - first) - ((num_r || num_l) ? pdqsort_block_size : 0);
+    if (num_r)
+    {
+        // Handle leftover block by assigning the unknown elements to the other
+        // block.
+        l_size = unknown_left;
+        r_size = pdqsort_block_size;
+    }
+    else if (num_l)
+    {
+        l_size = pdqsort_block_size;
+        r_size = unknown_left;
+    }
+    else
+    {
+        // No leftover block, split the unknown elements in two blocks.
+        l_size = unknown_left / 2;
+        r_size = unknown_left - l_size;
+    }
+
+    // Fill offset buffers if needed.
+    if (unknown_left && !num_l)
+    {
+        start_l = 0;
+        I it = first;
+        for (unsigned char i = 0; i < l_size;)
+        {
+            offsets_l[num_l] = i++;
+            num_l += !nano::invoke(comp, nano::invoke(pred, *it), nano::invoke(pred, pivot));
+            ++it;
+        }
+    }
+    if (unknown_left && !num_r)
+    {
+        start_r = 0;
+        I it = last;
+        for (unsigned char i = 0; i < r_size;)
+        {
+            offsets_r[num_r] = ++i;
+            num_r += nano::invoke(comp, nano::invoke(pred, *--it), nano::invoke(pred, pivot));
+        }
+    }
+
+    int num = (nano::min)(num_l, num_r);
+    swap_offsets(first, last, offsets_l + start_l, offsets_r + start_r, num, num_l == num_r);
+    num_l -= num;
+    num_r -= num;
+    start_l += num;
+    start_r += num;
+    if (num_l == 0)
+        first += l_size;
+    if (num_r == 0)
+        last -= r_size;
+
+    // We have now fully identified [first, last)'s proper position. Swap the
+    // last elements.
+    if (num_l)
+    {
+        offsets_l += start_l;
+        while (num_l--)
+            nano::iter_swap(first + offsets_l[num_l], --last);
+        first = last;
+    }
+    if (num_r)
+    {
+        offsets_r += start_r;
+        while (num_r--)
+            nano::iter_swap(last - offsets_r[num_r], first), ++first;
+        last = first;
+    }
+
+    // Put the pivot in the right place.
+    I pivot_pos = first - 1;
+    *begin = nano::iter_move(pivot_pos);
+    *pivot_pos = ::std::move(pivot);
+
+    return ::std::make_pair(::std::move(pivot_pos), already_partitioned);
+}
+
+// Partitions [begin, end) around pivot *begin using comparison function comp.
+// Elements equal to the pivot are put in the right-hand partition. Returns the
+// position of the pivot after partitioning and whether the passed sequence
+// already was correctly partitioned. Assumes the pivot is a median of at least
+// 3 elements and that [begin, end) is at least insertion_sort_threshold long.
+template <typename I, typename Comp, typename Proj>
+constexpr ::std::pair<I, bool>
+partition_right(I begin, I end, Comp& comp, Proj& proj)
+{
+    using T = iter_value_t<I>;
+
+    // Move pivot into local for speed.
+    T pivot(nano::iter_move(begin));
+
+    I first = begin;
+    I last = end;
+
+    // Find the first element greater than or equal than the pivot (the median
+    // of 3 guarantees this exists).
+    while (nano::invoke(comp, nano::invoke(proj, *++first), nano::invoke(proj, pivot)))
+    {
+    }
+
+    // Find the first element strictly smaller than the pivot. We have to guard
+    // this search if there was no element before *first.
+    if (first - 1 == begin)
+    {
+        while (first < last && !nano::invoke(comp, nano::invoke(proj, *--last), nano::invoke(proj, pivot)))
+        {
+        }
+    }
+    else
+    {
+        while (!nano::invoke(comp, nano::invoke(proj, *--last), nano::invoke(proj, pivot)))
+        {
+        }
+    }
+
+    // If the first pair of elements that should be swapped to partition are the
+    // same element, the passed in sequence already was correctly partitioned.
+    bool already_partitioned = first >= last;
+
+    // Keep swapping pairs of elements that are on the wrong side of the pivot.
+    // Previously swapped pairs guard the searches, which is why the first
+    // iteration is special-cased above.
+    while (first < last)
+    {
+        nano::iter_swap(first, last);
+        while (nano::invoke(comp, nano::invoke(proj, *++first), nano::invoke(proj, pivot)))
+            ;
+        while (!nano::invoke(comp, nano::invoke(proj, *--last), nano::invoke(proj, pivot)))
+            ;
+    }
+
+    // Put the pivot in the right place.
+    I pivot_pos = first - 1;
+    *begin = nano::iter_move(pivot_pos);
+    *pivot_pos = ::std::move(pivot);
+
+    return ::std::make_pair(::std::move(pivot_pos), already_partitioned);
+}
+
+// Similar function to the one above, except elements equal to the pivot are put
+// to the left of the pivot and it doesn't check or return if the passed
+// sequence already was partitioned. Since this is rarely used (the many equal
+// case), and in that case pdqsort already has O(n) performance, no block
+// quicksort is applied here for simplicity.
+template <typename I, typename Comp, typename Proj>
+constexpr I
+partition_left(I begin, I end, Comp& comp, Proj& proj)
+{
+    using T = iter_value_t<I>;
+
+    T pivot(nano::iter_move(begin));
+    I first = begin;
+    I last = end;
+
+    while (nano::invoke(comp, nano::invoke(proj, pivot), nano::invoke(proj, *--last)))
+        ;
+
+    if (last + 1 == end)
+    {
+        while (first < last && !nano::invoke(comp, nano::invoke(proj, pivot), nano::invoke(proj, *++first)))
+            ;
+    }
+    else
+    {
+        while (!nano::invoke(comp, nano::invoke(proj, pivot), nano::invoke(proj, *++first)))
+            ;
+    }
+
+    while (first < last)
+    {
+        nano::iter_swap(first, last);
+        while (nano::invoke(comp, nano::invoke(proj, pivot), nano::invoke(proj, *--last)))
+            ;
+        while (!nano::invoke(comp, nano::invoke(proj, pivot), nano::invoke(proj, *++first)))
+            ;
+    }
+
+    I pivot_pos = last;
+    *begin = nano::iter_move(pivot_pos);
+    *pivot_pos = ::std::move(pivot);
+
+    return pivot_pos;
+}
+
+template <bool Branchless, typename I, typename Comp, typename Proj>
+constexpr void
+pdqsort_loop(I begin, I end, Comp& comp, Proj& proj, int bad_allowed, bool leftmost = true)
+{
+    using diff_t = iter_difference_t<I>;
+
+    // Use a while loop for tail recursion elimination.
+    while (true)
+    {
+        diff_t size = nano::distance(begin, end);
+
+        // Insertion sort is faster for small arrays.
+        if (size < pdqsort_insertion_sort_threshold)
+        {
+            if (leftmost)
+            {
+                insertion_sort(begin, end, comp, proj);
+            }
+            else
+            {
+                unguarded_insertion_sort(begin, end, comp, proj);
+            }
+            return;
+        }
+
+        // Choose pivot as median of 3 or pseudomedian of 9.
+        diff_t s2 = size / 2;
+        if (size > pdqsort_ninther_threshold)
+        {
+            sort3(begin, begin + s2, end - 1, comp, proj);
+            sort3(begin + 1, begin + (s2 - 1), end - 2, comp, proj);
+            sort3(begin + 2, begin + (s2 + 1), end - 3, comp, proj);
+            sort3(begin + (s2 - 1), begin + s2, begin + (s2 + 1), comp, proj);
+            nano::iter_swap(begin, begin + s2);
+        }
+        else
+        {
+            sort3(begin + s2, begin, end - 1, comp, proj);
+        }
+
+        // If *(begin - 1) is the end of the right partition of a previous
+        // partition operation there is no element in [begin, end) that is
+        // smaller than *(begin - 1). Then if our pivot compares equal to
+        // *(begin - 1) we change strategy, putting equal elements in the left
+        // partition, greater elements in the right partition. We do not have to
+        // recurse on the left partition, since it's sorted (all equal).
+        if (!leftmost && !nano::invoke(comp, nano::invoke(proj, *(begin - 1)), nano::invoke(proj, *begin)))
+        {
+            begin = partition_left(begin, end, comp, proj) + 1;
+            continue;
+        }
+
+        // Partition and get results.
+        ::std::pair<I, bool> part_result =
+            Branchless ? partition_right_branchless(begin, end, comp, proj) : partition_right(begin, end, comp, proj);
+        I pivot_pos = part_result.first;
+        bool already_partitioned = part_result.second;
+
+        // Check for a highly unbalanced partition.
+        diff_t l_size = pivot_pos - begin;
+        diff_t r_size = end - (pivot_pos + 1);
+        bool highly_unbalanced = l_size < size / 8 || r_size < size / 8;
+
+        // If we got a highly unbalanced partition we shuffle elements to break
+        // many patterns.
+        if (highly_unbalanced)
+        {
+            // If we had too many bad partitions, switch to heapsort to
+            // guarantee O(n log n).
+            if (--bad_allowed == 0)
+            {
+                nano::make_heap(begin, end, comp, proj);
+                nano::sort_heap(begin, end, comp, proj);
+                return;
+            }
+
+            if (l_size >= pdqsort_insertion_sort_threshold)
+            {
+                nano::iter_swap(begin, begin + l_size / 4);
+                nano::iter_swap(pivot_pos - 1, pivot_pos - l_size / 4);
+
+                if (l_size > pdqsort_ninther_threshold)
+                {
+                    nano::iter_swap(begin + 1, begin + (l_size / 4 + 1));
+                    nano::iter_swap(begin + 2, begin + (l_size / 4 + 2));
+                    nano::iter_swap(pivot_pos - 2, pivot_pos - (l_size / 4 + 1));
+                    nano::iter_swap(pivot_pos - 3, pivot_pos - (l_size / 4 + 2));
+                }
+            }
+
+            if (r_size >= pdqsort_insertion_sort_threshold)
+            {
+                nano::iter_swap(pivot_pos + 1, pivot_pos + (1 + r_size / 4));
+                nano::iter_swap(end - 1, end - r_size / 4);
+
+                if (r_size > pdqsort_ninther_threshold)
+                {
+                    nano::iter_swap(pivot_pos + 2, pivot_pos + (2 + r_size / 4));
+                    nano::iter_swap(pivot_pos + 3, pivot_pos + (3 + r_size / 4));
+                    nano::iter_swap(end - 2, end - (1 + r_size / 4));
+                    nano::iter_swap(end - 3, end - (2 + r_size / 4));
+                }
+            }
+        }
+        else
+        {
+            // If we were decently balanced and we tried to sort an already
+            // partitioned sequence try to use insertion sort.
+            if (already_partitioned && partial_insertion_sort(begin, pivot_pos, comp, proj) &&
+                partial_insertion_sort(pivot_pos + 1, end, comp, proj))
+                return;
+        }
+
+        // Sort the left partition first using recursion and do tail recursion
+        // elimination for the right-hand partition.
+        detail::pdqsort_loop<Branchless>(begin, pivot_pos, comp, proj, bad_allowed, leftmost);
+        begin = pivot_pos + 1;
+        leftmost = false;
+    }
+}
+
+template <typename I, typename Comp, typename Proj,
+          bool Branchless = is_default_compare_v<::std::remove_const_t<Comp>>&&
+              same_as<Proj, identity>&& ::std::is_arithmetic<iter_value_t<I>>::value>
+constexpr void
+pdqsort(I begin, I end, Comp& comp, Proj& proj)
+{
+    if (begin == end)
+    {
+        return;
+    }
+
+    detail::pdqsort_loop<Branchless>(::std::move(begin), ::std::move(end), comp, proj,
+                                     detail::log2(nano::distance(begin, end)));
+}
+
+} // namespace detail
+
+NANO_END_NAMESPACE
+
+#        endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct sort_fn
+{
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<random_access_iterator<I> && sentinel_for<S, I> && sortable<I, Comp, Proj>, I>
+    operator()(I first, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        I last_it = nano::next(first, last);
+        detail::pdqsort(::std::move(first), last_it, comp, proj);
+        return last_it;
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    constexpr ::std::enable_if_t<random_access_range<Rng> && sortable<iterator_t<Rng>, Comp, Proj>,
+                                 borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        iterator_t<Rng> last_it = nano::next(nano::begin(rng), nano::end(rng));
+        detail::pdqsort(nano::begin(rng), last_it, comp, proj);
+        return last_it;
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::sort_fn, sort)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/stl/stable_partition.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+//===-------------------------- algorithm ---------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#    ifndef NANORANGE_ALGORITHM_STABLE_PARTITION_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_STABLE_PARTITION_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct stable_partition_fn
+{
+  private:
+    template <typename I, typename Buf, typename Pred, typename Proj>
+    static subrange<I>
+    impl_buffered(I first, I last, Buf& buf, Pred& pred, Proj& proj)
+    {
+        // first is known to be false, so pop it straight into the buffer
+        buf.push_back(nano::iter_move(first));
+
+        const auto res =
+            nano::partition_copy(nano::make_move_iterator(nano::next(first)), nano::make_move_sentinel(--last), first,
+                                 nano::back_inserter(buf), ::std::ref(pred), ::std::ref(proj));
+
+        // last is known to be true, move that to the correct pos
+        first = ::std::move(res.out1);
+        *first = nano::iter_move(last);
+        ++first;
+
+        // Now move all the other elements from the buffer back into the sequence
+        nano::move(buf, first);
+        return {::std::move(first), ::std::move(last)};
+    }
+
+    // Note to self: this is a closed range, last is NOT past-the-end!
+    template <typename I, typename Pred, typename Proj>
+    static subrange<I>
+    impl_unbuffered(I first, I last, iter_difference_t<I> dist, Pred& pred, Proj& proj)
+    {
+        using dist_t = iter_difference_t<I>;
+
+        if (dist == 2)
+        {
+            // We know first is false and last is true, so swap them
+            nano::iter_swap(first, last);
+            return {nano::next(first), nano::next(last)};
+        }
+
+        if (dist == 3)
+        {
+            // We know first is false and last is true, so look at middle
+            I middle = nano::next(first);
+
+            if (nano::invoke(pred, nano::invoke(proj, *middle)))
+            {
+                nano::iter_swap(first, middle);
+                nano::iter_swap(middle, last);
+                return {nano::next(first, 2), nano::next(last)};
+            }
+
+            // middle is false
+            nano::iter_swap(middle, last);
+            nano::iter_swap(first, middle);
+            return {::std::move(middle), ::std::next(last)};
+        }
+
+        const dist_t half = dist / 2;
+        const I middle = nano::next(first, half);
+
+        I m1 = nano::prev(middle);
+        dist_t len_half = half;
+
+        while (m1 != first && !nano::invoke(pred, nano::invoke(proj, *m1)))
+        {
+            --len_half;
+            --m1;
+        }
+
+        const I first_false = (m1 == first) ? first : impl_unbuffered(first, m1, len_half, pred, proj).begin();
+
+        m1 = middle;
+        len_half = dist - half;
+
+        while (nano::invoke(pred, nano::invoke(proj, *m1)))
+        {
+            if (++m1 == last)
+            {
+                auto rot = nano::rotate(first_false, middle, ++last);
+                return {::std::move(rot.begin()), nano::next(last)};
+            }
+        }
+
+        const I last_false = impl_unbuffered(m1, last, len_half, pred, proj).begin();
+
+        auto rot = nano::rotate(first_false, middle, last_false);
+        return {rot.begin(), nano::next(last)};
+    }
+
+    template <typename I, typename Pred, typename Proj>
+    static subrange<I>
+    impl(I first, I last, Pred& pred, Proj& proj)
+    {
+        // Find the first non-true value
+        first = nano::find_if_not(::std::move(first), last, ::std::ref(pred), ::std::ref(proj));
+        if (first == last)
+        {
+            return {::std::move(first), ::std::move(last)};
+        }
+
+        // Find the last true value
+        I it = nano::find_if(nano::make_reverse_iterator(last), nano::make_reverse_iterator(first), ::std::ref(pred),
+                             ::std::ref(proj))
+                   .base();
+        if (it == first)
+        {
+            return {::std::move(first), ::std::move(it)};
+        }
+
+        const auto dist = nano::distance(first, it);
+
+        auto buf = detail::temporary_vector<iter_value_t<I>>(dist);
+        if (buf.capacity() < static_cast<::std::size_t>(dist))
+        {
+            return {impl_unbuffered(first, --it, dist, pred, proj).begin(), last};
+        }
+        return {impl_buffered(first, it, buf, pred, proj).begin(), last};
+    }
+
+    template <typename I, typename S, typename Pred, typename Proj>
+    static ::std::enable_if_t<!same_as<I, S>, subrange<I>>
+    impl(I first, S last, Pred& pred, Proj& proj)
+    {
+        return impl(first, nano::next(first, last), pred, proj);
+    }
+
+  public:
+    template <typename I, typename S, typename Pred, typename Proj = identity>
+    ::std::enable_if_t<bidirectional_iterator<I> && sentinel_for<S, I> &&
+                           indirect_unary_predicate<Pred, projected<I, Proj>> && permutable<I>,
+                       subrange<I>>
+    operator()(I first, S last, Pred pred, Proj proj = Proj{}) const
+    {
+        return stable_partition_fn::impl(::std::move(first), ::std::move(last), pred, proj);
+    }
+
+    template <typename Rng, typename Pred, typename Proj = identity>
+    ::std::enable_if_t<bidirectional_range<Rng> && indirect_unary_predicate<Pred, projected<iterator_t<Rng>, Proj>> &&
+                           permutable<iterator_t<Rng>>,
+                       borrowed_subrange_t<Rng>>
+    operator()(Rng&& rng, Pred pred, Proj proj = Proj{}) const
+    {
+        return stable_partition_fn::impl(nano::begin(rng), nano::end(rng), pred, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::stable_partition_fn, stable_partition)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/stable_sort.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+// Uses code from cmcstl2 - A concept-enabled C++ standard library
+//
+//  Copyright Eric Niebler 2014
+//  Copyright Casey Carter 2015
+//
+
+//
+//  Copyright (c) 1994
+//  Hewlett-Packard Company
+//
+//  Permission to use, copy, modify, distribute and sell this software
+//  and its documentation for any purpose is hereby granted without fee,
+//  provided that the above copyright notice appear in all copies and
+//  that both that copyright notice and this permission notice appear
+//  in supporting documentation.  Hewlett-Packard Company makes no
+//  representations about the suitability of this software for any
+//  purpose.  It is provided "as is" without express or implied warranty.
+//
+//  Copyright (c) 1996
+//  Silicon Graphics Computer Systems, Inc.
+//
+//  Permission to use, copy, modify, distribute and sell this software
+//  and its documentation for any purpose is hereby granted without fee,
+//  provided that the above copyright notice appear in all copies and
+//  that both that copyright notice and this permission notice appear
+//  in supporting documentation.  Silicon Graphics makes no
+//  representations about the suitability of this software for any
+//  purpose.  It is provided "as is" without express or implied warranty.
+
+#    ifndef NANORANGE_ALGORITHM_STABLE_SORT_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_STABLE_SORT_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct stable_sort_fn
+{
+  private:
+    static constexpr int merge_sort_chunk_size = 7;
+
+    template <typename I, typename Comp, typename Proj>
+    static void
+    inplace_stable_sort(I first, I last, Comp& comp, Proj& proj)
+    {
+        if (last - first < 15)
+        {
+            detail::insertion_sort(::std::move(first), ::std::move(last), comp, proj);
+        }
+        else
+        {
+            I middle = first + iter_difference_t<I>(last - first) / 2;
+            inplace_stable_sort(first, middle, comp, proj);
+            inplace_stable_sort(middle, last, comp, proj);
+            inplace_merge_fn::impl_slow(first, middle, last, middle - first, last - middle, comp, proj);
+        }
+    }
+
+    template <typename I, typename Buf, typename Comp, typename Proj>
+    static void
+    stable_sort_adaptive(I first, I last, Buf& buf, Comp& comp, Proj& proj)
+    {
+        auto len = iter_difference_t<I>((last - first + 1) / 2);
+        auto middle = first + len;
+        if (static_cast<::std::size_t>(len) > buf.capacity())
+        {
+            stable_sort_adaptive(first, middle, buf, comp, proj);
+            stable_sort_adaptive(middle, last, buf, comp, proj);
+        }
+        else
+        {
+            merge_sort_with_buffer(first, middle, buf, comp, proj);
+            merge_sort_with_buffer(middle, last, buf, comp, proj);
+        }
+        inplace_merge_fn::impl_buffered(first, middle, last, middle - first, last - middle, buf, comp, proj);
+    }
+
+    template <typename I, typename Buf, typename Comp, typename Proj>
+    static void
+    merge_sort_with_buffer(I first, I last, Buf& buf, Comp& comp, Proj& proj)
+    {
+        auto len = iter_difference_t<I>(last - first);
+        auto step_size = iter_difference_t<I>(merge_sort_chunk_size);
+        chunk_insertion_sort(first, last, step_size, comp, proj);
+        if (step_size >= len)
+        {
+            return;
+        }
+        assert(buf.empty());
+        merge_sort_loop(first, last, nano::back_inserter(buf), step_size, comp, proj);
+        step_size *= 2;
+        while (true)
+        {
+            merge_sort_loop(buf.begin(), buf.end(), first, step_size, comp, proj);
+            step_size *= 2;
+            if (step_size >= len)
+            {
+                buf.clear();
+                return;
+            }
+            merge_sort_loop(first, last, buf.begin(), step_size, comp, proj);
+            step_size *= 2;
+        }
+        buf.clear();
+    }
+
+    template <typename I, typename Comp, typename Proj>
+    static void
+    chunk_insertion_sort(I first, I last, iter_difference_t<I> chunk_size, Comp& comp, Proj& proj)
+    {
+        while (last - first >= chunk_size)
+        {
+            detail::insertion_sort(first, first + chunk_size, comp, proj);
+            first += chunk_size;
+        }
+        detail::insertion_sort(first, last, comp, proj);
+    }
+
+    template <typename I, typename O, typename Comp, typename Proj>
+    static void
+    merge_sort_loop(I first, I last, O result, iter_difference_t<I> step_size, Comp& comp, Proj& proj)
+    {
+        auto two_step = iter_difference_t<I>(2 * step_size);
+        while (last - first >= two_step)
+        {
+            result =
+                nano::merge(nano::make_move_iterator(first), nano::make_move_iterator(first + step_size),
+                            nano::make_move_iterator(first + step_size), nano::make_move_iterator(first + two_step),
+                            result, ::std::ref(comp), ::std::ref(proj), ::std::ref(proj))
+                    .out;
+            first += two_step;
+        }
+        step_size = nano::min(iter_difference_t<I>(last - first), step_size);
+        nano::merge(nano::make_move_iterator(first), nano::make_move_iterator(first + step_size),
+                    nano::make_move_iterator(first + step_size), nano::make_move_iterator(last), result,
+                    ::std::ref(comp), ::std::ref(proj), ::std::ref(proj));
+    }
+
+    template <typename I, typename Comp, typename Proj>
+    static void
+    impl(I first, I last, Comp& comp, Proj& proj)
+    {
+        auto len = last - first;
+        if (len == 0)
+        {
+            return;
+        }
+
+        temporary_vector<iter_value_t<I>> buf(len > 256 ? len : 0);
+
+        if (buf.capacity() != 0)
+        {
+            stable_sort_adaptive(::std::move(first), ::std::move(last), buf, comp, proj);
+        }
+        else
+        {
+            inplace_stable_sort(::std::move(first), ::std::move(last), comp, proj);
+        }
+    }
+
+  public:
+    template <typename I, typename S, typename Comp = ranges::less, typename Proj = identity>
+    ::std::enable_if_t<random_access_iterator<I> && sentinel_for<S, I> && sortable<I, Comp, Proj>, I>
+    operator()(I first, S last, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        const auto ilast = nano::next(first, last);
+        impl(::std::move(first), ilast, comp, proj);
+        return ilast;
+    }
+
+    template <typename Rng, typename Comp = ranges::less, typename Proj = identity>
+    ::std::enable_if_t<random_access_range<Rng> && sortable<iterator_t<Rng>, Comp, Proj>, borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, Comp comp = Comp{}, Proj proj = Proj{}) const
+    {
+        auto first = nano::begin(rng);
+        const auto last = nano::next(first, nano::end(rng));
+        impl(::std::move(first), last, comp, proj);
+        return last;
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::stable_sort_fn, stable_sort)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/transform.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_TRANSFORM_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_TRANSFORM_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I, typename O>
+using unary_transform_result = in_out_result<I, O>;
+
+template <typename I1, typename I2, typename O>
+using binary_transform_result = in_in_out_result<I1, I2, O>;
+
+namespace detail
+{
+
+struct transform_fn
+{
+  private:
+    template <typename I, typename S, typename O, typename F, typename Proj>
+    static constexpr unary_transform_result<I, O>
+    unary_impl(I first, S last, O result, F& op, Proj& proj)
+    {
+        while (first != last)
+        {
+            *result = nano::invoke(op, nano::invoke(proj, *first));
+            ++first;
+            ++result;
+        }
+
+        return {::std::move(first), ::std::move(result)};
+    }
+
+    template <typename I1, typename S1, typename I2, typename O, typename F, typename Proj1, typename Proj2>
+    static constexpr binary_transform_result<I1, I2, O>
+    binary_impl3(I1 first1, S1 last1, I2 first2, O result, F& op, Proj1& proj1, Proj2& proj2)
+    {
+        while (first1 != last1)
+        {
+            *result = nano::invoke(op, nano::invoke(proj1, *first1), nano::invoke(proj2, *first2));
+            ++first1;
+            ++first2;
+            ++result;
+        }
+
+        return {::std::move(first1), ::std::move(first2), ::std::move(result)};
+    }
+
+    template <typename I1, typename S1, typename I2, typename S2, typename O, typename F, typename Proj1,
+              typename Proj2>
+    static constexpr binary_transform_result<I1, I2, O>
+    binary_impl4(I1 first1, S1 last1, I2 first2, S2 last2, O result, F& op, Proj1& proj1, Proj2& proj2)
+    {
+        while (first1 != last1 && first2 != last2)
+        {
+            *result = nano::invoke(op, nano::invoke(proj1, *first1), nano::invoke(proj2, *first2));
+            ++first1;
+            ++first2;
+            ++result;
+        }
+
+        return {::std::move(first1), ::std::move(first2), ::std::move(result)};
+    }
+
+  public:
+    // Unary op, iterators
+    template <typename I, typename S, typename O, typename F, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> && weakly_incrementable<O> &&
+                                     copy_constructible<F> && writable<O, indirect_result_t<F&, projected<I, Proj>>>,
+                                 unary_transform_result<I, O>>
+    operator()(I first, S last, O result, F op, Proj proj = Proj{}) const
+    {
+        return transform_fn::unary_impl(::std::move(first), ::std::move(last), ::std::move(result), op, proj);
+    }
+
+    // Unary op, range
+    template <typename Rng, typename O, typename F, typename Proj = identity>
+    constexpr ::std::enable_if_t<input_range<Rng> && weakly_incrementable<O> && copy_constructible<F> &&
+                                     writable<O, indirect_result_t<F&, projected<iterator_t<Rng>, Proj>>>,
+                                 unary_transform_result<borrowed_iterator_t<Rng>, O>>
+    operator()(Rng&& rng, O result, F op, Proj proj = Proj{}) const
+    {
+        return transform_fn::unary_impl(nano::begin(rng), nano::end(rng), ::std::move(result), op, proj);
+    }
+
+    // Binary op, four-legged
+    template <typename I1, typename S1, typename I2, typename S2, typename O, typename F, typename Proj1 = identity,
+              typename Proj2 = identity>
+    constexpr ::std::enable_if_t<input_iterator<I1> && sentinel_for<S1, I1> && input_iterator<I2> &&
+                                     sentinel_for<S2, I2> && weakly_incrementable<O> && copy_constructible<F> &&
+                                     writable<O, indirect_result_t<F&, projected<I1, Proj1>, projected<I2, Proj2>>>,
+                                 binary_transform_result<I1, I2, O>>
+    operator()(I1 first1, S1 last1, I2 first2, S2 last2, O result, F op, Proj1 proj1 = Proj1{},
+               Proj2 proj2 = Proj2{}) const
+    {
+        return transform_fn::binary_impl4(::std::move(first1), ::std::move(last1), ::std::move(first2),
+                                          ::std::move(last2), ::std::move(result), op, proj1, proj2);
+    }
+
+    // Binary op, two ranges
+    template <typename Rng1, typename Rng2, typename O, typename F, typename Proj1 = identity,
+              typename Proj2 = identity>
+    constexpr ::std::enable_if_t<
+        input_range<Rng1> && input_range<Rng2> && weakly_incrementable<O> && copy_constructible<F> &&
+            writable<O, indirect_result_t<F&, projected<iterator_t<Rng1>, Proj1>, projected<iterator_t<Rng2>, Proj2>>>,
+        binary_transform_result<borrowed_iterator_t<Rng1>, borrowed_iterator_t<Rng2>, O>>
+    operator()(Rng1&& rng1, Rng2&& rng2, O result, F op, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return transform_fn::binary_impl4(nano::begin(rng1), nano::end(rng1), nano::begin(rng2), nano::end(rng2),
+                                          ::std::move(result), op, proj1, proj2);
+    }
+
+    // Binary op, three-legged
+    template <typename I1, typename S1, typename I2, typename O, typename F, typename Proj1 = identity,
+              typename Proj2 = identity>
+    NANO_DEPRECATED constexpr ::std::enable_if_t<
+        input_iterator<I1> && sentinel_for<S1, I1> && input_iterator<::std::decay_t<I2>> && !input_range<I2> &&
+            weakly_incrementable<O> && copy_constructible<F> &&
+            writable<O, indirect_result_t<F&, projected<I1, Proj1>, projected<::std::decay_t<I2>, Proj2>>>,
+        binary_transform_result<I1, ::std::decay_t<I2>, O>>
+    operator()(I1 first1, S1 last1, I2&& first2, O result, F op, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return transform_fn::binary_impl3(::std::move(first1), ::std::move(last1), ::std::forward<I2>(first2),
+                                          ::std::move(result), op, proj1, proj2);
+    }
+
+    // binary op, range-and-a-half
+    template <typename Rng1, typename I2, typename O, typename F, typename Proj1 = identity, typename Proj2 = identity>
+    NANO_DEPRECATED constexpr ::std::enable_if_t<
+        input_range<Rng1> && input_iterator<::std::decay_t<I2>> && !input_range<I2> && weakly_incrementable<O> &&
+            copy_constructible<F> &&
+            writable<O,
+                     indirect_result_t<F&, projected<iterator_t<Rng1>, Proj1>, projected<::std::decay_t<I2>, Proj2>>>,
+        binary_transform_result<borrowed_iterator_t<Rng1>, ::std::decay_t<I2>, O>>
+    operator()(Rng1&& rng1, I2&& first2, O result, F op, Proj1 proj1 = Proj1{}, Proj2 proj2 = Proj2{}) const
+    {
+        return transform_fn::binary_impl3(nano::begin(rng1), nano::end(rng1), ::std::forward<I2>(first2),
+                                          ::std::move(result), op, proj1, proj2);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::transform_fn, transform)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/unique.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_UNIQUE_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_UNIQUE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct unique_fn
+{
+  private:
+    template <typename I, typename S, typename R, typename Proj>
+    static constexpr subrange<I>
+    impl(I first, S last, R& comp, Proj& proj)
+    {
+        I it = adjacent_find_fn::impl(first, last, comp, proj);
+
+        if (it == last)
+        {
+            return {it, ::std::move(it)};
+        }
+
+        I n = nano::next(it, 2, last);
+        for (; n != last; ++n)
+        {
+            if (!nano::invoke(comp, nano::invoke(proj, *it), nano::invoke(proj, *n)))
+            {
+                *++it = iter_move(n);
+            }
+        }
+
+        return {nano::next(it), ::std::move(n)};
+    }
+
+  public:
+    template <typename I, typename S, typename R = ranges::equal_to, typename Proj = identity>
+    constexpr ::std::enable_if_t<forward_iterator<I> && sentinel_for<S, I> &&
+                                     indirect_relation<R, projected<I, Proj>> && permutable<I>,
+                                 subrange<I>>
+    operator()(I first, S last, R comp = {}, Proj proj = Proj{}) const
+    {
+        return unique_fn::impl(::std::move(first), ::std::move(last), comp, proj);
+    }
+
+    template <typename Rng, typename R = ranges::equal_to, typename Proj = identity>
+    constexpr ::std::enable_if_t<forward_range<Rng> && indirect_relation<R, projected<iterator_t<Rng>, Proj>> &&
+                                     permutable<iterator_t<Rng>>,
+                                 borrowed_subrange_t<Rng>>
+    operator()(Rng&& rng, R comp = {}, Proj proj = Proj{}) const
+    {
+        return unique_fn::impl(nano::begin(rng), nano::end(rng), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::unique_fn, unique)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/algorithm/unique_copy.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ALGORITHM_UNIQUE_COPY_HPP_INCLUDED
+#        define NANORANGE_ALGORITHM_UNIQUE_COPY_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I, typename O>
+using unique_copy_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct unique_copy_fn
+{
+  private:
+    template <typename I, typename S, typename O, typename Comp, typename Proj>
+    static constexpr unique_copy_result<I, O>
+    impl(I first, S last, O result, Comp& comp, Proj& proj)
+    {
+        if (first != last)
+        {
+            iter_value_t<I> saved = *first;
+            *result = saved;
+            ++result;
+
+            while (++first != last)
+            {
+                auto&& v = *first;
+                if (!nano::invoke(comp, nano::invoke(proj, v), nano::invoke(proj, saved)))
+                {
+                    saved = ::std::forward<decltype(v)>(v);
+                    *result = saved;
+                    ++result;
+                }
+            }
+        }
+
+        return {::std::move(first), ::std::move(result)};
+    }
+
+    template <typename I, typename O>
+    static auto constraint_helper(priority_tag<2>) -> ::std::enable_if_t<forward_iterator<I>, ::std::true_type>;
+
+    template <typename I, typename O>
+    static auto constraint_helper(priority_tag<1>)
+        -> ::std::enable_if_t<input_iterator<O> && same_as<iter_value_t<I>, iter_value_t<O>>, ::std::true_type>;
+
+    template <typename I, typename O>
+    static auto constraint_helper(priority_tag<0>)
+        -> ::std::enable_if_t<indirectly_copyable_storable<I, O>, ::std::true_type>;
+
+  public:
+    template <typename I, typename S, typename O, typename Comp = ranges::equal_to, typename Proj = identity>
+    constexpr auto operator()(I first, S last, O result, Comp comp = Comp{}, Proj proj = Proj{}) const
+        -> ::std::enable_if_t<
+            input_iterator<I> && sentinel_for<S, I> && weakly_incrementable<O> &&
+                indirect_relation<Comp, projected<I, Proj>> &&
+                indirectly_copyable<I, O>&& decltype(constraint_helper<I, O>(priority_tag<2>{}))::value,
+            unique_copy_result<I, O>>
+    {
+        return unique_copy_fn::impl(::std::move(first), ::std::move(last), ::std::move(result), comp, proj);
+    }
+
+    template <typename Rng, typename O, typename Comp = ranges::equal_to, typename Proj = identity>
+    constexpr auto operator()(Rng&& rng, O result, Comp comp = Comp{}, Proj proj = Proj{}) const
+        -> ::std::enable_if_t<input_range<Rng> && weakly_incrementable<O> &&
+                                  indirect_relation<Comp, projected<iterator_t<Rng>, Proj>> &&
+                                  indirectly_copyable<iterator_t<Rng>, O>&& decltype(
+                                      constraint_helper<iterator_t<Rng>, O>(priority_tag<2>{}))::value,
+                              unique_copy_result<borrowed_iterator_t<Rng>, O>>
+    {
+        return unique_copy_fn::impl(nano::begin(rng), nano::end(rng), ::std::move(result), comp, proj);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::unique_copy_fn, unique_copy)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+#endif
+
+// nanorange/iterator.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#ifndef NANORANGE_ITERATOR_HPP_INCLUDED
+#    define NANORANGE_ITERATOR_HPP_INCLUDED
+
+// nanorange/iterator/front_insert_iterator.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ITERATOR_FRONT_INSERT_ITERATOR_HPP_INCLUDED
+#        define NANORANGE_ITERATOR_FRONT_INSERT_ITERATOR_HPP_INCLUDED
+
+#        include <iterator>
+
+NANO_BEGIN_NAMESPACE
+
+template <typename Container>
+struct front_insert_iterator
+{
+    using container_type = Container;
+    using difference_type = ::std::ptrdiff_t;
+
+    constexpr front_insert_iterator() = default;
+
+    explicit front_insert_iterator(Container& x) : cont_(::std::addressof(x)) {}
+
+    front_insert_iterator&
+    operator=(const iter_value_t<Container>& value)
+    {
+        cont_->push_front(value);
+        return *this;
+    }
+
+    front_insert_iterator&
+    operator=(iter_value_t<Container>&& value)
+    {
+        cont_->push_front(::std::move(value));
+        return *this;
+    }
+
+    front_insert_iterator& operator*() { return *this; }
+    front_insert_iterator&
+    operator++()
+    {
+        return *this;
+    }
+    front_insert_iterator&
+    operator++(int)
+    {
+        return *this;
+    }
+
+  private:
+    container_type* cont_ = nullptr;
+};
+
+template <typename Container>
+front_insert_iterator<Container>
+front_inserter(Container& x)
+{
+    return front_insert_iterator<Container>(x);
+}
+
+NANO_END_NAMESPACE
+
+namespace std
+{
+
+template <typename Cont>
+struct iterator_traits<__nanorange::nano::front_insert_iterator<Cont>>
+{
+    using value_type = void;
+    using difference_type = ptrdiff_t;
+    using reference = void;
+    using pointer = void;
+    using iterator_category = output_iterator_tag;
+};
+
+} // namespace std
+
+#    endif
+
+// nanorange/iterator/insert_iterator.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ITERATOR_INSERT_ITERATOR_HPP_INCLUDED
+#        define NANORANGE_ITERATOR_INSERT_ITERATOR_HPP_INCLUDED
+
+#        include <iterator>
+
+NANO_BEGIN_NAMESPACE
+
+template <typename Container>
+struct insert_iterator
+{
+    using container_type = Container;
+    using difference_type = ::std::ptrdiff_t;
+
+    constexpr insert_iterator() = default;
+
+    explicit insert_iterator(Container& x, iterator_t<Container> i) : cont_(::std::addressof(x)), it_(i) {}
+
+    insert_iterator&
+    operator=(const iter_value_t<Container>& value)
+    {
+        cont_->insert(it_, value);
+        ++it_;
+        return *this;
+    }
+
+    insert_iterator&
+    operator=(iter_value_t<Container>&& value)
+    {
+        cont_->push_back(it_, ::std::move(value));
+        ++it_;
+        return *this;
+    }
+
+    insert_iterator& operator*() { return *this; }
+    insert_iterator&
+    operator++()
+    {
+        return *this;
+    }
+    insert_iterator&
+    operator++(int)
+    {
+        return *this;
+    }
+
+  private:
+    container_type* cont_ = nullptr;
+    iterator_t<container_type> it_{};
+};
+
+template <typename Container>
+insert_iterator<Container>
+inserter(Container& x)
+{
+    return back_insert_iterator<Container>(x);
+}
+
+NANO_END_NAMESPACE
+
+namespace std
+{
+
+template <typename Container>
+struct iterator_traits<__nanorange::nano::insert_iterator<Container>>
+{
+    using value_type = void;
+    using difference_type = ptrdiff_t;
+    using reference = void;
+    using pointer = void;
+    using iterator_category = output_iterator_tag;
+};
+
+} // namespace std
+
+#    endif
+// nanorange/iterator/istream_iterator.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ITERATOR_ISTREAM_ITERATOR_HPP_INCLUDED
+#        define NANORANGE_ITERATOR_ISTREAM_ITERATOR_HPP_INCLUDED
+
+#        include <iosfwd>
+
+NANO_BEGIN_NAMESPACE
+
+template <typename T, typename CharT = char, typename Traits = ::std::char_traits<CharT>,
+          typename Distance = ::std::ptrdiff_t>
+class istream_iterator
+{
+  public:
+    using iterator_category = input_iterator_tag;
+    using difference_type = Distance;
+    using value_type = T;
+    using reference = const T&;
+    using pointer = const T*;
+    using char_type = CharT;
+    using traits_type = Traits;
+    using istream_type = ::std::basic_istream<CharT, Traits>;
+
+    constexpr istream_iterator() = default;
+
+    constexpr istream_iterator(default_sentinel_t) {}
+
+    istream_iterator(istream_type& s) : in_stream_(::std::addressof(s)) { s >> value_; }
+
+    istream_iterator(const istream_iterator& x) = default;
+
+    ~istream_iterator() = default;
+
+    const T& operator*() const { return value_; }
+
+    const T* operator->() const { return ::std::addressof(value_); }
+
+    istream_iterator&
+    operator++()
+    {
+        *in_stream_ >> value_;
+        if (in_stream_->fail())
+        {
+            in_stream_ = nullptr;
+        }
+        return *this;
+    }
+
+    istream_iterator
+    operator++(int)
+    {
+        istream_iterator tmp = *this;
+        this->operator++();
+        return tmp;
+    }
+
+    friend bool
+    operator==(const istream_iterator& x, const istream_iterator& y)
+    {
+        return x.in_stream_ == y.in_stream_;
+    }
+
+    friend bool
+    operator==(default_sentinel_t, const istream_iterator y)
+    {
+        return nullptr == y.in_stream_;
+    }
+
+    friend bool
+    operator==(const istream_iterator& x, default_sentinel_t)
+    {
+        return x.in_stream_ == nullptr;
+    }
+
+    friend bool
+    operator!=(const istream_iterator& x, const istream_iterator& y)
+    {
+        return !(x == y);
+    }
+
+    friend bool
+    operator!=(default_sentinel_t x, const istream_iterator y)
+    {
+        return !(x == y);
+    }
+
+    friend bool
+    operator!=(const istream_iterator& x, default_sentinel_t y)
+    {
+        return !(x == y);
+    }
+
+  private:
+    istream_type* in_stream_ = nullptr;
+    T value_{};
+};
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/iterator/istreambuf_iterator.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ITERATOR_ISTREAMBUF_ITERATOR_HPP_INCLUDED
+#        define NANORANGE_ITERATOR_ISTREAMBUF_ITERATOR_HPP_INCLUDED
+
+#        include <iosfwd>
+
+NANO_BEGIN_NAMESPACE
+
+template <typename CharT, typename Traits = ::std::char_traits<CharT>>
+class istreambuf_iterator
+{
+    class proxy
+    {
+        friend class istreambuf_iterator;
+        CharT keep_;
+        ::std::basic_streambuf<CharT, Traits>* sbuf_;
+
+        proxy(CharT c, ::std::basic_streambuf<CharT, Traits>* sbuf) : keep_(c), sbuf_(sbuf) {}
+
+      public:
+        CharT operator*() const { return keep_; }
+    };
+
+  public:
+    using iterator_category = input_iterator_tag;
+    using value_type = CharT;
+    using difference_type = typename Traits::off_type;
+    using reference = CharT;
+    using pointer = CharT*;
+    using char_type = CharT;
+    using traits_type = Traits;
+    using int_type = typename Traits::int_type;
+    using streambuf_type = ::std::basic_streambuf<CharT, Traits>;
+    using istream_type = ::std::basic_istream<CharT, Traits>;
+
+    constexpr istreambuf_iterator() noexcept = default;
+
+    constexpr istreambuf_iterator(default_sentinel_t) noexcept {}
+
+    istreambuf_iterator(const istreambuf_iterator&) noexcept = default;
+
+    ~istreambuf_iterator() = default;
+
+    istreambuf_iterator(istream_type& s) noexcept : sbuf_(s.rdbuf()) {}
+
+    istreambuf_iterator(streambuf_type* s) noexcept : sbuf_(s) {}
+
+    istreambuf_iterator(const proxy& p) noexcept : sbuf_(p.sbuf_) {}
+
+    char_type operator*() const { return Traits::to_char_type(sbuf_->sgetc()); }
+
+    istreambuf_iterator&
+    operator++()
+    {
+        sbuf_->sbumpc();
+        return *this;
+    }
+
+    proxy
+    operator++(int)
+    {
+        return proxy(Traits::to_char_type(sbuf_->sbumpc()), sbuf_);
+    }
+
+    bool
+    equal(const istreambuf_iterator& b) const
+    {
+        return is_eof() == b.is_eof();
+    }
+
+  private:
+    bool
+    is_eof() const
+    {
+        if (sbuf_ && sbuf_->sgetc() == Traits::eof())
+        {
+            sbuf_ = nullptr;
+            return true;
+        }
+
+        return sbuf_ == nullptr;
+    }
+
+    mutable streambuf_type* sbuf_ = nullptr;
+};
+
+template <typename CharT, typename Traits>
+bool
+operator==(const istreambuf_iterator<CharT, Traits>& a, const istreambuf_iterator<CharT, Traits>& b)
+{
+    return a.equal(b);
+}
+
+template <typename CharT, typename Traits>
+bool
+operator==(default_sentinel_t, const istreambuf_iterator<CharT, Traits>& b)
+{
+    return istreambuf_iterator<CharT, Traits>{}.equal(b);
+}
+
+template <typename CharT, typename Traits>
+bool
+operator==(const istreambuf_iterator<CharT, Traits>& a, default_sentinel_t)
+{
+    return a.equal(istreambuf_iterator<CharT, Traits>{});
+}
+
+template <typename CharT, typename Traits>
+bool
+operator!=(const istreambuf_iterator<CharT, Traits>& a, const istreambuf_iterator<CharT, Traits>& b)
+{
+    return !(a == b);
+}
+
+template <typename CharT, typename Traits>
+bool
+operator!=(default_sentinel_t a, const istreambuf_iterator<CharT, Traits>& b)
+{
+    return !(a == b);
+}
+
+template <typename CharT, typename Traits>
+bool
+operator!=(const istreambuf_iterator<CharT, Traits>& a, default_sentinel_t b)
+{
+    return !(a == b);
+}
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/iterator/ostream_iterator.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ITERATOR_OSTREAM_ITERATOR_HPP_INCLUDED
+#        define NANORANGE_ITERATOR_OSTREAM_ITERATOR_HPP_INCLUDED
+
+#        include <iosfwd>
+#        include <iterator>
+#        include <memory>
+
+NANO_BEGIN_NAMESPACE
+
+template <typename T, typename CharT = char, typename Traits = ::std::char_traits<CharT>>
+struct ostream_iterator
+{
+    using char_type = CharT;
+    using traits_type = Traits;
+    using ostream_type = ::std::basic_ostream<CharT, Traits>;
+    using difference_type = ::std::ptrdiff_t;
+
+    constexpr ostream_iterator() noexcept = default;
+
+    ostream_iterator(ostream_type& os, const CharT* delim = nullptr) noexcept : os_(::std::addressof(os)), delim_(delim)
+    {
+    }
+
+    ostream_iterator&
+    operator=(const T& value)
+    {
+        *os_ << value;
+        if (delim_)
+        {
+            *os_ << delim_;
+        }
+        return *this;
+    }
+
+    ostream_iterator& operator*() { return *this; }
+    ostream_iterator&
+    operator++()
+    {
+        return *this;
+    }
+    ostream_iterator&
+    operator++(int)
+    {
+        return *this;
+    }
+
+  private:
+    ostream_type* os_ = nullptr;
+    const char_type* delim_ = nullptr;
+};
+
+NANO_END_NAMESPACE
+
+namespace std
+{
+
+template <typename T, typename C, typename Tr>
+struct iterator_traits<__nanorange::nano::ranges::ostream_iterator<T, C, Tr>>
+{
+    using value_type = void;
+    using difference_type = ptrdiff_t;
+    using reference = void;
+    using pointer = void;
+    using iterator_category = ::std::output_iterator_tag;
+};
+
+} // namespace std
+
+#    endif
+// nanorange/iterator/ostreambuf_iterator.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_ITERATOR_OSTREAMBUF_ITERATOR_HPP_INCLUDED
+#        define NANORANGE_ITERATOR_OSTREAMBUF_ITERATOR_HPP_INCLUDED
+
+#        include <iosfwd> // for basic_streambuf
+#        include <iterator>
+
+NANO_BEGIN_NAMESPACE
+
+template <typename CharT, typename Traits = ::std::char_traits<CharT>>
+struct ostreambuf_iterator
+{
+
+    using char_type = CharT;
+    using traits = Traits;
+    using difference_type = ::std::ptrdiff_t;
+    using streambuf_type = ::std::basic_streambuf<CharT, Traits>;
+    using ostream_type = ::std::basic_ostream<CharT, Traits>;
+
+    constexpr ostreambuf_iterator() = default;
+
+    ostreambuf_iterator(ostream_type& s) noexcept : sbuf_(s.rdbuf()) {}
+
+    ostreambuf_iterator(streambuf_type* s) noexcept : sbuf_(s) {}
+
+    ostreambuf_iterator&
+    operator=(char_type c)
+    {
+        if (!failed())
+        {
+            failed_ = (sbuf_->sputc(c) == traits::eof());
+        }
+        return *this;
+    }
+
+    ostreambuf_iterator& operator*() { return *this; }
+    ostreambuf_iterator&
+    operator++()
+    {
+        return *this;
+    }
+    ostreambuf_iterator&
+    operator++(int)
+    {
+        return *this;
+    }
+
+    bool
+    failed() const noexcept
+    {
+        return failed_;
+    }
+
+  private:
+    streambuf_type* sbuf_ = nullptr;
+    bool failed_ = false;
+};
+
+NANO_END_NAMESPACE
+
+namespace std
+{
+
+template <typename C, typename T>
+struct iterator_traits<__nanorange::nano::ranges::ostreambuf_iterator<C, T>>
+{
+    using value_type = void;
+    using difference_type = ptrdiff_t;
+    using reference = void;
+    using pointer = void;
+    using iterator_category = output_iterator_tag;
+};
+
+} // namespace std
+
+#    endif
+
+#endif
+
+// nanorange/memory.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#ifndef NANORANGE_MEMORY_HPP_INCLUDED
+
+// nanorange/memory/uninitialized_copy.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_MEMORY_UNINITIALIZED_COPY_HPP_INCLUDED
+#        define NANORANGE_MEMORY_UNINITIALIZED_COPY_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I, typename O>
+using uninitialized_copy_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct uninitialized_copy_fn
+{
+  private:
+    friend struct uninitialized_copy_n_fn;
+
+    template <typename I, typename S, typename O, typename S2>
+    static uninitialized_copy_result<I, O>
+    impl4(I ifirst, S ilast, O ofirst, S2 olast)
+    {
+        O oit = ofirst;
+        try
+        {
+            for (; ifirst != ilast && oit != olast; ++ifirst, (void)++oit)
+            {
+                ::new (detail::voidify(*oit))::std::remove_reference_t<iter_reference_t<O>>(*ifirst);
+            }
+            return {::std::move(ifirst), ::std::move(oit)};
+        }
+        catch (...)
+        {
+            nano::destroy(ofirst, ++oit);
+            throw;
+        }
+    }
+
+    template <typename I, typename S, typename O>
+    static uninitialized_copy_result<I, O>
+    impl3(I ifirst, S ilast, O ofirst)
+    {
+        O oit = ofirst;
+        try
+        {
+            for (; ifirst != ilast; ++ifirst, (void)++oit)
+            {
+                ::new (const_cast<void*>(static_cast<const volatile void*>(
+                    ::std::addressof(*oit))))::std::remove_reference_t<iter_reference_t<O>>(*ifirst);
+            }
+            return {::std::move(ifirst), ::std::move(oit)};
+        }
+        catch (...)
+        {
+            nano::destroy(ofirst, ++oit);
+            throw;
+        }
+    }
+
+  public:
+    // Four-legged
+    template <typename I, typename S, typename O, typename S2>
+    ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> && no_throw_forward_iterator<O> &&
+                           no_throw_sentinel<S2, O> && constructible_from<iter_value_t<O>, iter_reference_t<I>>,
+                       uninitialized_copy_result<I, O>>
+    operator()(I ifirst, S ilast, O ofirst, S2 olast) const
+    {
+        return uninitialized_copy_fn::impl4(::std::move(ifirst), ::std::move(ilast), ::std::move(ofirst),
+                                            ::std::move(olast));
+    }
+
+    // Two ranges
+    template <typename IRng, typename ORng>
+    ::std::enable_if_t<input_range<IRng> && no_throw_forward_range<ORng> &&
+                           constructible_from<iter_value_t<iterator_t<ORng>>, iter_reference_t<iterator_t<IRng>>>,
+                       uninitialized_copy_result<borrowed_iterator_t<IRng>, borrowed_iterator_t<ORng>>>
+    operator()(IRng&& irng, ORng&& orng) const
+    {
+        return uninitialized_copy_fn::impl4(nano::begin(irng), nano::end(irng), nano::begin(orng), nano::end(orng));
+    }
+
+    // Three-legged
+    template <typename I, typename S, typename O>
+    NANO_DEPRECATED ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> && no_throw_forward_iterator<O> &&
+                                           constructible_from<iter_value_t<O>, iter_reference_t<I>>,
+                                       uninitialized_copy_result<I, O>>
+    operator()(I ifirst, S ilast, O ofirst) const
+    {
+        return uninitialized_copy_fn::impl3(::std::move(ifirst), ::std::move(ilast), ::std::move(ofirst));
+    }
+
+    // Range and a half
+    template <typename IRng, typename O>
+    NANO_DEPRECATED ::std::enable_if_t<
+        input_range<IRng> && no_throw_forward_iterator<::std::decay_t<O>> && !no_throw_forward_range<O> &&
+            constructible_from<iter_value_t<::std::decay_t<O>>, iter_reference_t<iterator_t<IRng>>>,
+        uninitialized_copy_result<borrowed_iterator_t<IRng>, ::std::decay_t<O>>>
+    operator()(IRng&& irng, O&& ofirst) const
+    {
+        return uninitialized_copy_fn::impl3(nano::begin(irng), nano::end(irng), ::std::forward<O>(ofirst));
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::uninitialized_copy_fn, uninitialized_copy)
+
+template <typename I, typename O>
+using uninitialized_copy_n_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct uninitialized_copy_n_fn
+{
+    template <typename I, typename O, typename S>
+    ::std::enable_if_t<input_iterator<I> && no_throw_forward_iterator<O> && no_throw_sentinel<S, O> &&
+                           constructible_from<iter_value_t<O>, iter_reference_t<I>>,
+                       uninitialized_copy_n_result<I, O>>
+    operator()(I ifirst, iter_difference_t<I> n, O ofirst, S olast) const
+    {
+        auto t = uninitialized_copy_fn::impl4(make_counted_iterator(::std::move(ifirst), n), default_sentinel,
+                                              ::std::move(ofirst), ::std::move(olast));
+        return {::std::move(t).in.base(), ::std::move(t).out};
+    }
+
+    template <typename I, typename O>
+    NANO_DEPRECATED ::std::enable_if_t<input_iterator<I> && no_throw_forward_iterator<O> &&
+                                           constructible_from<iter_value_t<O>, iter_reference_t<I>>,
+                                       uninitialized_copy_n_result<I, O>>
+    operator()(I ifirst, iter_difference_t<I> n, O ofirst) const
+    {
+        auto t = uninitialized_copy_fn::impl3(make_counted_iterator(::std::move(ifirst), n), default_sentinel,
+                                              ::std::move(ofirst));
+        return {::std::move(t).in.base(), ::std::move(t).out};
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::uninitialized_copy_n_fn, uninitialized_copy_n)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/memory/uninitialized_default_construct.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_MEMORY_UNINITIALIZED_DEFAULT_CONSTRUCT_HPP_INCLUDED
+#        define NANORANGE_MEMORY_UNINITIALIZED_DEFAULT_CONSTRUCT_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct uninitialized_default_construct_fn
+{
+  private:
+    template <typename I, typename S>
+    static I
+    impl(I first, S last)
+    {
+        I it = first;
+        try
+        {
+            for (; it != last; ++it)
+            {
+                ::new (detail::voidify(*it))::std::remove_reference_t<iter_reference_t<I>>;
+            }
+            return it;
+        }
+        catch (...)
+        {
+            nano::destroy(first, ++it);
+            throw;
+        }
+    }
+
+  public:
+    template <typename I, typename S>
+    ::std::enable_if_t<
+        no_throw_forward_iterator<I> && no_throw_sentinel<S, I> && default_initializable<iter_value_t<I>>, I>
+    operator()(I first, S last) const
+    {
+        return uninitialized_default_construct_fn::impl(::std::move(first), ::std::move(last));
+    }
+
+    template <typename Rng>
+    ::std::enable_if_t<no_throw_forward_range<Rng> && default_initializable<iter_value_t<iterator_t<Rng>>>,
+                       borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng) const
+    {
+        return uninitialized_default_construct_fn::impl(nano::begin(rng), nano::end(rng));
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::uninitialized_default_construct_fn, uninitialized_default_construct)
+
+namespace detail
+{
+
+struct uninitialized_default_construct_n_fn
+{
+    template <typename I>
+    ::std::enable_if_t<no_throw_forward_iterator<I> && default_initializable<iter_value_t<I>>, I>
+    operator()(I first, iter_difference_t<I> n) const
+    {
+        return nano::uninitialized_default_construct(make_counted_iterator(::std::move(first), n), default_sentinel)
+            .base();
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::uninitialized_default_construct_n_fn, uninitialized_default_construct_n)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/memory/uninitialized_fill.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_MEMORY_UNINITIALIZED_FILL_HPP_INCLUDED
+#        define NANORANGE_MEMORY_UNINITIALIZED_FILL_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct uninitialized_fill_fn
+{
+  private:
+    friend struct uninitialized_fill_n_fn;
+
+    template <typename I, typename S, typename T>
+    static I
+    impl(I first, S last, const T& x)
+    {
+        I it = first;
+        try
+        {
+            for (; it != last; ++it)
+            {
+                ::new (detail::voidify(*it))::std::remove_reference_t<iter_reference_t<I>>(x);
+            }
+            return it;
+        }
+        catch (...)
+        {
+            nano::destroy(first, ++it);
+            throw;
+        }
+    }
+
+  public:
+    template <typename I, typename S, typename T>
+    ::std::enable_if_t<
+        no_throw_forward_iterator<I> && no_throw_sentinel<S, I> && constructible_from<iter_value_t<I>, const T&>, I>
+    operator()(I first, S last, const T& x) const
+    {
+        return uninitialized_fill_fn::impl(::std::move(first), ::std::move(last), x);
+    }
+
+    template <typename Rng, typename T>
+    ::std::enable_if_t<no_throw_forward_range<Rng> && constructible_from<iter_value_t<iterator_t<Rng>>, const T&>,
+                       borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng, const T& x) const
+    {
+        return uninitialized_fill_fn::impl(nano::begin(rng), nano::end(rng), x);
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::uninitialized_fill_fn, uninitialized_fill)
+
+namespace detail
+{
+
+struct uninitialized_fill_n_fn
+{
+    template <typename I, typename T>
+    ::std::enable_if_t<no_throw_forward_iterator<I> && constructible_from<iter_value_t<I>, const T&>, I>
+    operator()(I first, iter_difference_t<I> n, const T& x) const
+    {
+        return uninitialized_fill_fn::impl(make_counted_iterator(::std::move(first), n), default_sentinel, x).base();
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::uninitialized_fill_n_fn, uninitialized_fill_n)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/memory/uninitialized_move.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_MEMORY_UNINITIALIZED_MOVE_HPP_INCLUDED
+#        define NANORANGE_MEMORY_UNINITIALIZED_MOVE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I, typename O>
+using uninitialized_move_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct uninitialized_move_fn
+{
+  private:
+    friend struct uninitialized_move_n_fn;
+
+    template <typename I, typename S, typename O, typename S2>
+    static uninitialized_move_result<I, O>
+    impl4(I ifirst, S ilast, O ofirst, S2 olast)
+    {
+        O oit = ofirst;
+        try
+        {
+            for (; ifirst != ilast && oit != olast; ++ifirst, (void)++oit)
+            {
+                ::new (detail::voidify(*oit))::std::remove_reference_t<iter_reference_t<O>>(nano::iter_move(ifirst));
+            }
+            return {::std::move(ifirst), ::std::move(oit)};
+        }
+        catch (...)
+        {
+            nano::destroy(ofirst, ++oit);
+            throw;
+        }
+    }
+
+    template <typename I, typename S, typename O>
+    static uninitialized_move_result<I, O>
+    impl3(I ifirst, S ilast, O ofirst)
+    {
+        O oit = ofirst;
+        try
+        {
+            for (; ifirst != ilast; ++ifirst, (void)++oit)
+            {
+                ::new (detail::voidify(*oit))::std::remove_reference_t<iter_reference_t<O>>(nano::iter_move(ifirst));
+            }
+            return {::std::move(ifirst), ::std::move(oit)};
+        }
+        catch (...)
+        {
+            nano::destroy(ofirst, ++oit);
+            throw;
+        }
+    }
+
+  public:
+    // Four-legged
+    template <typename I, typename S, typename O, typename S2>
+    ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> && no_throw_forward_iterator<O> &&
+                           no_throw_sentinel<S2, O> && constructible_from<iter_value_t<O>, iter_rvalue_reference_t<I>>,
+                       uninitialized_move_result<I, O>>
+    operator()(I ifirst, S ilast, O ofirst, S2 olast) const
+    {
+        return uninitialized_move_fn::impl4(::std::move(ifirst), ::std::move(ilast), ::std::move(ofirst),
+                                            ::std::move(olast));
+    }
+
+    // Two ranges
+    template <typename IRng, typename ORng>
+    ::std::enable_if_t<
+        input_range<IRng> && no_throw_forward_range<ORng> &&
+            constructible_from<iter_value_t<iterator_t<ORng>>, iter_rvalue_reference_t<iterator_t<IRng>>>,
+        uninitialized_move_result<borrowed_iterator_t<IRng>, borrowed_iterator_t<ORng>>>
+    operator()(IRng&& irng, ORng&& orng) const
+    {
+        return uninitialized_move_fn::impl4(nano::begin(irng), nano::end(irng), nano::begin(orng), nano::end(orng));
+    }
+
+    // Three-legged
+    template <typename I, typename S, typename O>
+    NANO_DEPRECATED ::std::enable_if_t<input_iterator<I> && sentinel_for<S, I> && no_throw_forward_iterator<O> &&
+                                           constructible_from<iter_value_t<O>, iter_rvalue_reference_t<I>>,
+                                       uninitialized_move_result<I, O>>
+    operator()(I ifirst, S ilast, O ofirst) const
+    {
+        return uninitialized_move_fn::impl3(::std::move(ifirst), ::std::move(ilast), ::std::move(ofirst));
+    }
+
+    // Range and a half
+    template <typename IRng, typename O>
+    NANO_DEPRECATED ::std::enable_if_t<
+        input_range<IRng> && no_throw_forward_iterator<::std::decay_t<O>> && !no_throw_forward_range<O> &&
+            constructible_from<iter_value_t<::std::decay_t<O>>, iter_rvalue_reference_t<iterator_t<IRng>>>,
+        uninitialized_move_result<borrowed_iterator_t<IRng>, ::std::decay_t<O>>>
+    operator()(IRng&& irng, O&& ofirst) const
+    {
+        return uninitialized_move_fn::impl3(nano::begin(irng), nano::end(irng), ::std::forward<O>(ofirst));
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::uninitialized_move_fn, uninitialized_move)
+
+template <typename I, typename O>
+using uninitialized_move_n_result = in_out_result<I, O>;
+
+namespace detail
+{
+
+struct uninitialized_move_n_fn
+{
+    template <typename I, typename O, typename S>
+    ::std::enable_if_t<input_iterator<I> && no_throw_forward_iterator<O> && no_throw_sentinel<S, O> &&
+                           constructible_from<iter_value_t<O>, iter_rvalue_reference_t<I>>,
+                       uninitialized_move_n_result<I, O>>
+    operator()(I ifirst, iter_difference_t<I> n, O ofirst, S olast) const
+    {
+        auto t = uninitialized_move_fn::impl4(make_counted_iterator(::std::move(ifirst), n), default_sentinel,
+                                              ::std::move(ofirst), ::std::move(olast));
+        return {::std::move(t).in.base(), ::std::move(t).out};
+    }
+
+    template <typename I, typename O>
+    NANO_DEPRECATED ::std::enable_if_t<input_iterator<I> && no_throw_forward_iterator<O> &&
+                                           constructible_from<iter_value_t<O>, iter_rvalue_reference_t<I>>,
+                                       uninitialized_move_n_result<I, O>>
+    operator()(I ifirst, iter_difference_t<I> n, O ofirst) const
+    {
+        auto t = uninitialized_move_fn::impl3(make_counted_iterator(::std::move(ifirst), n), default_sentinel,
+                                              ::std::move(ofirst));
+        return {::std::move(t).in.base(), ::std::move(t).out};
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::uninitialized_move_n_fn, uninitialized_move_n)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/memory/uninitialized_value_construct.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_MEMORY_UNINITIALIZED_VALUE_CONSTRUCT_HPP_INCLUDED
+#        define NANORANGE_MEMORY_UNINITIALIZED_VALUE_CONSTRUCT_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct uninitialized_value_construct_fn
+{
+  private:
+    template <typename I, typename S>
+    static I
+    impl(I first, S last)
+    {
+        I it = first;
+        try
+        {
+            for (; it != last; ++it)
+            {
+                ::new (detail::voidify(*it))::std::remove_reference_t<iter_reference_t<I>>();
+            }
+            return it;
+        }
+        catch (...)
+        {
+            nano::destroy(first, ++it);
+            throw;
+        }
+    }
+
+  public:
+    template <typename I, typename S>
+    ::std::enable_if_t<
+        no_throw_forward_iterator<I> && no_throw_sentinel<S, I> && default_initializable<iter_value_t<I>>, I>
+    operator()(I first, S last) const
+    {
+        return uninitialized_value_construct_fn::impl(::std::move(first), ::std::move(last));
+    }
+
+    template <typename Rng>
+    ::std::enable_if_t<no_throw_forward_range<Rng> && default_initializable<iter_value_t<iterator_t<Rng>>>,
+                       borrowed_iterator_t<Rng>>
+    operator()(Rng&& rng) const
+    {
+        return uninitialized_value_construct_fn::impl(nano::begin(rng), nano::end(rng));
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::uninitialized_value_construct_fn, uninitialized_value_construct)
+
+namespace detail
+{
+
+struct uninitialized_value_construct_n_fn
+{
+    template <typename I>
+    ::std::enable_if_t<no_throw_forward_iterator<I> && default_initializable<iter_value_t<I>>, I>
+    operator()(I first, iter_difference_t<I> n) const
+    {
+        return nano::uninitialized_value_construct(make_counted_iterator(::std::move(first), n), default_sentinel)
+            .base();
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::uninitialized_value_construct_n_fn, uninitialized_value_construct_n)
+
+NANO_END_NAMESPACE
+
+#    endif
+
+#endif
+
+// nanorange/utility.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#ifndef NANORANGE_UTILITY_HPP_INCLUDED
+#    define NANORANGE_UTILITY_HPP_INCLUDED
+
+#endif
+
+// nanorange/range.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#ifndef NANORANGE_VIEWS_HPP_INCLUDED
+#    define NANORANGE_VIEWS_HPP_INCLUDED
+
+// nanorange/views/all.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_ALL_HPP_INCLUDED
+#        define NANORANGE_VIEWS_ALL_HPP_INCLUDED
+
+// nanorange/detail/views/range_adaptors.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_DETAIL_VIEW_RANGE_ADAPTORS_HPP_INCLUDED
+#            define NANORANGE_DETAIL_VIEW_RANGE_ADAPTORS_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+template <typename>
+inline constexpr bool is_raco = false;
+
+template <typename R, typename C,
+          typename = ::std::enable_if_t<viewable_range<R> && !is_raco<remove_cvref_t<R>> && is_raco<remove_cvref_t<C>>>>
+constexpr auto
+operator|(R&& lhs, C&& rhs) -> decltype(::std::forward<C>(rhs)(::std::forward<R>(lhs)))
+{
+    return ::std::forward<C>(rhs)(::std::forward<R>(lhs));
+}
+
+template <typename LHS, typename RHS>
+struct raco_pipe
+{
+  private:
+    LHS lhs_;
+    RHS rhs_;
+
+  public:
+    constexpr raco_pipe(LHS&& lhs, RHS&& rhs) : lhs_(::std::move(lhs)), rhs_(::std::move(rhs)) {}
+
+    // FIXME: Do I need to do ref-qualified overloads of these too?
+
+    template <typename R, ::std::enable_if_t<viewable_range<R>, int> = 0>
+    constexpr auto
+    operator()(R&& r) -> decltype(rhs_(lhs_(::std::forward<R>(r))))
+    {
+        return rhs_(lhs_(::std::forward<R>(r)));
+    }
+
+    template <typename R, ::std::enable_if_t<viewable_range<R>, int> = 0>
+    constexpr auto
+    operator()(R&& r) const -> decltype(rhs_(lhs_(::std::forward<R>(r))))
+    {
+        return rhs_(lhs_(::std::forward<R>(r)));
+    }
+};
+
+template <typename LHS, typename RHS>
+inline constexpr bool is_raco<raco_pipe<LHS, RHS>> = true;
+
+template <typename LHS, typename RHS>
+constexpr auto
+operator|(LHS&& lhs, RHS&& rhs)
+    -> ::std::enable_if_t<is_raco<remove_cvref_t<LHS>> && is_raco<remove_cvref_t<RHS>>, raco_pipe<LHS, RHS>>
+{
+    return raco_pipe<LHS, RHS>{::std::forward<LHS>(lhs), ::std::forward<RHS>(rhs)};
+}
+
+template <typename Lambda>
+struct rao_proxy : Lambda
+{
+    constexpr explicit rao_proxy(Lambda&& l) : Lambda(::std::move(l)) {}
+};
+
+template <typename L>
+inline constexpr bool is_raco<rao_proxy<L>> = true;
+
+} // namespace detail
+
+NANO_END_NAMESPACE
+
+#        endif
+
+// nanorange/detail/views/ref.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_VIEWS_REF_HPP_INCLUDED
+#            define NANORANGE_VIEWS_REF_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace ref_view_
+{
+
+template <typename R>
+class ref_view : public view_interface<ref_view<R>>
+{
+
+    static_assert(range<R> && ::std::is_object<R>::value, "");
+
+    R* r_ = nullptr;
+
+    struct constructor_req
+    {
+        static void
+        FUN(R&);
+        static void
+        FUN(R&&) = delete;
+
+        template <typename T>
+        auto
+        requires_() -> decltype(FUN(::std::declval<T>()));
+    };
+
+  public:
+    constexpr ref_view() noexcept = default;
+
+    template <typename T, ::std::enable_if_t<detail::not_same_as<T, ref_view>, int> = 0,
+              ::std::enable_if_t<detail::requires_<constructor_req, T>, int> = 0,
+              ::std::enable_if_t<convertible_to<T, R&>, int> = 0>
+    constexpr ref_view(T&& t) : r_(::std::addressof(static_cast<R&>(::std::forward<T>(t))))
+    {
+    }
+
+    constexpr R&
+    base() const
+    {
+        return *r_;
+    }
+
+    constexpr iterator_t<R>
+    begin() const
+    {
+        return ranges::begin(*r_);
+    }
+
+    constexpr sentinel_t<R>
+    end() const
+    {
+        return ranges::end(*r_);
+    }
+
+    template <typename RR = R, typename = decltype(ranges::empty(::std::declval<RR&>()))>
+    constexpr bool
+    empty() const
+    {
+        return ranges::empty(*r_);
+    }
+
+    template <typename RR = R, ::std::enable_if_t<sized_range<RR>, int> = 0>
+    constexpr auto
+    size() const
+    {
+        return ranges::size(*r_);
+    }
+
+    template <typename RR = R, ::std::enable_if_t<contiguous_range<RR>, int> = 0>
+    constexpr auto
+    data() const
+    {
+        return ranges::data(*r_);
+    }
+};
+
+template <typename R, ::std::enable_if_t<range<R>&& ::std::is_object_v<R>, int> = 0>
+ref_view(R&)->ref_view<R>;
+
+} // namespace ref_view_
+
+using ref_view_::ref_view;
+
+template <typename R>
+inline constexpr bool enable_borrowed_range<ref_view<R>> = true;
+
+NANO_END_NAMESPACE
+
+#        endif
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct all_view_fn
+{
+  private:
+    template <typename T>
+    static constexpr auto
+    impl(T&& t, priority_tag<2>) noexcept(noexcept(detail::decay_copy(::std::forward<T>(t))))
+        -> ::std::enable_if_t<view<::std::decay_t<T>>, decltype(detail::decay_copy(::std::forward<T>(t)))>
+    {
+        return ::std::forward<T>(t);
+    }
+
+    template <typename T>
+    static constexpr auto
+    impl(T&& t, priority_tag<1>) noexcept -> decltype(ref_view(::std::forward<T>(t)))
+    {
+        return ref_view(::std::forward<T>(t));
+    }
+
+    template <typename T>
+    static constexpr auto
+    impl(T&& t, priority_tag<0>) noexcept(noexcept(nano::subrange{::std::forward<T>(t)}))
+        -> decltype(nano::subrange{::std::forward<T>(t)})
+    {
+        return nano::subrange{::std::forward<T>(t)};
+    }
+
+  public:
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const noexcept(noexcept(all_view_fn::impl(::std::forward<T>(t), priority_tag<2>{})))
+        -> decltype(all_view_fn::impl(::std::forward<T>(t), priority_tag<2>{}))
+    {
+        return all_view_fn::impl(::std::forward<T>(t), priority_tag<2>{});
+    }
+};
+
+template <>
+inline constexpr bool is_raco<all_view_fn> = true;
+
+} // namespace detail
+
+namespace views
+{
+
+NANO_INLINE_VAR(nano::detail::all_view_fn, all)
+}
+
+template <typename R>
+using all_view = ::std::enable_if_t<viewable_range<R>, decltype(views::all(::std::declval<R>()))>;
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/views/common.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_COMMON_HPP_INCLUDED
+#        define NANORANGE_VIEWS_COMMON_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename V>
+class common_view : public view_interface<common_view<V>>
+{
+
+    static_assert(view<V> && !common_range<V>, "");
+
+    template <typename VV>
+    using random_and_sized_t = ::std::integral_constant<bool, random_access_range<VV> && sized_range<VV>>;
+
+    V base_ = V();
+
+    template <typename VV>
+    static constexpr auto
+    do_begin(VV& base, ::std::true_type)
+    {
+        return ranges::begin(base);
+    }
+
+    template <typename VV>
+    static constexpr auto
+    do_begin(VV& base, ::std::false_type)
+    {
+        return common_iterator<iterator_t<VV>, sentinel_t<VV>>(ranges::begin(base));
+    }
+
+    template <typename VV>
+    static constexpr auto
+    do_end(VV& base, ::std::true_type)
+    {
+        return ranges::begin(base) + ranges::size(base);
+    }
+
+    template <typename VV>
+    static constexpr auto
+    do_end(VV& base, ::std::false_type)
+    {
+        return common_iterator<iterator_t<VV>, sentinel_t<VV>>(ranges::end(base));
+    }
+
+  public:
+    common_view() = default;
+
+    constexpr explicit common_view(V r) : base_(::std::move(r)) {}
+
+    template <typename R, ::std::enable_if_t<detail::not_same_as<R, common_view>, int> = 0,
+              ::std::enable_if_t<viewable_range<R> && !common_range<R> && constructible_from<V, all_view<R>>, int> = 0>
+    constexpr explicit common_view(R&& r) : base_(views::all(::std::forward<R>(r)))
+    {
+    }
+
+    constexpr V
+    base() const
+    {
+        return base_;
+    }
+
+    template <typename VV = V, ::std::enable_if_t<sized_range<VV>, int> = 0>
+    constexpr auto
+    size()
+    {
+        return ranges::size(base_);
+    }
+
+    template <typename VV = V, ::std::enable_if_t<sized_range<const VV>, int> = 0>
+    constexpr auto
+    size() const
+    {
+        return ranges::size(base_);
+    }
+
+    constexpr auto
+    begin()
+    {
+        return do_begin<V>(base_, random_and_sized_t<V>{});
+    }
+
+    template <typename VV = V, ::std::enable_if_t<range<const VV>, int> = 0>
+    constexpr auto
+    begin() const
+    {
+        return do_begin<const V>(base_, random_and_sized_t<const V>{});
+    }
+
+    constexpr auto
+    end()
+    {
+        return do_end<V>(base_, random_and_sized_t<V>{});
+    }
+
+    template <typename VV = V, ::std::enable_if_t<range<const VV>, int> = 0>
+    constexpr auto
+    end() const
+    {
+        return do_end<const V>(base_, random_and_sized_t<const V>{});
+    }
+};
+
+template <typename R>
+common_view(R &&)->common_view<all_view<R>>;
+
+namespace detail
+{
+
+struct common_view_fn
+{
+  private:
+    template <typename T>
+    static constexpr auto
+    impl(T&& t, nano::detail::priority_tag<1>) noexcept(noexcept(views::all(::std::forward<T>(t))))
+        -> ::std::enable_if_t<common_range<T>, decltype(views::all(::std::forward<T>(t)))>
+    {
+        return views::all(::std::forward<T>(t));
+    }
+
+    template <typename T>
+    static constexpr auto
+    impl(T&& t, nano::detail::priority_tag<0>) -> common_view<all_view<T>>
+    {
+        return common_view<all_view<T>>{::std::forward<T>(t)};
+    }
+
+  public:
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const
+        -> ::std::enable_if_t<viewable_range<T>,
+                              decltype(common_view_fn::impl(::std::forward<T>(t), nano::detail::priority_tag<1>{}))>
+    {
+        return common_view_fn::impl(::std::forward<T>(t), nano::detail::priority_tag<1>{});
+    }
+};
+
+template <>
+inline constexpr bool is_raco<common_view_fn> = true;
+
+} // namespace detail
+
+namespace views
+{
+
+NANO_INLINE_VAR(nano::detail::common_view_fn, common)
+
+} // namespace views
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/views/counted.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_COUNTED_HPP_INCLUDED
+#        define NANORANGE_VIEWS_COUNTED_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace views
+{
+
+namespace detail
+{
+
+struct counted_fn
+{
+  private:
+    template <typename I>
+    static constexpr auto
+    impl(I i, iter_difference_t<I> n, nano::detail::priority_tag<1>) noexcept(noexcept(nano::subrange{i, i + n}))
+        -> ::std::enable_if_t<random_access_iterator<I>, decltype(nano::subrange{i, i + n})>
+    {
+        return nano::subrange{i, i + n};
+    }
+
+    template <typename I>
+    static constexpr auto
+    impl(I i, iter_difference_t<I> n, nano::detail::priority_tag<0>) noexcept(noexcept(nano::subrange{
+        nano::make_counted_iterator(::std::move(i), n), default_sentinel}))
+        -> decltype(nano::subrange{nano::make_counted_iterator(::std::move(i), n), default_sentinel})
+    {
+        return nano::subrange{nano::make_counted_iterator(::std::move(i), n), default_sentinel};
+    }
+
+  public:
+    template <typename E, typename F, typename T = ::std::decay_t<E>>
+    constexpr auto
+    operator()(E&& e, F&& f) const
+        noexcept(noexcept(impl(::std::forward<E>(e), static_cast<iter_difference_t<T>>(::std::forward<F>(f)),
+                               nano::detail::priority_tag<1>{})))
+            -> ::std::enable_if_t<input_or_output_iterator<T> && convertible_to<F, iter_difference_t<T>>,
+                                  decltype(impl(::std::forward<E>(e),
+                                                static_cast<iter_difference_t<T>>(::std::forward<F>(f)),
+                                                nano::detail::priority_tag<1>{}))>
+    {
+        return impl(::std::forward<E>(e), static_cast<iter_difference_t<T>>(::std::forward<F>(f)),
+                    nano::detail::priority_tag<1>{});
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::counted_fn, counted)
+
+} // namespace views
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/views/drop.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_DROP_HPP_INCLUDED
+#        define NANORANGE_VIEWS_DROP_HPP_INCLUDED
+
+#        include <optional>
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+template <bool IsRandomAccess, typename>
+struct drop_view_cache
+{
+};
+
+template <typename I>
+struct drop_view_cache<false, I>
+{
+    ::std::optional<I> cached{};
+};
+
+} // namespace detail
+
+template <typename R>
+struct drop_view : view_interface<drop_view<R>>, private detail::drop_view_cache<random_access_range<R>, iterator_t<R>>
+{
+
+    static_assert(view<R>);
+
+    drop_view() = default;
+
+    constexpr drop_view(R base, range_difference_t<R> count) : base_(::std::move(base)), count_(count) {}
+
+    constexpr R
+    base() const
+    {
+        return base_;
+    }
+
+    template <typename RR = R, ::std::enable_if_t<!(detail::simple_view<RR> && random_access_range<RR>), int> = 0>
+    constexpr auto
+    begin()
+    {
+        if constexpr (random_access_range<R>)
+        {
+            return ranges::next(ranges::begin(base_), count_, ranges::end(base_));
+        }
+        else
+        {
+            auto& c = this->cached;
+            if (!c.has_value())
+            {
+                c = ranges::next(ranges::begin(base_), count_, ranges::end(base_));
+            }
+            return *c;
+        }
+    }
+
+    template <typename RR = R, ::std::enable_if_t<random_access_range<const RR>, int> = 0>
+    constexpr auto
+    begin() const
+    {
+        return ranges::next(ranges::begin(base_), count_, ranges::end(base_));
+    }
+
+    template <typename RR = R, ::std::enable_if_t<!detail::simple_view<RR>, int> = 0>
+    constexpr auto
+    end()
+    {
+        return ranges::end(base_);
+    }
+
+    template <typename RR = R, ::std::enable_if_t<range<const RR>, int> = 0>
+    constexpr auto
+    end() const
+    {
+        return ranges::end(base_);
+    }
+
+    template <typename RR = R, ::std::enable_if_t<sized_range<RR>, int> = 0>
+    constexpr auto
+    size()
+    {
+        const auto s = ranges::size(base_);
+        const auto c = static_cast<decltype(s)>(count_);
+        return s < c ? 0 : s - c;
+    }
+
+    template <typename RR = R, ::std::enable_if_t<sized_range<const RR>, int> = 0>
+    constexpr auto
+    size() const
+    {
+        const auto s = ranges::size(base_);
+        const auto c = static_cast<decltype(s)>(count_);
+        return s < c ? 0 : s - c;
+    }
+
+    constexpr bool
+    empty() const
+    {
+        return size() == 0;
+    }
+
+  private:
+    R base_ = R();
+    range_difference_t<R> count_ = 0;
+};
+
+template <typename R>
+drop_view(R&&, range_difference_t<R>)->drop_view<all_view<R>>;
+
+namespace detail
+{
+
+struct drop_view_fn
+{
+
+    template <typename E, typename F>
+    constexpr auto
+    operator()(E&& e, F&& f) const -> decltype(drop_view{::std::forward<E>(e), ::std::forward<F>(f)})
+    {
+        return drop_view{::std::forward<E>(e), ::std::forward<F>(f)};
+    }
+
+    template <typename C>
+    constexpr auto
+    operator()(C c) const
+    {
+        return detail::rao_proxy{[c = ::std::move(c)](auto&& r) mutable
+#        ifndef NANO_MSVC_LAMBDA_PIPE_WORKAROUND
+                                 -> decltype(drop_view{::std::forward<decltype(r)>(r), ::std::declval<C&&>()})
+#        endif
+                                 {
+                                     return drop_view{::std::forward<decltype(r)>(r), ::std::move(c)};
+                                 }};
+    }
+};
+
+} // namespace detail
+
+namespace views
+{
+
+NANO_INLINE_VAR(nano::detail::drop_view_fn, drop)
+}
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/views/drop_while.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_DROP_WHILE_HPP_INCLUDED
+#        define NANORANGE_VIEWS_DROP_WHILE_HPP_INCLUDED
+
+// nanorange/detail/views/semiregular_box.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#        ifndef NANORANGE_DETAIL_VIEW_SEMIREGULAR_BOX_HPP_INCLUDED
+#            define NANORANGE_DETAIL_VIEW_SEMIREGULAR_BOX_HPP_INCLUDED
+
+#            include <optional>
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+template <typename T>
+struct semiregular_box : ::std::optional<T>
+{
+    static_assert(copy_constructible<T>);
+    static_assert(::std::is_object_v<T>);
+
+  private:
+    ::std::optional<T>&
+    base()
+    {
+        return *this;
+    }
+    ::std::optional<T> const&
+    base() const
+    {
+        return *this;
+    }
+
+  public:
+    template <typename U = T, ::std::enable_if_t<default_initializable<U>, int> = 0>
+    constexpr semiregular_box() noexcept(::std::is_nothrow_default_constructible_v<T>)
+        : semiregular_box{::std::in_place}
+    {
+    }
+
+    template <typename U = T, ::std::enable_if_t<!default_initializable<U>, int> = 0>
+    constexpr semiregular_box()
+    {
+    }
+
+    // All other constructors get forwarded to optional -- but don't hijack
+    // copy/move construct
+    template <typename Arg0, typename... Args,
+              ::std::enable_if_t<constructible_from<::std::optional<T>, Arg0, Args...> &&
+                                     !same_as<remove_cvref_t<Arg0>, semiregular_box>,
+                                 int> = 0>
+    constexpr semiregular_box(Arg0&& arg0, Args&&... args)
+        : ::std::optional<T>{::std::forward<Arg0>(arg0), ::std::forward<Args>(args)...}
+    {
+    }
+
+    constexpr semiregular_box(const semiregular_box&) = default;
+    constexpr semiregular_box(semiregular_box&&) = default;
+
+    semiregular_box&
+    operator=(const semiregular_box& other)
+    {
+        if constexpr (assignable_from<T&, const T&>)
+        {
+            base() = other.base();
+        }
+        else
+        {
+            if (other)
+            {
+                this->emplace(*other);
+            }
+            else
+            {
+                this->reset();
+            }
+        }
+
+        return *this;
+    }
+
+    semiregular_box&
+    operator=(semiregular_box&& other) noexcept
+    {
+        if constexpr (assignable_from<T&, T>)
+        {
+            base() = ::std::move(other.base());
+        }
+        else
+        {
+            if (other)
+            {
+                this->emplace(::std::move(*other));
+            }
+            else
+            {
+                this->reset();
+            }
+        }
+
+        return *this;
+    }
+};
+
+} // namespace detail
+
+NANO_END_NAMESPACE
+
+#        endif
+
+NANO_BEGIN_NAMESPACE
+
+template <typename R, typename Pred>
+struct drop_while_view : view_interface<drop_while_view<R, Pred>>
+{
+
+    static_assert(view<R>);
+    static_assert(input_range<R>);
+    static_assert(::std::is_object_v<Pred>);
+    static_assert(indirect_unary_predicate<const Pred, iterator_t<R>>);
+
+    drop_while_view() = default;
+
+    constexpr drop_while_view(R base, Pred pred) : base_(::std::move(base)), pred_(::std::move(pred)) {}
+
+    constexpr R
+    base() const
+    {
+        return base_;
+    }
+
+    constexpr const Pred&
+    pred() const
+    {
+        return *pred_;
+    }
+
+    constexpr auto
+    begin()
+    {
+        if (!cached_.has_value())
+        {
+            cached_ = ranges::find_if(
+                base_, [& p = pred()](auto&& arg) { return !nano::invoke(p, ::std::forward<decltype(arg)>(arg)); });
+        }
+
+        return *cached_;
+    }
+
+    constexpr auto
+    end()
+    {
+        return ranges::end(base_);
+    }
+
+  private:
+    R base_;
+    detail::semiregular_box<Pred> pred_;
+    ::std::optional<iterator_t<R>> cached_;
+};
+
+template <typename R, typename Pred>
+drop_while_view(R&& r, Pred pred)->drop_while_view<all_view<R>, Pred>;
+
+namespace detail
+{
+
+struct drop_while_view_fn
+{
+
+    template <typename E, typename F>
+    constexpr auto
+    operator()(E&& e, F&& f) const -> decltype(drop_while_view{::std::forward<E>(e), ::std::forward<F>(f)})
+    {
+        return drop_while_view{::std::forward<E>(e), ::std::forward<F>(f)};
+    }
+
+    template <typename Pred>
+    constexpr auto
+    operator()(Pred&& pred) const
+    {
+        return detail::rao_proxy{[p = ::std::forward<Pred>(pred)](auto&& r) mutable
+#        ifndef NANO_MSVC_LAMBDA_PIPE_WORKAROUND
+                                 -> decltype(drop_while_view{::std::forward<decltype(r)>(r), ::std::declval<Pred&&>()})
+#        endif
+                                 {
+                                     return drop_while_view{::std::forward<decltype(r)>(r), ::std::move(p)};
+                                 }};
+    }
+};
+
+} // namespace detail
+
+namespace views
+{
+
+NANO_INLINE_VAR(nano::detail::drop_while_view_fn, drop_while)
+}
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/views/elements.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_ELEMENTS_HPP_INCLUDED
+#        define NANORANGE_VIEWS_ELEMENTS_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct has_tuple_element_concept
+{
+    template <typename T, typename I, ::std::size_t N = I::value, typename = typename ::std::tuple_size<T>::type>
+    auto
+    requires_(T t)
+        -> decltype(requires_expr<(N < ::std::tuple_size_v<T>)>{}, ::std::declval<::std::tuple_element_t<N, T>>(),
+                    requires_expr<convertible_to<decltype(::std::get<N>(t)), ::std::tuple_element_t<N, T>>>{});
+};
+
+template <typename T, ::std::size_t N>
+NANO_CONCEPT has_tuple_element =
+    detail::requires_<has_tuple_element_concept, T, ::std::integral_constant<::std::size_t, N>>;
+
+} // namespace detail
+
+template <typename R, ::std::size_t N>
+struct elements_view : view_interface<elements_view<R, N>>
+{
+
+    static_assert(input_range<R>);
+    static_assert(view<R>);
+    static_assert(detail::has_tuple_element<range_value_t<R>, N>);
+    static_assert(detail::has_tuple_element<::std::remove_reference_t<range_reference_t<R>>, N>);
+
+    elements_view() = default;
+
+    constexpr explicit elements_view(R base) : base_(::std::move(base)) {}
+
+    template <typename RR = R, ::std::enable_if_t<!detail::simple_view<RR>, int> = 0>
+    constexpr auto
+    begin()
+    {
+        return iterator<false>(ranges::begin(base_));
+    }
+
+    template <typename RR = R, ::std::enable_if_t<detail::simple_view<RR>, int> = 0>
+    constexpr auto
+    begin() const
+    {
+        return iterator<true>(ranges::begin(base_));
+    }
+
+    template <typename RR = R, ::std::enable_if_t<!detail::simple_view<RR>, int> = 0>
+    constexpr auto
+    end()
+    {
+        return ranges::end(base_);
+    }
+
+    template <typename RR = R, ::std::enable_if_t<detail::simple_view<RR>, int> = 0>
+    constexpr auto
+    end() const
+    {
+        return ranges::end(base_);
+    }
+
+    template <typename RR = R, ::std::enable_if_t<sized_range<RR>, int> = 0>
+    constexpr auto
+    size()
+    {
+        return ranges::size(base_);
+    }
+
+    template <typename RR = R, ::std::enable_if_t<sized_range<const RR>, int> = 0>
+    constexpr auto
+    size() const
+    {
+        return ranges::size(base_);
+    }
+
+  private:
+    template <bool Const>
+    struct iterator
+    {
+      private:
+        using base_t = detail::conditional_t<Const, const R, R>;
+        friend iterator<!Const>;
+
+        iterator_t<base_t> current_;
+
+      public:
+        using iterator_category = iterator_category_t<iterator_t<base_t>>;
+        using value_type = remove_cvref_t<::std::tuple_element_t<N, range_value_t<base_t>>>;
+        using difference_type = range_difference_t<base_t>;
+
+        iterator() = default;
+
+        constexpr explicit iterator(iterator_t<base_t> current) : current_(::std::move(current)) {}
+
+        template <typename I, ::std::enable_if_t<same_as<I, iterator<!Const>>, int> = 0, bool C = Const,
+                  typename B = base_t, ::std::enable_if_t<C && convertible_to<iterator_t<R>, iterator_t<B>>, int> = 0>
+        constexpr iterator(I i) : current_(::std::move(i.current_))
+        {
+        }
+
+        constexpr iterator_t<base_t>
+        base() const
+        {
+            return current_;
+        }
+
+        constexpr decltype(auto) operator*() const { return ::std::get<N>(*current_); }
+
+        constexpr iterator&
+        operator++()
+        {
+            ++current_;
+            return *this;
+        }
+
+        constexpr auto
+        operator++(int)
+        {
+            if constexpr (forward_range<base_t>)
+            {
+                auto temp = *this;
+                ++*this;
+                return temp;
+            }
+            else
+            {
+                ++*this;
+            }
+        }
+
+        template <typename B = base_t>
+        constexpr auto
+        operator--() -> ::std::enable_if_t<bidirectional_range<B>, iterator&>
+        {
+            --current_;
+            return *this;
+        }
+
+        template <typename B = base_t>
+        constexpr auto
+        operator--(int) -> ::std::enable_if_t<bidirectional_range<B>, iterator>
+        {
+            auto temp = *this;
+            ++*this;
+            return temp;
+        }
+
+        template <typename B = base_t>
+        constexpr auto
+        operator+=(difference_type x) -> ::std::enable_if_t<random_access_range<B>, iterator&>
+        {
+            current_ += x;
+            return *this;
+        }
+
+        template <typename B = base_t>
+        constexpr auto
+        operator-=(difference_type x) -> ::std::enable_if_t<random_access_range<B>, iterator&>
+        {
+            current_ -= x;
+            return *this;
+        }
+
+        template <typename B = base_t, ::std::enable_if_t<random_access_range<B>, int> = 0>
+        constexpr decltype(auto) operator[](difference_type n) const
+        {
+            return ::std::get<N>(*(current_ + n));
+        }
+
+        template <typename B = base_t>
+        friend constexpr auto
+        operator==(const iterator& x, const iterator& y) -> ::std::enable_if_t<equality_comparable<iterator_t<B>>, bool>
+        {
+            return x.current_ == y.current_;
+        }
+
+        template <typename B = base_t>
+        friend constexpr auto
+        operator!=(const iterator& x, const iterator& y) -> ::std::enable_if_t<equality_comparable<iterator_t<B>>, bool>
+        {
+            return !(x == y);
+        }
+
+        // Make these friend functions templates to keep MSVC happy
+#        if (defined(_MSC_VER) && _MSC_VER < 1922)
+        template <typename = void>
+#        endif
+        friend constexpr bool
+        operator==(const iterator& x, const sentinel_t<base_t>& y)
+        {
+            return x.current_ == y;
+        }
+
+#        if (defined(_MSC_VER) && _MSC_VER < 1922)
+        template <typename = void>
+#        endif
+        friend constexpr bool
+        operator==(const sentinel_t<base_t>& y, const iterator& x)
+        {
+            return x.current_ == y;
+        }
+
+#        if (defined(_MSC_VER) && _MSC_VER < 1922)
+        template <typename = void>
+#        endif
+        friend constexpr bool
+        operator!=(const iterator& x, const sentinel_t<base_t>& y)
+        {
+            return !(x == y);
+        }
+
+#        if (defined(_MSC_VER) && _MSC_VER < 1922)
+        template <typename = void>
+#        endif
+        friend constexpr bool
+        operator!=(const sentinel_t<base_t>& y, const iterator& x)
+        {
+            return !(x == y);
+        }
+
+        template <typename B = base_t>
+        friend constexpr auto
+        operator<(const iterator& x, const iterator& y) -> ::std::enable_if_t<random_access_range<B>, bool>
+        {
+            return x.current_ < y.current_;
+        }
+
+        template <typename B = base_t>
+        friend constexpr auto
+        operator>(const iterator& x, const iterator& y) -> ::std::enable_if_t<random_access_range<B>, bool>
+        {
+            return (y < x);
+        }
+
+        template <typename B = base_t>
+        friend constexpr auto
+        operator<=(const iterator& x, const iterator& y) -> ::std::enable_if_t<random_access_range<B>, bool>
+        {
+            return !(y < x);
+        }
+
+        template <typename B = base_t>
+        friend constexpr auto
+        operator>=(const iterator& x, const iterator& y) -> ::std::enable_if_t<random_access_range<B>, bool>
+        {
+            return !(x < y);
+        }
+
+        template <typename B = base_t>
+        friend constexpr auto
+        operator+(const iterator& x, difference_type y) -> ::std::enable_if_t<random_access_range<B>, iterator>
+        {
+            return iterator{x} += y;
+        }
+
+        template <typename B = base_t>
+        friend constexpr auto
+        operator+(difference_type x, const iterator& y) -> ::std::enable_if_t<random_access_range<B>, iterator>
+        {
+            return y + x;
+        }
+
+        template <typename B = base_t>
+        friend constexpr auto
+        operator-(const iterator& x, difference_type y) -> ::std::enable_if_t<random_access_range<B>, iterator>
+        {
+            return iterator{x} -= y;
+        }
+
+        template <typename B = base_t>
+        friend constexpr auto
+        operator-(const iterator& x, const iterator& y) -> ::std::enable_if_t<random_access_range<B>, difference_type>
+        {
+            return x.current_ - y.current_;
+        }
+
+        template <typename B = base_t>
+        friend constexpr auto
+        operator-(const iterator& x, const sentinel_t<base_t>& y)
+            -> ::std::enable_if_t<sized_sentinel_for<sentinel_t<B>, iterator_t<B>>, difference_type>
+        {
+            return x.current_ - y;
+        }
+
+        template <typename B = base_t>
+        friend constexpr auto
+        operator-(const sentinel_t<base_t>& x, const iterator& y)
+            -> ::std::enable_if_t<sized_sentinel_for<sentinel_t<B>, iterator_t<B>>, difference_type>
+        {
+            return -(y - x);
+        }
+    };
+
+    R base_ = R();
+};
+
+template <typename R>
+using keys_view = elements_view<all_view<R>, 0>;
+
+template <typename R>
+using values_view = elements_view<all_view<R>, 1>;
+
+namespace detail
+{
+
+template <::std::size_t N>
+struct elements_view_fn
+{
+    template <typename E>
+    constexpr auto
+    operator()(E&& e) const
+        -> decltype(elements_view<all_view<decltype(::std::forward<E>(e))>, N>{::std::forward<E>(e)})
+    {
+        return elements_view<all_view<decltype(::std::forward<E>(e))>, N>{::std::forward<E>(e)};
+    }
+};
+
+template <::std::size_t N>
+inline constexpr bool is_raco<elements_view_fn<N>> = true;
+
+} // namespace detail
+
+namespace views
+{
+
+inline namespace function_objects
+{
+
+template <::std::size_t N>
+inline constexpr nano::detail::elements_view_fn<N> elements{};
+
+inline constexpr nano::detail::elements_view_fn<0> keys{};
+
+inline constexpr nano::detail::elements_view_fn<1> values{};
+
+} // namespace function_objects
+
+} // namespace views
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/views/empty.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_EMPTY_HPP_INCLUDED
+#        define NANORANGE_VIEWS_EMPTY_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace empty_view_
+{
+
+template <typename T>
+class empty_view : view_interface<empty_view<T>>
+{
+    static_assert(::std::is_object<T>::value, "");
+
+  public:
+    static constexpr T*
+    begin() noexcept
+    {
+        return nullptr;
+    }
+    static constexpr T*
+    end() noexcept
+    {
+        return nullptr;
+    }
+    static constexpr ::std::ptrdiff_t
+    size() noexcept
+    {
+        return 0;
+    }
+    static constexpr T*
+    data() noexcept
+    {
+        return nullptr;
+    }
+
+    static constexpr bool
+    empty() noexcept
+    {
+        return true;
+    }
+
+    friend constexpr T* begin(empty_view) noexcept { return nullptr; }
+    friend constexpr T* end(empty_view) noexcept { return nullptr; }
+};
+
+} // namespace empty_view_
+
+using empty_view_::empty_view;
+
+template <typename T>
+inline constexpr bool enable_borrowed_range<empty_view<T>> = true;
+
+namespace views
+{
+
+template <typename T, typename = ::std::enable_if_t<::std::is_object<T>::value>>
+inline constexpr empty_view<T> empty{};
+}
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/views/filter.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_FILTER_HPP_INCLUDED
+#        define NANORANGE_VIEWS_FILTER_HPP_INCLUDED
+
+#        include <cassert>
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+template <typename V>
+constexpr auto
+filter_view_iter_cat_helper()
+{
+    using C = iterator_category_t<iterator_t<V>>;
+    if constexpr (derived_from<C, bidirectional_iterator_tag>)
+    {
+        return bidirectional_iterator_tag{};
+    }
+    else if constexpr (derived_from<C, forward_iterator_tag>)
+    {
+        return forward_iterator_tag{};
+    }
+    else
+    {
+        return input_iterator_tag{};
+    }
+}
+
+constexpr inline auto as_ref = [](auto& pred) {
+    return [&p = pred](auto&& arg) { return nano::invoke(p, ::std::forward<decltype(arg)>(arg)); };
+};
+
+} // namespace detail
+
+namespace filter_view_
+{
+
+template <typename V, typename Pred>
+struct filter_view : view_interface<filter_view<V, Pred>>
+{
+
+    // FIXME: GCC9 recursive constraint (?) problems again
+    // static_assert(input_range<V>);
+    static_assert(input_iterator<iterator_t<V>>);
+    static_assert(indirect_unary_predicate<Pred, iterator_t<V>>);
+    static_assert(view<V>);
+    static_assert(::std::is_object_v<Pred>);
+
+  private:
+    V base_ = V();
+    detail::semiregular_box<Pred> pred_;
+
+    struct iterator
+    {
+      private:
+        iterator_t<V> current_ = iterator_t<V>();
+        filter_view* parent_ = nullptr;
+
+      public:
+        // using iterator_concept = ...
+        using iterator_category = decltype(detail::filter_view_iter_cat_helper<V>());
+        using value_type = iter_value_t<iterator_t<V>>;
+        using difference_type = iter_difference_t<iterator_t<V>>;
+        // Extension: legacy typedefs
+        using pointer = iterator_t<V>;
+        using reference = iter_reference_t<iterator_t<V>>;
+
+        iterator() = default;
+        constexpr iterator(filter_view& parent, iterator_t<V> current)
+            : current_(::std::move(current)), parent_(::std::addressof(parent))
+        {
+        }
+
+        constexpr iterator_t<V>
+        base() const
+        {
+            return current_;
+        }
+
+        constexpr iter_reference_t<iterator_t<V>> operator*() const { return *current_; }
+
+        template <typename VV = V>
+        constexpr auto operator-> () const -> ::std::enable_if_t<detail::has_arrow<iterator_t<VV>>, iterator_t<V>>
+        {
+            return current_;
+        }
+
+        constexpr iterator&
+        operator++()
+        {
+            current_ = ranges::find_if(++current_, ranges::end(parent_->base_), detail::as_ref(*parent_->pred_));
+            return *this;
+        }
+
+        constexpr auto
+        operator++(int)
+        {
+            if constexpr (forward_range<V>)
+            {
+                auto tmp = *this;
+                ++*this;
+                return tmp;
+            }
+            else
+            {
+                ++*this;
+            }
+        }
+
+        template <typename VV = V>
+        constexpr auto
+        operator--() -> ::std::enable_if_t<bidirectional_range<VV>, iterator&>
+        {
+            do
+            {
+                --current_;
+            } while (!nano::invoke(*parent_->pred_, *current_));
+            return *this;
+        }
+
+        template <typename VV = V>
+        constexpr auto
+        operator--(int) -> ::std::enable_if_t<bidirectional_range<VV>, iterator>
+        {
+            auto tmp = *this;
+            --*this;
+            return tmp;
+        }
+
+        template <typename VV = V>
+        friend constexpr auto
+        operator==(const iterator& x, const iterator& y)
+            -> ::std::enable_if_t<equality_comparable<iterator_t<VV>>, bool>
+        {
+            return x.current_ == y.current_;
+        }
+
+        template <typename VV = V>
+        friend constexpr auto
+        operator!=(const iterator& x, const iterator& y)
+            -> ::std::enable_if_t<equality_comparable<iterator_t<VV>>, bool>
+        {
+            return !(x == y);
+        }
+
+        friend constexpr iter_rvalue_reference_t<iterator_t<V>>
+        iter_move(const iterator& i) noexcept(noexcept(ranges::iter_move(i.current_)))
+        {
+            return ranges::iter_move(i.current_);
+        }
+
+        template <typename VV = V>
+        friend constexpr auto
+        iter_swap(const iterator& x, const iterator& y) noexcept(noexcept(ranges::iter_swap(x.current_, y.current_)))
+            -> ::std::enable_if_t<indirectly_swappable<iterator_t<VV>>>
+        {
+            ranges::iter_swap(x.current_, y.current_);
+        }
+    };
+
+    struct sentinel
+    {
+      private:
+        sentinel_t<V> end_ = sentinel_t<V>();
+
+      public:
+        sentinel() = default;
+
+        constexpr explicit sentinel(filter_view& parent) : end_(ranges::end(parent.base_)) {}
+
+        constexpr sentinel_t<V>
+        base() const
+        {
+            return end_;
+        }
+
+        // Make these friend functions templates to keep MSVC happy
+#        if (defined(_MSC_VER) && _MSC_VER < 1922)
+        template <typename = void>
+#        endif
+        friend constexpr bool
+        operator==(const iterator& i, const sentinel& s)
+        {
+            return i.base() == s.end_;
+        }
+
+#        if (defined(_MSC_VER) && _MSC_VER < 1922)
+        template <typename = void>
+#        endif
+        friend constexpr bool
+        operator==(const sentinel& s, const iterator& i)
+        {
+            return i == s;
+        }
+
+#        if (defined(_MSC_VER) && _MSC_VER < 1922)
+        template <typename = void>
+#        endif
+        friend constexpr bool
+        operator!=(const iterator& i, const sentinel& s)
+        {
+            return !(i == s);
+        }
+
+#        if (defined(_MSC_VER) && _MSC_VER < 1922)
+        template <typename = void>
+#        endif
+        friend constexpr bool
+        operator!=(const sentinel& s, const iterator& i)
+        {
+            return !(i == s);
+        }
+    };
+
+    ::std::optional<iterator> begin_cache_{};
+
+  public:
+    filter_view() = default;
+
+    constexpr filter_view(V base, Pred pred) : base_(::std::move(base)), pred_(::std::move(pred)) {}
+
+    template <typename R, ::std::enable_if_t<input_range<R> && constructible_from<V, all_view<R>>, int> = 0>
+    constexpr filter_view(R&& r, Pred pred) : base_(views::all(::std::forward<R>(r))), pred_(::std::move(pred))
+    {
+    }
+
+    constexpr V
+    base() const
+    {
+        return base_;
+    }
+
+    constexpr iterator
+    begin()
+    {
+        if (begin_cache_)
+        {
+            return *begin_cache_;
+        }
+
+        assert(pred_.has_value());
+        begin_cache_ = ::std::optional<iterator>{iterator{*this, nano::find_if(base_, detail::as_ref(*pred_))}};
+        return *begin_cache_;
+    }
+
+    constexpr auto
+    end()
+    {
+        if constexpr (common_range<V>)
+        {
+            return iterator{*this, ranges::end(base_)};
+        }
+        else
+        {
+            return sentinel{*this};
+        }
+    }
+};
+
+template <typename R, typename Pred>
+filter_view(R&&, Pred)->filter_view<all_view<R>, Pred>;
+
+} // namespace filter_view_
+
+using filter_view_::filter_view;
+
+namespace detail
+{
+
+struct filter_view_fn
+{
+    template <typename Pred>
+    constexpr auto
+    operator()(Pred pred) const
+    {
+        return detail::rao_proxy{[p = ::std::move(pred)](auto&& r) mutable
+#        ifndef NANO_MSVC_LAMBDA_PIPE_WORKAROUND
+                                 -> decltype(filter_view{::std::forward<decltype(r)>(r), ::std::declval<Pred&&>()})
+#        endif
+                                 {
+                                     return filter_view{::std::forward<decltype(r)>(r), ::std::move(p)};
+                                 }};
+    }
+
+    template <typename R, typename Pred>
+    constexpr auto
+    operator()(R&& r, Pred pred) const noexcept(noexcept(filter_view{::std::forward<R>(r), ::std::move(pred)}))
+        -> decltype(filter_view{::std::forward<R>(r), ::std::move(pred)})
+    {
+        return filter_view{::std::forward<R>(r), ::std::move(pred)};
+    }
+};
+
+} // namespace detail
+
+namespace views
+{
+
+NANO_INLINE_VAR(nano::detail::filter_view_fn, filter)
+}
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/views/iota.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_IOTA_HPP_INCLUDED
+#        define NANORANGE_VIEWS_IOTA_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct decrementable_concept
+{
+    template <typename I>
+    auto
+    requires_(I i) -> decltype(requires_expr<same_as<decltype(--i), I&>>{}, requires_expr<same_as<decltype(i--), I>>{});
+};
+
+template <typename I>
+NANO_CONCEPT decrementable = incrementable<I>&& requires_<decrementable_concept, I>;
+
+template <typename W>
+using iota_diff_t = iter_difference_t<W>;
+
+struct advanceable_concept
+{
+    template <typename I>
+    auto
+    requires_(I i, const I j, const iota_diff_t<I> n)
+        -> decltype(requires_expr<same_as<decltype(i += n), I&>>{}, requires_expr<same_as<decltype(i -= n), I&>>{},
+                    I(j + n), I(n + j), I(j - n), requires_expr<convertible_to<decltype(j - j), iota_diff_t<I>>>{});
+};
+
+template <typename I>
+NANO_CONCEPT advanceable = decrementable<I>&& totally_ordered<I>&& requires_<advanceable_concept, I>;
+
+template <typename W>
+constexpr auto
+iota_view_iter_cat_helper()
+{
+    if constexpr (detail::advanceable<W>)
+    {
+        return random_access_iterator_tag{};
+    }
+    else if constexpr (detail::decrementable<W>)
+    {
+        return bidirectional_iterator_tag{};
+    }
+    else if constexpr (incrementable<W>)
+    {
+        return forward_iterator_tag{};
+    }
+    else
+    {
+        return input_iterator_tag{};
+    }
+}
+
+} // namespace detail
+
+template <typename W, typename Bound = unreachable_sentinel_t>
+struct iota_view : view_interface<iota_view<W, Bound>>
+{
+    static_assert(weakly_incrementable<W>);
+    static_assert(semiregular<Bound>);
+    static_assert(detail::weakly_equality_comparable_with<W, Bound>);
+
+  private:
+    struct sentinel;
+
+    struct iterator
+    {
+      private:
+        friend struct sentinel;
+        W value_ = W();
+
+      public:
+        using iterator_category = decltype(detail::iota_view_iter_cat_helper<W>());
+        using value_type = W;
+        using difference_type = detail::iota_diff_t<W>;
+        // Extension: legacy typedefs
+        using pointer = void;
+        using reference = W;
+
+        iterator() = default;
+
+        constexpr explicit iterator(W value) : value_(value) {}
+
+        constexpr W operator*() const noexcept(::std::is_nothrow_copy_constructible_v<W>) { return value_; }
+
+        constexpr iterator&
+        operator++()
+        {
+            ++value_;
+            return *this;
+        }
+
+        constexpr auto
+        operator++(int)
+        {
+            if constexpr (incrementable<W>)
+            {
+                auto tmp = *this;
+                ++*this;
+                return tmp;
+            }
+            else
+            {
+                ++*this;
+            }
+        }
+
+        template <typename WW = W>
+        constexpr auto
+        operator--() -> ::std::enable_if_t<detail::decrementable<WW>, iterator&>
+        {
+            --value_;
+            return *this;
+        }
+
+        constexpr iterator
+        operator--(int)
+        {
+            auto tmp = *this;
+            ++*this;
+            return tmp;
+        }
+
+        template <typename WW = W>
+        constexpr auto
+        operator+=(difference_type n) -> ::std::enable_if_t<detail::advanceable<WW>, iterator&>
+        {
+            if constexpr (integral<W> && !signed_integral<W>)
+            {
+                if (n >= difference_type(0))
+                {
+                    value_ += static_cast<W>(n);
+                }
+                else
+                {
+                    value_ -= static_cast<W>(-n);
+                }
+            }
+            else
+            {
+                value_ += n;
+            }
+            return *this;
+        }
+
+        template <typename WW = W>
+        constexpr auto
+        operator-=(difference_type n) -> ::std::enable_if_t<detail::advanceable<WW>, iterator&>
+        {
+            if constexpr (integral<W> && !signed_integral<W>)
+            {
+                if (n >= difference_type(0))
+                {
+                    value_ -= static_cast<W>(n);
+                }
+                else
+                {
+                    value_ += static_cast<W>(-n);
+                }
+            }
+            else
+            {
+                value_ -= n;
+            }
+            return *this;
+        }
+
+        template <typename WW = W>
+        constexpr auto operator[](difference_type n) const -> ::std::enable_if_t<detail::advanceable<WW>, W>
+        {
+            return W(value_ + n);
+        }
+
+        template <typename WW = W>
+        friend constexpr auto
+        operator==(const iterator& x, const iterator& y) -> ::std::enable_if_t<equality_comparable<WW>, bool>
+        {
+            return x.value_ == y.value_;
+        }
+
+        template <typename WW = W>
+        friend constexpr auto
+        operator!=(const iterator& x, const iterator& y) -> ::std::enable_if_t<equality_comparable<WW>, bool>
+        {
+            return !(x == y);
+        }
+
+        template <typename WW = W>
+        friend constexpr auto
+        operator<(const iterator& x, const iterator& y) -> ::std::enable_if_t<totally_ordered<WW>, bool>
+        {
+            return x.value_ < y.value_;
+        }
+
+        template <typename WW = W>
+        friend constexpr auto
+        operator>(const iterator& x, const iterator& y) -> ::std::enable_if_t<totally_ordered<WW>, bool>
+        {
+            return y < x;
+        }
+
+        template <typename WW = W>
+        friend constexpr auto
+        operator<=(const iterator& x, const iterator& y) -> ::std::enable_if_t<totally_ordered<WW>, bool>
+        {
+            return !(y < x);
+        }
+
+        template <typename WW = W>
+        friend constexpr auto
+        operator>=(const iterator& x, const iterator& y) -> ::std::enable_if_t<totally_ordered<WW>, bool>
+        {
+            return !(x < y);
+        }
+
+        template <typename WW = W>
+        friend constexpr auto
+        operator+(iterator i, difference_type n) -> ::std::enable_if_t<detail::advanceable<WW>, iterator>
+        {
+            return i += n;
+        }
+
+        template <typename WW = W>
+        friend constexpr auto
+        operator+(difference_type n, iterator i) -> ::std::enable_if_t<detail::advanceable<WW>, iterator>
+        {
+            return i + n;
+        }
+
+        template <typename WW = W>
+        friend constexpr auto
+        operator-(iterator i, difference_type n) -> ::std::enable_if_t<detail::advanceable<WW>, iterator>
+        {
+            return i -= n;
+        }
+
+        template <typename WW = W>
+        friend constexpr auto
+        operator-(const iterator& x, const iterator& y) -> ::std::enable_if_t<detail::advanceable<WW>, difference_type>
+        {
+            using D = difference_type;
+            if constexpr (integral<D>)
+            {
+                if constexpr (signed_integral<D>)
+                {
+                    return D(D(x.value_) - D(y.value_));
+                }
+                else
+                {
+                    return (y.value_ > x.value_) ? D(-D(y.value_ - x.value_)) : D(x.value_ - y.value_);
+                }
+            }
+            else
+            {
+                return x.value_ - y.value_;
+            }
+        }
+    };
+
+    struct sentinel
+    {
+      private:
+        Bound bound_ = Bound();
+
+      public:
+        sentinel() = default;
+        constexpr explicit sentinel(Bound bound) : bound_(bound) {}
+
+        friend constexpr bool
+        operator==(const iterator& i, const sentinel& s)
+        {
+            return i.value_ == s.bound_;
+        }
+
+        friend constexpr bool
+        operator==(const sentinel& s, const iterator& i)
+        {
+            return i == s;
+        }
+
+        friend constexpr bool
+        operator!=(const iterator& i, const sentinel& s)
+        {
+            return !(i == s);
+        }
+
+        friend constexpr bool
+        operator!=(const sentinel& s, const iterator& i)
+        {
+            return !(i == s);
+        }
+
+        template <typename WW = W>
+        friend constexpr auto
+        operator-(const iterator& i, const sentinel& s)
+            -> ::std::enable_if_t<sized_sentinel_for<Bound, WW>, iter_difference_t<WW>>
+        {
+            return i.value_ - s.bound_;
+        }
+
+        template <typename WW = W>
+        friend constexpr auto
+        operator-(const sentinel& s, const iterator& i)
+            -> ::std::enable_if_t<sized_sentinel_for<Bound, WW>, iter_difference_t<WW>>
+        {
+            return -(i - s);
+        }
+    };
+
+    W value_ = W();
+    Bound bound_ = Bound();
+
+  public:
+    iota_view() = default;
+
+    constexpr explicit iota_view(W value) : value_(value) {}
+
+    constexpr iota_view(type_identity_t<W> value, type_identity_t<Bound> bound) : value_(value), bound_(bound) {}
+
+    constexpr iota_view(iterator first, sentinel last) : iota_view(*first, last.bound_) {}
+
+    constexpr iterator
+    begin() const
+    {
+        return iterator{value_};
+    }
+
+    template <typename WW = W, ::std::enable_if_t<!same_as<WW, Bound>, int> = 0>
+    constexpr auto
+    end() const
+    {
+        if constexpr (same_as<Bound, unreachable_sentinel_t>)
+        {
+            return unreachable_sentinel;
+        }
+        else
+        {
+            return sentinel{bound_};
+        }
+    }
+
+    template <typename WW = W, ::std::enable_if_t<same_as<WW, Bound>, int> = 0>
+    constexpr iterator
+    end() const
+    {
+        return iterator{bound_};
+    }
+
+    template <typename WW = W, typename BB = Bound,
+              ::std::enable_if_t<(same_as<WW, BB> && detail::advanceable<W>) || (integral<WW> && integral<BB>) ||
+                                     sized_sentinel_for<BB, WW>,
+                                 int> = 0>
+    constexpr auto
+    size() const
+    {
+        constexpr auto make_unsigned_like = [](auto i) { return ::std::make_unsigned_t<decltype(i)>(i); };
+
+        if constexpr (integral<W> && integral<Bound>)
+        {
+            return (value_ < 0) ? ((bound_ < 0) ? make_unsigned_like(-value_) - make_unsigned_like(-bound_)
+                                                : make_unsigned_like(bound_) - make_unsigned_like(-value_))
+                                : make_unsigned_like(bound_) - make_unsigned_like(value_);
+        }
+        else
+        {
+            make_unsigned_like(bound_ - value_);
+        }
+    }
+};
+
+template <
+    typename W, typename Bound,
+    ::std::enable_if_t<!integral<W> || !integral<Bound> || (signed_integral<W> == signed_integral<Bound>), int> = 0>
+iota_view(W, Bound)->iota_view<W, Bound>;
+
+template <typename W, typename Bound>
+inline constexpr bool enable_borrowed_range<iota_view<W, Bound>> = true;
+
+namespace views
+{
+
+namespace detail
+{
+
+struct iota_view_fn
+{
+    template <typename W>
+    constexpr auto
+    operator()(W&& value) const noexcept(noexcept(iota_view{::std::forward<W>(value)}))
+        -> decltype(iota_view(::std::forward<W>(value)))
+    {
+        return iota_view(::std::forward<W>(value));
+    }
+
+    template <typename W, typename Bound>
+    constexpr auto
+    operator()(W&& value, Bound&& bound) const
+        noexcept(noexcept(iota_view{::std::forward<W>(value), ::std::forward<Bound>(bound)}))
+            -> decltype(iota_view(::std::forward<W>(value), ::std::forward<Bound>(bound)))
+    {
+        return iota_view{::std::forward<W>(value), ::std::forward<Bound>(bound)};
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::iota_view_fn, iota)
+
+} // namespace views
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/views/istream.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_ISTREAM_HPP_INCLUDED
+#        define NANORANGE_VIEWS_ISTREAM_HPP_INCLUDED
+
+#        include <iosfwd>
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+struct StreamExtractable_req
+{
+    template <typename Val, typename CharT, typename Traits>
+    auto
+    requires_(::std::basic_istream<CharT, Traits>& is, Val& t) -> decltype(is >> t);
+};
+
+template <typename Val, typename CharT, typename Traits>
+NANO_CONCEPT StreamExtractable = requires_<StreamExtractable_req, Val, CharT, Traits>;
+
+} // namespace detail
+
+template <typename Val, typename CharT, typename Traits = ::std::char_traits<CharT>>
+struct basic_istream_view : view_interface<basic_istream_view<Val, CharT, Traits>>
+{
+
+    static_assert(movable<Val>);
+    static_assert(default_initializable<Val>);
+    static_assert(detail::StreamExtractable<Val, CharT, Traits>);
+
+    basic_istream_view() = default;
+
+    constexpr explicit basic_istream_view(::std::basic_istream<CharT, Traits>& stream)
+        : stream_(::std::addressof(stream))
+    {
+    }
+
+    constexpr auto
+    begin()
+    {
+        if (stream_)
+        {
+            *stream_ >> object_;
+        }
+        return iterator{*this};
+    }
+
+    constexpr default_sentinel_t
+    end() const noexcept
+    {
+        return default_sentinel;
+    }
+
+  private:
+    struct iterator
+    {
+        using iterator_category = input_iterator_tag;
+        using difference_type = ::std::ptrdiff_t;
+        using value_type = Val;
+
+        iterator() = default;
+
+        constexpr explicit iterator(basic_istream_view& parent) noexcept : parent_(::std::addressof(parent)) {}
+
+        // Disable move-only iterator until views support them properly
+#        if 0
+        iterator(const iterator&) = delete;
+        iterator(iterator&&) = default;
+
+        iterator& operator=(const iterator&) = delete;
+        iterator& operator=(iterator&&) = default;
+#        endif
+        iterator&
+        operator++()
+        {
+            *parent_->stream_ >> parent_->object_;
+            return *this;
+        }
+
+        void
+        operator++(int)
+        {
+            ++*this;
+        }
+
+        Val& operator*() const { return parent_->object_; }
+
+        friend bool
+        operator==(const iterator& x, default_sentinel_t)
+        {
+            return x.done();
+        }
+
+        friend bool
+        operator==(default_sentinel_t s, const iterator& x)
+        {
+            return x == s;
+        }
+
+        friend bool
+        operator!=(const iterator& x, default_sentinel_t s)
+        {
+            return !(x == s);
+        }
+
+        friend bool
+        operator!=(default_sentinel_t s, const iterator& x)
+        {
+            return !(x == s);
+        }
+
+      private:
+        [[nodiscard]] bool
+        done() const { return parent_ == nullptr || parent_->stream_ == nullptr || !*parent_->stream_; }
+
+        basic_istream_view* parent_{};
+    };
+
+    ::std::basic_istream<CharT, Traits>* stream_{};
+    Val object_ = Val();
+};
+
+template <typename Val, typename CharT, typename Traits>
+auto
+istream_view(::std::basic_istream<CharT, Traits>& s) -> basic_istream_view<Val, CharT, Traits>
+{
+    return basic_istream_view<Val, CharT, Traits>{s};
+}
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/views/join.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_JOIN_HPP_INCLUDED
+#        define NANORANGE_VIEWS_JOIN_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+template <typename V, bool InnerIsReference>
+struct join_view_data
+{
+    V base_ = V();
+};
+
+template <typename V>
+struct join_view_data<V, false>
+{
+    V base_ = V();
+    all_view<range_reference_t<V>> inner_ = all_view<range_reference_t<V>>();
+};
+
+template <typename B>
+constexpr auto
+join_view_iter_cat_helper()
+{
+    constexpr bool ref_is_glvalue = ::std::is_reference_v<range_reference_t<B>>;
+
+    if constexpr (ref_is_glvalue)
+    {
+        using OuterCat = iterator_category_t<iterator_t<B>>;
+        using InnerCat = iterator_category_t<iterator_t<range_reference_t<B>>>;
+
+        if constexpr (derived_from<OuterCat, bidirectional_iterator_tag> &&
+                      derived_from<InnerCat, bidirectional_iterator_tag>)
+        {
+            return bidirectional_iterator_tag{};
+        }
+        else if constexpr (derived_from<OuterCat, forward_iterator_tag> && derived_from<InnerCat, forward_iterator_tag>)
+        {
+            return forward_iterator_tag{};
+        }
+        else
+        {
+            return input_iterator_tag{};
+        }
+    }
+    else
+    {
+        return input_iterator_tag{};
+    }
+}
+
+} // namespace detail
+
+namespace join_view_
+{
+
+template <typename V>
+struct join_view : view_interface<join_view<V>>
+{
+  private:
+    static_assert(input_range<V>);
+    static_assert(view<V>);
+    static_assert(input_range<range_reference_t<V>>);
+    static_assert(::std::is_reference_v<range_reference_t<V>> || view<range_value_t<V>>);
+
+    using InnerRng = range_reference_t<V>;
+
+    template <bool>
+    struct sentinel;
+
+    template <bool Const>
+    struct iterator
+    {
+
+        friend struct sentinel<Const>;
+
+        template <typename B>
+        static constexpr bool ref_is_glvalue = ::std::is_reference_v<range_reference_t<B>>;
+
+        using Base = detail::conditional_t<Const, const V, V>;
+
+        // https://github.com/ericniebler/stl2/issues/604
+        using Parent = detail::conditional_t<Const && ref_is_glvalue<Base>, const join_view, join_view>;
+
+        iterator_t<Base> outer_ = iterator_t<Base>();
+        iterator_t<range_reference_t<Base>> inner_ = iterator_t<range_reference_t<Base>>();
+        Parent* parent_ = nullptr;
+
+        template <typename B = Base>
+        constexpr decltype(auto)
+        update_inner(range_reference_t<Base> x)
+        {
+            if constexpr (ref_is_glvalue<B>)
+            {
+                return (x);
+            }
+            else
+            {
+                return (parent_->data_.inner_ = views::all(x));
+            }
+        }
+
+        constexpr void
+        satisfy()
+        {
+            for (; outer_ != ranges::end(parent_->data_.base_); ++outer_)
+            {
+                auto& inner = update_inner(*outer_);
+                inner_ = ranges::begin(inner);
+                if (inner_ != ranges::end(inner))
+                {
+                    return;
+                }
+            }
+
+            if constexpr (ref_is_glvalue<Base>)
+            {
+                inner_ = iterator_t<range_reference_t<Base>>();
+            }
+        }
+
+      public:
+        //using iterator_concept = ...
+        using iterator_category = decltype(detail::join_view_iter_cat_helper<Base>());
+        using value_type = range_value_t<range_reference_t<Base>>;
+        using difference_type =
+            nano::common_type_t<range_difference_t<Base>, range_difference_t<range_reference_t<Base>>>;
+        // Extension: legacy typedefs
+        using pointer = iterator_t<Base>;
+        using reference = range_reference_t<range_reference_t<Base>>;
+
+        iterator() = default;
+
+        constexpr iterator(Parent& parent, iterator_t<Base> outer)
+            : outer_(::std::move(outer)), parent_(::std::addressof(parent))
+        {
+            satisfy();
+        }
+
+        // constexpr iterator(iterator<!Const>);
+
+        constexpr decltype(auto) operator*() const { return *inner_; }
+
+        template <typename B = Base>
+        constexpr auto operator-> () const -> ::std::enable_if_t<detail::has_arrow<B>, iterator_t<Base>>
+        {
+            return inner_;
+        }
+
+      private:
+        template <typename B = Base>
+        constexpr decltype(auto)
+        get_inner_rng()
+        {
+            if constexpr (ref_is_glvalue<B>)
+            {
+                return (*outer_);
+            }
+            else
+            {
+                return (parent_->data_.inner_);
+            }
+        }
+
+      public:
+        template <typename B = Base>
+        constexpr iterator&
+        operator++()
+        {
+            auto&& inner_rng = get_inner_rng();
+
+            if (++inner_ == ranges::end(inner_rng))
+            {
+                ++outer_;
+                satisfy();
+            }
+
+            return *this;
+        }
+
+        template <typename B = Base>
+        constexpr auto
+        operator++(int)
+            -> ::std::enable_if_t<!(ref_is_glvalue<B> && forward_range<B> && forward_range<range_reference_t<B>>)>
+        {
+            ++*this;
+        }
+
+        template <typename B = Base>
+        constexpr auto
+        operator++(int)
+            -> ::std::enable_if_t<ref_is_glvalue<B> && forward_range<B> && forward_range<range_reference_t<B>>,
+                                  iterator>
+        {
+            auto tmp = *this;
+            ++*this;
+            return tmp;
+        }
+
+        template <typename B = Base>
+        constexpr auto
+        operator--() -> ::std::enable_if_t<
+            ref_is_glvalue<B> && bidirectional_range<B> && bidirectional_range<range_reference_t<B>>, iterator&>
+        {
+            if (outer_ == ranges::end(parent_->data_.base_))
+            {
+                inner_ = ranges::end(*outer_);
+            }
+
+            while (inner_ == ranges::begin(*outer_))
+            {
+                inner_ = ranges::end(*--outer_);
+            }
+            --inner_;
+            return *this;
+        }
+
+        template <typename B = Base>
+        constexpr auto
+        operator--(int) -> ::std::enable_if_t<
+            ref_is_glvalue<B> && bidirectional_range<B> && bidirectional_range<range_reference_t<B>>, iterator>
+        {
+            auto tmp = *this;
+            --*this;
+            return *tmp;
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator==(const iterator& x, const iterator& y)
+            -> ::std::enable_if_t<ref_is_glvalue<B> && equality_comparable<iterator_t<B>> &&
+                                      equality_comparable<iterator_t<range_reference_t<B>>>,
+                                  bool>
+        {
+            return x.outer_ == y.outer_ && x.inner_ == y.inner_;
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator!=(const iterator& x, const iterator& y)
+            -> ::std::enable_if_t<ref_is_glvalue<B> && equality_comparable<iterator_t<B>> &&
+                                      equality_comparable<iterator_t<range_reference_t<B>>>,
+                                  bool>
+        {
+            return !(x == y);
+        }
+
+        friend constexpr decltype(auto)
+        iter_move(const iterator& i) noexcept(noexcept(ranges::iter_move(i.inner_)))
+        {
+            return ranges::iter_move(i.inner_);
+        }
+
+        friend constexpr void
+        iter_swap(const iterator& x, const iterator& y) noexcept(noexcept(ranges::iter_swap(x.inner_, y.inner_)))
+        {
+            ranges::iter_swap(x.inner_, y.inner_);
+        }
+    };
+
+    template <bool Const>
+    struct sentinel
+    {
+      private:
+        using Parent = detail::conditional_t<Const, const join_view, join_view>;
+        using Base = detail::conditional_t<Const, const V, V>;
+
+        sentinel_t<Base> end_ = sentinel_t<Base>();
+
+      public:
+        sentinel() = default;
+
+        constexpr explicit sentinel(Parent& parent) : end_(ranges::end(parent.data_.base_)) {}
+
+        // constexpr sentinel(sentinel<!Const> s);
+
+        friend constexpr bool
+        operator==(const iterator<Const>& x, const sentinel& y)
+        {
+            return x.outer_ == y.end_;
+        }
+
+        friend constexpr bool
+        operator!=(const iterator<Const>& x, const sentinel& y)
+        {
+            return !(x == y);
+        }
+
+        friend constexpr bool
+        operator==(const sentinel& x, const iterator<Const>& y)
+        {
+            return y == x;
+        }
+
+        friend constexpr bool
+        operator!=(const sentinel& x, const iterator<Const>& y)
+        {
+            return !(y == x);
+        }
+    };
+
+    detail::join_view_data<V, ::std::is_reference_v<InnerRng>> data_{};
+
+  public:
+    join_view() = default;
+
+    constexpr explicit join_view(V base) : data_{::std::move(base)} {}
+
+    template <typename R, ::std::enable_if_t<detail::not_same_as<R, join_view>, int> = 0,
+              ::std::enable_if_t<input_range<R>, int> = 0, ::std::enable_if_t<viewable_range<R>, int> = 0,
+              ::std::enable_if_t<constructible_from<V, all_view<R>>, int> = 0>
+    constexpr join_view(R&& r) : data_{views::all(::std::forward<R>(r))}
+    {
+    }
+
+    constexpr auto
+    begin()
+    {
+        return iterator<detail::simple_view<V>>{*this, ranges::begin(data_.base_)};
+    }
+
+    template <typename VV = V,
+              ::std::enable_if_t<input_range<const VV>&& ::std::is_reference_v<range_reference_t<const VV>>, int> = 0>
+    constexpr auto
+    begin() const
+    {
+        return iterator<true>{*this, ranges::begin(data_.base_)};
+    }
+
+    constexpr auto
+    end()
+    {
+        if constexpr (forward_range<V> && ::std::is_reference_v<InnerRng> && forward_range<InnerRng> &&
+                      common_range<V> && common_range<InnerRng>)
+        {
+            return iterator<detail::simple_view<V>>{*this, ranges::end(data_.base_)};
+        }
+        else
+        {
+            return sentinel<detail::simple_view<V>>{*this};
+        }
+    }
+
+    template <typename VV = V,
+              ::std::enable_if_t<input_range<const VV>&& ::std::is_reference_v<range_reference_t<const VV>>, int> = 0>
+    constexpr auto
+    end() const
+    {
+        if constexpr (forward_range<const V> && ::std::is_reference_v<range_reference_t<const V>> &&
+                      forward_range<range_reference_t<const V>> && common_range<const V> &&
+                      common_range<range_reference_t<const V>>)
+        {
+            return iterator<true>{*this, ranges::end(data_.base_)};
+        }
+        else
+        {
+            return sentinel<true>{*this};
+        }
+    }
+};
+
+template <typename R>
+explicit join_view(R &&)->join_view<all_view<R>>;
+
+} // namespace join_view_
+
+using join_view_::join_view;
+
+namespace detail
+{
+
+struct join_view_fn
+{
+
+    template <typename E>
+    constexpr auto
+    operator()(E&& e) const -> decltype(join_view{::std::forward<E>(e)})
+    {
+        return join_view{::std::forward<E>(e)};
+    }
+};
+
+template <>
+inline constexpr bool is_raco<join_view_fn> = true;
+
+} // namespace detail
+
+namespace views
+{
+
+NANO_INLINE_VAR(nano::detail::join_view_fn, join)
+}
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/views/reverse.hpp
+//
+// Copyright (c) 2018 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_REVERSE_HPP_INCLUDED
+#        define NANORANGE_VIEWS_REVERSE_HPP_INCLUDED
+
+#        include <optional>
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+template <bool IsCommonRange, typename>
+struct reverse_view_cache
+{
+};
+
+template <typename I>
+struct reverse_view_cache<false, I>
+{
+    ::std::optional<I> cached{};
+};
+
+} // namespace detail
+
+template <typename V>
+struct reverse_view : view_interface<reverse_view<V>>,
+                      private detail::reverse_view_cache<common_range<V>, iterator_t<V>>
+{
+
+    static_assert(view<V>);
+    static_assert(bidirectional_range<V>);
+
+    reverse_view() = default;
+
+    constexpr explicit reverse_view(V r) : base_(::std::move(r)) {}
+
+    template <
+        typename R,
+        /* FIXME: This is not to spec, but we get in horrible recursive trouble if it's omitted */
+        ::std::enable_if_t<detail::not_same_as<R, reverse_view>, int> = 0,
+        ::std::enable_if_t<viewable_range<R> && bidirectional_range<R> && constructible_from<V, all_view<R>>, int> = 0>
+    constexpr explicit reverse_view(R&& r) : base_(views::all(::std::forward<R>(r)))
+    {
+    }
+
+    constexpr reverse_view(const reverse_view& other) = default;
+
+    constexpr V
+    base() const
+    {
+        return base_;
+    }
+
+    constexpr reverse_iterator<iterator_t<V>>
+    begin()
+    {
+        if constexpr (common_range<V>)
+        {
+            return nano::make_reverse_iterator(ranges::end(base_));
+        }
+        else
+        {
+            auto& c = this->cached;
+            if (!c.has_value())
+            {
+                c = ranges::next(ranges::begin(base_), ranges::end(base_));
+            }
+            return nano::make_reverse_iterator(*c);
+        }
+    }
+
+    template <typename VV = V>
+    constexpr auto
+    begin() const -> ::std::enable_if_t<common_range<const VV>, reverse_iterator<iterator_t<const VV>>>
+    {
+        return nano::make_reverse_iterator(ranges::end(base_));
+    }
+
+    constexpr reverse_iterator<iterator_t<V>>
+    end()
+    {
+        return nano::make_reverse_iterator(ranges::begin(base_));
+    }
+
+    template <typename VV = V>
+    constexpr auto
+    end() const -> ::std::enable_if_t<common_range<const VV>, reverse_iterator<iterator_t<const VV>>>
+    {
+        return nano::make_reverse_iterator(ranges::begin(base_));
+    }
+
+    template <typename VV = V, ::std::enable_if_t<sized_range<VV>, int> = 0>
+    constexpr auto
+    size()
+    {
+        return ranges::size(base_);
+    }
+
+    template <typename VV = V, ::std::enable_if_t<sized_range<const VV>, int> = 0>
+    constexpr auto
+    size() const
+    {
+        return ranges::size(base_);
+    }
+
+  private:
+    V base_ = V{};
+};
+
+template <typename R>
+reverse_view(R &&)->reverse_view<all_view<R>>;
+
+namespace detail
+{
+
+struct reverse_view_fn
+{
+  private:
+    template <typename R>
+    static constexpr auto
+    impl(reverse_view<R> r, detail::priority_tag<1>)
+    {
+        return r.base();
+    }
+
+    template <typename I, subrange_kind K>
+    static constexpr auto
+    impl(subrange<reverse_iterator<I>, reverse_iterator<I>, K> s, detail::priority_tag<1>)
+    {
+        if constexpr (K == subrange_kind::sized)
+        {
+            return subrange<I, I, K>(s.end().base(), s.begin().base(), s.size());
+        }
+        else
+        {
+            return subrange<I, I, K>(s.end().base(), s.begin().base());
+        }
+    }
+
+    template <typename R>
+    static constexpr auto
+    impl(R&& r, detail::priority_tag<0>) -> decltype(reverse_view{::std::forward<R>(r)})
+    {
+        return reverse_view{::std::forward<R>(r)};
+    }
+
+  public:
+    template <typename R>
+    constexpr auto
+    operator()(R&& r) const -> decltype(impl(::std::forward<R>(r), priority_tag<1>{}))
+    {
+        return impl(::std::forward<R>(r), priority_tag<1>{});
+    }
+};
+
+template <>
+inline constexpr bool is_raco<reverse_view_fn> = true;
+
+} // namespace detail
+
+namespace views
+{
+
+NANO_INLINE_VAR(nano::detail::reverse_view_fn, reverse)
+
+} // namespace views
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/views/single.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_SINGLE_HPP_INCLUDED
+#        define NANORANGE_VIEWS_SINGLE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename T>
+struct single_view : view_interface<single_view<T>>
+{
+    static_assert(copy_constructible<T>);
+    static_assert(::std::is_object<T>::value);
+
+    single_view() = default;
+
+    constexpr explicit single_view(const T& t) : value_(t) {}
+
+    constexpr explicit single_view(T&& t) : value_(::std::move(t)) {}
+
+    template <typename... Args, ::std::enable_if_t<constructible_from<T, Args...>, int> = 0>
+    constexpr single_view(::std::in_place_t, Args&&... args) : value_{::std::in_place, ::std::forward<Args>(args)...}
+    {
+    }
+
+    constexpr T*
+    begin() noexcept
+    {
+        return data();
+    }
+    constexpr const T*
+    begin() const noexcept
+    {
+        return data();
+    }
+
+    constexpr T*
+    end() noexcept
+    {
+        return data() + 1;
+    }
+    constexpr const T*
+    end() const noexcept
+    {
+        return data() + 1;
+    }
+
+    static constexpr ::std::size_t
+    size()
+    {
+        return 1;
+    }
+
+    constexpr T*
+    data() noexcept
+    {
+        return value_.operator->();
+    }
+    constexpr const T*
+    data() const noexcept
+    {
+        return value_.operator->();
+    }
+
+  private:
+    detail::semiregular_box<T> value_;
+};
+
+namespace views
+{
+
+namespace detail
+{
+
+struct single_view_fn
+{
+    template <typename T>
+    constexpr auto
+    operator()(T&& t) const noexcept(noexcept(single_view{::std::forward<T>(t)}))
+        -> decltype(single_view{::std::forward<T>(t)})
+    {
+        return single_view{::std::forward<T>(t)};
+    }
+};
+
+} // namespace detail
+
+NANO_INLINE_VAR(detail::single_view_fn, single)
+
+} // namespace views
+
+NANO_END_NAMESPACE
+
+#    endif
+// nanorange/views/split.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_SPLIT_HPP_INCLUDED
+#        define NANORANGE_VIEWS_SPLIT_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace detail
+{
+
+template <auto>
+struct require_constant;
+
+struct tiny_range_concept
+{
+
+    template <typename R>
+    auto
+    requires_() -> decltype(::std::declval<require_constant<::std::remove_reference_t<R>::size()>>());
+
+    template <typename R>
+    static auto
+    test(long) -> ::std::false_type;
+
+    template <typename R>
+    static auto
+    test(int) -> ::std::enable_if_t<sized_range<R> && detail::requires_<tiny_range_concept, R> &&
+                                        (::std::remove_reference_t<R>::size() <= 1),
+                                    ::std::true_type>;
+};
+
+template <typename R>
+NANO_CONCEPT tiny_range = decltype(tiny_range_concept::test<R>(0))::value;
+
+template <typename V, typename P, bool NotForwardRange>
+struct split_view_data
+{
+    V base_ = V();
+    P pattern_ = P();
+};
+
+template <typename V, typename P>
+struct split_view_data<V, P, true>
+{
+    V base_ = V();
+    P pattern_ = P();
+    iterator_t<V> current_ = iterator_t<V>();
+};
+
+} // namespace detail
+
+namespace split_view_
+{
+
+template <typename V, typename Pattern>
+struct split_view : view_interface<split_view<V, Pattern>>
+{
+  private:
+    static_assert(input_range<V>);
+    static_assert(forward_range<Pattern>);
+    static_assert(view<V>);
+    static_assert(view<Pattern>);
+    static_assert(indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to>);
+    static_assert(forward_range<V> || detail::tiny_range<Pattern>);
+
+    detail::split_view_data<V, Pattern, !forward_range<V>> data_{};
+
+    template <bool>
+    struct inner_iterator;
+
+    template <bool Const>
+    struct outer_iterator
+    {
+      private:
+        friend struct outer_iterator<!Const>;
+        friend struct inner_iterator<Const>;
+
+        using Parent = detail::conditional_t<Const, const split_view, split_view>;
+        using Base = detail::conditional_t<Const, const V, V>;
+        Parent* parent_ = nullptr;
+        iterator_t<Base> current_ = iterator_t<Base>();
+
+        constexpr decltype(auto)
+        get_current()
+        {
+            if constexpr (forward_range<V>)
+            {
+                return (current_);
+            }
+            else
+            {
+                return (parent_->data_.current_);
+            }
+        }
+
+        constexpr decltype(auto)
+        get_current() const
+        {
+            if constexpr (forward_range<V>)
+            {
+                return (current_);
+            }
+            else
+            {
+                return (parent_->data_.current_);
+            }
+        }
+
+        constexpr bool
+        done() const
+        {
+            return get_current() == ranges::end(parent_->data_.base_);
+        }
+
+      public:
+        // FIXME: iterator_concept
+        using iterator_category = detail::conditional_t<forward_range<Base>, forward_iterator_tag, input_iterator_tag>;
+
+        struct value_type
+        {
+          private:
+            outer_iterator i_ = outer_iterator();
+
+          public:
+            value_type() = default;
+
+            constexpr explicit value_type(outer_iterator i) : i_(::std::move(i)) {}
+
+            constexpr inner_iterator<Const>
+            begin() const
+            {
+                return inner_iterator<Const>{i_};
+            }
+
+            constexpr default_sentinel_t
+            end() const
+            {
+                return default_sentinel;
+            }
+        };
+
+        using difference_type = range_difference_t<Base>;
+        // Extension: legacy typedefs
+        using pointer = void;
+        using reference = value_type;
+
+        outer_iterator() = default;
+
+        template <typename B = Base, ::std::enable_if_t<!forward_range<B>, int> = 0>
+        constexpr explicit outer_iterator(Parent& parent) : parent_(::std::addressof(parent))
+        {
+        }
+
+        template <typename B = Base, ::std::enable_if_t<forward_range<B>, int> = 0>
+        constexpr outer_iterator(Parent& parent, iterator_t<Base> current)
+            : parent_(::std::addressof(parent)), current_(::std::move(current))
+        {
+        }
+
+        template <typename I, ::std::enable_if_t<same_as<I, outer_iterator<!Const>>, int> = 0, bool C = Const,
+                  typename VV = V,
+                  ::std::enable_if_t<C && convertible_to<iterator_t<VV>, iterator_t<const VV>>, int> = 0>
+        constexpr outer_iterator(I i) : parent_(i.parent_), current_(::std::move(i.current_))
+        {
+        }
+
+        constexpr value_type operator*() const { return value_type{*this}; }
+
+        constexpr outer_iterator&
+        operator++()
+        {
+            const auto end = ranges::end(parent_->data_.base_);
+            if (get_current() == end)
+            {
+                return *this;
+            }
+            const auto [pbegin, pend] = subrange{parent_->data_.pattern_};
+            if (pbegin == pend)
+            {
+                ++get_current();
+            }
+            else
+            {
+                do
+                {
+                    const auto [b, p] = ranges::mismatch(get_current(), end, pbegin, pend);
+                    if (p == pend)
+                    {
+                        get_current() = b;
+                        break;
+                    }
+                } while (++get_current() != end);
+            }
+            return *this;
+        }
+
+        constexpr decltype(auto)
+        operator++(int)
+        {
+            if constexpr (forward_range<Base>)
+            {
+                auto tmp = *this;
+                ++*this;
+                return tmp;
+            }
+            else
+            {
+                ++*this;
+            }
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator==(const outer_iterator& x, const outer_iterator& y) -> ::std::enable_if_t<forward_range<B>, bool>
+        {
+            return x.current_ == y.current_;
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator!=(const outer_iterator& x, const outer_iterator& y) -> ::std::enable_if_t<forward_range<B>, bool>
+        {
+            return !(x == y);
+        }
+
+        friend constexpr bool
+        operator==(const outer_iterator& x, default_sentinel_t)
+        {
+            return x.done();
+        }
+
+        friend constexpr bool
+        operator==(default_sentinel_t d, const outer_iterator& x)
+        {
+            return x == d;
+        }
+
+        friend constexpr bool
+        operator!=(const outer_iterator& x, default_sentinel_t d)
+        {
+            return !(x == d);
+        }
+
+        friend constexpr bool
+        operator!=(default_sentinel_t d, const outer_iterator& x)
+        {
+            return !(x == d);
+        }
+    };
+
+    template <bool Const>
+    struct inner_iterator
+    {
+      private:
+        using Base = detail::conditional_t<Const, const V, V>;
+        static constexpr bool NoReallyGccConst = Const;
+        outer_iterator<Const> i_ = outer_iterator<NoReallyGccConst>();
+        bool incremented_ = false;
+
+        constexpr bool
+        done() const
+        {
+            auto cur = i_.get_current();
+            auto end = ranges::end(i_.parent_->data_.base_);
+            if (cur == end)
+            {
+                return true;
+            }
+            auto [pcur, pend] = subrange{i_.parent_->data_.pattern_};
+            if (pcur == pend)
+            {
+                return incremented_;
+            }
+            do
+            {
+                if (*cur != *pcur)
+                {
+                    return false;
+                }
+                if (++pcur == pend)
+                {
+                    return true;
+                }
+            } while (++cur != end);
+            return false;
+        }
+
+        constexpr decltype(auto)
+        get_outer_current() const
+        {
+            return i_.get_current();
+        }
+
+      public:
+        using iterator_category =
+            detail::conditional_t<derived_from<iterator_category_t<iterator_t<Base>>, forward_iterator_tag>,
+                                  forward_iterator_tag, input_iterator_tag>;
+        using value_type = range_value_t<Base>;
+        using difference_type = range_difference_t<Base>;
+
+        inner_iterator() = default;
+
+        constexpr explicit inner_iterator(outer_iterator<Const> i) : i_(::std::move(i)) {}
+
+        constexpr decltype(auto) operator*() const { return *i_.get_current(); }
+
+        constexpr inner_iterator&
+        operator++()
+        {
+            incremented_ = true;
+            if constexpr (!forward_range<Base>)
+            {
+                if constexpr (Pattern::size() == 0)
+                {
+                    return *this;
+                }
+            }
+            ++i_.get_current();
+            return *this;
+        }
+
+        constexpr decltype(auto)
+        operator++(int)
+        {
+            if constexpr (forward_range<V>)
+            {
+                auto tmp = *this;
+                ++*this;
+                return tmp;
+            }
+            else
+            {
+                ++*this;
+            }
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator==(const inner_iterator& x, const inner_iterator& y) -> ::std::enable_if_t<forward_range<B>, bool>
+        {
+            return x.get_outer_current() == y.get_outer_current();
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator!=(const inner_iterator& x, const inner_iterator& y) -> ::std::enable_if_t<forward_range<B>, bool>
+        {
+            return !(x == y);
+        }
+
+        friend constexpr bool
+        operator==(const inner_iterator& x, default_sentinel_t)
+        {
+            return x.done();
+        }
+
+        friend constexpr bool
+        operator==(default_sentinel_t d, const inner_iterator& x)
+        {
+            return x == d;
+        }
+
+        friend constexpr bool
+        operator!=(const inner_iterator& x, default_sentinel_t d)
+        {
+            return !(x == d);
+        }
+
+        friend constexpr bool
+        operator!=(default_sentinel_t d, const inner_iterator& x)
+        {
+            return !(x == d);
+        }
+
+        friend constexpr decltype(auto)
+        iter_move(const inner_iterator& i) noexcept(noexcept(ranges::iter_move(i.get_outer_current())))
+        {
+            return ranges::iter_move(i.get_outer_current());
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        iter_swap(const inner_iterator& x,
+                  const inner_iterator& y) noexcept(noexcept(ranges::iter_swap(x.get_outer_current(),
+                                                                               y.get_outer_current())))
+            -> ::std::enable_if_t<indirectly_swappable<B>>
+        {
+            ranges::iter_swap(x.get_outer_current(), y.get_outer_current());
+        }
+    };
+
+  public:
+    split_view() = default;
+
+    constexpr split_view(V base, Pattern pattern) : data_{::std::move(base), ::std::move(pattern)} {}
+
+    template <typename R, typename P, ::std::enable_if_t<constructible_from<V, all_view<R>>, int> = 0,
+              ::std::enable_if_t<constructible_from<Pattern, all_view<P>>, int> = 0,
+              ::std::enable_if_t<input_range<R> && forward_range<P>, int> = 0>
+    constexpr split_view(R&& r, P&& p) : data_{views::all(::std::forward<R>(r)), views::all(::std::forward<P>(p))}
+    {
+    }
+
+    template <typename R, ::std::enable_if_t<constructible_from<V, all_view<R>>, int> = 0,
+              ::std::enable_if_t<constructible_from<Pattern, single_view<range_value_t<R>>>, int> = 0,
+              ::std::enable_if_t<input_range<R>, int> = 0>
+    constexpr split_view(R&& r, range_value_t<R> e)
+        : data_{views::all(::std::forward<R>(r)), single_view{::std::move(e)}}
+    {
+    }
+
+    constexpr auto
+    begin()
+    {
+        if constexpr (forward_range<V>)
+        {
+            return outer_iterator<detail::simple_view<V>>{*this, ranges::begin(data_.base_)};
+        }
+        else
+        {
+            data_.current_ = ranges::begin(data_.base_);
+            return outer_iterator<false>{*this};
+        }
+    }
+
+    template <typename VV = V, ::std::enable_if_t<forward_range<VV> && forward_range<const VV>, int> = 0>
+    constexpr auto
+    begin() const
+    {
+        return outer_iterator<true>{*this, ranges::begin(data_.base_)};
+    }
+
+    template <typename VV = V, ::std::enable_if_t<forward_range<VV> && common_range<VV>, int> = 0>
+    constexpr auto
+    end()
+    {
+        return outer_iterator<detail::simple_view<V>>{*this, ranges::end(data_.base_)};
+    }
+
+    constexpr auto
+    end() const
+    {
+        if constexpr (forward_range<V> && forward_range<const V> && common_range<const V>)
+        {
+            return outer_iterator<true>{*this, ranges::end(data_.base_)};
+        }
+        else
+        {
+            return default_sentinel;
+        }
+    }
+};
+
+template <typename R, typename P>
+split_view(R&&, P &&)->split_view<all_view<R>, all_view<P>>;
+
+template <typename R, ::std::enable_if_t<input_range<R>, int> = 0>
+split_view(R&&, range_value_t<R>)->split_view<all_view<R>, single_view<range_value_t<R>>>;
+
+} // namespace split_view_
+
+using split_view_::split_view;
+
+namespace detail
+{
+
+struct split_view_fn
+{
+
+    template <typename E, typename F>
+    constexpr auto
+    operator()(E&& e, F&& f) const -> decltype(split_view{::std::forward<E>(e), ::std::forward<F>(f)})
+    {
+        return split_view{::std::forward<E>(e), ::std::forward<F>(f)};
+    }
+
+    template <typename P>
+    constexpr auto
+    operator()(P&& p) const
+    {
+        return detail::rao_proxy{[p = ::std::forward<P>(p)](auto&& r) mutable
+#        ifndef NANO_MSVC_LAMBDA_PIPE_WORKAROUND
+                                 -> decltype(split_view{::std::forward<decltype(r)>(r), ::std::declval<P&&>()})
+#        endif
+                                 {
+                                     return split_view{::std::forward<decltype(r)>(r), ::std::move(p)};
+                                 }};
+    }
+};
+
+} // namespace detail
+
+namespace views
+{
+
+NANO_INLINE_VAR(nano::detail::split_view_fn, split)
+}
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/views/take.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_TAKE_HPP_INCLUDED
+#        define NANORANGE_VIEWS_TAKE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename V>
+struct take_view : view_interface<take_view<V>>
+{
+  private:
+    static_assert(view<V>);
+
+    V base_ = V();
+    range_difference_t<V> count_ = 0;
+
+    template <bool Const>
+    struct sentinel
+    {
+      private:
+        friend struct sentinel<!Const>;
+        using Base = detail::conditional_t<Const, const V, V>;
+        using CI = counted_iterator<iterator_t<Base>>;
+
+        sentinel_t<Base> end_ = sentinel_t<Base>();
+
+      public:
+        sentinel() = default;
+
+        constexpr explicit sentinel(sentinel_t<Base> end) : end_(::std::move(end)) {}
+
+        // Use deduced type to avoid constraint recursion in GCC8
+        template <typename S, ::std::enable_if_t<same_as<S, sentinel<!Const>>, int> = 0, bool C = Const,
+                  typename VV = V, ::std::enable_if_t<C && convertible_to<sentinel_t<VV>, sentinel_t<Base>>, int> = 0>
+        constexpr explicit sentinel(S s) : end_(::std::move(s.end_))
+        {
+        }
+
+        constexpr sentinel_t<Base>
+        base() const
+        {
+            return end_;
+        }
+
+        friend constexpr bool
+        operator==(const CI& y, const sentinel& x)
+        {
+            return y.count() == 0 || y.base() == x.end_;
+        }
+
+        friend constexpr bool
+        operator==(const sentinel& x, const CI& y)
+        {
+            return y == x;
+        }
+
+        friend constexpr bool
+        operator!=(const CI& y, const sentinel& x)
+        {
+            return !(y == x);
+        }
+
+        friend constexpr bool
+        operator!=(const sentinel& x, const CI& y)
+        {
+            return !(y == x);
+        }
+    };
+
+  public:
+    take_view() = default;
+
+    constexpr take_view(V base, range_difference_t<V> count) : base_(::std::move(base)), count_(count) {}
+
+    template <typename R, ::std::enable_if_t<viewable_range<R> && constructible_from<V, all_view<R>>, int> = 0>
+    constexpr take_view(R&& r, range_difference_t<V> count) : base_(views::all(::std::forward<R>(r))), count_(count)
+    {
+    }
+
+    constexpr V
+    base() const
+    {
+        return base_;
+    }
+
+    template <typename VV = V, ::std::enable_if_t<!detail::simple_view<VV>, int> = 0>
+    constexpr auto
+    begin()
+    {
+        if constexpr (sized_range<V>)
+        {
+            if constexpr (random_access_range<V>)
+            {
+                return ranges::begin(base_);
+            }
+            else
+            {
+                // N.B spec doesn't static_cast here, but I'm pretty
+                // sure it should
+                return counted_iterator{ranges::begin(base_), static_cast<range_difference_t<V>>(size())};
+            }
+        }
+        else
+        {
+            return counted_iterator{ranges::begin(base_), count_};
+        }
+    }
+
+    template <typename VV = V, ::std::enable_if_t<range<const VV>, int> = 0>
+    constexpr auto
+    begin() const
+    {
+        if constexpr (sized_range<const V>)
+        {
+            if constexpr (random_access_range<V>)
+            {
+                return ranges::begin(base_);
+            }
+            else
+            {
+                // N.B spec doesn't static_cast here, but I'm pretty
+                // sure it should
+                return counted_iterator{ranges::begin(base_), static_cast<range_difference_t<V>>(size())};
+            }
+        }
+        else
+        {
+            return counted_iterator{ranges::begin(base_), count_};
+        }
+    }
+
+    template <typename VV = V, ::std::enable_if_t<!detail::simple_view<VV>, int> = 0>
+    constexpr auto
+    end()
+    {
+        if constexpr (sized_range<V>)
+        {
+            if constexpr (random_access_range<V>)
+            {
+                return ranges::begin(base_) + size();
+            }
+            else
+            {
+                return default_sentinel;
+            }
+        }
+        else
+        {
+            return sentinel<false>{ranges::end(base_)};
+        }
+    }
+
+    template <typename VV = V, ::std::enable_if_t<range<const VV>, int> = 0>
+    constexpr auto
+    end() const
+    {
+        if constexpr (sized_range<const V>)
+        {
+            if constexpr (random_access_range<const V>)
+            {
+                return ranges::begin(base_) + size();
+            }
+            else
+            {
+                return default_sentinel;
+            }
+        }
+        else
+        {
+            return sentinel<true>{ranges::end(base_)};
+        }
+    }
+
+    template <typename VV = V, ::std::enable_if_t<sized_range<VV>, int> = 0>
+    constexpr auto
+    size()
+    {
+        auto n = ranges::size(base_);
+        return ranges::min(n, static_cast<decltype(n)>(count_));
+    }
+
+    template <typename VV = V, ::std::enable_if_t<sized_range<const VV>, int> = 0>
+    constexpr auto
+    size() const
+    {
+        auto n = ranges::size(base_);
+        return ranges::min(n, static_cast<decltype(n)>(count_));
+    }
+};
+
+template <typename R, ::std::enable_if_t<range<R>, int> = 0>
+take_view(R&&, range_difference_t<R>)->take_view<all_view<R>>;
+
+namespace detail
+{
+
+#        ifdef NANO_MSVC_LAMBDA_PIPE_WORKAROUND
+template <typename R>
+using take_view_helper_t = take_view<all_view<R>>;
+#        endif
+
+struct take_view_fn
+{
+
+    template <typename C>
+    constexpr auto
+    operator()(C c) const
+    {
+
+        return detail::rao_proxy{[c = ::std::move(c)](auto&& r) mutable
+#        ifdef NANO_MSVC_LAMBDA_PIPE_WORKAROUND
+                                 -> take_view_helper_t<decltype(r)>
+#        else
+                                 -> decltype(take_view{::std::forward<decltype(r)>(r), ::std::declval<C&&>()})
+#        endif
+                                 {
+                                     return take_view{::std::forward<decltype(r)>(r), ::std::move(c)};
+                                 }};
+    }
+
+    template <typename E, typename F>
+    constexpr auto
+    operator()(E&& e, F&& f) const -> decltype(take_view{::std::forward<E>(e), ::std::forward<F>(f)})
+    {
+        return take_view{::std::forward<E>(e), ::std::forward<F>(f)};
+    }
+};
+
+} // namespace detail
+
+namespace views
+{
+
+NANO_INLINE_VAR(nano::detail::take_view_fn, take)
+}
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/views/take_while.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_TAKE_WHILE_HPP_INCLUDED
+#        define NANORANGE_VIEWS_TAKE_WHILE_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+template <typename R, typename Pred>
+struct take_while_view : view_interface<take_while_view<R, Pred>>
+{
+  private:
+    static_assert(view<R>);
+    // FIXME: Should be input_range (GCC9)
+    static_assert(input_iterator<iterator_t<R>>);
+    static_assert(::std::is_object_v<Pred>);
+    static_assert(indirect_unary_predicate<const Pred, iterator_t<R>>);
+
+    template <bool Const>
+    struct sentinel
+    {
+      private:
+        friend struct sentinel<!Const>;
+        using base_t = detail::conditional_t<Const, const R, R>;
+        sentinel_t<base_t> end_ = sentinel_t<base_t>();
+        const Pred* pred_{};
+
+      public:
+        sentinel() = default;
+
+        constexpr explicit sentinel(sentinel_t<base_t>(end), const Pred* pred) : end_(::std::move(end)), pred_(pred) {}
+
+        // Use deduced type to avoid constraint recursion in GCC8
+        template <typename S, ::std::enable_if_t<same_as<S, sentinel<!Const>>, int> = 0, bool C = Const,
+                  typename VV = R, ::std::enable_if_t<C && convertible_to<sentinel_t<VV>, sentinel_t<base_t>>, int> = 0>
+        constexpr sentinel(S s) : end_(::std::move(s.end_)), pred_(s.pred_)
+        {
+        }
+
+        constexpr sentinel_t<base_t>
+        base() const
+        {
+            return end_;
+        }
+
+        // Make these friend functions templates to keep MSVC happy
+#        if (defined(_MSC_VER) && _MSC_VER < 1922)
+        template <typename = void>
+#        endif
+        friend constexpr bool
+        operator==(const iterator_t<base_t>& x, const sentinel& y)
+        {
+            return y.end_ == x || !nano::invoke(*y.pred_, *x);
+        }
+
+#        if (defined(_MSC_VER) && _MSC_VER < 1922)
+        template <typename = void>
+#        endif
+        friend constexpr bool
+        operator==(const sentinel& y, const iterator_t<base_t>& x)
+        {
+            return x == y;
+        }
+
+#        if (defined(_MSC_VER) && _MSC_VER < 1922)
+        template <typename = void>
+#        endif
+        friend constexpr bool
+        operator!=(const iterator_t<base_t>& x, const sentinel& y)
+        {
+            return !(x == y);
+        }
+
+#        if (defined(_MSC_VER) && _MSC_VER < 1922)
+        template <typename = void>
+#        endif
+        friend constexpr bool
+        operator!=(const sentinel& y, const iterator_t<base_t>& x)
+        {
+            return !(x == y);
+        }
+    };
+
+    R base_;
+    detail::semiregular_box<Pred> pred_;
+
+  public:
+    take_while_view() = default;
+
+    constexpr take_while_view(R base, Pred pred) : base_(::std::move(base)), pred_(::std::move(pred)) {}
+
+    constexpr R
+    base() const
+    {
+        return base_;
+    }
+
+    constexpr const Pred&
+    pred() const
+    {
+        return *pred_;
+    }
+
+    template <typename RR = R, ::std::enable_if_t<!detail::simple_view<RR>, int> = 0>
+    constexpr auto
+    begin()
+    {
+        return ranges::begin(base_);
+    }
+
+    template <typename RR = R, ::std::enable_if_t<range<const RR>, int> = 0>
+    constexpr auto
+    begin() const
+    {
+        return ranges::begin(base_);
+    }
+
+    template <typename RR = R, ::std::enable_if_t<!detail::simple_view<RR>, int> = 0>
+    constexpr auto
+    end()
+    {
+        return sentinel<false>{ranges::end(base_), ::std::addressof(*pred_)};
+    }
+
+    template <typename RR = R, ::std::enable_if_t<range<const RR>, int> = 0>
+    constexpr auto
+    end() const
+    {
+        return sentinel<true>{ranges::end(base_), ::std::addressof(*pred_)};
+    }
+};
+
+template <typename R, typename Pred>
+take_while_view(R&&, Pred)->take_while_view<all_view<R>, Pred>;
+
+namespace detail
+{
+
+struct take_while_view_fn
+{
+
+    template <typename E, typename F>
+    constexpr auto
+    operator()(E&& e, F&& f) const -> decltype(take_while_view{::std::forward<E>(e), ::std::forward<F>(f)})
+    {
+        return take_while_view{::std::forward<E>(e), ::std::forward<F>(f)};
+    }
+
+    template <typename Pred>
+    constexpr auto
+    operator()(Pred&& pred) const
+    {
+        return detail::rao_proxy{[p = ::std::forward<Pred>(pred)](auto&& r) mutable
+#        ifndef NANO_MSVC_LAMBDA_PIPE_WORKAROUND
+                                 -> decltype(take_while_view{::std::forward<decltype(r)>(r), ::std::declval<Pred&&>()})
+#        endif
+                                 {
+                                     return take_while_view{::std::forward<decltype(r)>(r), ::std::move(p)};
+                                 }};
+    }
+};
+
+} // namespace detail
+
+namespace views
+{
+
+NANO_INLINE_VAR(nano::detail::take_while_view_fn, take_while)
+}
+
+NANO_END_NAMESPACE
+
+#    endif
+
+// nanorange/views/transform.hpp
+//
+// Copyright (c) 2019 Tristan Brindle (tcbrindle at gmail dot com)
+// 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)
+
+#    ifndef NANORANGE_VIEWS_TRANSFORM_HPP_INCLUDED
+#        define NANORANGE_VIEWS_TRANSFORM_HPP_INCLUDED
+
+NANO_BEGIN_NAMESPACE
+
+namespace transform_view_
+{
+
+template <typename V, typename F>
+struct transform_view : view_interface<transform_view<V, F>>
+{
+  private:
+    // FIXME: Weird GCC9 bug strikes again!
+    // These two conditions are equivalent to input_range<V>, but if we test
+    // that directly with GCC9 then it fails?!
+    static_assert(range<V>);
+    static_assert(input_iterator<iterator_t<V>>);
+    static_assert(view<V>);
+    static_assert(copy_constructible<F>);
+    static_assert(::std::is_object_v<F>);
+    static_assert(regular_invocable<F&, range_reference_t<V>>);
+
+    template <bool>
+    struct sentinel;
+
+    template <bool Const>
+    struct iterator
+    {
+      private:
+        friend struct iterator<!Const>;
+        friend struct sentinel<Const>;
+
+        using Parent = detail::conditional_t<Const, const transform_view, transform_view>;
+        using Base = detail::conditional_t<Const, const V, V>;
+
+        iterator_t<Base> current_ = iterator_t<Base>();
+        Parent* parent_ = nullptr;
+
+        static constexpr bool iter_move_noexcept_helper = noexcept(nano::invoke(*parent_->fun_, *current_));
+
+      public:
+        using iterator_category =
+            detail::conditional_t<derived_from<iterator_category_t<iterator_t<Base>>, contiguous_iterator_tag>,
+                                  random_access_iterator_tag, iterator_category_t<iterator_t<Base>>>;
+
+        using value_type = remove_cvref_t<invoke_result_t<F&, range_reference_t<Base>>>;
+        using difference_type = range_difference_t<Base>;
+        // Extension: legacy typedefs
+        using pointer = void;
+        using reference = invoke_result_t<F&, range_reference_t<Base>>;
+
+        iterator() = default;
+
+        constexpr iterator(Parent& parent, iterator_t<Base> current)
+            : current_(::std::move(current)), parent_(::std::addressof(parent))
+        {
+        }
+
+        template <typename I, ::std::enable_if_t<same_as<I, iterator<!Const>>, int> = 0, bool C = Const,
+                  typename VV = V, ::std::enable_if_t<C && convertible_to<iterator_t<VV>, iterator_t<Base>>, int> = 0>
+        constexpr iterator(I i) : current_(::std::move(i.current_)), parent_(i.parent_)
+        {
+        }
+
+        constexpr iterator_t<Base>
+        base() const
+        {
+            return current_;
+        }
+
+        constexpr decltype(auto) operator*() const { return nano::invoke(*parent_->fun_, *current_); }
+
+        constexpr iterator&
+        operator++()
+        {
+            ++current_;
+            return *this;
+        }
+
+        constexpr auto
+        operator++(int)
+        {
+            if constexpr (forward_range<Base>)
+            {
+                auto tmp = *this;
+                ++*this;
+                return tmp;
+            }
+            else
+            {
+                ++current_;
+            }
+        }
+
+        template <typename B = Base>
+        constexpr auto
+        operator--() -> ::std::enable_if_t<bidirectional_range<B>, iterator&>
+        {
+            --current_;
+            return *this;
+        }
+
+        template <typename B = Base>
+        constexpr auto
+        operator--(int) -> ::std::enable_if_t<bidirectional_range<B>, iterator>
+        {
+            auto tmp = *this;
+            --*this;
+            return tmp;
+        }
+
+        template <typename B = Base>
+        constexpr auto
+        operator+=(difference_type n) -> ::std::enable_if_t<random_access_range<B>, iterator&>
+        {
+            current_ += n;
+            return *this;
+        }
+
+        template <typename B = Base>
+        constexpr auto
+        operator-=(difference_type n) -> ::std::enable_if_t<random_access_range<B>, iterator&>
+        {
+            current_ -= n;
+            return *this;
+        }
+
+        template <typename B = Base, typename = ::std::enable_if_t<random_access_range<B>>>
+        constexpr decltype(auto) operator[](difference_type n) const
+        {
+            return nano::invoke(*parent_->fun_, current_[n]);
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator==(const iterator& x, const iterator& y) -> ::std::enable_if_t<equality_comparable<iterator_t<B>>, bool>
+        {
+            return x.current_ == y.current_;
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator!=(const iterator& x, const iterator& y) -> ::std::enable_if_t<equality_comparable<iterator_t<B>>, bool>
+        {
+            return !(x == y);
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator<(const iterator& x, const iterator& y) -> ::std::enable_if_t<random_access_range<B>, bool>
+        {
+            return x.current_ < y.current_;
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator>(const iterator& x, const iterator& y) -> ::std::enable_if_t<random_access_range<B>, bool>
+        {
+            return y < x;
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator<=(const iterator& x, const iterator& y) -> ::std::enable_if_t<random_access_range<B>, bool>
+        {
+            return !(y < x);
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator>=(const iterator& x, const iterator& y) -> ::std::enable_if_t<random_access_range<B>, bool>
+        {
+            return !(x < y);
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator+(iterator i, difference_type n) -> ::std::enable_if_t<random_access_range<B>, iterator>
+        {
+            return iterator{*i.parent_, i.current_ + n};
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator+(difference_type n, iterator i) -> ::std::enable_if_t<random_access_range<B>, iterator>
+        {
+            return iterator{*i.parent_, i.current_ + n};
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator-(iterator i, difference_type n) -> ::std::enable_if_t<random_access_range<B>, iterator>
+        {
+            return iterator{*i.parent_, i.current_ - n};
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator-(const iterator& x, const iterator& y) -> ::std::enable_if_t<random_access_range<B>, difference_type>
+        {
+            return x.current_ - y.current_;
+        }
+
+        friend constexpr decltype(auto)
+        iter_move(const iterator& i) noexcept(iter_move_noexcept_helper)
+        {
+            if constexpr (::std::is_lvalue_reference_v<decltype(*i)>)
+            {
+                return ::std::move(*i);
+            }
+            else
+            {
+                return *i;
+            }
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        iter_swap(const iterator& x, const iterator& y) noexcept(noexcept(ranges::iter_swap(x.current_, y.current_)))
+            -> ::std::enable_if_t<indirectly_swappable<iterator_t<B>>>
+        {
+            return ranges::iter_swap(x.current_, y.current_);
+        }
+    };
+
+    template <bool Const>
+    struct sentinel
+    {
+      private:
+        friend struct sentinel<!Const>;
+
+        using Parent = detail::conditional_t<Const, const transform_view, transform_view>;
+        using Base = detail::conditional_t<Const, const V, V>;
+        sentinel_t<Base> end_ = sentinel_t<Base>();
+
+      public:
+        sentinel() = default;
+
+        constexpr explicit sentinel(sentinel_t<Base> end) : end_(::std::move(end)) {}
+
+        template <typename S, ::std::enable_if_t<same_as<S, sentinel<!Const>>, int> = 0, bool C = Const,
+                  typename VV = V, ::std::enable_if_t<C && convertible_to<sentinel_t<VV>, sentinel_t<Base>>, int> = 0>
+        constexpr sentinel(S i) : end_(::std::move(i.end_))
+        {
+        }
+
+        constexpr sentinel_t<Base>
+        base()
+        {
+            return end_;
+        }
+
+        friend constexpr bool
+        operator==(const iterator<Const>& x, const sentinel& y)
+        {
+            return x.base() == y.end_;
+        }
+
+        friend constexpr bool
+        operator==(const sentinel& x, const iterator<Const>& y)
+        {
+            return x.end_ == y.base();
+        }
+
+        friend constexpr bool
+        operator!=(const iterator<Const>& x, const sentinel& y)
+        {
+            return !(x == y);
+        }
+
+        friend constexpr bool
+        operator!=(const sentinel& x, const iterator<Const>& y)
+        {
+            return !(x == y);
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator-(const iterator<Const>& x, const sentinel& y)
+            -> ::std::enable_if_t<sized_sentinel_for<sentinel_t<B>, iterator_t<B>>, range_difference_t<B>>
+        {
+            return x.current_ - y.end_;
+        }
+
+        template <typename B = Base>
+        friend constexpr auto
+        operator-(const sentinel& x, const iterator<Const>& y)
+            -> ::std::enable_if_t<sized_sentinel_for<sentinel_t<B>, iterator_t<B>>, range_difference_t<B>>
+        {
+            x.end_ - y.current_;
+        }
+    };
+
+    V base_ = V();
+    detail::semiregular_box<F> fun_;
+
+  public:
+    transform_view() = default;
+
+    constexpr transform_view(V base, F fun) : base_(::std::move(base)), fun_(::std::move(fun)) {}
+
+    template <typename R,
+              ::std::enable_if_t<input_range<R> && viewable_range<R> && constructible_from<V, all_view<R>>, int> = 0>
+    constexpr transform_view(R&& r, F fun) : base_(views::all(::std::forward<R>(r))), fun_(::std::move(fun))
+    {
+    }
+
+    constexpr V
+    base() const
+    {
+        return base_;
+    }
+
+    constexpr iterator<false>
+    begin()
+    {
+        return iterator<false>{*this, ranges::begin(base_)};
+    }
+
+    template <typename VV = V,
+              ::std::enable_if_t<range<const VV> && regular_invocable<const F&, range_reference_t<const VV>>, int> = 0>
+    constexpr iterator<true>
+    begin() const
+    {
+        return iterator<true>{*this, ranges::begin(base_)};
+    }
+
+    constexpr auto
+    end()
+    {
+        if constexpr (common_range<V>)
+        {
+            return iterator<false>{*this, ranges::end(base_)};
+        }
+        else
+        {
+            return sentinel<false>{ranges::end(base_)};
+        }
+    }
+
+    template <typename VV = V,
+              ::std::enable_if_t<range<const VV> && regular_invocable<const F&, range_reference_t<const VV>>, int> = 0>
+    constexpr auto
+    end() const
+    {
+        if constexpr (common_range<V>)
+        {
+            return iterator<true>{*this, ranges::end(base_)};
+        }
+        else
+        {
+            return sentinel<true>{ranges::end(base_)};
+        }
+    }
+
+    template <typename VV = V, ::std::enable_if_t<sized_range<VV>, int> = 0>
+    constexpr auto
+    size()
+    {
+        return ranges::size(base_);
+    }
+
+    template <typename VV = V, ::std::enable_if_t<sized_range<const VV>, int> = 0>
+    constexpr auto
+    size() const
+    {
+        return ranges::size(base_);
+    }
+};
+
+template <typename R, typename F,
+          ::std::enable_if_t<input_range<all_view<R>> && copy_constructible<F>&& ::std::is_object_v<F> &&
+                                 regular_invocable<F&, range_reference_t<all_view<R>>>,
+                             int> = 0>
+transform_view(R&&, F)->transform_view<all_view<R>, F>;
+
+} // namespace transform_view_
+
+using transform_view_::transform_view;
+
+namespace detail
+{
+
+struct transform_view_fn
+{
+    template <typename E, typename F>
+    constexpr auto
+    operator()(E&& e, F&& f) const -> decltype(transform_view{::std::forward<E>(e), ::std::forward<F>(f)})
+    {
+        return transform_view{::std::forward<E>(e), ::std::forward<F>(f)};
+    }
+
+    template <typename F>
+    constexpr auto
+    operator()(F f) const
+    {
+        return detail::rao_proxy{[f = ::std::move(f)](auto&& r) mutable
+#        ifndef NANO_MSVC_LAMBDA_PIPE_WORKAROUND
+                                 -> decltype(transform_view{::std::forward<decltype(r)>(r), ::std::declval<F&&>()})
+#        endif
+                                 {
+                                     return transform_view{::std::forward<decltype(r)>(r), ::std::move(f)};
+                                 }};
+    }
+};
+
+} // namespace detail
+
+namespace views
+{
+
+NANO_INLINE_VAR(nano::detail::transform_view_fn, transform)
+}
+
+NANO_END_NAMESPACE
+
+#    endif
+
+#endif
+
+#endif // NANORANGE_HPP_INCLUDED
diff --git a/libstdc++-v3/include/pstl/ranges/nanorange_ext.h b/libstdc++-v3/include/pstl/ranges/nanorange_ext.h
new file mode 100644
index 000000000000..7e970afecaa2
--- /dev/null
+++ b/libstdc++-v3/include/pstl/ranges/nanorange_ext.h
@@ -0,0 +1,274 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_NANO_RANGES_EXT_H
+#define _ONEDPL_NANO_RANGES_EXT_H
+
+NANO_BEGIN_NAMESPACE
+
+template <typename I>
+class offset_iterator
+{
+  public:
+    using iterator_type = I;
+    using difference_type = iter_difference_t<I>;
+    using value_type = iter_value_t<I>;
+    using iterator_category = detail::legacy_iterator_category_t<I>;
+    using reference = iter_reference_t<I>;
+    using pointer = I;
+
+    offset_iterator() = default;
+    offset_iterator(const offset_iterator&) = default;
+    constexpr offset_iterator&
+    operator=(const offset_iterator&) = default;
+
+    explicit offset_iterator(I it, I b, I e) : current_(it), beg_(b), n_(e - b) { assert(it >= b && it < e); }
+
+  private:
+    constexpr difference_type
+    offset_position() const
+    {
+        return current_ - beg_;
+    }
+
+  public:
+    constexpr reference operator*() const { return *(beg_ + offset_position() % n_); }
+    constexpr reference operator[](difference_type __i) const { return *(*this + __i); }
+    constexpr difference_type
+    operator-(const offset_iterator& __it) const
+    {
+        return current_ - __it.current_;
+    }
+    constexpr offset_iterator&
+    operator+=(difference_type __forward)
+    {
+        current_ += __forward;
+        return *this;
+    }
+    constexpr offset_iterator&
+    operator-=(difference_type __backward)
+    {
+        return *this += -__backward;
+    }
+    constexpr offset_iterator&
+    operator++()
+    {
+        return *this += 1;
+    }
+    constexpr offset_iterator&
+    operator--()
+    {
+        return *this -= 1;
+    }
+    constexpr offset_iterator
+    operator++(int)
+    {
+        offset_iterator __it(*this);
+        ++(*this);
+        return __it;
+    }
+    constexpr offset_iterator
+    operator--(int)
+    {
+        offset_iterator __it(*this);
+        --(*this);
+        return __it;
+    }
+
+    constexpr offset_iterator
+    operator-(difference_type __backward) const
+    {
+        offset_iterator it(*this);
+        return it -= __backward;
+    }
+    constexpr offset_iterator
+    operator+(difference_type __forward) const
+    {
+        offset_iterator it(*this);
+        return it += __forward;
+    }
+    friend constexpr offset_iterator
+    operator+(difference_type __forward, const offset_iterator __it)
+    {
+        return __it + __forward;
+    }
+    constexpr bool
+    operator==(const offset_iterator& __it) const
+    {
+        return *this - __it == 0;
+    }
+    constexpr bool
+    operator!=(const offset_iterator& __it) const
+    {
+        return !(*this == __it);
+    }
+    constexpr bool
+    operator<(const offset_iterator& __it) const
+    {
+        return *this - __it < 0;
+    }
+    constexpr bool
+    operator>(const offset_iterator& __it) const
+    {
+        return __it < *this;
+    }
+    constexpr bool
+    operator<=(const offset_iterator& __it) const
+    {
+        return !(*this > __it);
+    }
+    constexpr bool
+    operator>=(const offset_iterator& __it) const
+    {
+        return !(*this < __it);
+    }
+
+  private:
+    I current_{};
+    I beg_{};
+    difference_type n_;
+};
+
+namespace rotate_view_
+{
+
+template <typename V>
+struct rotate_view : view_interface<rotate_view<V>>
+{
+  private:
+    static_assert(range<V>);
+    static_assert(input_iterator<iterator_t<V>>);
+    static_assert(view<V>);
+
+    V base_ = V();
+    range_difference_t<V> offset_;
+
+  public:
+    rotate_view() = default;
+
+    constexpr rotate_view(V base, range_difference_t<V> offset) : base_(::std::move(base)), offset_(offset) {}
+
+    template <typename R,
+              ::std::enable_if_t<input_range<R> && viewable_range<R> && constructible_from<V, all_view<R>>, int> = 0>
+    constexpr rotate_view(R&& r, range_difference_t<V> offset)
+        : base_(views::all(::std::forward<R>(r))), offset_(offset)
+    {
+    }
+
+    constexpr V
+    base() const
+    {
+        return base_;
+    }
+
+    constexpr auto
+    begin() const
+    {
+        return offset_iterator(base().begin() + offset_, base().begin(), base().end());
+    }
+
+    constexpr auto
+    end() const
+    {
+        return begin() + size();
+    }
+
+    constexpr auto
+    size() const
+    {
+        return base_.size();
+    }
+
+    constexpr bool
+    empty() const
+    {
+        return size() == 0;
+    }
+};
+
+template <typename R>
+rotate_view(R &&)->rotate_view<all_view<R>>;
+
+} // namespace rotate_view_
+
+using rotate_view_::rotate_view;
+
+namespace detail
+{
+
+struct rotate_view_fn
+{
+    template <typename E>
+    constexpr auto
+    operator()(E&& e, range_difference_t<E> offset) const -> decltype(rotate_view{::std::forward<E>(e), offset})
+    {
+        return rotate_view{::std::forward<E>(e), offset};
+    }
+
+    template <typename D>
+    constexpr auto
+    operator()(D offset) const
+    {
+        return detail::rao_proxy{[offset](auto&& r) mutable
+#ifndef NANO_MSVC_LAMBDA_PIPE_WORKAROUND
+                                 -> decltype(rotate_view{::std::forward<decltype(r)>(r), offset})
+#endif
+                                 {
+                                     return rotate_view{::std::forward<decltype(r)>(r), offset};
+                                 }};
+    }
+};
+
+} // namespace detail
+
+namespace views
+{
+NANO_INLINE_VAR(nano::detail::rotate_view_fn, rotate)
+}
+
+namespace detail
+{
+
+struct generate_view_fn
+{
+    template <typename G, typename Bound = unreachable_sentinel_t>
+    constexpr auto
+    operator()(G g, Bound size) const
+    {
+        return transform_view{iota_view{0, size}, [g](auto) { return g(); }};
+    }
+};
+
+struct fill_view_fn
+{
+    template <typename T, typename Bound = unreachable_sentinel_t>
+    constexpr auto
+    operator()(const T& value, Bound size) const
+    {
+        return transform_view{iota_view{0, size}, [value](auto) { return value; }};
+    }
+};
+
+} // namespace detail
+
+namespace views
+{
+NANO_INLINE_VAR(nano::detail::generate_view_fn, generate)
+NANO_INLINE_VAR(nano::detail::fill_view_fn, fill)
+} // namespace views
+
+NANO_END_NAMESPACE
+
+#endif // _ONEDPL_NANO_RANGES_EXT_H
diff --git a/libstdc++-v3/include/pstl/ranges_defs.h b/libstdc++-v3/include/pstl/ranges_defs.h
new file mode 100644
index 000000000000..121dbd831cd6
--- /dev/null
+++ b/libstdc++-v3/include/pstl/ranges_defs.h
@@ -0,0 +1,96 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_RANGES_DEFS_H
+#define _ONEDPL_RANGES_DEFS_H
+
+#include "ranges/nanorange.hpp"
+#include "ranges/nanorange_ext.h"
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+#include <ranges>
+//support zip_view (like in C++23) for C++20
+#include "zip_view_impl.h"
+#endif
+
+#include "utils_ranges.h"
+#if _ONEDPL_BACKEND_SYCL
+#    include "hetero/dpcpp/utils_ranges_sycl.h"
+#endif
+
+namespace std::__onedpl
+{
+
+namespace experimental
+{
+namespace ranges
+{
+
+//custom views
+#if _ONEDPL_BACKEND_SYCL
+using __onedpl::__ranges::all_view;
+#endif // _ONEDPL_BACKEND_SYCL
+using __onedpl::__ranges::guard_view;
+#if _ONEDPL_CPP20_RANGES_PRESENT
+using __onedpl::ranges::__internal::zip_view;
+#else
+using __onedpl::__ranges::zip_view;
+#endif //_ONEDPL_CPP20_RANGES_PRESENT
+
+//views
+using __nanorange::nano::ranges::drop_view;
+using __nanorange::nano::ranges::iota_view;
+using __nanorange::nano::ranges::reverse_view;
+using __nanorange::nano::ranges::take_view;
+using __nanorange::nano::ranges::transform_view;
+
+//adaptors
+namespace views
+{
+#if _ONEDPL_BACKEND_SYCL
+using __onedpl::__ranges::views::all;
+using __onedpl::__ranges::views::all_read;
+using __onedpl::__ranges::views::all_write;
+using __onedpl::__ranges::views::host_all;
+#endif // _ONEDPL_BACKEND_SYCL
+
+using __nanorange::nano::views::drop;
+using __nanorange::nano::views::fill;
+using __nanorange::nano::views::generate;
+using __nanorange::nano::views::iota;
+using __nanorange::nano::views::reverse;
+using __nanorange::nano::views::rotate;
+using __nanorange::nano::views::take;
+using __nanorange::nano::views::transform;
+
+using __nanorange::nano::subrange;
+#if _ONEDPL_CPP20_RANGES_PRESENT
+using __onedpl::ranges::__internal::zip;
+#endif //_ONEDPL_CPP20_RANGES_PRESENT
+} // namespace views
+
+} // namespace ranges
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+namespace views
+{
+using __onedpl::ranges::__internal::zip;
+} // namespace views
+#endif //_ONEDPL_CPP20_RANGES_PRESENT
+
+} // namespace experimental
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_RANGES_DEFS_H
diff --git a/libstdc++-v3/include/pstl/tuple_impl.h b/libstdc++-v3/include/pstl/tuple_impl.h
new file mode 100644
index 000000000000..ed4070da3ce2
--- /dev/null
+++ b/libstdc++-v3/include/pstl/tuple_impl.h
@@ -0,0 +1,854 @@
+// -*- C++ -*-
+//===-- tuple_impl.h ---------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_TUPLE_IMPL_H
+#define _ONEDPL_TUPLE_IMPL_H
+
+#include <iterator>
+#include <tuple>
+#include <cassert>
+#include <type_traits>
+
+namespace std::__onedpl
+{
+namespace __internal
+{
+template <typename... T>
+struct tuple;
+} // namespace __internal
+} // namespace std::__onedpl
+
+namespace std
+{
+template <::std::size_t N, typename T, typename... Rest>
+struct tuple_element<N, __onedpl::__internal::tuple<T, Rest...>>
+    : tuple_element<N - 1, __onedpl::__internal::tuple<Rest...>>
+{
+};
+
+template <typename T, typename... Rest>
+struct tuple_element<0, __onedpl::__internal::tuple<T, Rest...>>
+{
+    using type = T;
+};
+
+//forward declare new std::get<I>() functions so they can be used in impl
+template <size_t _Idx, typename... _Tp>
+constexpr std::tuple_element_t<_Idx, __onedpl::__internal::tuple<_Tp...>>&
+get(__onedpl::__internal::tuple<_Tp...>&);
+
+template <size_t _Idx, typename... _Tp>
+constexpr std::tuple_element_t<_Idx, __onedpl::__internal::tuple<_Tp...>> const&
+get(const __onedpl::__internal::tuple<_Tp...>&);
+
+template <size_t _Idx, typename... _Tp>
+constexpr std::tuple_element_t<_Idx, __onedpl::__internal::tuple<_Tp...>>&&
+get(__onedpl::__internal::tuple<_Tp...>&&);
+
+template <size_t _Idx, typename... _Tp>
+constexpr std::tuple_element_t<_Idx, __onedpl::__internal::tuple<_Tp...>> const&&
+get(const __onedpl::__internal::tuple<_Tp...>&&);
+
+template <typename... Args>
+struct tuple_size<__onedpl::__internal::tuple<Args...>> : ::std::integral_constant<::std::size_t, sizeof...(Args)>
+{
+};
+} // namespace std
+
+//custom tuple utilities
+namespace std::__onedpl
+{
+namespace __internal
+{
+template <typename... Size>
+struct get_value_by_idx;
+
+template <typename T1, typename... T, ::std::size_t... indices>
+::std::tuple<T...>
+get_tuple_tail_impl(const ::std::tuple<T1, T...>& t, const ::std::index_sequence<indices...>&)
+{
+    return ::std::tuple<T...>(::std::get<indices + 1>(t)...);
+}
+
+template <typename T1, typename... T>
+::std::tuple<T...>
+get_tuple_tail(const ::std::tuple<T1, T...>& other)
+{
+    return __onedpl::__internal::get_tuple_tail_impl(other, ::std::make_index_sequence<sizeof...(T)>());
+}
+
+// Maps an incoming type for tuplewrapper to simplify tuple-related handling.
+// as it doesn't work well with rvalue refs.
+// T& -> T&, T&& -> T, T -> T
+template <typename _Tp, bool = ::std::is_lvalue_reference_v<_Tp>>
+struct __lvref_or_val
+{
+    using __type = _Tp&&;
+};
+
+template <typename _Tp>
+struct __lvref_or_val<_Tp, false>
+{
+    using __type = ::std::remove_reference_t<_Tp>;
+};
+
+template <typename T>
+struct MapValue
+{
+    T id;
+    template <typename T1>
+    auto
+    operator()(const T1& t1) -> decltype(t1[id]) const
+    {
+        return t1[id];
+    }
+};
+
+// It serves the same purpose as tuplewrapper in iterator_impl.h, but in this case we don't need
+// swap, so we can simply map it to tuple adjusting the types
+template <typename... T>
+using tuplewrapper = __onedpl::__internal::tuple<typename __onedpl::__internal::__lvref_or_val<T>::__type...>;
+
+// __internal::make_tuple
+template <typename... T>
+constexpr __onedpl::__internal::tuple<T...>
+make_tuple(T... args)
+{
+    return __onedpl::__internal::tuple<T...>{args...};
+}
+
+// __internal::make_tuplewrapper
+template <typename... T>
+__onedpl::__internal::tuplewrapper<T&&...>
+make_tuplewrapper(T&&... t)
+{
+    return {::std::forward<T>(t)...};
+}
+
+template <size_t N>
+struct get_impl
+{
+    template <typename... T>
+    constexpr auto
+    operator()(__onedpl::__internal::tuple<T...>& t) const -> decltype(get_impl<N - 1>()(t.next))
+    {
+        return get_impl<N - 1>()(t.next);
+    }
+
+    template <typename... T>
+    constexpr auto
+    operator()(const __onedpl::__internal::tuple<T...>& t) const -> decltype(get_impl<N - 1>()(t.next))
+    {
+        return get_impl<N - 1>()(t.next);
+    }
+
+    template <typename... T>
+    constexpr auto
+    operator()(__onedpl::__internal::tuple<T...>&& t) const -> decltype(get_impl<N - 1>()(::std::move(t.next)))
+    {
+        return get_impl<N - 1>()(::std::move(t.next));
+    }
+
+    template <typename... T>
+    constexpr auto
+    operator()(const __onedpl::__internal::tuple<T...>&& t) const -> decltype(get_impl<N - 1>()(::std::move(t.next)))
+    {
+        return get_impl<N - 1>()(::std::move(t.next));
+    }
+};
+
+template <>
+struct get_impl<0>
+{
+    template <typename... T>
+    using ret_type = ::std::tuple_element_t<0, __onedpl::__internal::tuple<T...>>;
+
+    template <typename... T>
+    constexpr ret_type<T...>&
+    operator()(__onedpl::__internal::tuple<T...>& t) const
+    {
+        return t.holder.value;
+    }
+
+    template <typename... T>
+    constexpr const ret_type<T...>&
+    operator()(const __onedpl::__internal::tuple<T...>& t) const
+    {
+        return t.holder.value;
+    }
+
+    template <typename... T>
+    constexpr ret_type<T...>&&
+    operator()(__onedpl::__internal::tuple<T...>&& t) const
+    {
+        return ::std::forward<ret_type<T...>&&>(t.holder.value);
+    }
+
+    template <typename... T>
+    constexpr const ret_type<T...>&&
+    operator()(const __onedpl::__internal::tuple<T...>&& t) const
+    {
+        return ::std::forward<const ret_type<T...>&&>(t.holder.value);
+    }
+};
+
+// __internal::map_tuple
+template <size_t I, typename F, typename... T>
+auto
+apply_to_tuple(F f, T... in) -> decltype(f(__onedpl::__internal::get_impl<I>()(in)...))
+{
+    return f(__onedpl::__internal::get_impl<I>()(in)...);
+}
+
+struct make_inner_tuple_functor
+{
+    template <typename... Args>
+    auto
+    operator()(Args&&... args) const -> decltype(__onedpl::__internal::make_tuple(::std::forward<Args>(args)...))
+    {
+        return __onedpl::__internal::make_tuple(::std::forward<Args>(args)...);
+    }
+};
+
+struct make_tuplewrapper_functor
+{
+    template <typename... Args>
+    auto
+    operator()(Args&&... args) const
+        -> decltype(__onedpl::__internal::make_tuplewrapper(::std::forward<Args>(args)...))
+    {
+        return __onedpl::__internal::make_tuplewrapper(::std::forward<Args>(args)...);
+    }
+};
+
+template <typename MakeTupleF, typename F, size_t... indices, typename... T>
+auto
+map_tuple_impl(MakeTupleF mtf, F f, ::std::index_sequence<indices...>, T... in)
+    -> decltype(mtf(__onedpl::__internal::apply_to_tuple<indices>(f, in...)...))
+{
+    return mtf(__onedpl::__internal::apply_to_tuple<indices>(f, in...)...);
+}
+
+//
+template <typename F, template <typename...> class TBig, typename... T, typename... RestTuples>
+auto
+map_tuple(F f, TBig<T...> in, RestTuples... rest)
+    -> decltype(__onedpl::__internal::map_tuple_impl(__onedpl::__internal::make_inner_tuple_functor{}, f,
+                                                        ::std::make_index_sequence<sizeof...(T)>(), in, rest...))
+{
+    return __onedpl::__internal::map_tuple_impl(__onedpl::__internal::make_inner_tuple_functor{}, f,
+                                                   ::std::make_index_sequence<sizeof...(T)>(), in, rest...);
+}
+
+// Functions are needed to call get_value_by_idx: it requires to store in tuple wrapper
+template <typename F, template <typename...> class TBig, typename... T, typename... RestTuples>
+auto
+map_tuplewrapper(F f, TBig<T...> in, RestTuples... rest)
+    -> decltype(__onedpl::__internal::map_tuple_impl(__onedpl::__internal::make_tuplewrapper_functor{}, f,
+                                                        ::std::make_index_sequence<sizeof...(T)>(), in, rest...))
+{
+    return __onedpl::__internal::map_tuple_impl(__onedpl::__internal::make_tuplewrapper_functor{}, f,
+                                                   ::std::make_index_sequence<sizeof...(T)>(), in, rest...);
+}
+
+template <typename _Tp>
+struct __value_holder
+{
+    __value_holder() = default;
+    template <typename _Up>
+    __value_holder(_Up&& t) : value(::std::forward<_Up>(t))
+    {
+    }
+    _Tp value;
+};
+
+// Necessary to make tuple trivially_copy_assignable. This type decided
+// if it's needed to have user-defined operator=.
+template <typename _Tp, bool = ::std::is_trivially_copy_assignable_v<__onedpl::__internal::__value_holder<_Tp>>>
+struct __copy_assignable_holder : __onedpl::__internal::__value_holder<_Tp>
+{
+    using __onedpl::__internal::__value_holder<_Tp>::__value_holder;
+};
+
+template <typename _Tp>
+struct __copy_assignable_holder<_Tp, false> : __onedpl::__internal::__value_holder<_Tp>
+{
+    using __onedpl::__internal::__value_holder<_Tp>::__value_holder;
+    __copy_assignable_holder() = default;
+    __copy_assignable_holder(const __copy_assignable_holder&) = default;
+    __copy_assignable_holder(__copy_assignable_holder&&) = default;
+    __copy_assignable_holder&
+    operator=(const __copy_assignable_holder& other)
+    {
+        this->value = other.value;
+        return *this;
+    }
+    __copy_assignable_holder&
+    operator=(__copy_assignable_holder&& other) = default;
+};
+
+template <typename _Tuple1, typename _Tuple2, int I = 0>
+constexpr bool
+__equal(_Tuple1&& __lhs, _Tuple2&& __rhs)
+{
+    static_assert(std::tuple_size_v<std::decay_t<_Tuple1>> == std::tuple_size_v<std::decay_t<_Tuple2>>,
+                  "Tuples must have the same size to be equality compared");
+    if constexpr (I < std::tuple_size_v<std::decay_t<_Tuple1>>)
+    {
+        return std::get<I>(__lhs) == std::get<I>(__rhs) &&
+               __onedpl::__internal::__equal<_Tuple1, _Tuple2, I + 1>(std::forward<_Tuple1>(__lhs),
+                                                                         std::forward<_Tuple2>(__rhs));
+    }
+    else
+    {
+        return true;
+    }
+}
+template <typename _Tuple1, typename _Tuple2, int I = 0>
+constexpr bool
+__less(_Tuple1&& __lhs, _Tuple2&& __rhs)
+{
+    static_assert(std::tuple_size_v<std::decay_t<_Tuple1>> == std::tuple_size_v<std::decay_t<_Tuple2>>,
+                  "Tuples must have the same size to be compared");
+    if constexpr (I < std::tuple_size_v<std::decay_t<_Tuple1>>)
+    {
+        return std::get<I>(__lhs) < std::get<I>(__rhs) ||
+               (!(std::get<I>(__rhs) < std::get<I>(__lhs)) &&
+                __onedpl::__internal::__less<_Tuple1, _Tuple2, I + 1>(std::forward<_Tuple1>(__lhs),
+                                                                         std::forward<_Tuple2>(__rhs)));
+    }
+    else
+    {
+        return false;
+    }
+}
+
+template <typename T>
+struct __is_internal_tuple : std::false_type
+{
+};
+
+template <typename... Ts>
+struct __is_internal_tuple<__onedpl::__internal::tuple<Ts...>> : std::true_type
+{
+};
+
+template <typename T>
+inline constexpr bool __is_internal_tuple_v = __is_internal_tuple<T>::value;
+
+template <typename T>
+struct __is_std_tuple : std::false_type
+{
+};
+
+template <typename... Ts>
+struct __is_std_tuple<std::tuple<Ts...>> : std::true_type
+{
+};
+
+template <typename T>
+inline constexpr bool __is_std_tuple_v = __is_std_tuple<T>::value;
+
+// Either LHS = this internal tuple type + RHS = any compatible tuple type
+// or     LHS = std::tuple               + RHS = this internal tuple type
+// Note: We do not allow LHS to be "any compatible type" with a RHS as this internal tuple type because then we would
+//       have ambiguity comparing two different compatible internal tuple types, because both instantiations would
+//       create the necessary comparison. As written, the type instantiation of the type in the LHS is always
+//       responsible for creating this comparison operator.
+template <typename _ThisTuple, typename _U, typename _V>
+inline constexpr bool __enable_comparison_op_v =
+    (std::is_same_v<std::decay_t<_ThisTuple>, std::decay_t<_U>> &&                         //LHS +
+                    (__onedpl::__internal::__is_std_tuple_v<std::decay_t<_V>> ||        //RHS option 1
+                     __onedpl::__internal::__is_internal_tuple_v<std::decay_t<_V>>)) || //RHS option 2  - OR -
+    (__onedpl::__internal::__is_std_tuple_v<std::decay_t<_U>> &&                        //LHS +
+                    std::is_same_v<std::decay_t<_ThisTuple>, std::decay_t<_V>>);           //RHS
+
+template <typename T1, typename... T>
+struct tuple<T1, T...>
+{
+    __onedpl::__internal::__copy_assignable_holder<T1> holder;
+    tuple<T...> next;
+
+    using tuple_type = ::std::tuple<T1, T...>;
+
+    template <::std::size_t I>
+    constexpr auto
+    get() & -> decltype(get_impl<I>()(*this))
+    {
+        return get_impl<I>()(*this);
+    }
+
+    template <::std::size_t I>
+    constexpr auto
+    get() const& -> decltype(get_impl<I>()(*this))
+    {
+        return get_impl<I>()(*this);
+    }
+
+    template <::std::size_t I>
+    constexpr auto
+    get() && -> decltype(get_impl<I>()(::std::move(*this)))
+    {
+        return get_impl<I>()(::std::move(*this));
+    }
+
+    template <::std::size_t I>
+    constexpr auto
+    get() const&& -> decltype(get_impl<I>()(::std::move(*this)))
+    {
+        return get_impl<I>()(::std::move(*this));
+    }
+
+    template <typename _Tp = T1,
+              std::enable_if_t<
+                  std::conjunction_v<std::is_default_constructible<_Tp>, std::is_default_constructible<T>...>, int> = 0>
+    tuple() : holder{}, next{}
+    {
+    } //The std::tuple value-initializes all elements, so we also follow this.
+    tuple(const tuple& other) = default;
+    tuple(tuple&& other) = default;
+    template <typename _U1, typename... _U, typename = ::std::enable_if_t<(sizeof...(_U) == sizeof...(T))>>
+    tuple(const tuple<_U1, _U...>& other) : holder(other.template get<0>()), next(other.next)
+    {
+    }
+
+    template <typename _U1, typename... _U, typename = ::std::enable_if_t<(sizeof...(_U) == sizeof...(T))>>
+    tuple(tuple<_U1, _U...>&& other) : holder(std::move(other).template get<0>()), next(std::move(other.next))
+    {
+    }
+
+    template <typename _U1, typename... _U,
+              typename = ::std::enable_if_t<
+                  (sizeof...(_U) == sizeof...(T) &&
+                   ::std::conjunction_v<::std::is_constructible<T1, _U1&&>, ::std::is_constructible<T, _U&&>...>)>>
+    tuple(_U1&& _value, _U&&... _next) : holder(::std::forward<_U1>(_value)), next(::std::forward<_U>(_next)...)
+    {
+    }
+
+    // required to convert ::std::tuple to inner tuple in user-provided functor
+    tuple(const ::std::tuple<T1, T...>& other)
+        : holder(::std::get<0>(other)), next(__onedpl::__internal::get_tuple_tail(other))
+    {
+    }
+
+    // conversion to ::std::tuple with the same template arguments
+    operator ::std::tuple<T1, T...>() const
+    {
+        static constexpr ::std::size_t __tuple_size = sizeof...(T) + 1;
+        return to_std_tuple(*this, ::std::make_index_sequence<__tuple_size>());
+    }
+
+    // conversion to ::std::tuple with the different template arguments
+    template <typename U1, typename... U>
+    operator ::std::tuple<U1, U...>() const
+    {
+        constexpr ::std::size_t __tuple_size = sizeof...(T) + 1;
+        return to_std_tuple(static_cast<tuple<U1, U...>>(*this), ::std::make_index_sequence<__tuple_size>());
+    }
+
+    // non-const subscript operator with tuple argument
+    template <typename Size1, typename... SizeRest>
+    auto operator[](__onedpl::__internal::tuple<Size1, SizeRest...> tuple_size)
+        -> decltype(__onedpl::__internal::get_value_by_idx<Size1, SizeRest...>()(*this, tuple_size))
+    {
+        return __onedpl::__internal::get_value_by_idx<Size1, SizeRest...>()(*this, tuple_size);
+    }
+
+    // const subscript operator with tuple argument
+    template <typename Size1, typename... SizeRest>
+    auto operator[](const __onedpl::__internal::tuple<Size1, SizeRest...> tuple_size) const
+        -> decltype(__onedpl::__internal::get_value_by_idx<Size1, SizeRest...>()(*this, tuple_size))
+    {
+        return __onedpl::__internal::get_value_by_idx<Size1, SizeRest...>()(*this, tuple_size);
+    }
+
+    // non-const subscript operator with scalar argument
+    template <typename Idx>
+    auto operator[](Idx idx)
+        -> decltype(__onedpl::__internal::map_tuplewrapper(__onedpl::__internal::MapValue<Idx>{idx}, *this))
+    {
+        return __onedpl::__internal::map_tuplewrapper(__onedpl::__internal::MapValue<Idx>{idx}, *this);
+    }
+
+    // const subscript operator with scalar argument
+    template <typename Idx>
+    auto operator[](Idx idx) const
+        -> decltype(__onedpl::__internal::map_tuplewrapper(__onedpl::__internal::MapValue<Idx>{idx}, *this))
+    {
+        return __onedpl::__internal::map_tuplewrapper(__onedpl::__internal::MapValue<Idx>{idx}, *this);
+    }
+
+    template <typename U1, typename... U>
+    tuple&
+    operator=(const tuple<U1, U...>& other)
+    {
+        holder.value = other.holder.value;
+        next = other.next;
+        return *this;
+    }
+
+    template <typename U1, typename... U>
+    const tuple&
+    operator=(const tuple<U1, U...>& other) const
+    {
+        holder.value = other.holder.value;
+        next = other.next;
+        return *this;
+    }
+
+    // if T1 is deduced with reference, compiler generates deleted operator= and,
+    // since "template operator=" is not considered as operator= overload
+    // the deleted operator= has a preference during lookup
+    tuple&
+    operator=(const tuple<T1, T...>& other) = default;
+
+    // for cases when we assign ::std::tuple to __internal::tuple
+    template <typename U1, typename... U>
+    tuple&
+    operator=(const ::std::tuple<U1, U...>& other)
+    {
+        holder.value = ::std::get<0>(other);
+        next = __onedpl::__internal::get_tuple_tail(other);
+        return *this;
+    }
+
+    template <typename _U, typename _V,
+              std::enable_if_t<__onedpl::__internal::__enable_comparison_op_v<tuple, _U, _V>, int> = 0>
+    friend constexpr bool
+    operator==(_U&& __lhs, _V&& __rhs)
+    {
+        return __onedpl::__internal::__equal(std::forward<_U>(__lhs), std::forward<_V>(__rhs));
+    }
+
+    template <typename _U, typename _V,
+              std::enable_if_t<__onedpl::__internal::__enable_comparison_op_v<tuple, _U, _V>, int> = 0>
+    friend constexpr bool
+    operator!=(_U&& __lhs, _V&& __rhs)
+    {
+        return !__onedpl::__internal::__equal(std::forward<_U>(__lhs), std::forward<_V>(__rhs));
+    }
+
+    template <typename _U, typename _V,
+              std::enable_if_t<__onedpl::__internal::__enable_comparison_op_v<tuple, _U, _V>, int> = 0>
+    friend constexpr bool
+    operator<(_U&& __lhs, _V&& __rhs)
+    {
+        return __onedpl::__internal::__less(std::forward<_U>(__lhs), std::forward<_V>(__rhs));
+    }
+
+    template <typename _U, typename _V,
+              std::enable_if_t<__onedpl::__internal::__enable_comparison_op_v<tuple, _U, _V>, int> = 0>
+    friend constexpr bool
+    operator<=(_U&& __lhs, _V&& __rhs)
+    {
+        return !__onedpl::__internal::__less(std::forward<_V>(__rhs), std::forward<_U>(__lhs));
+    }
+
+    template <typename _U, typename _V,
+              std::enable_if_t<__onedpl::__internal::__enable_comparison_op_v<tuple, _U, _V>, int> = 0>
+    friend constexpr bool
+    operator>(_U&& __lhs, _V&& __rhs)
+    {
+        return __onedpl::__internal::__less(std::forward<_V>(__rhs), std::forward<_U>(__lhs));
+    }
+
+    template <typename _U, typename _V,
+              std::enable_if_t<__onedpl::__internal::__enable_comparison_op_v<tuple, _U, _V>, int> = 0>
+    friend constexpr bool
+    operator>=(_U&& __lhs, _V&& __rhs)
+    {
+        return !__onedpl::__internal::__less(std::forward<_U>(__lhs), std::forward<_V>(__rhs));
+    }
+
+    template <typename U1, typename... U, ::std::size_t... _Ip>
+    static ::std::tuple<U1, U...>
+    to_std_tuple(const __onedpl::__internal::tuple<U1, U...>& __t, ::std::index_sequence<_Ip...>)
+    {
+        return ::std::tuple<U1, U...>(__onedpl::__internal::get_impl<_Ip>()(__t)...);
+    }
+};
+
+template <>
+struct tuple<>
+{
+    using tuple_type = ::std::tuple<>;
+    // since compiler does not autogenerate ctors
+    // if user defines its own, we have to define them too
+    tuple() = default;
+    tuple(const tuple& other) = default;
+
+    tuple(const ::std::tuple<>&) {}
+
+    tuple operator[](tuple) { return {}; }
+    tuple operator[](const tuple&) const { return {}; }
+    operator tuple_type() const { return tuple_type{}; }
+    tuple&
+    operator=(const tuple&) = default;
+    tuple&
+    operator=(const ::std::tuple<>& /*other*/)
+    {
+        return *this;
+    }
+    const tuple&
+    operator=(const std::tuple<>&) const
+    {
+        return *this;
+    }
+    friend constexpr bool
+    operator==(const tuple&, const tuple&)
+    {
+        return true;
+    }
+    friend constexpr bool
+    operator!=(const tuple&, const tuple&)
+    {
+        return false;
+    }
+    friend constexpr bool
+    operator<(const tuple&, const tuple&)
+    {
+        return false;
+    }
+    friend constexpr bool
+    operator<=(const tuple&, const tuple&)
+    {
+        return true;
+    }
+    friend constexpr bool
+    operator>(const tuple&, const tuple&)
+    {
+        return false;
+    }
+    friend constexpr bool
+    operator>=(const tuple&, const tuple&)
+    {
+        return true;
+    }
+};
+
+inline void
+swap(__onedpl::__internal::tuple<>& /*__x*/, __onedpl::__internal::tuple<>& /*__y*/)
+{
+}
+
+template <typename... _T>
+void
+swap(__onedpl::__internal::tuple<_T...>& __x, __onedpl::__internal::tuple<_T...>& __y)
+{
+    using ::std::swap;
+    swap(__x.holder.value, __y.holder.value);
+    swap(__x.next, __y.next);
+}
+
+template <typename... _T>
+void
+swap(__onedpl::__internal::tuple<_T...>&& __x, __onedpl::__internal::tuple<_T...>&& __y)
+{
+    using ::std::swap;
+    swap(__x.holder.value, __y.holder.value);
+    swap(__x.next, __y.next);
+}
+
+// Get corresponding ::std::tuple for our internal tuple(i.e. access tuple_type member
+// which is ::std::tuple<Ts...> for internal::tuple<Ts...>).
+// Do nothing for other types or if both operands are internal tuples.
+template <class _T, class>
+struct __get_tuple_type
+{
+    using __type = _T;
+};
+
+template <class... _Ts, class... _Us>
+struct __get_tuple_type<__onedpl::__internal::tuple<_Ts...>, __onedpl::__internal::tuple<_Us...>>
+{
+    using __type = typename __onedpl::__internal::tuple<_Ts...>;
+};
+
+template <class... _Ts, class _Other>
+struct __get_tuple_type<__onedpl::__internal::tuple<_Ts...>, _Other>
+{
+    using __type = typename __onedpl::__internal::tuple<_Ts...>::tuple_type;
+};
+
+template <typename Size>
+struct AddIndexes
+{
+    Size idx;
+
+    template <typename T1>
+    T1
+    operator()(const T1& t1) const
+    {
+        return t1 + idx;
+    }
+};
+
+template <typename Size>
+struct SubTupleFromIndex
+{
+    Size idx;
+
+    template <typename T1>
+    T1
+    operator()(const T1& t1) const
+    {
+        return idx - t1;
+    }
+};
+
+template <typename Size>
+struct SubIndexFromTuple
+{
+    Size idx;
+
+    template <typename T1>
+    T1
+    operator()(const T1& t1) const
+    {
+        return t1 - idx;
+    }
+};
+
+struct subscription_functor
+{
+    template <typename _A, typename _Index>
+    auto
+    operator()(_A __a, _Index __idx) -> decltype(__a[__idx]) const
+    {
+        return __a[__idx];
+    }
+};
+
+template <typename... Size>
+struct get_value_by_idx
+{
+    template <typename... Acc>
+    auto
+    operator()(__onedpl::__internal::tuple<Acc...>& acc, __onedpl::__internal::tuple<Size...>& idx)
+        -> decltype(__onedpl::__internal::map_tuplewrapper(__onedpl::__internal::subscription_functor{}, acc,
+                                                              idx))
+    {
+        return __onedpl::__internal::map_tuplewrapper(__onedpl::__internal::subscription_functor{}, acc, idx);
+    }
+    template <typename... Acc>
+    auto
+    operator()(const __onedpl::__internal::tuple<Acc...>& acc,
+               const __onedpl::__internal::tuple<Size...>& idx) const
+        -> decltype(__onedpl::__internal::map_tuplewrapper(__onedpl::__internal::subscription_functor{}, acc,
+                                                              idx))
+    {
+        return __onedpl::__internal::map_tuplewrapper(__onedpl::__internal::subscription_functor{}, acc, idx);
+    }
+};
+
+template <typename Size, typename... T1>
+__onedpl::__internal::tuple<T1...>
+operator+(const __onedpl::__internal::tuple<T1...>& tuple1, Size idx)
+{
+    return __onedpl::__internal::map_tuple(__onedpl::__internal::AddIndexes<Size>{idx}, tuple1);
+}
+
+template <typename Size, typename... T1>
+__onedpl::__internal::tuple<T1...>
+operator+(Size idx, const __onedpl::__internal::tuple<T1...>& tuple1)
+{
+    return __onedpl::__internal::map_tuple(__onedpl::__internal::AddIndexes<Size>{idx}, tuple1);
+}
+
+template <typename Size, typename... T1>
+__onedpl::__internal::tuple<T1...>
+operator-(const __onedpl::__internal::tuple<T1...>& tuple1, Size idx)
+{
+    return __onedpl::__internal::map_tuple(__onedpl::__internal::SubIndexFromTuple<Size>{idx}, tuple1);
+}
+
+// required in scan implementation for false offset calculation
+template <typename Size, typename... T1>
+auto
+operator-(Size idx, const __onedpl::__internal::tuple<T1...>& tuple1)
+    -> decltype(__onedpl::__internal::map_tuple(__onedpl::__internal::SubTupleFromIndex<Size>{idx}, tuple1))
+{
+    return __onedpl::__internal::map_tuple(__onedpl::__internal::SubTupleFromIndex<Size>{idx}, tuple1);
+}
+
+// Decay wrapper struct with specialization to decay tuple elements
+template <typename _T>
+struct __decay_with_tuple_specialization
+{
+    using type = ::std::decay_t<_T>;
+};
+
+template <typename... _Args>
+struct __decay_with_tuple_specialization<__onedpl::__internal::tuple<_Args...>>
+{
+    using type = __onedpl::__internal::tuple<::std::decay_t<_Args>...>;
+};
+
+template <typename... _Args>
+struct __decay_with_tuple_specialization<::std::tuple<_Args...>>
+{
+    using type = ::std::tuple<::std::decay_t<_Args>...>;
+};
+
+template <typename... _Args>
+using __decay_with_tuple_specialization_t = typename __decay_with_tuple_specialization<_Args...>::type;
+
+} // namespace __internal
+} // namespace std::__onedpl
+
+namespace std
+{
+template <size_t _Idx, typename... _Tp>
+constexpr ::std::tuple_element_t<_Idx, __onedpl::__internal::tuple<_Tp...>>&
+get(__onedpl::__internal::tuple<_Tp...>& __a)
+{
+    return __a.template get<_Idx>();
+}
+
+template <size_t _Idx, typename... _Tp>
+constexpr ::std::tuple_element_t<_Idx, __onedpl::__internal::tuple<_Tp...>> const&
+get(const __onedpl::__internal::tuple<_Tp...>& __a)
+{
+    return __a.template get<_Idx>();
+}
+template <size_t _Idx, typename... _Tp>
+constexpr ::std::tuple_element_t<_Idx, __onedpl::__internal::tuple<_Tp...>>&&
+get(__onedpl::__internal::tuple<_Tp...>&& __a)
+{
+    return ::std::move(__a).template get<_Idx>();
+}
+
+template <size_t _Idx, typename... _Tp>
+constexpr ::std::tuple_element_t<_Idx, __onedpl::__internal::tuple<_Tp...>> const&&
+get(const __onedpl::__internal::tuple<_Tp...>&& __a)
+{
+    return ::std::move(__a).template get<_Idx>();
+}
+
+// To enable __onedpl::zip_iterator to satisfy the requirements for the std::input_iterator concept in C++20,
+// we must provide a basic_common_reference specialization for our internal tuple implementation. std::basic_common_reference
+// is introduced in __cpp_lib_concepts, so we must ensure this feature is present.
+#if _ONEDPL_CPP20_CONCEPTS_PRESENT
+template <typename... TTypes, typename... UTypes, template <typename> typename TQual,
+          template <typename> typename UQual>
+struct basic_common_reference<__onedpl::__internal::tuple<TTypes...>, __onedpl::__internal::tuple<UTypes...>,
+                              TQual, UQual>
+{
+    using type = __onedpl::__internal::tuple<::std::common_reference_t<TQual<TTypes>, UQual<UTypes>>...>;
+};
+#endif
+} // namespace std
+
+#endif // _ONEDPL_TUPLE_IMPL_H
diff --git a/libstdc++-v3/include/pstl/unseq_backend_simd.h b/libstdc++-v3/include/pstl/unseq_backend_simd.h
index 58a2c0c0adb3..8fb75051aa79 100644
--- a/libstdc++-v3/include/pstl/unseq_backend_simd.h
+++ b/libstdc++-v3/include/pstl/unseq_backend_simd.h
@@ -1,72 +1,58 @@
 // -*- C++ -*-
-//===-- unseq_backend_simd.h ----------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_UNSEQ_BACKEND_SIMD_H
-#define _PSTL_UNSEQ_BACKEND_SIMD_H
+#ifndef _ONEDPL_UNSEQ_BACKEND_SIMD_H
+#define _ONEDPL_UNSEQ_BACKEND_SIMD_H
 
 #include <type_traits>
 
 #include "utils.h"
 
 // This header defines the minimum set of vector routines required
-// to support parallel STL.
-namespace __pstl
+// to support Parallel STL.
+namespace std::__onedpl
 {
 namespace __unseq_backend
 {
 
 // Expect vector width up to 64 (or 512 bit)
-inline const std::size_t __lane_size = 64;
+const ::std::size_t __lane_size = 64;
 
-template <class _Iterator, class _DifferenceType, class _Function>
-_Iterator
-__simd_walk_1(_Iterator __first, _DifferenceType __n, _Function __f) noexcept
+template <typename _DifferenceType, typename _Function, typename... _Iterators>
+auto
+__simd_walk_n(_DifferenceType __n, _Function __f, _Iterators... __it)
 {
-    _PSTL_PRAGMA_SIMD
+    _ONEDPL_PRAGMA_SIMD
     for (_DifferenceType __i = 0; __i < __n; ++__i)
-        __f(__first[__i]);
+        __f(__it[__i]...);
 
-    return __first + __n;
-}
-
-template <class _Iterator1, class _DifferenceType, class _Iterator2, class _Function>
-_Iterator2
-__simd_walk_2(_Iterator1 __first1, _DifferenceType __n, _Iterator2 __first2, _Function __f) noexcept
-{
-    _PSTL_PRAGMA_SIMD
-    for (_DifferenceType __i = 0; __i < __n; ++__i)
-        __f(__first1[__i], __first2[__i]);
-    return __first2 + __n;
-}
-
-template <class _Iterator1, class _DifferenceType, class _Iterator2, class _Iterator3, class _Function>
-_Iterator3
-__simd_walk_3(_Iterator1 __first1, _DifferenceType __n, _Iterator2 __first2, _Iterator3 __first3,
-              _Function __f) noexcept
-{
-    _PSTL_PRAGMA_SIMD
-    for (_DifferenceType __i = 0; __i < __n; ++__i)
-        __f(__first1[__i], __first2[__i], __first3[__i]);
-    return __first3 + __n;
+    //A conciser writing (__it, ...) produces a warning in -Wunused-value mode.
+    return __internal::__get_last_arg(__it...) + __n;
 }
 
 // TODO: check whether __simd_first() can be used here
 template <class _Index, class _DifferenceType, class _Pred>
 bool
-__simd_or(_Index __first, _DifferenceType __n, _Pred __pred) noexcept
+__simd_or_impl(_Index __first, _DifferenceType __n, _Pred __pred) noexcept
 {
-#if defined(_PSTL_EARLYEXIT_PRESENT)
+#if (_PSTL_EARLYEXIT_PRESENT || _ONEDPL_EARLYEXIT_PRESENT)
     _DifferenceType __i;
-    _PSTL_PRAGMA_VECTOR_UNALIGNED
-    _PSTL_PRAGMA_SIMD_EARLYEXIT
+    _ONEDPL_PRAGMA_VECTOR_UNALIGNED
+    _ONEDPL_PRAGMA_SIMD_EARLYEXIT
     for (__i = 0; __i < __n; ++__i)
-        if (__pred(__first[__i]))
+        if (__pred(__first + __i))
             break;
     return __i < __n;
 #else
@@ -74,10 +60,12 @@ __simd_or(_Index __first, _DifferenceType __n, _Pred __pred) noexcept
     const _Index __last = __first + __n;
     while (__last != __first)
     {
-        __INT32_TYPE__ __flag = 1;
-        _PSTL_PRAGMA_SIMD_REDUCTION(& : __flag)
+        // Some compilers may have issue with reduction(||:...) and reduction(&&:...),
+        // so use DeMorgan dual
+        int32_t __flag = 1;
+        _ONEDPL_PRAGMA_SIMD_REDUCTION(& : __flag)
         for (_DifferenceType __i = 0; __i < __block_size; ++__i)
-            if (__pred(*(__first + __i)))
+            if (__pred(__first + __i))
                 __flag = 0;
         if (!__flag)
             return true;
@@ -97,16 +85,30 @@ __simd_or(_Index __first, _DifferenceType __n, _Pred __pred) noexcept
 #endif
 }
 
+template <class _Index, class _DifferenceType, class _Pred>
+bool
+__simd_or(_Index __first, _DifferenceType __n, _Pred __pred) noexcept
+{
+    return __unseq_backend::__simd_or_impl(__first, __n, [&__pred](_Index __it) { return __pred(*__it); });
+}
+
+template <class _Index, class _DifferenceType, class _Pred>
+bool
+__simd_or_iter(_Index __first, _DifferenceType __n, _Pred __pred) noexcept
+{
+    return __unseq_backend::__simd_or_impl(__first, __n, __pred);
+}
+
 template <class _Index, class _DifferenceType, class _Compare>
 _Index
 __simd_first(_Index __first, _DifferenceType __begin, _DifferenceType __end, _Compare __comp) noexcept
 {
-#if defined(_PSTL_EARLYEXIT_PRESENT)
+#if (_PSTL_EARLYEXIT_PRESENT || _ONEDPL_EARLYEXIT_PRESENT)
     _DifferenceType __i = __begin;
-    _PSTL_PRAGMA_VECTOR_UNALIGNED // Do not generate peel loop part
-        _PSTL_PRAGMA_SIMD_EARLYEXIT for (; __i < __end; ++__i)
+    _ONEDPL_PRAGMA_VECTOR_UNALIGNED // Do not generate peel loop part
+        _ONEDPL_PRAGMA_SIMD_EARLYEXIT for (; __i < __end; ++__i)
     {
-        if (__comp(__first, __i))
+        if (std::invoke(__comp, __first, __i))
         {
             break;
         }
@@ -119,12 +121,12 @@ __simd_first(_Index __first, _DifferenceType __begin, _DifferenceType __end, _Co
     while (__end - __begin >= __block_size)
     {
         _DifferenceType __found = 0;
-        _PSTL_PRAGMA_VECTOR_UNALIGNED // Do not generate peel loop part
-            _PSTL_PRAGMA_SIMD_REDUCTION(|
-                                        : __found) for (_DifferenceType __i = __begin; __i < __begin + __block_size;
-                                                        ++__i)
+        _ONEDPL_PRAGMA_VECTOR_UNALIGNED // Do not generate peel loop part
+            _ONEDPL_PRAGMA_SIMD_REDUCTION(|
+                                          : __found) for (_DifferenceType __i = __begin; __i < __begin + __block_size;
+                                                          ++__i)
         {
-            const _DifferenceType __t = __comp(__first, __i);
+            const _DifferenceType __t = std::invoke(__comp, __first, __i);
             __lane[__i - __begin] = __t;
             __found |= __t;
         }
@@ -147,28 +149,28 @@ __simd_first(_Index __first, _DifferenceType __begin, _DifferenceType __end, _Co
     //Keep remainder scalar
     while (__begin != __end)
     {
-        if (__comp(__first, __begin))
+        if (std::invoke(__comp, __first, __begin))
         {
             return __first + __begin;
         }
         ++__begin;
     }
     return __first + __end;
-#endif //_PSTL_EARLYEXIT_PRESENT
+#endif //_PSTL_EARLYEXIT_PRESENT || _ONEDPL_EARLYEXIT_PRESENT
 }
 
 template <class _Index1, class _DifferenceType, class _Index2, class _Pred>
-std::pair<_Index1, _Index2>
+::std::pair<_Index1, _Index2>
 __simd_first(_Index1 __first1, _DifferenceType __n, _Index2 __first2, _Pred __pred) noexcept
 {
-#if defined(_PSTL_EARLYEXIT_PRESENT)
+#if (_PSTL_EARLYEXIT_PRESENT || _ONEDPL_EARLYEXIT_PRESENT)
     _DifferenceType __i = 0;
-    _PSTL_PRAGMA_VECTOR_UNALIGNED
-    _PSTL_PRAGMA_SIMD_EARLYEXIT
+    _ONEDPL_PRAGMA_VECTOR_UNALIGNED
+    _ONEDPL_PRAGMA_SIMD_EARLYEXIT
     for (; __i < __n; ++__i)
         if (__pred(__first1[__i], __first2[__i]))
             break;
-    return std::make_pair(__first1 + __i, __first2 + __i);
+    return ::std::make_pair(__first1 + __i, __first2 + __i);
 #else
     const _Index1 __last1 = __first1 + __n;
     const _Index2 __last2 = __first2 + __n;
@@ -179,9 +181,9 @@ __simd_first(_Index1 __first1, _DifferenceType __n, _Index2 __first2, _Pred __pr
     {
         _DifferenceType __found = 0;
         _DifferenceType __i;
-        _PSTL_PRAGMA_VECTOR_UNALIGNED // Do not generate peel loop part
-            _PSTL_PRAGMA_SIMD_REDUCTION(|
-                                        : __found) for (__i = 0; __i < __block_size; ++__i)
+        _ONEDPL_PRAGMA_VECTOR_UNALIGNED // Do not generate peel loop part
+            _ONEDPL_PRAGMA_SIMD_REDUCTION(|
+                                          : __found) for (__i = 0; __i < __block_size; ++__i)
         {
             const _DifferenceType __t = __pred(__first1[__i], __first2[__i]);
             __lane[__i] = __t;
@@ -189,26 +191,26 @@ __simd_first(_Index1 __first1, _DifferenceType __n, _Index2 __first2, _Pred __pr
         }
         if (__found)
         {
-            _DifferenceType __i2;
+            _DifferenceType __i;
             // This will vectorize
-            for (__i2 = 0; __i2 < __block_size; ++__i2)
+            for (__i = 0; __i < __block_size; ++__i)
             {
-                if (__lane[__i2])
+                if (__lane[__i])
                     break;
             }
-            return std::make_pair(__first1 + __i2, __first2 + __i2);
+            return ::std::make_pair(__first1 + __i, __first2 + __i);
         }
         __first1 += __block_size;
         __first2 += __block_size;
     }
 
     //Keep remainder scalar
-    for (; __last1 != __first1; ++__first1, ++__first2)
+    for (; __last1 != __first1; ++__first1, (void)++__first2)
         if (__pred(*(__first1), *(__first2)))
-            return std::make_pair(__first1, __first2);
+            return ::std::make_pair(__first1, __first2);
 
-    return std::make_pair(__last1, __last2);
-#endif //_PSTL_EARLYEXIT_PRESENT
+    return ::std::make_pair(__last1, __last2);
+#endif //_PSTL_EARLYEXIT_PRESENT || _ONEDPL_EARLYEXIT_PRESENT
 }
 
 template <class _Index, class _DifferenceType, class _Pred>
@@ -216,7 +218,7 @@ _DifferenceType
 __simd_count(_Index __index, _DifferenceType __n, _Pred __pred) noexcept
 {
     _DifferenceType __count = 0;
-    _PSTL_PRAGMA_SIMD_REDUCTION(+ : __count)
+    _ONEDPL_PRAGMA_SIMD_REDUCTION(+ : __count)
     for (_DifferenceType __i = 0; __i < __n; ++__i)
         if (__pred(*(__index + __i)))
             ++__count;
@@ -224,108 +226,98 @@ __simd_count(_Index __index, _DifferenceType __n, _Pred __pred) noexcept
     return __count;
 }
 
-template <class _InputIterator, class _DifferenceType, class _OutputIterator, class _BinaryPredicate>
-_OutputIterator
-__simd_unique_copy(_InputIterator __first, _DifferenceType __n, _OutputIterator __result,
-                   _BinaryPredicate __pred) noexcept
-{
-    if (__n == 0)
-        return __result;
-
-    _DifferenceType __cnt = 1;
-    __result[0] = __first[0];
-
-    _PSTL_PRAGMA_SIMD
-    for (_DifferenceType __i = 1; __i < __n; ++__i)
-    {
-        _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(__cnt : 1)
-        if (!__pred(__first[__i], __first[__i - 1]))
-        {
-            __result[__cnt] = __first[__i];
-            ++__cnt;
-        }
-    }
-    return __result + __cnt;
-}
-
 template <class _InputIterator, class _DifferenceType, class _OutputIterator, class _Assigner>
 _OutputIterator
 __simd_assign(_InputIterator __first, _DifferenceType __n, _OutputIterator __result, _Assigner __assigner) noexcept
 {
     _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
-    _PSTL_PRAGMA_SIMD
+    _ONEDPL_PRAGMA_SIMD
     for (_DifferenceType __i = 0; __i < __n; ++__i)
         __assigner(__first + __i, __result + __i);
     return __result + __n;
 }
 
-template <class _InputIterator, class _DifferenceType, class _OutputIterator, class _UnaryPredicate>
-_OutputIterator
-__simd_copy_if(_InputIterator __first, _DifferenceType __n, _OutputIterator __result, _UnaryPredicate __pred) noexcept
+template <bool __Bounded, class _InIterator, class _DifferenceType, class _OutIterator, class _IndexPredicate>
+std::pair<_DifferenceType, _DifferenceType>
+__simd_selective_copy(_InIterator __first, _DifferenceType __n, _OutIterator __result, _DifferenceType __n_out,
+                      _IndexPredicate __pred) noexcept
 {
-    _DifferenceType __cnt = 0;
+    static_assert(std::is_signed_v<_DifferenceType>);
+    _DifferenceType __stop = -1, __write_pos = -1; // to use inclusive scan
+    bool __suitable;
 
-    _PSTL_PRAGMA_SIMD
+#if _ONEDPL_OMP_SIMD_LASTPRIVATE_CONDITIONAL_BROKEN
+    _ONEDPL_PRAGMA_SIMD_SCAN_EX(+ : __write_pos, private(__suitable))
+#else
+    _ONEDPL_PRAGMA_SIMD_SCAN_EX(+ : __write_pos, private(__suitable) lastprivate(conditional : __stop))
+#endif
     for (_DifferenceType __i = 0; __i < __n; ++__i)
     {
-        _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(__cnt : 1)
-        if (__pred(__first[__i]))
+        __suitable = __pred(__first, __i);
+        __write_pos += __suitable;
+        _ONEDPL_PRAGMA_SIMD_INCLUSIVE_SCAN(__write_pos)
+        if (__suitable)
         {
-            __result[__cnt] = __first[__i];
-            ++__cnt;
+            if constexpr (__Bounded)
+            {
+                if (__write_pos < __n_out)
+                    __result[__write_pos] = __first[__i];
+                if (__write_pos == __n_out) // together with __suitable, the conditions are true for only one index
+                    __stop = __i;
+            }
+            else
+                __result[__write_pos] = __first[__i];
         }
     }
-    return __result + __cnt;
+    _DifferenceType __cnt = __write_pos + 1;
+    return {__stop < 0 ? __n : __stop, __cnt < __n_out ? __cnt : __n_out};
 }
 
-template <class _InputIterator, class _DifferenceType, class _BinaryPredicate>
+template <typename _Iterator, typename _DifferenceType, typename _IndexPredicate>
 _DifferenceType
-__simd_calc_mask_2(_InputIterator __first, _DifferenceType __n, bool* __mask, _BinaryPredicate __pred) noexcept
+__simd_compute_mask(_Iterator __first, _DifferenceType __n, _IndexPredicate __pred, bool* __mask) noexcept
 {
     _DifferenceType __count = 0;
 
-    _PSTL_PRAGMA_SIMD_REDUCTION(+ : __count)
+    _ONEDPL_PRAGMA_SIMD_REDUCTION(+ : __count)
     for (_DifferenceType __i = 0; __i < __n; ++__i)
     {
-        __mask[__i] = !__pred(__first[__i], __first[__i - 1]);
+        __mask[__i] = __pred(__first, __i);
         __count += __mask[__i];
     }
     return __count;
 }
 
-template <class _InputIterator, class _DifferenceType, class _UnaryPredicate>
+template <bool __Bounded, class _InputIterator, class _DifferenceType, class _OutputIterator, class _Assigner>
 _DifferenceType
-__simd_calc_mask_1(_InputIterator __first, _DifferenceType __n, bool* __mask, _UnaryPredicate __pred) noexcept
+__simd_copy_by_mask(_InputIterator __first, _DifferenceType __n, _OutputIterator __result, _DifferenceType __n_out,
+                    bool* __mask, _Assigner __assign) noexcept
 {
-    _DifferenceType __count = 0;
+    std::make_signed_t<_DifferenceType> __stop = -1, __write_pos = -1; // to use inclusive scan of the mask
 
-    _PSTL_PRAGMA_SIMD_REDUCTION(+ : __count)
-    for (_DifferenceType __i = 0; __i < __n; ++__i)
-    {
-        __mask[__i] = __pred(__first[__i]);
-        __count += __mask[__i];
-    }
-    return __count;
-}
-
-template <class _InputIterator, class _DifferenceType, class _OutputIterator, class _Assigner>
-void
-__simd_copy_by_mask(_InputIterator __first, _DifferenceType __n, _OutputIterator __result, bool* __mask,
-                    _Assigner __assigner) noexcept
-{
-    _DifferenceType __cnt = 0;
-    _PSTL_PRAGMA_SIMD
+#if _ONEDPL_OMP_SIMD_LASTPRIVATE_CONDITIONAL_BROKEN
+    _ONEDPL_PRAGMA_SIMD_SCAN_EX(+ : __write_pos)
+#else
+    _ONEDPL_PRAGMA_SIMD_SCAN_EX(+ : __write_pos, lastprivate(conditional : __stop))
+#endif
     for (_DifferenceType __i = 0; __i < __n; ++__i)
     {
+        __write_pos += __mask[__i];
+        _ONEDPL_PRAGMA_SIMD_INCLUSIVE_SCAN(__write_pos)
         if (__mask[__i])
         {
-            _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(__cnt : 1)
+            if constexpr (__Bounded)
             {
-                __assigner(__first + __i, __result + __cnt);
-                ++__cnt;
+                if (__write_pos < __n_out)
+                    __assign(__first + __i, __result + __write_pos);
+                if (__write_pos == __n_out) // together with the mask, the conditions are true for only one index
+                    __stop = __i;
             }
+            else
+                __assign(__first + __i, __result + __write_pos);
         }
     }
+    return __stop < 0 ? __n : __stop;
 }
 
 template <class _InputIterator, class _DifferenceType, class _OutputIterator1, class _OutputIterator2>
@@ -334,10 +326,10 @@ __simd_partition_by_mask(_InputIterator __first, _DifferenceType __n, _OutputIte
                          _OutputIterator2 __out_false, bool* __mask) noexcept
 {
     _DifferenceType __cnt_true = 0, __cnt_false = 0;
-    _PSTL_PRAGMA_SIMD
+    _ONEDPL_PRAGMA_SIMD
     for (_DifferenceType __i = 0; __i < __n; ++__i)
     {
-        _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(__cnt_true : 1, __cnt_false : 1)
+        _ONEDPL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(__cnt_true : 1, __cnt_false : 1)
         if (__mask[__i])
         {
             __out_true[__cnt_true] = __first[__i];
@@ -356,7 +348,7 @@ _Index
 __simd_fill_n(_Index __first, _DifferenceType __n, const _Tp& __value) noexcept
 {
     _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
-    _PSTL_PRAGMA_SIMD
+    _ONEDPL_PRAGMA_SIMD
     for (_DifferenceType __i = 0; __i < __n; ++__i)
         __first[__i] = __value;
     return __first + __n;
@@ -367,7 +359,7 @@ _Index
 __simd_generate_n(_Index __first, _DifferenceType __size, _Generator __g) noexcept
 {
     _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
-    _PSTL_PRAGMA_SIMD
+    _ONEDPL_PRAGMA_SIMD
     for (_DifferenceType __i = 0; __i < __size; ++__i)
         __first[__i] = __g();
     return __first + __size;
@@ -380,14 +372,14 @@ __simd_adjacent_find(_Index __first, _Index __last, _BinaryPredicate __pred, boo
     if (__last - __first < 2)
         return __last;
 
-    typedef typename std::iterator_traits<_Index>::difference_type _DifferenceType;
+    using _DifferenceType = typename std::iterator_traits<_Index>::difference_type;
     _DifferenceType __i = 0;
 
-#if defined(_PSTL_EARLYEXIT_PRESENT)
+#if (_PSTL_EARLYEXIT_PRESENT || _ONEDPL_EARLYEXIT_PRESENT)
     //Some compiler versions fail to compile the following loop when iterators are used. Indices are used instead
     const _DifferenceType __n = __last - __first - 1;
-    _PSTL_PRAGMA_VECTOR_UNALIGNED
-    _PSTL_PRAGMA_SIMD_EARLYEXIT
+    _ONEDPL_PRAGMA_VECTOR_UNALIGNED
+    _ONEDPL_PRAGMA_SIMD_EARLYEXIT
     for (; __i < __n; ++__i)
         if (__pred(__first[__i], __first[__i + 1]))
             break;
@@ -401,9 +393,9 @@ __simd_adjacent_find(_Index __first, _Index __last, _BinaryPredicate __pred, boo
     while (__last - __first >= __block_size)
     {
         _DifferenceType __found = 0;
-        _PSTL_PRAGMA_VECTOR_UNALIGNED // Do not generate peel loop part
-            _PSTL_PRAGMA_SIMD_REDUCTION(|
-                                        : __found) for (__i = 0; __i < __block_size - 1; ++__i)
+        _ONEDPL_PRAGMA_VECTOR_UNALIGNED // Do not generate peel loop part
+            _ONEDPL_PRAGMA_SIMD_REDUCTION(|
+                                          : __found) for (__i = 0; __i < __block_size - 1; ++__i)
         {
             //TODO: to improve SIMD vectorization
             const _DifferenceType __t = __pred(*(__first + __i), *(__first + __i + 1));
@@ -437,23 +429,27 @@ __simd_adjacent_find(_Index __first, _Index __last, _BinaryPredicate __pred, boo
 #endif
 }
 
-// It was created to reduce the code inside std::enable_if
+// It was created to reduce the code inside ::std::enable_if
 template <typename _Tp, typename _BinaryOperation>
-using is_arithmetic_plus = std::integral_constant<bool, std::is_arithmetic<_Tp>::value &&
-                                                            std::is_same<_BinaryOperation, std::plus<_Tp>>::value>;
+using is_arithmetic_plus = ::std::integral_constant<bool, ::std::is_arithmetic_v<_Tp> &&
+                                                              (::std::is_same_v<_BinaryOperation, ::std::plus<_Tp>> ||
+                                                               ::std::is_same_v<_BinaryOperation, ::std::plus<void>>)>;
+
+template <typename _Tp, typename _BinaryOperation>
+inline constexpr bool is_arithmetic_plus_v = is_arithmetic_plus<_Tp, _BinaryOperation>::value;
 
 template <typename _DifferenceType, typename _Tp, typename _BinaryOperation, typename _UnaryOperation>
-typename std::enable_if<is_arithmetic_plus<_Tp, _BinaryOperation>::value, _Tp>::type
+::std::enable_if_t<is_arithmetic_plus_v<_Tp, _BinaryOperation> && std::is_copy_constructible_v<_Tp>, _Tp>
 __simd_transform_reduce(_DifferenceType __n, _Tp __init, _BinaryOperation, _UnaryOperation __f) noexcept
 {
-    _PSTL_PRAGMA_SIMD_REDUCTION(+ : __init)
+    _ONEDPL_PRAGMA_SIMD_REDUCTION(+ : __init)
     for (_DifferenceType __i = 0; __i < __n; ++__i)
         __init += __f(__i);
     return __init;
 }
 
 template <typename _Size, typename _Tp, typename _BinaryOperation, typename _UnaryOperation>
-typename std::enable_if<!is_arithmetic_plus<_Tp, _BinaryOperation>::value, _Tp>::type
+::std::enable_if_t<!is_arithmetic_plus_v<_Tp, _BinaryOperation>, _Tp>
 __simd_transform_reduce(_Size __n, _Tp __init, _BinaryOperation __binary_op, _UnaryOperation __f) noexcept
 {
     const _Size __block_size = __lane_size / sizeof(_Tp);
@@ -463,7 +459,7 @@ __simd_transform_reduce(_Size __n, _Tp __init, _BinaryOperation __binary_op, _Un
         _Tp* __lane = reinterpret_cast<_Tp*>(__lane_);
 
         // initializer
-        _PSTL_PRAGMA_SIMD
+        _ONEDPL_PRAGMA_SIMD
         for (_Size __i = 0; __i < __block_size; ++__i)
         {
             ::new (__lane + __i) _Tp(__binary_op(__f(__i), __f(__block_size + __i)));
@@ -473,55 +469,55 @@ __simd_transform_reduce(_Size __n, _Tp __init, _BinaryOperation __binary_op, _Un
         const _Size last_iteration = __block_size * (__n / __block_size);
         for (; __i < last_iteration; __i += __block_size)
         {
-            _PSTL_PRAGMA_SIMD
+            _ONEDPL_PRAGMA_SIMD
             for (_Size __j = 0; __j < __block_size; ++__j)
             {
                 __lane[__j] = __binary_op(__lane[__j], __f(__i + __j));
             }
         }
         // remainder
-        _PSTL_PRAGMA_SIMD
+        _ONEDPL_PRAGMA_SIMD
         for (_Size __j = 0; __j < __n - last_iteration; ++__j)
         {
             __lane[__j] = __binary_op(__lane[__j], __f(last_iteration + __j));
         }
         // combiner
-        for (_Size __j = 0; __j < __block_size; ++__j)
+        for (_Size __i = 0; __i < __block_size; ++__i)
         {
-            __init = __binary_op(__init, __lane[__j]);
+            __init = __binary_op(std::move(__init), __lane[__i]);
         }
         // destroyer
-        _PSTL_PRAGMA_SIMD
-        for (_Size __j = 0; __j < __block_size; ++__j)
+        _ONEDPL_PRAGMA_SIMD
+        for (_Size __i = 0; __i < __block_size; ++__i)
         {
-            __lane[__j].~_Tp();
+            __lane[__i].~_Tp();
         }
     }
     else
     {
         for (_Size __i = 0; __i < __n; ++__i)
         {
-            __init = __binary_op(__init, __f(__i));
+            __init = __binary_op(std::move(__init), __f(__i));
         }
     }
-    return __init;
+    return std::move(__init);
 }
 
 // Exclusive scan for "+" and arithmetic types
 template <class _InputIterator, class _Size, class _OutputIterator, class _UnaryOperation, class _Tp,
           class _BinaryOperation>
-typename std::enable_if<is_arithmetic_plus<_Tp, _BinaryOperation>::value, std::pair<_OutputIterator, _Tp>>::type
+::std::enable_if_t<is_arithmetic_plus_v<_Tp, _BinaryOperation>, ::std::pair<_OutputIterator, _Tp>>
 __simd_scan(_InputIterator __first, _Size __n, _OutputIterator __result, _UnaryOperation __unary_op, _Tp __init,
-            _BinaryOperation, /*Inclusive*/ std::false_type)
+            _BinaryOperation, /*Inclusive*/ ::std::false_type)
 {
-    _PSTL_PRAGMA_SIMD_SCAN(+ : __init)
+    _ONEDPL_PRAGMA_SIMD_SCAN(+ : __init)
     for (_Size __i = 0; __i < __n; ++__i)
     {
         __result[__i] = __init;
-        _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(__init)
+        _ONEDPL_PRAGMA_SIMD_EXCLUSIVE_SCAN(__init)
         __init += __unary_op(__first[__i]);
     }
-    return std::make_pair(__result + __n, __init);
+    return ::std::make_pair(__result + __n, __init);
 }
 
 // As soon as we cannot call __binary_op in "combiner" we create a wrapper over _Tp to encapsulate __binary_op
@@ -532,9 +528,18 @@ struct _Combiner
     _BinaryOp* __bin_op; // Here is a pointer to function because of default ctor
 
     _Combiner() : __value{}, __bin_op(nullptr) {}
-    _Combiner(const _Tp& __v, const _BinaryOp* __b) : __value(__v), __bin_op(const_cast<_BinaryOp*>(__b)) {}
+    _Combiner(const _Tp& value, const _BinaryOp* bin_op) : __value(value), __bin_op(const_cast<_BinaryOp*>(bin_op)) {}
+    // TODO: That copy constructor breaks a private accumulator initialization according to the OpenMP spec:
+    // "initializer(omp_priv = omp_orig). That solution was done just for UDR simd bricks, when an identity
+    // value unknown and it assumes getting an identity by _Tp value initialization - _Tp{}.
     _Combiner(const _Combiner& __obj) : __value{}, __bin_op(__obj.__bin_op) {}
 
+    // This assignment operator copies the reduced value back to the caller
+    // It does not participate in the creation of an initial value,
+    // hence its behaviour is different from the copy constructor above
+    _Combiner&
+    operator=(const _Combiner& __obj) = default;
+
     void
     operator()(const _Combiner& __obj)
     {
@@ -545,67 +550,67 @@ struct _Combiner
 // Exclusive scan for other binary operations and types
 template <class _InputIterator, class _Size, class _OutputIterator, class _UnaryOperation, class _Tp,
           class _BinaryOperation>
-typename std::enable_if<!is_arithmetic_plus<_Tp, _BinaryOperation>::value, std::pair<_OutputIterator, _Tp>>::type
+::std::enable_if_t<!is_arithmetic_plus_v<_Tp, _BinaryOperation>, ::std::pair<_OutputIterator, _Tp>>
 __simd_scan(_InputIterator __first, _Size __n, _OutputIterator __result, _UnaryOperation __unary_op, _Tp __init,
-            _BinaryOperation __binary_op, /*Inclusive*/ std::false_type)
+            _BinaryOperation __binary_op, /*Inclusive*/ ::std::false_type)
 {
-    typedef _Combiner<_Tp, _BinaryOperation> _CombinerType;
+    using _CombinerType = _Combiner<_Tp, _BinaryOperation>;
     _CombinerType __init_{__init, &__binary_op};
 
-    _PSTL_PRAGMA_DECLARE_REDUCTION(__bin_op, _CombinerType)
+    _ONEDPL_PRAGMA_DECLARE_REDUCTION(__bin_op, _CombinerType)
 
-    _PSTL_PRAGMA_SIMD_SCAN(__bin_op : __init_)
+    _ONEDPL_PRAGMA_SIMD_SCAN(__bin_op : __init_)
     for (_Size __i = 0; __i < __n; ++__i)
     {
         __result[__i] = __init_.__value;
-        _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(__init_)
-        _PSTL_PRAGMA_FORCEINLINE
+        _ONEDPL_PRAGMA_SIMD_EXCLUSIVE_SCAN(__init_)
+        _ONEDPL_PRAGMA_FORCEINLINE
         __init_.__value = __binary_op(__init_.__value, __unary_op(__first[__i]));
     }
-    return std::make_pair(__result + __n, __init_.__value);
+    return ::std::make_pair(__result + __n, __init_.__value);
 }
 
 // Inclusive scan for "+" and arithmetic types
 template <class _InputIterator, class _Size, class _OutputIterator, class _UnaryOperation, class _Tp,
           class _BinaryOperation>
-typename std::enable_if<is_arithmetic_plus<_Tp, _BinaryOperation>::value, std::pair<_OutputIterator, _Tp>>::type
+::std::enable_if_t<is_arithmetic_plus_v<_Tp, _BinaryOperation>, ::std::pair<_OutputIterator, _Tp>>
 __simd_scan(_InputIterator __first, _Size __n, _OutputIterator __result, _UnaryOperation __unary_op, _Tp __init,
-            _BinaryOperation, /*Inclusive*/ std::true_type)
+            _BinaryOperation, /*Inclusive*/ ::std::true_type)
 {
-    _PSTL_PRAGMA_SIMD_SCAN(+ : __init)
+    _ONEDPL_PRAGMA_SIMD_SCAN(+ : __init)
     for (_Size __i = 0; __i < __n; ++__i)
     {
         __init += __unary_op(__first[__i]);
-        _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(__init)
+        _ONEDPL_PRAGMA_SIMD_INCLUSIVE_SCAN(__init)
         __result[__i] = __init;
     }
-    return std::make_pair(__result + __n, __init);
+    return ::std::make_pair(__result + __n, __init);
 }
 
 // Inclusive scan for other binary operations and types
 template <class _InputIterator, class _Size, class _OutputIterator, class _UnaryOperation, class _Tp,
           class _BinaryOperation>
-typename std::enable_if<!is_arithmetic_plus<_Tp, _BinaryOperation>::value, std::pair<_OutputIterator, _Tp>>::type
+::std::enable_if_t<!is_arithmetic_plus_v<_Tp, _BinaryOperation>, ::std::pair<_OutputIterator, _Tp>>
 __simd_scan(_InputIterator __first, _Size __n, _OutputIterator __result, _UnaryOperation __unary_op, _Tp __init,
-            _BinaryOperation __binary_op, std::true_type)
+            _BinaryOperation __binary_op, ::std::true_type)
 {
-    typedef _Combiner<_Tp, _BinaryOperation> _CombinerType;
+    using _CombinerType = _Combiner<_Tp, _BinaryOperation>;
     _CombinerType __init_{__init, &__binary_op};
 
-    _PSTL_PRAGMA_DECLARE_REDUCTION(__bin_op, _CombinerType)
+    _ONEDPL_PRAGMA_DECLARE_REDUCTION(__bin_op, _CombinerType)
 
-    _PSTL_PRAGMA_SIMD_SCAN(__bin_op : __init_)
+    _ONEDPL_PRAGMA_SIMD_SCAN(__bin_op : __init_)
     for (_Size __i = 0; __i < __n; ++__i)
     {
-        _PSTL_PRAGMA_FORCEINLINE
+        _ONEDPL_PRAGMA_FORCEINLINE
         __init_.__value = __binary_op(__init_.__value, __unary_op(__first[__i]));
-        _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(__init_)
+        _ONEDPL_PRAGMA_SIMD_INCLUSIVE_SCAN(__init_)
         __result[__i] = __init_.__value;
     }
-    return std::make_pair(__result + __n, __init_.__value);
+    return ::std::make_pair(__result + __n, __init_.__value);
 }
 
-// [restriction] - std::iterator_traits<_ForwardIterator>::value_type should be DefaultConstructible.
+// [restriction] - ::std::iterator_traits<_ForwardIterator>::value_type should be DefaultConstructible.
 // complexity [violation] - We will have at most (__n-1 + number_of_lanes) comparisons instead of at most __n-1.
 template <typename _ForwardIterator, typename _Size, typename _Compare>
 _ForwardIterator
@@ -616,29 +621,28 @@ __simd_min_element(_ForwardIterator __first, _Size __n, _Compare __comp) noexcep
         return __first;
     }
 
-    typedef typename std::iterator_traits<_ForwardIterator>::value_type _ValueType;
+    using _ValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
     struct _ComplexType
     {
         _ValueType __min_val;
         _Size __min_ind;
         _Compare* __min_comp;
+        // The default constructor is not used during the algorithm, so it is not required for it.
+        // However, some compilers may require it.
 
         _ComplexType() : __min_val{}, __min_ind{}, __min_comp(nullptr) {}
         _ComplexType(const _ValueType& val, const _Compare* comp)
             : __min_val(val), __min_ind(0), __min_comp(const_cast<_Compare*>(comp))
         {
         }
-        _ComplexType(const _ComplexType& __obj)
-            : __min_val(__obj.__min_val), __min_ind(__obj.__min_ind), __min_comp(__obj.__min_comp)
-        {
-        }
+        _ComplexType(const _ComplexType& __obj) = default;
 
-        _PSTL_PRAGMA_DECLARE_SIMD
+        _ONEDPL_PRAGMA_DECLARE_SIMD
         void
         operator()(const _ComplexType& __obj)
         {
-            if (!(*__min_comp)(__min_val, __obj.__min_val) &&
-                ((*__min_comp)(__obj.__min_val, __min_val) || __obj.__min_ind - __min_ind < 0))
+            if (!std::invoke(*__min_comp, __min_val, __obj.__min_val) &&
+                (std::invoke(*__min_comp, __obj.__min_val, __min_val) || __obj.__min_ind - __min_ind < 0))
             {
                 __min_val = __obj.__min_val;
                 __min_ind = __obj.__min_ind;
@@ -648,14 +652,14 @@ __simd_min_element(_ForwardIterator __first, _Size __n, _Compare __comp) noexcep
 
     _ComplexType __init{*__first, &__comp};
 
-    _PSTL_PRAGMA_DECLARE_REDUCTION(__min_func, _ComplexType)
+    _ONEDPL_PRAGMA_DECLARE_REDUCTION(__min_func, _ComplexType)
 
-    _PSTL_PRAGMA_SIMD_REDUCTION(__min_func : __init)
+    _ONEDPL_PRAGMA_SIMD_REDUCTION(__min_func : __init)
     for (_Size __i = 1; __i < __n; ++__i)
     {
         const _ValueType __min_val = __init.__min_val;
         const _ValueType __current = __first[__i];
-        if (__comp(__current, __min_val))
+        if (std::invoke(__comp, __current, __min_val))
         {
             __init.__min_val = __current;
             __init.__min_ind = __i;
@@ -664,17 +668,17 @@ __simd_min_element(_ForwardIterator __first, _Size __n, _Compare __comp) noexcep
     return __first + __init.__min_ind;
 }
 
-// [restriction] - std::iterator_traits<_ForwardIterator>::value_type should be DefaultConstructible.
+// [restriction] - ::std::iterator_traits<_ForwardIterator>::value_type should be DefaultConstructible.
 // complexity [violation] - We will have at most (2*(__n-1) + 4*number_of_lanes) comparisons instead of at most [1.5*(__n-1)].
 template <typename _ForwardIterator, typename _Size, typename _Compare>
-std::pair<_ForwardIterator, _ForwardIterator>
+::std::pair<_ForwardIterator, _ForwardIterator>
 __simd_minmax_element(_ForwardIterator __first, _Size __n, _Compare __comp) noexcept
 {
     if (__n == 0)
     {
-        return std::make_pair(__first, __first);
+        return ::std::make_pair(__first, __first);
     }
-    typedef typename std::iterator_traits<_ForwardIterator>::value_type _ValueType;
+    using _ValueType = typename std::iterator_traits<_ForwardIterator>::value_type;
 
     struct _ComplexType
     {
@@ -683,41 +687,40 @@ __simd_minmax_element(_ForwardIterator __first, _Size __n, _Compare __comp) noex
         _Size __min_ind;
         _Size __max_ind;
         _Compare* __minmax_comp;
+        // The default constructor is not used during the algorithm, so it is not required for it.
+        // However, some compilers may require it.
 
         _ComplexType() : __min_val{}, __max_val{}, __min_ind{}, __max_ind{}, __minmax_comp(nullptr) {}
-        _ComplexType(const _ValueType& __min, const _ValueType& __max, const _Compare* __comp)
-            : __min_val(__min), __max_val(__max), __min_ind(0), __max_ind(0),
-              __minmax_comp(const_cast<_Compare*>(__comp))
-        {
-        }
-        _ComplexType(const _ComplexType& __obj)
-            : __min_val(__obj.__min_val), __max_val(__obj.__max_val), __min_ind(__obj.__min_ind),
-              __max_ind(__obj.__max_ind), __minmax_comp(__obj.__minmax_comp)
+        _ComplexType(const _ValueType& min_val, const _ValueType& max_val, const _Compare* comp)
+            : __min_val(min_val), __max_val(max_val), __min_ind(0), __max_ind(0),
+              __minmax_comp(const_cast<_Compare*>(comp))
         {
         }
+        _ComplexType(const _ComplexType& __obj) = default;
 
+        _ONEDPL_PRAGMA_DECLARE_SIMD
         void
         operator()(const _ComplexType& __obj)
         {
             // min
-            if ((*__minmax_comp)(__obj.__min_val, __min_val))
+            if (std::invoke(*__minmax_comp, __obj.__min_val, __min_val))
             {
                 __min_val = __obj.__min_val;
                 __min_ind = __obj.__min_ind;
             }
-            else if (!(*__minmax_comp)(__min_val, __obj.__min_val))
+            else if (!std::invoke(*__minmax_comp, __min_val, __obj.__min_val))
             {
                 __min_val = __obj.__min_val;
                 __min_ind = (__min_ind - __obj.__min_ind < 0) ? __min_ind : __obj.__min_ind;
             }
 
             // max
-            if ((*__minmax_comp)(__max_val, __obj.__max_val))
+            if (std::invoke(*__minmax_comp, __max_val, __obj.__max_val))
             {
                 __max_val = __obj.__max_val;
                 __max_ind = __obj.__max_ind;
             }
-            else if (!(*__minmax_comp)(__obj.__max_val, __max_val))
+            else if (!std::invoke(*__minmax_comp, __obj.__max_val, __max_val))
             {
                 __max_val = __obj.__max_val;
                 __max_ind = (__max_ind - __obj.__max_ind < 0) ? __obj.__max_ind : __max_ind;
@@ -727,40 +730,40 @@ __simd_minmax_element(_ForwardIterator __first, _Size __n, _Compare __comp) noex
 
     _ComplexType __init{*__first, *__first, &__comp};
 
-    _PSTL_PRAGMA_DECLARE_REDUCTION(__min_func, _ComplexType);
+    _ONEDPL_PRAGMA_DECLARE_REDUCTION(__min_func, _ComplexType);
 
-    _PSTL_PRAGMA_SIMD_REDUCTION(__min_func : __init)
+    _ONEDPL_PRAGMA_SIMD_REDUCTION(__min_func : __init)
     for (_Size __i = 1; __i < __n; ++__i)
     {
         auto __min_val = __init.__min_val;
         auto __max_val = __init.__max_val;
-        auto __current = __first + __i;
-        if (__comp(*__current, __min_val))
+        auto __current = __first[__i];
+        if (std::invoke(__comp, __current, __min_val))
         {
-            __init.__min_val = *__current;
+            __init.__min_val = __current;
             __init.__min_ind = __i;
         }
-        else if (!__comp(*__current, __max_val))
+        else if (!std::invoke(__comp, __current, __max_val))
         {
-            __init.__max_val = *__current;
+            __init.__max_val = __current;
             __init.__max_ind = __i;
         }
     }
-    return std::make_pair(__first + __init.__min_ind, __first + __init.__max_ind);
+    return ::std::make_pair(__first + __init.__min_ind, __first + __init.__max_ind);
 }
 
 template <class _InputIterator, class _DifferenceType, class _OutputIterator1, class _OutputIterator2,
           class _UnaryPredicate>
-std::pair<_OutputIterator1, _OutputIterator2>
+::std::pair<_OutputIterator1, _OutputIterator2>
 __simd_partition_copy(_InputIterator __first, _DifferenceType __n, _OutputIterator1 __out_true,
                       _OutputIterator2 __out_false, _UnaryPredicate __pred) noexcept
 {
     _DifferenceType __cnt_true = 0, __cnt_false = 0;
 
-    _PSTL_PRAGMA_SIMD
+    _ONEDPL_PRAGMA_SIMD
     for (_DifferenceType __i = 0; __i < __n; ++__i)
     {
-        _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(__cnt_true : 1, __cnt_false : 1)
+        _ONEDPL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(__cnt_true : 1, __cnt_false : 1)
         if (__pred(__first[__i]))
         {
             __out_true[__cnt_true] = __first[__i];
@@ -772,7 +775,7 @@ __simd_partition_copy(_InputIterator __first, _DifferenceType __n, _OutputIterat
             ++__cnt_false;
         }
     }
-    return std::make_pair(__out_true + __cnt_true, __out_false + __cnt_false);
+    return ::std::make_pair(__out_true + __cnt_true, __out_false + __cnt_false);
 }
 
 template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
@@ -780,7 +783,7 @@ _ForwardIterator1
 __simd_find_first_of(_ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
                      _ForwardIterator2 __s_last, _BinaryPredicate __pred) noexcept
 {
-    typedef typename std::iterator_traits<_ForwardIterator1>::difference_type _DifferencType;
+    using _DifferencType = typename std::iterator_traits<_ForwardIterator1>::difference_type;
 
     const _DifferencType __n1 = __last - __first;
     const _DifferencType __n2 = __s_last - __s_first;
@@ -794,11 +797,11 @@ __simd_find_first_of(_ForwardIterator1 __first, _ForwardIterator1 __last, _Forwa
     // Otherwise, vice versa.
     if (__n1 < __n2)
     {
+        auto __u_pred =
+            [__pred, __first](auto&& __val) mutable { return __pred(std::forward<decltype(__val)>(__val), *__first); };
         for (; __first != __last; ++__first)
         {
-            if (__unseq_backend::__simd_or(
-                    __s_first, __n2,
-                    __internal::__equal_value_by_pred<decltype(*__first), _BinaryPredicate>(*__first, __pred)))
+            if (__unseq_backend::__simd_or(__s_first, __n2, __u_pred))
             {
                 return __first;
             }
@@ -826,31 +829,29 @@ _RandomAccessIterator
 __simd_remove_if(_RandomAccessIterator __first, _DifferenceType __n, _UnaryPredicate __pred) noexcept
 {
     // find first element we need to remove
-    auto __current = __unseq_backend::__simd_first(
-        __first, _DifferenceType(0), __n,
-        [&__pred](_RandomAccessIterator __it, _DifferenceType __i) { return __pred(__it[__i]); });
-    __n -= __current - __first;
+    auto __start = __unseq_backend::__simd_first(__first, _DifferenceType(0), __n, __internal::__pred_at_index{__pred});
+    __n -= __start - __first;
 
-    // if we have in sequence only one element that pred(__current[1]) != false we can exit the function
+    // if we have in sequence only one element that pred(__start[1]) != false we can exit the function
     if (__n < 2)
     {
-        return __current;
+        return __start;
     }
 
     _DifferenceType __cnt = 0;
-    _PSTL_PRAGMA_SIMD
+    _ONEDPL_PRAGMA_SIMD
     for (_DifferenceType __i = 1; __i < __n; ++__i)
     {
-        _PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(__cnt : 1)
-        if (!__pred(__current[__i]))
+        _ONEDPL_PRAGMA_SIMD_ORDERED_MONOTONIC(__cnt : 1)
+        if (!__pred(__start[__i]))
         {
-            __current[__cnt] = std::move(__current[__i]);
+            __start[__cnt] = ::std::move(__start[__i]);
             ++__cnt;
         }
     }
-    return __current + __cnt;
+    return __start + __cnt;
 }
 } // namespace __unseq_backend
-} // namespace __pstl
+} // namespace std::__onedpl
 
-#endif /* _PSTL_UNSEQ_BACKEND_SIMD_H */
+#endif // _ONEDPL_UNSEQ_BACKEND_SIMD_H
diff --git a/libstdc++-v3/include/pstl/utils.h b/libstdc++-v3/include/pstl/utils.h
index e2611053f534..2e127205e5dd 100644
--- a/libstdc++-v3/include/pstl/utils.h
+++ b/libstdc++-v3/include/pstl/utils.h
@@ -1,23 +1,67 @@
 // -*- C++ -*-
-//===-- utils.h -----------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef _PSTL_UTILS_H
-#define _PSTL_UTILS_H
+#ifndef _ONEDPL_UTILS_H
+#define _ONEDPL_UTILS_H
+
+#include "onedpl_config.h"
+#include "tuple_impl.h" // Internal tuple and get specializations needed by __segmented_scan_fun
 
 #include <new>
+#include <tuple>
+#include <utility>
+#include <climits>
+#include <iterator>
+#include <functional>
 #include <type_traits>
+#include <algorithm>
+#include <cmath>
+#include <cstdint>
+#include <exception>
 
-namespace __pstl
+#if _ONEDPL_BACKEND_SYCL
+#    include "hetero/dpcpp/sycl_defs.h"
+#    include "hetero/dpcpp/sycl_iterator.h"
+#endif
+
+#if __has_include(<bit>)
+#    include <bit>
+#endif
+
+#if !(__cpp_lib_bit_cast >= 201806L)
+#    ifndef __has_builtin
+#        define __has_builtin(__x) 0
+#    endif
+#    include <cstring> // memcpy
+#endif
+
+#if _ONEDPL_CPP20_CONCEPTS_PRESENT
+#    include <concepts> // for std::equality_comparable_with
+#endif
+
+#include "functional_impl.h"
+
+namespace std::__onedpl
 {
 namespace __internal
 {
 
+template <typename Iterator>
+using is_const_iterator =
+    typename ::std::is_const<::std::remove_pointer_t<typename ::std::iterator_traits<Iterator>::pointer>>;
+
 template <typename _Fp>
 auto
 __except_handler(_Fp __f) -> decltype(__f())
@@ -26,96 +70,215 @@ __except_handler(_Fp __f) -> decltype(__f())
     {
         return __f();
     }
-    catch (const std::bad_alloc&)
+    catch (const ::std::bad_alloc&)
     {
         throw; // re-throw bad_alloc according to the standard [algorithms.parallel.exceptions]
     }
     catch (...)
     {
-        std::__terminate(); // Good bye according to the standard [algorithms.parallel.exceptions]
+        ::std::terminate(); // Good bye according to the standard [algorithms.parallel.exceptions]
     }
 }
 
-template <typename _Fp>
-void
-__invoke_if(std::true_type, _Fp __f)
+//! Logical negation of a predicate
+template <typename _Pred>
+class __not_pred
 {
-    __f();
-}
+    _Pred _M_pred;
 
-template <typename _Fp>
-void __invoke_if(std::false_type, _Fp)
-{
-}
+  public:
+    explicit __not_pred(_Pred __pred) : _M_pred(__pred) {}
 
-template <typename _Fp>
-void
-__invoke_if_not(std::false_type, _Fp __f)
-{
-    __f();
-}
-
-template <typename _Fp>
-void __invoke_if_not(std::true_type, _Fp)
-{
-}
-
-template <typename _F1, typename _F2>
-auto
-__invoke_if_else(std::true_type, _F1 __f1, _F2) -> decltype(__f1())
-{
-    return __f1();
-}
-
-template <typename _F1, typename _F2>
-auto
-__invoke_if_else(std::false_type, _F1, _F2 __f2) -> decltype(__f2())
-{
-    return __f2();
-}
-
-//! Unary operator that returns reference to its argument.
-struct __no_op
-{
-    template <typename _Tp>
-    _Tp&&
-    operator()(_Tp&& __a) const
+    template <typename... _Args>
+    bool
+    operator()(_Args&&... __args) const
     {
-        return std::forward<_Tp>(__a);
+        return !std::invoke(_M_pred, std::forward<_Args>(__args)...);
     }
 };
 
+//! Change the order of arguments when invoking a binary predicate
 template <typename _Pred>
 class __reorder_pred
 {
-    _Pred _M_pred;
+    mutable _Pred _M_pred;
 
   public:
     explicit __reorder_pred(_Pred __pred) : _M_pred(__pred) {}
 
     template <typename _FTp, typename _STp>
     bool
-    operator()(_FTp&& __a, _STp&& __b)
+    operator()(_FTp&& __a, _STp&& __b) const
     {
-        return _M_pred(std::forward<_STp>(__b), std::forward<_FTp>(__a));
+        return std::invoke(_M_pred, std::forward<_STp>(__b), std::forward<_FTp>(__a));
     }
 };
 
-//! Like a polymorphic lambda for pred(...,value)
-template <typename _Tp, typename _Predicate>
-class __equal_value_by_pred
+//! Apply a predicate to an element at a given index of a random-access sequence
+template <typename _Pred>
+class __pred_at_index
 {
-    const _Tp& _M_value;
-    _Predicate _M_pred;
+    mutable _Pred _M_pred;
 
   public:
-    __equal_value_by_pred(const _Tp& __value, _Predicate __pred) : _M_value(__value), _M_pred(__pred) {}
+    explicit __pred_at_index(_Pred __pred) : _M_pred(__pred) {}
 
-    template <typename _Arg>
+    template <typename _RandomAccessTp, typename _IndexTp>
     bool
-    operator()(_Arg&& __arg)
+    operator()(_RandomAccessTp&& __arr, _IndexTp __i) const
     {
-        return _M_pred(std::forward<_Arg>(__arg), _M_value);
+        return _M_pred(__arr[__i]);
+    }
+};
+
+//! Apply a predicate to two consecutive elements of a random-access sequence to find non-equivalent (unique) ones
+template <typename _Pred, bool _CheckZero = false>
+class __unique_at_index
+{
+    mutable _Pred _M_pred;
+
+  public:
+    explicit __unique_at_index(_Pred __pred) : _M_pred(__pred) {}
+
+    template <typename _RandomAccessTp, typename _IndexTp>
+    bool
+    operator()(_RandomAccessTp&& __arr, _IndexTp __i) const
+    {
+        if constexpr (_CheckZero)
+        {
+            if (__i == 0)
+                return true;
+        }
+        else
+            static_assert(std::is_signed_v<_IndexTp>, "The index of an unsigned type can cause a wraparound error.");
+
+        return !_M_pred(__arr[__i], __arr[__i - 1]);
+    }
+};
+
+//! Custom assignment operator used in copy_if and other algorithms using predicates
+class __pstl_assign
+{
+  public:
+    // rvalue reference used for output parameter to allow assignment of std::tuple of references.
+    // The output is the second argument because the output range is passed to the algorithm as the second range.
+    template <typename _Xp, typename _Yp>
+    void
+    operator()(const _Xp& __x, _Yp&& __y) const
+    {
+        ::std::forward<_Yp>(__y) = __x;
+    }
+};
+
+template <typename _F, typename _Proj>
+struct __unary_op
+{
+    //'mutable' is to relax the requirements for a user functor or/and projection type operator() may be non-const
+    mutable _F __f;
+    mutable _Proj __proj;
+
+    template <typename _TValue>
+    decltype(auto)
+    operator()(_TValue&& __val) const
+    {
+        return std::invoke(__f, std::invoke(__proj, std::forward<_TValue>(__val)));
+    }
+};
+
+template <typename _F, typename _Proj1, typename _Proj2>
+struct __binary_op
+{
+    //'mutable' is to relax the requirements for a user functor or/and projection type operator() may be non-const
+    mutable _F __f;
+    mutable _Proj1 __proj1;
+    mutable _Proj2 __proj2;
+
+    template <typename _TValue1, typename _TValue2>
+    decltype(auto)
+    operator()(_TValue1&& __val1, _TValue2&& __val2) const
+    {
+        return std::invoke(__f, std::invoke(__proj1, std::forward<_TValue1>(__val1)),
+                           std::invoke(__proj2, std::forward<_TValue2>(__val2)));
+    }
+};
+
+//! "==" comparison.
+/** Not called "equal" to avoid (possibly unfounded) concerns about accidental invocation via
+    argument-dependent name lookup by code expecting to find the usual ::std::equal. */
+class __pstl_equal
+{
+  public:
+    template <typename _Xp, typename _Yp>
+    bool
+    operator()(_Xp&& __x, _Yp&& __y) const
+    {
+        return ::std::forward<_Xp>(__x) == ::std::forward<_Yp>(__y);
+    }
+};
+
+//! "<" comparison.
+class __pstl_less
+{
+  public:
+    template <typename _Xp, typename _Yp>
+    bool
+    operator()(_Xp&& __x, _Yp&& __y) const
+    {
+        return ::std::forward<_Xp>(__x) < ::std::forward<_Yp>(__y);
+    }
+};
+
+//! ">" comparison.
+class __pstl_greater
+{
+  public:
+    template <typename _Xp, typename _Yp>
+    bool
+    operator()(_Xp&& __x, _Yp&& __y) const
+    {
+        return ::std::forward<_Xp>(__x) > ::std::forward<_Yp>(__y);
+    }
+};
+
+//! General "+" operation
+class __pstl_plus
+{
+  public:
+    template <typename _Xp, typename _Yp>
+    auto
+    operator()(_Xp&& __x, _Yp&& __y) const -> decltype(::std::forward<_Xp>(__x) + ::std::forward<_Yp>(__y))
+    {
+        return ::std::forward<_Xp>(__x) + ::std::forward<_Yp>(__y);
+    }
+};
+
+//! min calculation.
+class __pstl_min
+{
+  public:
+    template <typename _Xp, typename _Yp>
+    auto
+    operator()(_Xp&& __x, _Yp&& __y) const
+        -> decltype((::std::forward<_Xp>(__x) < ::std::forward<_Yp>(__y)) ? ::std::forward<_Xp>(__x)
+                                                                          : ::std::forward<_Yp>(__y))
+    {
+        return (::std::forward<_Xp>(__x) < ::std::forward<_Yp>(__y)) ? ::std::forward<_Xp>(__x)
+                                                                     : ::std::forward<_Yp>(__y);
+    }
+};
+
+//! max calculation.
+class __pstl_max
+{
+  public:
+    template <typename _Xp, typename _Yp>
+    auto
+    operator()(_Xp&& __x, _Yp&& __y) const
+        -> decltype((::std::forward<_Xp>(__x) > ::std::forward<_Yp>(__y)) ? ::std::forward<_Xp>(__x)
+                                                                          : ::std::forward<_Yp>(__y))
+    {
+        return (::std::forward<_Xp>(__x) > ::std::forward<_Yp>(__y)) ? ::std::forward<_Xp>(__x)
+                                                                     : ::std::forward<_Yp>(__y);
     }
 };
 
@@ -123,7 +286,7 @@ class __equal_value_by_pred
 template <typename _Tp>
 class __equal_value
 {
-    const _Tp& _M_value;
+    const _Tp _M_value;
 
   public:
     explicit __equal_value(const _Tp& __value) : _M_value(__value) {}
@@ -132,7 +295,7 @@ class __equal_value
     bool
     operator()(_Arg&& __arg) const
     {
-        return std::forward<_Arg>(__arg) == _M_value;
+        return ::std::forward<_Arg>(__arg) == _M_value;
     }
 };
 
@@ -140,7 +303,7 @@ class __equal_value
 template <typename _Tp>
 class __not_equal_value
 {
-    const _Tp& _M_value;
+    const _Tp _M_value;
 
   public:
     explicit __not_equal_value(const _Tp& __value) : _M_value(__value) {}
@@ -149,25 +312,869 @@ class __not_equal_value
     bool
     operator()(_Arg&& __arg) const
     {
-        return !(std::forward<_Arg>(__arg) == _M_value);
+        return !(::std::forward<_Arg>(__arg) == _M_value);
     }
 };
 
-template <typename _ForwardIterator, typename _Compare>
-_ForwardIterator
-__cmp_iterators_by_values(_ForwardIterator __a, _ForwardIterator __b, _Compare __comp)
+template <typename _Tp>
+class __set_value
 {
-    if (__a < __b)
+    const _Tp _M_value;
+
+  public:
+    explicit __set_value(const _Tp& __value) : _M_value(__value) {}
+
+    template <typename _Arg>
+    void
+    operator()(_Arg&& __arg) const
+    {
+        std::forward<_Arg>(__arg) = _M_value;
+    }
+};
+
+//TODO: to do the same fix  for output type (by re-using __transform_functor if applicable) for the other functor below:
+// __transform_if_unary_functor, __transform_if_binary_functor, __replace_functor, __replace_copy_functor
+template <typename _F, typename _RevTag = std::false_type>
+class __transform_functor
+{
+    mutable _F __f;
+
+  public:
+    explicit __transform_functor(_F __f) : __f(std::move(__f)) {}
+
+    template <typename _Input1Type, typename _Input2Type, typename _OutputType>
+    void
+    operator()(_Input1Type&& __x, _Input2Type&& __y, _OutputType&& __output) const
+    {
+        if constexpr (_RevTag())
+            __transform_impl(std::forward<_OutputType>(__output), std::forward<_Input1Type>(__y),
+                             std::forward<_Input2Type>(__x));
+        else
+            __transform_impl(std::forward<_OutputType>(__output), std::forward<_Input1Type>(__x),
+                             std::forward<_Input2Type>(__y));
+    }
+
+    template <typename _InputType, typename _OutputType>
+    void
+    operator()(_InputType&& __x, _OutputType&& __output) const
+    {
+        __transform_impl(std::forward<_OutputType>(__output), std::forward<_InputType>(__x));
+    }
+
+  private:
+    template <typename _OutputType, typename... _Args>
+    void
+    __transform_impl(_OutputType&& __output, _Args&&... __args) const
+    {
+        static_assert(sizeof...(_Args) < 3, "A functor supports either unary or binary transformation");
+        static_assert(::std::is_invocable_v<_F, _Args...>, "A functor cannot be called with the passed arguments");
+        std::forward<_OutputType>(__output) = __f(std::forward<_Args>(__args)...);
+    }
+};
+
+template <typename _UnaryOper, typename _UnaryPred>
+class __transform_if_unary_functor
+{
+    mutable _UnaryOper _M_oper;
+    mutable _UnaryPred _M_pred;
+
+  public:
+    explicit __transform_if_unary_functor(_UnaryOper __op, _UnaryPred __pred)
+        : _M_oper(std::move(__op)), _M_pred(std::move(__pred))
+    {
+    }
+
+    template <typename _Input1Type, typename _OutputType>
+    void
+    operator()(const _Input1Type& x, _OutputType& y) const
+    {
+        if (_M_pred(x))
+            y = _M_oper(x);
+    }
+};
+
+template <typename _BinaryOper, typename _BinaryPred>
+class __transform_if_binary_functor
+{
+    mutable _BinaryOper _M_oper;
+    mutable _BinaryPred _M_pred;
+
+  public:
+    explicit __transform_if_binary_functor(_BinaryOper __op, _BinaryPred __pred)
+        : _M_oper(std::move(__op)), _M_pred(std::move(__pred))
+    {
+    }
+
+    template <typename _Input1Type, typename _Input2Type, typename _OutputType>
+    void
+    operator()(const _Input1Type& x, const _Input2Type& y, _OutputType& z) const
+    {
+        if (_M_pred(x, y))
+            z = _M_oper(x, y);
+    }
+};
+
+template <typename _Tp, typename _Pred>
+class __replace_functor
+{
+    const _Tp _M_value;
+    _Pred _M_pred;
+
+  public:
+    __replace_functor(const _Tp& __value, _Pred __pred) : _M_value(__value), _M_pred(__pred) {}
+
+    template <typename _OutputType>
+    void
+    operator()(_OutputType& __elem) const
+    {
+        if (_M_pred(__elem))
+            __elem = _M_value;
+    }
+};
+
+template <typename _Tp, typename _Pred>
+class __replace_copy_functor
+{
+    const _Tp _M_value;
+    _Pred _M_pred;
+
+  public:
+    __replace_copy_functor(const _Tp& __value, _Pred __pred) : _M_value(__value), _M_pred(__pred) {}
+
+    template <typename _InputType, typename _OutputType>
+    void
+    operator()(const _InputType& __x, _OutputType& __y) const
+    {
+        __y = _M_pred(__x) ? _M_value : __x;
+    }
+};
+
+//! Like ::std::next, but with specialization for dpcpp case
+template <typename _Iter>
+_Iter
+__pstl_next(_Iter __iter, typename ::std::iterator_traits<_Iter>::difference_type __n = 1)
+{
+    return ::std::next(__iter, __n);
+}
+
+#if _ONEDPL_BACKEND_SYCL
+template <sycl::access::mode _Mode, typename... _Params>
+__onedpl::__internal::sycl_iterator<_Mode, _Params...>
+__pstl_next(
+    __onedpl::__internal::sycl_iterator<_Mode, _Params...> __iter,
+    typename ::std::iterator_traits<__onedpl::__internal::sycl_iterator<_Mode, _Params...>>::difference_type __n = 1)
+{
+    return __iter + __n;
+}
+#endif
+
+template <typename _ForwardIterator, typename _Compare, typename _CompareIt>
+_ForwardIterator
+__cmp_iterators_by_values(_ForwardIterator __a, _ForwardIterator __b, _Compare __comp, _CompareIt __comp_it)
+{
+    if (__comp_it(__a, __b))
     { // we should return closer iterator
-        return __comp(*__b, *__a) ? __b : __a;
+        return std::invoke(__comp, *__b, *__a) ? __b : __a;
     }
     else
     {
-        return __comp(*__a, *__b) ? __a : __b;
+        return std::invoke(__comp, *__a, *__b) ? __a : __b;
     }
 }
 
-} // namespace __internal
-} // namespace __pstl
+// Aliases for adjacent_find compile-time dispatching
+using __or_semantic = ::std::true_type;
+using __first_semantic = ::std::false_type;
 
-#endif /* _PSTL_UTILS_H */
+// is_callable_object
+template <typename _Tp, typename = void>
+struct __is_callable_object : ::std::false_type
+{
+};
+
+template <typename _Tp>
+struct __is_callable_object<_Tp, ::std::void_t<decltype(&_Tp::operator())>> : ::std::true_type
+{
+};
+
+// is_pointer_to_const_member
+template <typename _Tp>
+struct __is_pointer_to_const_member_impl : ::std::false_type
+{
+};
+
+template <typename _R, typename _U, typename... _Args>
+struct __is_pointer_to_const_member_impl<_R (_U::*)(_Args...) const> : ::std::true_type
+{
+};
+
+template <typename _R, typename _U, typename... _Args>
+struct __is_pointer_to_const_member_impl<_R (_U::*)(_Args...) const noexcept> : ::std::true_type
+{
+};
+
+template <typename _Tp, bool = __is_callable_object<_Tp>::value>
+struct __is_pointer_to_const_member : ::std::false_type
+{
+};
+
+template <typename _Tp>
+struct __is_pointer_to_const_member<_Tp, true> : __is_pointer_to_const_member_impl<decltype(&_Tp::operator())>
+{
+};
+
+// is_const_callable_object to check whether we call const or non-const object
+template <typename _Tp>
+using __is_const_callable_object =
+    ::std::integral_constant<bool, __is_callable_object<_Tp>::value && __is_pointer_to_const_member<_Tp>::value>;
+
+template <typename _Tp>
+inline constexpr bool __is_const_callable_object_v = __is_const_callable_object<_Tp>::value;
+
+struct __next_to_last
+{
+    template <typename _Iterator>
+    ::std::enable_if_t<::std::is_base_of_v<::std::random_access_iterator_tag,
+                                           typename ::std::iterator_traits<_Iterator>::iterator_category>,
+                       _Iterator>
+    operator()(_Iterator __it, _Iterator __last, typename ::std::iterator_traits<_Iterator>::difference_type __n)
+    {
+        return __n > __last - __it ? __last : __it + __n;
+    }
+
+    template <typename _Iterator>
+    ::std::enable_if_t<!::std::is_base_of_v<::std::random_access_iterator_tag,
+                                            typename ::std::iterator_traits<_Iterator>::iterator_category>,
+                       _Iterator>
+    operator()(_Iterator __it, _Iterator __last, typename ::std::iterator_traits<_Iterator>::difference_type __n)
+    {
+        for (; --__n >= 0 && __it != __last; ++__it)
+            ;
+        return __it;
+    }
+};
+
+template <typename _T, class _Enable = void>
+class __future;
+
+// empty base class for type erasure
+struct __lifetime_keeper_base
+{
+    virtual ~__lifetime_keeper_base() = default;
+};
+
+// derived class to keep temporaries (e.g. buffer) alive
+template <typename... Ts>
+struct __lifetime_keeper : public __lifetime_keeper_base
+{
+    ::std::tuple<Ts...> __my_tmps;
+    __lifetime_keeper(Ts... __t) : __my_tmps(::std::make_tuple(__t...)) {}
+};
+
+//-----------------------------------------------------------------------
+// Generic bit- and number-manipulation routines
+//-----------------------------------------------------------------------
+
+// Bitwise type casting, same as C++20 std::bit_cast
+template <typename _Dst, typename _Src>
+::std::enable_if_t<
+    sizeof(_Dst) == sizeof(_Src) && ::std::is_trivially_copyable_v<_Dst> && ::std::is_trivially_copyable_v<_Src>, _Dst>
+__dpl_bit_cast(const _Src& __src) noexcept
+{
+#if __cpp_lib_bit_cast >= 201806L
+    return ::std::bit_cast<_Dst>(__src);
+#elif _ONEDPL_BACKEND_SYCL && _ONEDPL_SYCL2020_BITCAST_PRESENT
+    return sycl::bit_cast<_Dst>(__src);
+#elif __has_builtin(__builtin_bit_cast)
+    return __builtin_bit_cast(_Dst, __src);
+#else
+    _Dst __result;
+    ::std::memcpy(&__result, &__src, sizeof(_Dst));
+    return __result;
+#endif
+}
+
+// The max power of 2 not exceeding the given value, same as C++20 std::bit_floor
+template <typename _T>
+::std::enable_if_t<::std::is_integral_v<_T> && ::std::is_unsigned_v<_T>, _T>
+__dpl_bit_floor(_T __x) noexcept
+{
+    if (__x == 0)
+        return 0;
+#if __cpp_lib_int_pow2 >= 202002L && !_ONEDPL_STD_BIT_FLOOR_BROKEN
+    return ::std::bit_floor(__x);
+#elif _ONEDPL_BACKEND_SYCL
+    // Use the count-leading-zeros function
+    return _T{1} << (sizeof(_T) * CHAR_BIT - sycl::clz(__x) - 1);
+#else
+    // Fill all the lower bits with 1s
+    __x |= (__x >> 1);
+    __x |= (__x >> 2);
+    __x |= (__x >> 4);
+    if constexpr (sizeof(_T) > 1) __x |= (__x >> 8);
+    if constexpr (sizeof(_T) > 2) __x |= (__x >> 16);
+    if constexpr (sizeof(_T) > 4) __x |= (__x >> 32);
+    __x += 1; // Now it equals to the next greater power of 2, or 0 in case of wraparound
+    return (__x == 0) ? _T{1} << (sizeof(_T) * CHAR_BIT - 1) : __x >> 1;
+#endif
+}
+
+// The max power of 2 not smaller than the given value, same as C++20 std::bit_ceil
+template <typename _T>
+::std::enable_if_t<::std::is_integral_v<_T> && ::std::is_unsigned_v<_T>, _T>
+__dpl_bit_ceil(_T __x) noexcept
+{
+    return ((__x & (__x - 1)) != 0) ? __dpl_bit_floor(__x) << 1 : __x;
+}
+
+// rounded up result of (__number / __divisor)
+template <typename _T1, typename _T2>
+constexpr auto
+__dpl_ceiling_div(_T1 __number, _T2 __divisor)
+{
+    return (__number - 1) / __divisor + 1;
+}
+
+template <typename _T>
+std::enable_if_t<std::is_floating_point_v<_T>, bool>
+__dpl_signbit(const _T& __x)
+{
+    return std::signbit(__x);
+}
+
+// This prevents ambiguity with std::signbit for integral types on MSVC without requiring double support
+template <typename _T>
+std::enable_if_t<!std::is_floating_point_v<_T>, bool>
+__dpl_signbit(const _T& __x)
+{
+    using __unsigned_type = std::make_unsigned_t<_T>;
+    static_assert(std::is_signed_v<_T>, "Only signed types have a signbit.");
+    constexpr __unsigned_type __mask = (__unsigned_type{1} << (sizeof(_T) * 8 - 1));
+    return (__x & __mask) != 0;
+}
+
+template <typename _Size, typename _Comparator>
+_Size
+__pstl_lower_bound_impl(_Size __first, _Size __last, _Comparator&& __comp)
+{
+    auto __n = __last - __first;
+    auto __cur = __n;
+    _Size __idx;
+    while (__n > 0)
+    {
+        __idx = __first;
+        __cur = __n / 2;
+        __idx += __cur;
+
+        if (std::invoke(__comp, __idx))
+        {
+            __n -= __cur + 1;
+            __first = ++__idx;
+        }
+        else
+            __n = __cur;
+    }
+    return __first;
+}
+
+template <typename _Rng1, typename _Size1, typename _Size2, typename _Rng2, typename _Compare, typename _Proj1,
+          typename _Proj2>
+_Size1
+__pstl_lower_bound_idx(_Rng1 __rng1, _Size1 __first1, _Size1 __last1, _Rng2 __rng2, _Size2 __rng2_idx, _Compare __comp,
+                       _Proj1 __proj1, _Proj2 __proj2)
+{
+    return __pstl_lower_bound_impl(__first1, __last1,
+                                   [__rng1, __rng2, __rng2_idx, __comp, __proj1, __proj2](_Size1 __rng1_idx) mutable {
+                                       return std::invoke(__comp, std::invoke(__proj1, __rng1[__rng1_idx]),
+                                                          std::invoke(__proj2, __rng2[__rng2_idx]));
+                                   });
+}
+
+template <typename _Rng1, typename _Size1, typename _Rng2It, typename _Compare, typename _Proj1, typename _Proj2>
+_Size1
+__pstl_lower_bound(_Rng1 __rng1, _Size1 __first1, _Size1 __last1, _Rng2It __rng2_it, _Compare __comp, _Proj1 __proj1,
+                   _Proj2 __proj2)
+{
+    return __pstl_lower_bound_impl(
+        __first1, __last1, [__rng1, __rng2_it, __comp, __proj1, __proj2](_Size1 __rng1_idx) mutable {
+            return std::invoke(__comp, std::invoke(__proj1, __rng1[__rng1_idx]), std::invoke(__proj2, *__rng2_it));
+        });
+}
+
+template <typename _Rng1, typename _Size1, typename _Size2, typename _Rng2, typename _Compare, typename _Proj1,
+          typename _Proj2>
+_Size1
+__pstl_upper_bound_idx(_Rng1 __rng1, _Size1 __first1, _Size1 __last1, _Rng2 __rng2, _Size2 __rng2_idx, _Compare __comp,
+                       _Proj1 __proj1, _Proj2 __proj2)
+{
+    __reorder_pred<_Compare> __reordered_comp{__comp};
+    __not_pred<decltype(__reordered_comp)> __negation_reordered_comp{__reordered_comp};
+
+    return __pstl_lower_bound_idx(__rng1, __first1, __last1, __rng2, __rng2_idx, __negation_reordered_comp, __proj1, __proj2);
+}
+
+template <typename _Rng1, typename _Size1, typename _Rng2It, typename _Compare, typename _Proj1, typename _Proj2>
+_Size1
+__pstl_upper_bound(_Rng1 __rng1, _Size1 __first1, _Size1 __last1, _Rng2It __rng2_it, _Compare __comp, _Proj1 __proj1,
+                   _Proj2 __proj2)
+{
+    __reorder_pred<_Compare> __reordered_comp{__comp};
+    __not_pred<decltype(__reordered_comp)> __negation_reordered_comp{__reordered_comp};
+
+    return __pstl_lower_bound(__rng1, __first1, __last1, __rng2_it, __negation_reordered_comp, __proj1, __proj2);
+}
+
+template <typename _Rng1, typename _Size1, typename _Size2, typename _Rng2, typename _Compare, typename _Proj1,
+          typename _Proj2>
+_Size1
+__pstl_right_bound_idx(_Rng1 __rng1, _Size1 __first1, _Size1 __last1, _Rng2 __rng2, _Size2 __rng2_idx, _Compare __comp,
+                       _Proj1 __proj1, _Proj2 __proj2)
+{
+    return __pstl_upper_bound_idx(__rng1, __first1, __last1, __rng2, __rng2_idx, __comp, __proj1, __proj2);
+}
+
+// Performs a "biased" binary search targets the split point close to one edge of the range.
+// When __bias_last==true, it searches first near the last element, otherwise it searches first near the first element.
+// After each iteration which fails to capture the element in the small side, it reduces the "bias", eventually
+// resulting in a standard binary search.
+template <bool __bias_last = true, typename _Rng1, typename _Size1, typename _Size2, typename _Rng2, typename _Compare,
+          typename _Proj1, typename _Proj2>
+_Size1
+__biased_lower_bound_idx(_Rng1 __rng1, _Size1 __first1, _Size1 __last1, _Rng2 __rng2, _Size2 __rng2_idx,
+                         _Compare __comp, _Proj1 __proj1, _Proj2 __proj2)
+{
+    auto __n = __last1 - __first1;
+    std::int8_t __shift_right_div = 10; // divide by 2^10 = 1024
+    _Size1 __it = 0;
+    _Size1 __cur_idx = 0;
+
+    while (__n > 0 && __shift_right_div > 1)
+    {
+        _Size1 __biased_step = (__n >> __shift_right_div);
+        if constexpr (__bias_last)
+            __cur_idx = __n - __biased_step - 1;
+        else
+            __cur_idx = __biased_step;
+        __it = __first1 + __cur_idx;
+
+        if (std::invoke(__comp, std::invoke(__proj1, __rng1[__it]), std::invoke(__proj2, __rng2[__rng2_idx])))
+        {
+            __first1 = __it + 1;
+        }
+        else
+        {
+            __last1 = __it;
+        }
+        __n = __last1 - __first1;
+        // get closer and closer to binary search with more iterations
+        __shift_right_div -= 3;
+    }
+    if (__n > 0)
+    {
+        // End up fully at binary search
+        return __onedpl::__internal::__pstl_lower_bound_idx(__rng1, __first1, __last1, __rng2, __rng2_idx, __comp,
+                                                               __proj1, __proj2);
+    }
+    return __first1;
+}
+
+template <bool __bias_last = true, typename _Rng1, typename _Size1, typename _Size2, typename _Rng2, typename _Compare,
+          typename _Proj1, typename _Proj2>
+_Size1
+__biased_upper_bound_idx(_Rng1 __rng1, _Size1 __first1, _Size1 __last1, _Rng2 __rng2, _Size2 __rng2_idx,
+                         _Compare __comp, _Proj1 __proj1, _Proj2 __proj2)
+{
+    __reorder_pred<_Compare> __reordered_comp{__comp};
+    __not_pred<decltype(__reordered_comp)> __negation_reordered_comp{__reordered_comp};
+
+    return __biased_lower_bound_idx<__bias_last>(__rng1, __first1, __last1, __rng2, __rng2_idx,
+                                                 __negation_reordered_comp, __proj1, __proj2);
+}
+
+template <typename _IntType, typename _Acc>
+struct _ReverseCounter
+{
+    using difference_type = std::make_signed_t<_IntType>;
+
+    _IntType __my_cn;
+
+    _ReverseCounter&
+    operator++()
+    {
+        --__my_cn;
+        return *this;
+    }
+
+    template <typename _DiffType>
+    _ReverseCounter&
+    operator+=(_DiffType __val)
+    {
+        __my_cn -= __val;
+        return *this;
+    }
+
+    difference_type
+    operator-(const _ReverseCounter& __a)
+    {
+        return __a.__my_cn - __my_cn;
+    }
+
+    operator _IntType() { return __my_cn; }
+
+// TODO: Temporary hotfix. Investigate the necessity of _ReverseCounter
+// Investigate potential user types convertible to integral
+// This is the compile-time trick where we define the conversion operator to sycl::id
+// conditionally. If we can call accessor::operator[] with the type that converts to the
+// same integral type as _ReverseCounter (it means that we can call accessor::operator[]
+// with the _ReverseCounter itself) then we don't need conversion operator to sycl::id.
+// Otherwise, we define conversion operator to sycl::id.
+#if _ONEDPL_BACKEND_SYCL
+    struct __integral
+    {
+        operator _IntType();
+    };
+
+    template <typename _Tp>
+    static auto
+    __check_braces(int) -> decltype(::std::declval<_Tp>()[::std::declval<__integral>()], ::std::false_type{});
+
+    template <typename _Tp>
+    static auto
+    __check_braces(...) -> ::std::true_type;
+
+    class __private_class;
+
+    operator ::std::conditional_t<decltype(__check_braces<_Acc>(0))::value, sycl::id<1>, __private_class>()
+    {
+        return sycl::id<1>(__my_cn);
+    }
+#endif
+};
+
+// Reverse searching for the first element strongly less than a passed value - left bound
+template <typename _Rng1, typename _Size1, typename _Size2, typename _Rng2, typename _Compare, typename _Proj1,
+          typename _Proj2>
+_Size1
+__pstl_left_bound_idx(_Rng1 __rng1, _Size1 __first1, _Size1 __last1, _Rng2 __rng2, _Size2 __rng2_idx, _Compare __comp,
+                      _Proj1 __proj1, _Proj2 __proj2)
+{
+    _ReverseCounter<_Size1, _Rng1> __beg{__last1 - 1};
+    _ReverseCounter<_Size1, _Rng1> __end{__first1 - 1};
+
+    __not_pred<decltype(__comp)> __negation_comp{__comp};
+
+    return __pstl_lower_bound_idx(__rng1, __beg, __end, __rng2, __rng2_idx, __negation_comp, __proj1, __proj2);
+}
+
+// Lower bound implementation based on Shar's algorithm for binary search.
+template <typename _Acc, typename _Size, typename _Value, typename _Compare>
+_Size
+__shars_lower_bound(_Acc __acc, _Size __first, _Size __last, const _Value& __value, _Compare __comp)
+{
+    static_assert(::std::is_unsigned_v<_Size>, "__shars_lower_bound requires an unsigned size type");
+    const _Size __n = __last - __first;
+    if (__n == 0)
+        return __first;
+    _Size __cur_pow2 = __dpl_bit_floor(__n);
+    const _Size __midpoint = __n / 2;
+    // Check the middle element to determine if we should search the first or last
+    // 2^(bit_floor(__n)) - 1 elements.
+    const _Size __shifted_first = std::invoke(__comp, __acc[__midpoint], __value) ? __n + 1 - __cur_pow2 : __first;
+    // Check descending powers of two. If __comp(__acc[__search_idx], __pow) holds for a __cur_pow2, then its
+    // bit must be set in the result.
+    _Size __search_offset{0};
+    for (__cur_pow2 >>= 1; __cur_pow2 > 0; __cur_pow2 >>= 1)
+    {
+        const _Size __search_idx = __shifted_first + (__search_offset | __cur_pow2) - 1;
+        if (std::invoke(__comp, __acc[__search_idx], __value))
+            __search_offset |= __cur_pow2;
+    }
+    return __shifted_first + __search_offset;
+}
+
+template <typename _Acc, typename _Size, typename _Value, typename _Compare>
+_Size
+__shars_upper_bound(_Acc __acc, _Size __first, _Size __last, const _Value& __value, _Compare __comp)
+{
+    return __shars_lower_bound(__acc, __first, __last, __value,
+                               __onedpl::__internal::__not_pred<__onedpl::__internal::__reorder_pred<_Compare>>{
+                                   __onedpl::__internal::__reorder_pred<_Compare>{__comp}});
+}
+
+#if _ONEDPL_CPP20_CONCEPTS_PRESENT
+
+template <typename _Iterator1, typename _Iterator2>
+inline constexpr bool __is_equality_comparable_with_v = std::equality_comparable_with<_Iterator1, _Iterator2>;
+
+#else
+
+template <typename _Iterator1, typename _Iterator2, typename = void>
+struct __has_equality_op : std::false_type
+{
+};
+
+template <typename _Iterator1, typename _Iterator2>
+struct __has_equality_op<_Iterator1, _Iterator2,
+                         std::void_t<decltype(std::declval<_Iterator1>() == std::declval<_Iterator2>())>>
+    : std::true_type
+{
+};
+
+template <typename _Iterator1, typename _Iterator2>
+struct __is_equality_comparable_with_impl : __has_equality_op<_Iterator1, _Iterator2>
+{
+};
+
+template <typename _Iterator1, typename _Iterator2>
+struct __is_equality_comparable_with_impl<std::reverse_iterator<_Iterator1>, std::reverse_iterator<_Iterator2>>
+    : __is_equality_comparable_with_impl<_Iterator1, _Iterator2>
+{
+};
+
+template <typename _Iterator1, typename _Iterator2>
+struct __is_equality_comparable_with_impl<std::move_iterator<_Iterator1>, std::move_iterator<_Iterator2>>
+    : __is_equality_comparable_with_impl<_Iterator1, _Iterator2>
+{
+};
+
+template <typename _Iterator1, typename _Iterator2>
+struct __is_equality_comparable_with
+    : __is_equality_comparable_with_impl<std::decay_t<_Iterator1>, std::decay_t<_Iterator2>>
+{
+};
+
+template <typename _Iterator1, typename _Iterator2>
+inline constexpr bool __is_equality_comparable_with_v = __is_equality_comparable_with<_Iterator1, _Iterator2>::value;
+
+#endif // _ONEDPL_CPP20_CONCEPTS_PRESENT
+
+// Checks if two iterators are possibly equal, i.e. if they can be compared for equality.
+template <typename _Iterator1, typename _Iterator2>
+constexpr bool
+__iterators_possibly_equal(_Iterator1 __it1, _Iterator2 __it2)
+{
+    if constexpr (__is_equality_comparable_with_v<_Iterator1, _Iterator2>)
+    {
+        return __it1 == __it2;
+    }
+    else if constexpr (__is_equality_comparable_with_v<_Iterator2, _Iterator1>)
+    {
+        return __it2 == __it1;
+    }
+    else
+    {
+        return false;
+    }
+}
+
+// Conditionally sets type to _SpirvT if oneDPL is being compiled to a SPIR-V target with the SYCL backend and _NonSpirvT otherwise.
+template <typename _SpirvT, typename _NonSpirvT>
+struct __spirv_target_conditional :
+#if _ONEDPL_DETECT_SPIRV_COMPILATION
+    _SpirvT
+#else
+    _NonSpirvT
+#endif
+{
+};
+
+// Trait that has a true value if _ONEDPL_DETECT_SPIRV_COMPILATION is set and false otherwise. This may be used within kernels
+// to determine SPIR-V targets.
+inline constexpr bool __is_spirv_target_v = __spirv_target_conditional<::std::true_type, ::std::false_type>::value;
+
+template <typename _T, typename = void>
+struct __is_type_with_iterator_traits : std::false_type
+{
+};
+
+template <typename _T>
+struct __is_type_with_iterator_traits<
+    _T, std::void_t<typename std::iterator_traits<std::remove_reference_t<_T>>::difference_type>> : std::true_type
+{
+};
+
+template <typename _T>
+static constexpr bool __is_type_with_iterator_traits_v = __is_type_with_iterator_traits<_T>::value;
+
+// Storage helper since _Tp may not have a default constructor.
+template <typename _Tp>
+union __lazy_ctor_storage
+{
+    using __value_type = _Tp;
+    _Tp __v;
+    __lazy_ctor_storage() {}
+
+    // Empty destructor, we must explicitly manage destruction of data constructed.
+    // A defaulted destructor of a union would not automatically call destructors of the variant __v, but also does not
+    // support non-trivial destructors for _Tp. This allows us to support non-trivial destructors for _Tp.
+    ~__lazy_ctor_storage() {}
+
+    template <typename _U>
+    void
+    __setup(_U&& init)
+    {
+        new (&__v) _Tp(std::forward<_U>(init));
+    }
+    void
+    __destroy()
+    {
+        __v.~_Tp();
+    }
+};
+
+// Scoped destroyer for __lazy_ctor_storage. It can be used to destroy the a __lazy_ctor_storage when it goes out of
+// scope.
+// Note: Should only be used *after* the storage has been initialized with __setup or some other method to ensure that
+//       data is not destroyed before it is initialized. This is relevant for exception handling which may change the
+//       control flow unexpectedly.
+template <typename _DataType>
+struct __scoped_destroyer
+{
+    __onedpl::__internal::__lazy_ctor_storage<_DataType>& ___lazy_ctor_storage_ref;
+    ~__scoped_destroyer()
+    {
+        // Explicitly call destructor of __lazy_ctor_storage
+        ___lazy_ctor_storage_ref.__destroy();
+    }
+};
+
+// To implement __min_nested_type_size, a general utility with an internal tuple
+// specialization, we need to forward declare our internal tuple first as tuple_impl.h
+// already includes this header.
+template <typename... T>
+struct tuple;
+
+// Returns the smallest type within a set of potentially nested template types. This function
+// recursively explores std::tuple and __onedpl::__internal::tuple for the smallest type.
+// For all other types, its size is used directly.
+// E.g. If we consider the type: T = tuple<float, tuple<short, long>, int, double>,
+// then __min_nested_type_size<T>::value returns sizeof(short).
+template <typename _T>
+struct __min_nested_type_size
+{
+    constexpr static std::size_t value = sizeof(_T);
+};
+
+template <typename... _Ts>
+struct __min_nested_type_size<std::tuple<_Ts...>>
+{
+    constexpr static std::size_t value = std::min({__min_nested_type_size<_Ts>::value...});
+};
+
+template <typename... _Ts>
+struct __min_nested_type_size<__onedpl::__internal::tuple<_Ts...>>
+{
+    constexpr static std::size_t value = std::min({__min_nested_type_size<_Ts>::value...});
+};
+
+struct __swap_fn
+{
+    template <typename _Type1, typename _Type2>
+    void
+    operator()(_Type1&& __x, _Type2&& __y) const
+    {
+        using ::std::swap;
+        swap(__x, __y);
+    }
+};
+
+template <typename _T>
+auto
+__get_last_arg(_T __t)
+{
+    return __t;
+}
+
+template <typename _T, typename... _Rest>
+auto
+__get_last_arg(_T, _Rest... __args)
+{
+    return __get_last_arg(__args...);
+}
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+template <typename _T, typename _Proj>
+struct __count_fn_pred
+{
+    _T __value;
+    _Proj __proj;
+
+    template <typename _TValue>
+    bool
+    operator()(_TValue&& __val) const
+    {
+        return std::ranges::equal_to{}(std::invoke(__proj, std::forward<_TValue>(__val)), __value);
+    }
+};
+#endif
+
+template <typename _ValueType, typename _FlagType, typename _BinaryOp>
+struct __segmented_scan_fun
+{
+    template <typename _T1, typename _T2>
+    _T1
+    operator()(const _T1& __x, const _T2& __y) const
+    {
+        using std::get;
+        using __x_t = std::tuple_element_t<0, _T1>;
+        auto __new_x = get<1>(__y) ? __x_t(get<0>(__y)) : __x_t(__binary_op(get<0>(__x), get<0>(__y)));
+        auto __new_y = get<1>(__x) | get<1>(__y);
+        return _T1(__new_x, __new_y);
+    }
+
+    _BinaryOp __binary_op;
+};
+
+template <typename _T, typename _Predicate>
+struct __replace_if_fun
+{
+    using __result_of = _T;
+
+    template <typename _T1, typename _T2>
+    _T
+    operator()(_T1&& __a, _T2&& __s) const
+    {
+        return __pred(std::forward<_T2>(__s)) ? __new_value : __a;
+    }
+
+    _Predicate __pred;
+    const _T __new_value;
+};
+
+template <typename _OutValueType, typename _OutRefType, typename _InRefType>
+inline constexpr bool __trivial_uninitialized_copy =
+    // Required operation is trivial
+    // If the required operation is trivial, we can skip it.
+    std::is_trivially_constructible_v<_OutValueType, _InRefType> &&
+    // Actual operations are trivial
+    // If the element type is trivially default constructible,
+    // we can assume that its "life" has begun even in the uninitialized memory, and we can assign to it
+    std::is_trivially_default_constructible_v<_OutValueType> &&
+    std::is_trivially_assignable_v<_OutRefType, _InRefType>;
+
+template <typename _OutValueType, typename _OutRefType, typename _InRefType>
+inline constexpr bool __trivial_uninitialized_move =
+    std::is_trivially_constructible_v<_OutValueType, std::remove_reference_t<_InRefType>&&> && // required operation
+    std::is_trivially_default_constructible_v<_OutValueType> &&                                // actual operations
+    std::is_trivially_assignable_v<_OutRefType, _InRefType>;
+
+template <typename _ValueType, typename _T>
+inline constexpr bool __trivial_uninitialized_fill =
+    std::is_trivially_constructible_v<_ValueType, _T> &&     // required operation
+    std::is_trivially_default_constructible_v<_ValueType> && // actual operations
+    // the value is expected to be converted to the element type by the caller in the actual operation
+    std::is_trivially_copy_assignable_v<_ValueType>;
+
+template <typename _ValueType>
+inline constexpr bool __trivial_uninitialized_value_construct =
+    std::is_trivially_default_constructible_v<_ValueType> && // required operation
+    std::is_trivially_copy_assignable_v<_ValueType>;         // actual operation
+
+// Trick to get behavior similar to static_assert(false) pre-C++23.
+template <typename...>
+inline constexpr bool __always_false_v = false;
+
+} // namespace __internal
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_UTILS_H
diff --git a/libstdc++-v3/include/pstl/utils_ranges.h b/libstdc++-v3/include/pstl/utils_ranges.h
new file mode 100644
index 000000000000..e0d1102ada68
--- /dev/null
+++ b/libstdc++-v3/include/pstl/utils_ranges.h
@@ -0,0 +1,838 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_UTILS_RANGES_H
+#define _ONEDPL_UTILS_RANGES_H
+
+#include <tuple>       // std::get
+#include <cstdint>     // std::uint8_t
+#include <cstddef>     // std::size_t, std::ptrdiff_t
+#include <utility>     // std::declval
+#include <iterator>    // std::iterator_traits
+#include <type_traits> // std::decay_t, std::remove_cv_t, std::remove_reference_t, std::invoke_result_t, ...
+#include <cassert>     // assert
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+#    include <ranges>   // std::ranges::sized_range, std::ranges::range_size_t
+#    include <concepts> // for std::default_initializable
+#endif
+
+#include "iterator_defs.h"
+#include "iterator_impl.h"
+
+namespace std::__onedpl
+{
+namespace __ranges
+{
+#if _ONEDPL_CPP20_RANGES_PRESENT
+template <typename _Range>
+auto
+__begin(_Range&& __rng) -> decltype(std::ranges::begin(std::forward<_Range>(__rng)))
+{
+    return std::ranges::begin(std::forward<_Range>(__rng));
+}
+#else
+template <typename _Range>
+auto
+__begin(_Range&& __rng) -> decltype(__rng.begin())
+{
+    return __rng.begin();
+}
+#endif
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+template <typename _Range>
+auto
+__end(_Range&& __rng) -> decltype(std::ranges::end(std::forward<_Range>(__rng)))
+{
+    return std::ranges::end(std::forward<_Range>(__rng));
+}
+#else
+template <typename _Range>
+auto
+__end(_Range&& __rng) -> decltype(__rng.end())
+{
+    return __rng.end();
+}
+#endif
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+template <typename _Range>
+auto
+__size(_Range&& __rng) -> decltype(std::ranges::size(std::forward<_Range>(__rng)))
+{
+    return std::ranges::size(std::forward<_Range>(__rng));
+}
+#else
+template <typename _R, typename = void>
+struct __has_size : std::false_type
+{
+};
+
+template <typename _R>
+struct __has_size<_R, std::void_t<decltype(std::declval<_R>().size())>> : std::true_type
+{
+};
+
+template <typename _Range>
+std::enable_if_t<__has_size<_Range>::value, decltype(std::declval<_Range>().size())>
+__size(_Range&& __rng)
+{
+    return __rng.size();
+}
+
+template <typename _Range>
+std::enable_if_t<!__has_size<_Range>::value, decltype(__end(std::declval<_Range>()) - __begin(std::declval<_Range>()))>
+__size(_Range&& __rng)
+{
+    return __end(__rng) - __begin(__rng);
+}
+#endif
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+template <typename _Range>
+bool
+__empty(_Range&& __rng)
+{
+    return std::ranges::empty(__rng);
+}
+#else
+template <typename _R, typename = void>
+struct __has_empty : std::false_type
+{
+};
+
+template <typename _R>
+struct __has_empty<_R, std::void_t<decltype(std::declval<_R>().empty())>> : std::true_type
+{
+};
+
+template <typename _Range>
+std::enable_if_t<__has_empty<_Range>::value, bool>
+__empty(_Range&& __rng)
+{
+    return __rng.empty();
+}
+
+template <typename _Range>
+std::enable_if_t<!__has_empty<_Range>::value, bool>
+__empty(_Range&& __rng)
+{
+    return __size(__rng) == 0;
+}
+#endif
+
+} // namespace __ranges
+
+namespace __internal
+{
+
+template <typename _R>
+auto
+get_value_type(int) -> typename ::std::decay_t<_R>::value_type;
+
+template <typename _R>
+auto
+get_value_type(long) -> typename std::iterator_traits<
+                         std::decay_t<decltype(__onedpl::__ranges::__begin(std::declval<_R&>()))>>::value_type;
+
+template <typename _It>
+auto
+get_value_type(long long) -> typename ::std::iterator_traits<_It>::value_type;
+
+template <typename _R>
+auto
+get_value_type(...)
+{
+    //static_assert should always fail when this overload is chosen, so its condition must depend on
+    //the template parameter and evaluate to false
+    static_assert(std::is_same_v<_R, void>,
+        "error: the range has no 'value_type'; define an alias or typedef named 'value_type' in the range class");
+}
+
+template <typename _R>
+using __value_t = decltype(__onedpl::__internal::get_value_type<_R>(0));
+
+template <typename _Proj, typename _R>
+using __key_t = ::std::remove_cv_t<::std::remove_reference_t<::std::invoke_result_t<_Proj&, __value_t<_R>>>>;
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+//The following '__range_size' type trait should be used in only the context with std::common_type
+//together with a sized range.
+template <typename R>
+struct __range_size {
+    using type = std::uint8_t;
+};
+
+template <std::ranges::sized_range R>
+struct __range_size<R> {
+    using type = std::ranges::range_size_t<R>;
+};
+
+template <typename _R>
+using __range_size_t = typename __range_size<_R>::type;
+
+#endif //_ONEDPL_CPP20_RANGES_PRESENT
+
+template <typename _R>
+auto
+__check_size(int) -> decltype(__get_buffer_size(std::declval<_R&>()));
+
+template <typename _R>
+auto
+__check_size(long) -> decltype(__onedpl::__ranges::__size(std::declval<_R&>()));
+
+template <typename _It>
+auto
+__check_size(long long) -> typename std::iterator_traits<_It>::difference_type;
+
+template <typename _R>
+auto
+__check_size(...)
+{
+    //static_assert should always fail when this overload is chosen, so its condition must depend on
+    //the template parameter and evaluate to false
+    static_assert(
+        std::is_same_v<_R, void>,
+        "error: unable to determine the size of the range; the range must provide a 'get_count()' or 'size()' member, "
+        "or otherwise support size determination (e.g., via std::ranges::size or by supporting begin/end for distance "
+        "calculation)");
+}
+
+template <typename _R>
+using __difference_t = std::make_signed_t<decltype(__check_size<_R>(0))>;
+
+} //namespace __internal
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+#    if _ONEDPL_CPP26_DEFAULT_VALUE_TYPE_PRESENT
+template <std::indirectly_readable I, std::indirectly_regular_unary_invocable<I> Proj>
+using projected_value_t = std::projected_value_t<I, Proj>;
+#    else
+template <std::indirectly_readable I, std::indirectly_regular_unary_invocable<I> Proj>
+using projected_value_t = std::remove_cvref_t<std::invoke_result_t<Proj&, std::iter_value_t<I>&>>;
+#    endif
+#endif //_ONEDPL_CPP20_RANGES_PRESENT
+
+namespace __ranges
+{
+
+template <typename... _Rng>
+using __common_size_t = std::common_type_t<std::make_unsigned_t<decltype(__size(std::declval<_Rng>()))>...>;
+
+template <std::size_t _RngIndex>
+struct __nth_range_size
+{
+  private:
+    template <std::size_t _RngIndexCurrent, typename _Range, typename... _Ranges>
+    auto
+    __nth_range_size_impl(const _Range& __rng, const _Ranges&... __rngs) const
+    {
+        if constexpr (_RngIndexCurrent == _RngIndex)
+            return __size(__rng);
+        else
+            return __nth_range_size_impl<_RngIndexCurrent + 1>(__rngs...);
+    }
+
+  public:
+    template <typename... _Ranges>
+    auto
+    operator()(const _Ranges&... __rngs) const
+    {
+        static_assert(_RngIndex < sizeof...(_Ranges));
+        return __nth_range_size_impl<0>(__rngs...);
+    }
+};
+
+using __first_size_calc = __nth_range_size<0>;
+using __second_size_calc = __nth_range_size<1>;
+
+struct __min_size_calc
+{
+    template <typename... _Ranges>
+    auto
+    operator()(const _Ranges&... __rngs) const
+    {
+        using _Size = std::make_unsigned_t<std::common_type_t<__onedpl::__internal::__difference_t<_Ranges>...>>;
+        return std::min({_Size(__onedpl::__ranges::__size(__rngs))...});
+    }
+};
+
+// helpers to check implement "has_base"
+template <typename U>
+auto
+test_pipeline_object(int) -> decltype(::std::declval<U>().base(), ::std::true_type{});
+
+template <typename U>
+auto
+test_pipeline_object(...) -> ::std::false_type;
+
+// has_base check definition
+template <typename Range>
+struct is_pipeline_object : decltype(test_pipeline_object<Range>(0))
+{
+};
+
+// Recursive helper
+template <typename Range, typename = void>
+struct pipeline_base
+{
+    using type = Range;
+};
+
+template <typename Range>
+struct pipeline_base<Range, ::std::enable_if_t<is_pipeline_object<Range>::value>>
+{
+    using type = typename pipeline_base<::std::decay_t<decltype(::std::declval<Range>().base())>>::type;
+};
+
+//pipeline_base_range
+template <typename Range, typename = void>
+struct pipeline_base_range
+{
+    Range rng;
+    using next_layer_view_t = Range;
+
+    pipeline_base_range(Range r) : rng(r) {}
+    constexpr Range
+    base_range()
+    {
+        return rng;
+    }
+};
+
+// use ::std::conditional to understand what class to inherit from
+template <typename Range>
+struct pipeline_base_range<Range, ::std::enable_if_t<is_pipeline_object<Range>::value>>
+{
+    Range rng;
+    using next_layer_view_t = decltype(std::declval<Range>().base());
+
+    pipeline_base_range(Range r) : rng(r) {}
+    constexpr auto
+    base_range() -> decltype(pipeline_base_range<decltype(rng.base())>(rng.base()).base_range())
+    {
+        return pipeline_base_range<decltype(rng.base())>(rng.base()).base_range();
+    }
+};
+
+template <typename _TupleType, typename _F, ::std::size_t... _Ip>
+void
+invoke(const _TupleType& __t, _F __f, ::std::index_sequence<_Ip...>)
+{
+    __f(::std::get<_Ip>(__t)...);
+}
+
+template <typename... _Ranges>
+class zip_view
+{
+    static_assert(sizeof...(_Ranges) > 0, "Cannot instantiate zip_view with empty template parameter pack");
+
+    using _tuple_ranges_t = __onedpl::__internal::tuple<_Ranges...>;
+
+    template <typename Idx, ::std::size_t... _Ip>
+    auto
+    make_reference(_tuple_ranges_t __t, Idx __i, ::std::index_sequence<_Ip...>) const
+        -> decltype(__onedpl::__internal::tuple<decltype(::std::declval<_Ranges&>().operator[](__i))...>(
+            ::std::get<_Ip>(__t).operator[](__i)...))
+    {
+        return __onedpl::__internal::tuple<decltype(::std::declval<_Ranges&>().operator[](__i))...>(
+            ::std::get<_Ip>(__t).operator[](__i)...);
+    }
+
+  public:
+    using value_type = __onedpl::__internal::tuple<__onedpl::__internal::__value_t<_Ranges>...>;
+    static constexpr ::std::size_t __num_ranges = sizeof...(_Ranges);
+
+    explicit zip_view(_Ranges... __args) : __m_ranges(__args...) {}
+
+    auto
+    size() const
+    {
+        return __onedpl::__ranges::__size(std::get<0>(__m_ranges));
+    }
+
+    //TODO: C++ Standard states that the operator[] index should be the diff_type of the underlying range.
+    template <typename Idx>
+    constexpr auto operator[](Idx __i) const
+        -> decltype(make_reference(::std::declval<_tuple_ranges_t>(), __i, ::std::make_index_sequence<__num_ranges>()))
+    {
+        return make_reference(__m_ranges, __i, ::std::make_index_sequence<__num_ranges>());
+    }
+
+    bool
+    empty() const
+    {
+        return size() == 0;
+    }
+
+    _tuple_ranges_t
+    base() const
+    {
+        return __m_ranges;
+    }
+
+  private:
+    _tuple_ranges_t __m_ranges;
+};
+
+template <typename... _Views>
+auto
+make_zip_view(_Views... args)
+{
+    return zip_view<_Views...>(args...);
+}
+
+// a custom view, over a pair of "passed directly" iterators
+template <typename _Iterator>
+class guard_view
+{
+    using diff_type = typename ::std::iterator_traits<_Iterator>::difference_type;
+
+  public:
+    using value_type = typename ::std::iterator_traits<_Iterator>::value_type;
+
+    guard_view(_Iterator __first = _Iterator(), diff_type __n = 0) : m_p(__first), m_count(__n) {}
+    guard_view(_Iterator __first, _Iterator __last) : m_p(__first), m_count(__last - __first) {}
+
+    _Iterator
+    begin() const
+    {
+        return m_p;
+    }
+
+    _Iterator
+    end() const
+    {
+        return begin() + size();
+    }
+
+    //TODO: to be consistent with C++ standard, this Idx should be changed to diff_type of underlying iterator
+    template <typename Idx>
+    auto operator[](Idx i) const -> decltype(begin()[i])
+    {
+        return begin()[i];
+    }
+
+    diff_type
+    size() const
+    {
+        return m_count;
+    }
+    bool
+    empty() const
+    {
+        return size() == 0;
+    }
+
+  private:
+    _Iterator m_p;     // a iterator (pointer)  to data in memory
+    diff_type m_count; // size of the data
+};
+
+//It is kind of pseudo-view for reverse_view support.
+template <typename _R>
+struct reverse_view_simple
+{
+    using value_type = __onedpl::__internal::__value_t<_R>;
+
+    _R __r;
+
+    reverse_view_simple(_R __rng) : __r(__rng) {}
+
+    //TODO: to be consistent with C++ standard, this Idx should be changed to diff_type of underlying range
+    template <typename Idx>
+    auto operator[](Idx __i) const -> decltype(__r[__i])
+    {
+        return __r[size() - __i - 1];
+    }
+
+    auto
+    size() const -> decltype(__onedpl::__ranges::__size(__r))
+    {
+        return __onedpl::__ranges::__size(__r);
+    }
+
+    bool
+    empty() const
+    {
+        return __onedpl::__ranges::__empty(__r);
+    }
+
+    auto
+    base() const -> decltype(__r)
+    {
+        return __r;
+    }
+};
+
+//It is kind of pseudo-view for take_view support. We assume that the underlying range will not shrink
+//after creation of the view to favor performance.
+template <typename _R, typename _Size>
+struct take_view_simple
+{
+    using value_type = __onedpl::__internal::__value_t<_R>;
+
+    _R __r;
+    _Size __n;
+
+    take_view_simple(_R __rng, _Size __size) : __r(__rng), __n(__size)
+    {
+        assert(__n >= 0 && __n <= __onedpl::__ranges::__size(__r));
+    }
+
+    //TODO: to be consistent with C++ standard, this Idx should be changed to diff_type of underlying range
+    template <typename Idx>
+    auto operator[](Idx __i) const -> decltype(__r[__i])
+    {
+        return __r[__i];
+    }
+
+    _Size
+    size() const
+    {
+        assert(__n <= __onedpl::__ranges::__size(__r));
+        return __n;
+    }
+
+    bool
+    empty() const
+    {
+        return size() == 0;
+    }
+
+    auto
+    base() const -> decltype(__r)
+    {
+        return __r;
+    }
+};
+
+//It is kind of pseudo-view for drop_view support. We assume that the underlying range will not shrink
+//after creation of the view to favor performance.
+template <typename _R, typename _Size>
+struct drop_view_simple
+{
+    using value_type = __onedpl::__internal::__value_t<_R>;
+
+    _R __r;
+    _Size __n;
+
+    drop_view_simple(_R __rng, _Size __size) : __r(__rng), __n(__size)
+    {
+        assert(__n >= 0 && __n <= __onedpl::__ranges::__size(__r));
+    }
+
+    //TODO: to be consistent with C++ standard, this Idx should be changed to diff_type of underlying range
+    template <typename Idx>
+    auto operator[](Idx __i) const -> decltype(__r[__i])
+    {
+        return __r[__n + __i];
+    }
+
+    _Size
+    size() const
+    {
+        assert(__onedpl::__ranges::__size(__r) >= __n);
+        return __onedpl::__ranges::__size(__r) - __n;
+    }
+
+    bool
+    empty() const
+    {
+        return size() == 0;
+    }
+
+    auto
+    base() const -> decltype(__r)
+    {
+        return __r;
+    }
+};
+
+//replicate_start_view_simple inserts replicates of the first element m times, then continues with the range as normal.
+// For counting iterator range {0,1,2,3,4,5,...}, and __replicate_count = 3, the result is {0,0,0,0,1,2,3,4,5,...}
+template <typename _R, typename _Size>
+struct replicate_start_view_simple
+{
+    using value_type = __onedpl::__internal::__value_t<_R>;
+
+    _R __r;
+    _Size __repl_count;
+
+    replicate_start_view_simple(_R __rng, _Size __replicate_count) : __r(__rng), __repl_count(__replicate_count)
+    {
+        assert(__repl_count >= 0);
+    }
+
+    //TODO: to be consistent with C++ standard, this Idx should be changed to diff_type of underlying range
+    template <typename Idx>
+    auto operator[](Idx __i) const -> decltype(__r[__i])
+    {
+        return (__i < __repl_count) ? __r[0] : __r[__i - __repl_count];
+    }
+
+    _Size
+    size() const
+    {
+        // if base range is empty, replication does not extend the valid size
+        return __onedpl::__ranges::__empty(__r) ? 0 : __onedpl::__ranges::__size(__r) + __repl_count;
+    }
+
+    bool
+    empty() const
+    {
+        return size() == 0;
+    }
+
+    auto
+    base() const -> decltype(__r)
+    {
+        return __r;
+    }
+};
+
+//It is kind of pseudo-view for transfom_iterator support.
+template <typename _R, typename _F>
+struct transform_view_simple
+{
+    using value_type = ::std::decay_t<::std::invoke_result_t<_F&, decltype(::std::declval<_R&>()[0])>>;
+
+    _R __r;
+    _F __f;
+
+    //TODO: to be consistent with C++ standard, this Idx should be changed to diff_type of underlying range
+    template <typename Idx>
+    auto operator[](Idx __i) const -> decltype(__f(__r[__i]))
+    {
+        return __f(__r[__i]);
+    }
+
+    auto
+    size() const -> decltype(__onedpl::__ranges::__size(__r))
+    {
+        return __onedpl::__ranges::__size(__r);
+    }
+
+    bool
+    empty() const
+    {
+        return __onedpl::__ranges::__empty(__r);
+    }
+
+    auto
+    base() const -> decltype(__r)
+    {
+        return __r;
+    }
+};
+
+template <typename _Map>
+auto
+test_map_view(int) -> decltype(::std::declval<_Map>()[0], ::std::true_type{});
+
+template <typename _Map>
+auto
+test_map_view(...) -> ::std::false_type;
+
+//pseudo-checking on viewable range concept
+template <typename _Map>
+struct is_map_view : decltype(test_map_view<_Map>(0))
+{
+};
+
+//It is kind of pseudo-view for permutation_iterator support.
+template <typename _Source, typename _M, typename = void>
+struct permutation_view_simple;
+
+//permutation view: specialization for an index map functor
+//size of such view  is specified by a caller
+template <typename _Source, typename _M>
+struct permutation_view_simple<_Source, _M, ::std::enable_if_t<__onedpl::__internal::__is_functor<_M>>>
+{
+    using value_type = __onedpl::__internal::__value_t<_Source>;
+    using _Size = __onedpl::__internal::__difference_t<_Source>;
+
+    _Source __src; //Iterator (pointer) or unreachable range
+    _M __map_fn;
+    _Size __size;
+
+    permutation_view_simple(_Source __data, _M __m, _Size __s) : __src(__data), __map_fn(__m), __size(__s) {}
+
+    //TODO: to be consistent with C++ standard, this Idx should be changed to diff_type of underlying range
+    template <typename Idx>
+    decltype(auto)
+    operator[](Idx __i) const
+    {
+        return __src[__map_fn(__i)];
+    }
+
+    auto
+    size() const
+    {
+        return __size;
+    }
+
+    bool
+    empty() const
+    {
+        return size() == 0;
+    }
+
+    auto
+    base() const
+    {
+        return __src;
+    }
+};
+
+//permutation view: specialization for a map view (a viewable range concept)
+//size of such view  is specified by size of the map view (permutation range)
+template <typename _Source, typename _M>
+struct permutation_view_simple<_Source, _M, ::std::enable_if_t<is_map_view<_M>::value>>
+{
+    using value_type = __onedpl::__internal::__value_t<_Source>;
+
+    _Source __src; //Iterator (pointer) or unreachable range
+    _M __map;      //permutation range
+
+    permutation_view_simple(_Source __data, _M __m) : __src(__data), __map(__m) {}
+
+    //TODO: to be consistent with C++ standard, this Idx should be changed to diff_type of underlying range
+    template <typename Idx>
+    decltype(auto)
+    operator[](Idx __i) const
+    {
+        return __src[__map[__i]];
+    }
+
+    auto
+    size() const
+    {
+        return __map.size();
+    }
+
+    bool
+    empty() const
+    {
+        return size() == 0;
+    }
+
+    auto
+    base() const
+    {
+        return __onedpl::__internal::make_tuple(__src, __map);
+    }
+};
+
+//permutation discard view:
+struct permutation_discard_view
+{
+    using value_type = __onedpl::internal::ignore_copyable;
+    using difference_type = ::std::ptrdiff_t;
+    difference_type m_count;
+
+    permutation_discard_view(difference_type __n) : m_count(__n) {}
+
+    __onedpl::internal::ignore_copyable operator[](difference_type) const { return __onedpl::internal::ignore; }
+
+    difference_type
+    size() const
+    {
+        return m_count;
+    }
+
+    bool
+    empty() const
+    {
+        return size() == 0;
+    }
+};
+
+template <typename _R, typename = void>
+struct __has_subscription_op : std::false_type
+{
+};
+
+template <typename _R>
+struct __has_subscription_op<_R, std::void_t<decltype(std::declval<_R>().operator[](0))>> : std::true_type
+{
+};
+
+template <typename _Range, typename = std::enable_if_t<__has_subscription_op<_Range>::value>>
+_Range&&
+__get_subscription_view(_Range&& __rng)
+{
+    // If the range supports operator[], return it as is
+    return std::forward<_Range>(__rng);
+}
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+template <std::ranges::view _View>
+    requires std::ranges::random_access_range<_View>
+struct __subscription_impl_view_simple : std::ranges::view_interface<__subscription_impl_view_simple<_View>>
+{
+    static_assert(!__has_subscription_op<_View>::value,
+                  "The usage of __subscription_impl_view_simple prohibited if _View::operator[] implemented");
+
+    _View __base;
+
+    constexpr __subscription_impl_view_simple()
+        requires std::default_initializable<_View>
+    = default;
+
+    constexpr explicit __subscription_impl_view_simple(_View __view) : __base(std::move(__view)) {}
+
+    constexpr auto
+    begin() const
+    {
+        return __begin(__base);
+    }
+
+    constexpr auto
+    end() const
+    {
+        return __end(__base);
+    }
+
+    constexpr auto
+    size() const
+    {
+        return __size(__base);
+    }
+
+    constexpr _View
+    base() const
+    {
+        return __base;
+    }
+};
+
+template <typename _View, typename _ViewInstance = std::remove_cvref_t<_View>>
+    requires(!__has_subscription_op<_ViewInstance>::value) && std::ranges::view<_ViewInstance> &&
+            std::ranges::random_access_range<_ViewInstance>
+auto
+__get_subscription_view(_View&& __view)
+{
+    // If the view doesn't support operator[], wrap it with __subscription_impl_view_simple
+    // to provide operator[] access and extend lifetime if necessary (for temporary ranges).
+    return __subscription_impl_view_simple<_ViewInstance>(__view);
+}
+#endif // _ONEDPL_CPP20_RANGES_PRESENT
+
+} // namespace __ranges
+} // namespace std::__onedpl
+
+#endif // _ONEDPL_UTILS_RANGES_H
diff --git a/libstdc++-v3/include/pstl/zip_view_impl.h b/libstdc++-v3/include/pstl/zip_view_impl.h
new file mode 100644
index 000000000000..17582d3facfd
--- /dev/null
+++ b/libstdc++-v3/include/pstl/zip_view_impl.h
@@ -0,0 +1,583 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Copyright (C) Intel Corporation
+//
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This file incorporates work covered by the following copyright and permission
+// notice:
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _ONEDPL_ZIP_VIEW_IMPL_H
+#define _ONEDPL_ZIP_VIEW_IMPL_H
+
+#if _ONEDPL_CPP20_RANGES_PRESENT
+
+#    include <ranges>
+#    include <type_traits>
+
+#    include "tuple_impl.h"
+#    include "iterator_impl.h"
+
+namespace std::__onedpl
+{
+
+namespace ranges
+{
+
+namespace __internal
+{
+
+template <bool _Const, typename _T>
+using __maybe_const = std::conditional_t<_Const, const _T, _T>;
+
+template <bool _C, typename... _Views>
+concept __all_forward = (std::ranges::forward_range<__maybe_const<_C, _Views>> && ...);
+
+template <bool _C, typename... _Views>
+concept __all_bidirectional = (std::ranges::bidirectional_range<__maybe_const<_C, _Views>> && ...);
+
+template <bool _C, typename... _Views>
+concept __all_random_access = (std::ranges::random_access_range<__maybe_const<_C, _Views>> && ...);
+
+// Determine when a zip_view can be a "common range" (where begin() and end() return the same type).
+// This is true in three cases:
+// 1. Only one range is being zipped and it's a common range
+// 2. All ranges are common ranges but NOT all bidirectional (simpler iteration logic)
+// 3. All ranges are both random-access AND sized (can calculate end position directly)
+// For details see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2321r2.html#when-is-zip_view-a-common_range
+template <typename... _Rs>
+concept __zip_is_common =
+    (sizeof...(_Rs) == 1 && (std::ranges::common_range<_Rs> && ...)) ||
+    (!(std::ranges::bidirectional_range<_Rs> && ...) && (std::ranges::common_range<_Rs> && ...)) ||
+    ((std::ranges::random_access_range<_Rs> && ...) && (std::ranges::sized_range<_Rs> && ...));
+
+template <bool _Const, typename... _Views>
+struct __declare_iterator_category
+{
+};
+
+template <bool _Const, typename... _Views>
+    requires __all_forward<_Const, _Views...>
+struct __declare_iterator_category<_Const, _Views...>
+{
+    using iterator_category = std::input_iterator_tag;
+};
+
+template <typename _R>
+concept __simple_view = std::ranges::view<_R> && std::ranges::range<const _R> &&
+                        std::same_as<std::ranges::iterator_t<_R>, std::ranges::iterator_t<const _R>> &&
+                        std::same_as<std::ranges::sentinel_t<_R>, std::ranges::sentinel_t<const _R>>;
+
+template <typename _F, typename _Tuple, std::size_t... _Ip>
+void
+__apply_to_tuple_impl(_F __f, _Tuple& __t, std::index_sequence<_Ip...>)
+{
+    (void(__f(std::get<_Ip>(__t))), ...);
+}
+
+template <typename _ReturnAdapter, typename _F, typename _Tuple, std::size_t... _Ip>
+decltype(auto)
+__apply_to_tuple_impl(_ReturnAdapter __tr, _F __f, _Tuple& __t, std::index_sequence<_Ip...>)
+{
+    return __tr(__f(std::get<_Ip>(__t))...);
+}
+
+template <typename _F, typename _Tuple1, typename _Tuple2, std::size_t... _Ip>
+void
+__apply_to_tuples_impl(_F __f, _Tuple1& __t1, _Tuple2& __t2, std::index_sequence<_Ip...>)
+{
+    (__f(std::get<_Ip>(__t1), std::get<_Ip>(__t2)), ...);
+}
+
+template <typename _F, typename _Tuple>
+void
+__apply_to_tuple(_F __f, _Tuple& __t)
+{
+    __apply_to_tuple_impl(__f, __t, std::make_index_sequence<std::tuple_size_v<_Tuple>>{});
+}
+
+template <typename _F, typename _Tuple, typename _ReturnAdapter>
+decltype(auto)
+__apply_to_tuple(_F __f, _Tuple& __t, _ReturnAdapter __tr)
+{
+    return __apply_to_tuple_impl(__tr, __f, __t, std::make_index_sequence<std::tuple_size_v<_Tuple>>{});
+}
+
+template <typename _F, typename _Tuple1, typename _Tuple2>
+void
+__apply_to_tuples(_F __f, _Tuple1& __t1, _Tuple2& __t2)
+{
+    static_assert(std::tuple_size_v<_Tuple1> == std::tuple_size_v<_Tuple2>);
+
+    __apply_to_tuples_impl(__f, __t1, __t2, std::make_index_sequence<std::tuple_size_v<_Tuple1>>{});
+}
+
+template <std::ranges::input_range... _Views>
+    requires((std::ranges::view<_Views> && ...) && (sizeof...(_Views) > 0))
+class zip_view : public std::ranges::view_interface<zip_view<_Views...>>
+{
+    template <typename... _Types>
+    using __tuple_type = __onedpl::__internal::tuple<_Types...>;
+
+  public:
+    zip_view() = default;
+    constexpr explicit zip_view(_Views... __views) : __views(std::move(__views)...) {}
+
+    //forward declaration of sentinel classes
+    template <bool _Const>
+    class sentinel;
+
+    template <bool _Const>
+    class iterator : public __internal::__declare_iterator_category<_Const, _Views...>
+    {
+      public:
+        using iterator_concept = std::conditional_t<
+            __internal::__all_random_access<_Const, _Views...>, std::random_access_iterator_tag,
+            std::conditional_t<__internal::__all_bidirectional<_Const, _Views...>, std::bidirectional_iterator_tag,
+                               std::conditional_t<__internal::__all_forward<_Const, _Views...>,
+                                                  std::forward_iterator_tag, std::input_iterator_tag>>>;
+
+        using value_type = __tuple_type<std::ranges::range_value_t<__internal::__maybe_const<_Const, _Views>>...>;
+        using difference_type =
+            std::common_type_t<std::ranges::range_difference_t<__internal::__maybe_const<_Const, _Views>>...>;
+
+      private:
+        using __reference_type =
+            __tuple_type<std::ranges::range_reference_t<__internal::__maybe_const<_Const, _Views>>...>;
+        using __rvalue_reference_type =
+            __tuple_type<std::ranges::range_rvalue_reference_t<__internal::__maybe_const<_Const, _Views>>...>;
+
+        using __iterators_type = __tuple_type<std::ranges::iterator_t<__internal::__maybe_const<_Const, _Views>>...>;
+
+      public:
+        iterator() = default;
+        constexpr iterator(iterator<!_Const> __i)
+            requires _Const &&
+                     (std::convertible_to<std::ranges::iterator_t<_Views>,
+                                          std::ranges::iterator_t<__internal::__maybe_const<_Const, _Views>>> &&
+                      ...)
+            : __current(std::move(__i.__current))
+        {
+        }
+
+      private:
+        constexpr explicit iterator(__iterators_type __current) : __current(std::move(__current)) {}
+
+        template <typename _Tp>
+        static constexpr _Tp
+        __abs(_Tp __t)
+        {
+            return __t < 0 ? -__t : __t;
+        }
+
+      public:
+        template <typename... _Iterators>
+        operator __onedpl::zip_iterator<_Iterators...>() const
+        {
+            auto __adaptor = [](auto&&... __iterators) -> decltype(auto) {
+                return __onedpl::make_zip_iterator(std::forward<decltype(__iterators)>(__iterators)...);
+            };
+            return __internal::__apply_to_tuple([](auto __it) -> decltype(auto) { return __it; }, __current, __adaptor);
+        }
+
+        constexpr decltype(auto)
+        operator*() const
+        {
+            auto __tr = [](auto&&... __args) -> decltype(auto) {
+                return __reference_type(std::forward<decltype(__args)>(__args)...);
+            };
+            return __internal::__apply_to_tuple([](auto& __it) -> decltype(auto) { return *__it; }, __current, __tr);
+        }
+
+        constexpr decltype(auto)
+        operator[](difference_type __n) const
+            requires __internal::__all_random_access<_Const, _Views...>
+        {
+            return *(*this + __n);
+        }
+
+        constexpr iterator&
+        operator++()
+        {
+            __internal::__apply_to_tuple([](auto& __it) -> decltype(auto) { return ++__it; }, __current);
+            return *this;
+        }
+
+        constexpr void
+        operator++(int)
+        {
+            ++*this;
+        }
+
+        constexpr iterator
+        operator++(int)
+            requires __internal::__all_forward<_Const, _Views...>
+        {
+            auto __tmp = *this;
+            ++*this;
+            return __tmp;
+        }
+
+        constexpr iterator&
+        operator--()
+            requires __internal::__all_bidirectional<_Const, _Views...>
+        {
+            __internal::__apply_to_tuple([](auto& __it) { return --__it; }, __current);
+            return *this;
+        }
+
+        constexpr iterator
+        operator--(int)
+            requires __internal::__all_bidirectional<_Const, _Views...>
+        {
+            auto __tmp = *this;
+            --*this;
+            return __tmp;
+        }
+
+        constexpr iterator&
+        operator+=(difference_type __n)
+            requires __internal::__all_random_access<_Const, _Views...>
+        {
+            __internal::__apply_to_tuple([__n](auto& __it) { return __it += __n; }, __current);
+            return *this;
+        }
+
+        constexpr iterator&
+        operator-=(difference_type __n)
+            requires __internal::__all_random_access<_Const, _Views...>
+        {
+            __internal::__apply_to_tuple([__n](auto& __it) { return __it -= __n; }, __current);
+            return *this;
+        }
+
+        friend constexpr bool
+        operator==(const iterator& __x, const iterator& __y)
+            requires(std::equality_comparable<std::ranges::iterator_t<__internal::__maybe_const<_Const, _Views>>> &&
+                     ...)
+        {
+            if constexpr (__internal::__all_bidirectional<_Const, _Views...>)
+            {
+                return __x.__current == __y.__current;
+            }
+            else
+            {
+                return __x.__compare_equal(__y, std::make_index_sequence<sizeof...(_Views)>());
+            }
+        }
+
+        template <bool _OtherConst>
+            requires(std::sentinel_for<std::ranges::sentinel_t<__internal::__maybe_const<_OtherConst, _Views>>,
+                                       std::ranges::iterator_t<__internal::__maybe_const<_Const, _Views>>> &&
+                     ...)
+        friend constexpr bool
+        operator==(const iterator& __x, const sentinel<_OtherConst>& __y)
+        {
+            return __x.__compare_with_sentinels(__y.__get_end(), std::make_index_sequence<sizeof...(_Views)>());
+        }
+
+        friend constexpr auto
+        operator<=>(const iterator& __x, const iterator& __y)
+            requires __internal::__all_random_access<_Const, _Views...>
+        {
+            if (__x.__current < __y.__current)
+                return std::weak_ordering::less;
+            else if (__x.__current == __y.__current)
+                return std::weak_ordering::equivalent;
+            return std::weak_ordering::greater; //__x.current > __y.__current
+        }
+
+        friend constexpr auto
+        operator-(const iterator& __x, const iterator& __y)
+            requires(std::sized_sentinel_for<std::ranges::iterator_t<__internal::__maybe_const<_Const, _Views>>,
+                                             std::ranges::iterator_t<__internal::__maybe_const<_Const, _Views>>> &&
+                     ...)
+        {
+            auto __calc_val = [&]<std::size_t... _In>(std::index_sequence<_In...>) {
+                return std::ranges::min(
+                    {difference_type(std::get<_In>(__x.__current) - std::get<_In>(__y.__current))...}, std::less{},
+                    [](auto __a) { return iterator::__abs(__a); });
+            };
+
+            return __calc_val(std::make_index_sequence<sizeof...(_Views)>());
+        }
+
+        template <bool _OtherConst>
+            requires(std::sized_sentinel_for<std::ranges::sentinel_t<__internal::__maybe_const<_OtherConst, _Views>>,
+                                             std::ranges::iterator_t<__internal::__maybe_const<_Const, _Views>>> &&
+                     ...)
+        friend constexpr difference_type
+        operator-(const iterator& __x, const sentinel<_OtherConst>& __y)
+        {
+            auto __calc_val = [&]<std::size_t... _In>(std::index_sequence<_In...>) {
+                return std::ranges::min(
+                    {difference_type(std::get<_In>(__x.__current) - std::get<_In>(__y.__get_end()))...}, std::less{},
+                    [](auto __a) { return iterator::__abs(__a); });
+            };
+
+            return __calc_val(std::make_index_sequence<sizeof...(_Views)>());
+        }
+
+        template <bool _OtherConst>
+            requires(std::sized_sentinel_for<std::ranges::sentinel_t<__internal::__maybe_const<_OtherConst, _Views>>,
+                                             std::ranges::iterator_t<__internal::__maybe_const<_Const, _Views>>> &&
+                     ...)
+        friend constexpr difference_type
+        operator-(const sentinel<_OtherConst>& __y, const iterator& __x)
+        {
+            return -(__x - __y);
+        }
+
+        friend constexpr iterator
+        operator+(iterator __it, difference_type __n)
+            requires __internal::__all_random_access<_Const, _Views...>
+        {
+            return __it += __n;
+        }
+
+        friend constexpr iterator
+        operator+(difference_type __n, iterator __it)
+            requires __internal::__all_random_access<_Const, _Views...>
+        {
+            return __it += __n;
+        }
+
+        friend constexpr iterator
+        operator-(iterator __it, difference_type __n)
+            requires __internal::__all_random_access<_Const, _Views...>
+        {
+            return __it -= __n;
+        }
+
+        friend constexpr decltype(auto)
+        iter_move(const iterator& __x) noexcept(
+            (noexcept(std::ranges::iter_move(
+                 std::declval<const std::ranges::iterator_t<__internal::__maybe_const<_Const, _Views>>&>())) &&
+             ...) &&
+            (std::is_nothrow_move_constructible_v<
+                 std::ranges::range_rvalue_reference_t<__internal::__maybe_const<_Const, _Views>>> &&
+             ...))
+        {
+            auto __tr = [](auto&&... __args) -> decltype(auto) {
+                return __rvalue_reference_type(std::forward<decltype(__args)>(__args)...);
+            };
+            return __internal::__apply_to_tuple(std::ranges::iter_move, __x.__current, __tr);
+        }
+
+        friend constexpr void
+        iter_swap(const iterator& __x, const iterator& __y) noexcept(
+            (noexcept(std::ranges::iter_swap(
+                 std::declval<const std::ranges::iterator_t<__internal::__maybe_const<_Const, _Views>>&>(),
+                 std::declval<const std::ranges::iterator_t<__internal::__maybe_const<_Const, _Views>>&>())) &&
+             ...))
+            requires(std::indirectly_swappable<std::ranges::iterator_t<__internal::__maybe_const<_Const, _Views>>> &&
+                     ...)
+        {
+            __internal::__apply_to_tuples(std::ranges::iter_swap, __x.__current, __y.__current);
+        }
+
+      private:
+        template <std::size_t... _In>
+        constexpr bool
+        __compare_equal(const iterator& __y, std::index_sequence<_In...>) const
+        {
+            return ((std::get<_In>(__current) == std::get<_In>(__y.__current)) || ...);
+        }
+
+        template <typename _SentinelsTuple, std::size_t... _In>
+        constexpr bool
+        __compare_with_sentinels(const _SentinelsTuple& __sentinels, std::index_sequence<_In...>) const
+        {
+            return ((std::get<_In>(__current) == std::get<_In>(__sentinels)) || ...);
+        }
+
+        friend class zip_view;
+
+        __iterators_type __current;
+    }; // class iterator
+
+    template <bool _Const>
+    class sentinel
+    {
+        using difference_type =
+            std::common_type_t<std::ranges::range_difference_t<__internal::__maybe_const<_Const, _Views>>...>;
+
+        template <typename... _Sentinels>
+        constexpr explicit sentinel(_Sentinels... __sentinels) : __end(std::move(__sentinels)...)
+        {
+        }
+
+      public:
+        sentinel() = default;
+        constexpr sentinel(sentinel<!_Const> __i)
+            requires _Const &&
+                     (std::convertible_to<std::ranges::sentinel_t<_Views>,
+                                          std::ranges::sentinel_t<__internal::__maybe_const<_Const, _Views>>> &&
+                      ...)
+            : __end(std::move(__i.__end))
+        {
+        }
+
+      private:
+        friend class zip_view;
+
+#    if _ONEDPL_HIDDEN_FRIENDS_SIBLING_ACCESS_BROKEN
+      public:
+#    endif
+        decltype(auto)
+        __get_end() const
+        {
+            return __end;
+        }
+
+        __tuple_type<std::ranges::sentinel_t<__internal::__maybe_const<_Const, _Views>>...> __end;
+    }; // class sentinel
+
+    constexpr auto
+    begin()
+        requires(!(__internal::__simple_view<_Views> && ...))
+    {
+        using __iterators_type = __tuple_type<std::ranges::iterator_t<__internal::__maybe_const<false, _Views>>...>;
+        auto __tr = [](auto&&... __args) {
+            return iterator<false>(__iterators_type(std::forward<decltype(__args)>(__args)...));
+        };
+        return __internal::__apply_to_tuple(std::ranges::begin, __views, __tr);
+    }
+
+    constexpr auto
+    begin() const
+        requires(std::ranges::range<const _Views> && ...)
+    {
+        using __iterators_type = __tuple_type<std::ranges::iterator_t<__internal::__maybe_const<true, _Views>>...>;
+        auto __tr = [](auto&&... __args) {
+            return iterator<true>(__iterators_type(std::forward<decltype(__args)>(__args)...));
+        };
+        return __internal::__apply_to_tuple(std::ranges::begin, __views, __tr);
+    }
+
+    constexpr auto
+    end()
+        requires(!(__internal::__simple_view<_Views> && ...))
+    {
+        if constexpr (!__internal::__zip_is_common<_Views...>)
+        {
+            auto __tr = [](auto&&... __args) { return sentinel<false>(std::forward<decltype(__args)>(__args)...); };
+            return __internal::__apply_to_tuple(std::ranges::end, __views, __tr);
+        }
+        else if constexpr ((std::ranges::random_access_range<_Views> && ...))
+        {
+            auto __it = begin();
+            __it += static_cast<typename decltype(__it)::difference_type>(size());
+            return __it;
+        }
+        else
+        {
+            using __iterators_type = __tuple_type<std::ranges::iterator_t<__internal::__maybe_const<false, _Views>>...>;
+            auto __tr = [](auto&&... __args) {
+                return iterator<false>(__iterators_type(std::forward<decltype(__args)>(__args)...));
+            };
+            return __internal::__apply_to_tuple(std::ranges::end, __views, __tr);
+        }
+    }
+
+    constexpr auto
+    end() const
+        requires(std::ranges::range<const _Views> && ...)
+    {
+        if constexpr (!__internal::__zip_is_common<const _Views...>)
+        {
+            auto __tr = [](auto&&... __args) { return sentinel<true>(std::forward<decltype(__args)>(__args)...); };
+            return __internal::__apply_to_tuple(std::ranges::end, __views, __tr);
+        }
+        else if constexpr ((std::ranges::random_access_range<const _Views> && ...))
+        {
+            auto __it = begin();
+            __it += static_cast<typename decltype(__it)::difference_type>(size());
+            return __it;
+        }
+        else
+        {
+            using __iterators_type = __tuple_type<std::ranges::iterator_t<__internal::__maybe_const<true, _Views>>...>;
+            auto __tr = [](auto&&... __args) {
+                return iterator<true>(__iterators_type(std::forward<decltype(__args)>(__args)...));
+            };
+            return __internal::__apply_to_tuple(std::ranges::end, __views, __tr);
+        }
+    }
+
+    constexpr auto
+    size()
+        requires(std::ranges::sized_range<_Views> && ...)
+    {
+        auto __tr = [](auto... __args) {
+            using _CT = std::make_unsigned_t<std::common_type_t<decltype(__args)...>>;
+            return std::ranges::min({_CT(__args)...});
+        };
+
+        return __internal::__apply_to_tuple(std::ranges::size, __views, __tr);
+    }
+
+    constexpr auto
+    size() const
+        requires(std::ranges::sized_range<const _Views> && ...)
+    {
+        auto __tr = [](auto... __args) {
+            using _CT = std::make_unsigned_t<std::common_type_t<decltype(__args)...>>;
+            return std::ranges::min({_CT(__args)...});
+        };
+
+        return __internal::__apply_to_tuple(std::ranges::size, __views, __tr);
+    }
+
+    const __tuple_type<_Views...>&
+    base() const
+    {
+        return __views; // Exposing the tuple of views for use in SYCL access requirement checks. Not part of the public API.
+    }
+
+  private:
+    __tuple_type<_Views...> __views;
+}; // class zip_view
+
+template <typename... _Rs>
+zip_view(_Rs&&...) -> zip_view<std::views::all_t<_Rs>...>;
+
+struct zip_fn
+{
+    template <typename... _Ranges>
+    constexpr auto
+    operator()(_Ranges&&... __rs) const
+        -> decltype(__onedpl::ranges::__internal::zip_view<std::views::all_t<_Ranges&&>...>(
+            std::forward<_Ranges>(__rs)...))
+    {
+        return __onedpl::ranges::__internal::zip_view<std::views::all_t<_Ranges>...>(std::forward<_Ranges>(__rs)...);
+    }
+
+    constexpr auto
+    operator()() const
+    {
+        return std::ranges::empty_view<__onedpl::__internal::tuple<>>{};
+    }
+};
+
+inline constexpr __onedpl::ranges::__internal::zip_fn zip{};
+
+} // namespace __internal
+
+} // namespace ranges
+
+} // namespace std::__onedpl
+
+template <typename... _Ranges>
+inline constexpr bool std::ranges::enable_borrowed_range<__onedpl::ranges::__internal::zip_view<_Ranges...>> =
+    (std::ranges::enable_borrowed_range<_Ranges> && ...);
+
+#endif //_ONEDPL_CPP20_RANGES_PRESENT
+
+#endif //_ONEDPL_ZIP_VIEW_IMPL_H
diff --git a/libstdc++-v3/include/std/algorithm b/libstdc++-v3/include/std/algorithm
index c3e433334fea..5a0577308c87 100644
--- a/libstdc++-v3/include/std/algorithm
+++ b/libstdc++-v3/include/std/algorithm
@@ -91,6 +91,76 @@
 #    include <pstl/glue_algorithm_defs.h>
 #    define _PSTL_ALGORITHM_FORWARD_DECLARED 1
 #  endif
+namespace std
+{
+  using __onedpl::all_of;
+  using __onedpl::any_of;
+  using __onedpl::none_of;
+  using __onedpl::for_each;
+  using __onedpl::for_each_n;
+  using __onedpl::find;
+  using __onedpl::find_if;
+  using __onedpl::find_if_not;
+  using __onedpl::find_end;
+  using __onedpl::find_first_of;
+  using __onedpl::adjacent_find;
+  using __onedpl::count;
+  using __onedpl::count_if;
+  using __onedpl::mismatch;
+  using __onedpl::equal;
+  using __onedpl::search;
+  using __onedpl::search_n;
+  using __onedpl::copy;
+  using __onedpl::copy_n;
+  using __onedpl::copy_if;
+  using __onedpl::move;
+  using __onedpl::swap_ranges;
+  using __onedpl::transform;
+  using __onedpl::replace;
+  using __onedpl::replace_if;
+  using __onedpl::replace_copy;
+  using __onedpl::replace_copy_if;
+  using __onedpl::fill;
+  using __onedpl::fill_n;
+  using __onedpl::generate;
+  using __onedpl::generate_n;
+  using __onedpl::remove;
+  using __onedpl::remove_if;
+  using __onedpl::remove_copy;
+  using __onedpl::remove_copy_if;
+  using __onedpl::unique;
+  using __onedpl::unique_copy;
+  using __onedpl::reverse;
+  using __onedpl::reverse_copy;
+  using __onedpl::rotate;
+  using __onedpl::rotate_copy;
+  using __onedpl::shift_left;
+  using __onedpl::shift_right;
+  using __onedpl::sort;
+  using __onedpl::stable_sort;
+  using __onedpl::partial_sort;
+  using __onedpl::partial_sort_copy;
+  using __onedpl::is_sorted;
+  using __onedpl::is_sorted_until;
+  using __onedpl::nth_element;
+  using __onedpl::is_partitioned;
+  using __onedpl::partition;
+  using __onedpl::stable_partition;
+  using __onedpl::partition_copy;
+  using __onedpl::merge;
+  using __onedpl::inplace_merge;
+  using __onedpl::includes;
+  using __onedpl::set_union;
+  using __onedpl::set_intersection;
+  using __onedpl::set_difference;
+  using __onedpl::set_symmetric_difference;
+  using __onedpl::is_heap;
+  using __onedpl::is_heap_until;
+  using __onedpl::min_element;
+  using __onedpl::max_element;
+  using __onedpl::minmax_element;
+  using __onedpl::lexicographical_compare;
+}
 #endif // __cpp_lib_parallel_algorithm
 
 #ifdef _GLIBCXX_PARALLEL
diff --git a/libstdc++-v3/include/std/execution b/libstdc++-v3/include/std/execution
index c76a11bc7a98..5993347edbdc 100644
--- a/libstdc++-v3/include/std/execution
+++ b/libstdc++-v3/include/std/execution
@@ -53,7 +53,7 @@
 # endif
 
 // Memory implementation
-# if _PSTL_NUMERIC_FORWARD_DECLARED
+# if _PSTL_MEMORY_FORWARD_DECLARED
 #  include <pstl/glue_memory_impl.h>
 # endif
 
diff --git a/libstdc++-v3/include/std/memory b/libstdc++-v3/include/std/memory
index aea83b6a7511..8009a2c9b40f 100644
--- a/libstdc++-v3/include/std/memory
+++ b/libstdc++-v3/include/std/memory
@@ -185,7 +185,23 @@ _GLIBCXX_END_NAMESPACE_VERSION
 # else
 // Otherwise just pull in forward declarations
 #  include <pstl/glue_memory_defs.h>
+#  define _PSTL_MEMORY_FORWARD_DECLARED 1
 # endif
+namespace std
+{
+  using __onedpl::uninitialized_copy;
+  using __onedpl::uninitialized_copy_n;
+  using __onedpl::uninitialized_move;
+  using __onedpl::uninitialized_move_n;
+  using __onedpl::uninitialized_fill;
+  using __onedpl::uninitialized_fill_n;
+  using __onedpl::destroy;
+  using __onedpl::destroy_n;
+  using __onedpl::uninitialized_default_construct;
+  using __onedpl::uninitialized_default_construct_n;
+  using __onedpl::uninitialized_value_construct;
+  using __onedpl::uninitialized_value_construct_n;
+}
 #endif // __cpp_lib_parallel_algorithm
 
 #endif /* _GLIBCXX_MEMORY */
diff --git a/libstdc++-v3/include/std/numeric b/libstdc++-v3/include/std/numeric
index 6dbea81e846d..dd52bd940d2f 100644
--- a/libstdc++-v3/include/std/numeric
+++ b/libstdc++-v3/include/std/numeric
@@ -860,6 +860,16 @@ _GLIBCXX_END_NAMESPACE_VERSION
 #  include <pstl/glue_numeric_defs.h>
 #  define _PSTL_NUMERIC_FORWARD_DECLARED 1
 # endif
+namespace std
+{
+  using __onedpl::reduce;
+  using __onedpl::transform_reduce;
+  using __onedpl::exclusive_scan;
+  using __onedpl::inclusive_scan;
+  using __onedpl::transform_exclusive_scan;
+  using __onedpl::transform_inclusive_scan;
+  using __onedpl::adjacent_difference;
+}
 #endif // __cpp_lib_parallel_algorithm
 
 #endif /* _GLIBCXX_NUMERIC */
diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/110512.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/110512.cc
index 188c7c915e51..862ff0a6e72b 100644
--- a/libstdc++-v3/testsuite/25_algorithms/pstl/110512.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/pstl/110512.cc
@@ -13,9 +13,8 @@ using RAIter = __gnu_test::random_access_iterator_wrapper<float>;
 
 template<typename... Iter>
 constexpr bool all_random_access
-  = __pstl::__internal::__are_random_access_iterators<Iter...>::value;
+  = std::__onedpl::__internal::__is_random_access_iterator_v<Iter...>;
 
-using __pstl::__internal::__are_random_access_iterators;
 static_assert( all_random_access<RAIter> );
 static_assert( all_random_access<int*, RAIter, const long*> );
 static_assert( ! all_random_access<RAIter, FwdIter> );
diff --git a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_modifying_operations/replace.cc b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_modifying_operations/replace.cc
index c6a515e4c88d..c90965f2a00e 100644
--- a/libstdc++-v3/testsuite/25_algorithms/pstl/alg_modifying_operations/replace.cc
+++ b/libstdc++-v3/testsuite/25_algorithms/pstl/alg_modifying_operations/replace.cc
@@ -157,7 +157,7 @@ struct test_non_const
 int
 main()
 {
-    test<int32_t, float32_t>(__pstl::__internal::__equal_value<int32_t>(666));
+    test<int32_t, float32_t>(std::__onedpl::__internal::__equal_value<int32_t>(666));
     test<uint16_t, uint8_t>([](const uint16_t& elem) { return elem % 3 < 2; });
     test<float64_t, int64_t>([](const float64_t& elem) { return elem * elem - 3.5 * elem > 10; });
     test<copy_int, copy_int>([](const copy_int& val) { return val.value / 5 > 2; });
diff --git a/libstdc++-v3/testsuite/util/pstl/test_utils.h b/libstdc++-v3/testsuite/util/pstl/test_utils.h
index 02861178e344..bda7e0f93a46 100644
--- a/libstdc++-v3/testsuite/util/pstl/test_utils.h
+++ b/libstdc++-v3/testsuite/util/pstl/test_utils.h
@@ -1304,15 +1304,12 @@ template <typename Policy, typename F>
 static void
 invoke_if(Policy&&, F f)
 {
-#if defined(_PSTL_ICC_16_VC14_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN) || defined(_PSTL_ICC_17_VC141_TEST_SIMD_LAMBDA_DEBUG_32_BROKEN)
     using decay_policy = typename std::decay<Policy>::type;
     using allow_unsequenced =
         std::integral_constant<bool, (std::is_same<decay_policy, std::execution::unsequenced_policy>::value ||
                                       std::is_same<decay_policy, std::execution::parallel_unsequenced_policy>::value)>;
-    __pstl::__internal::__invoke_if_not(allow_unsequenced{}, f);
-#else
-    f();
-#endif
+    if constexpr (!allow_unsequenced::value)
+	f();
 }
 
 } /* namespace TestUtils */
-- 
2.56.0



More information about the Libstdc++ mailing list