/**************************************************************************** * Copyright (c) 2017-2022 by the ArborX authors * * All rights reserved. * * * * This file is part of the ArborX library. ArborX is * * distributed under a BSD 3-clause license. For the licensing terms see * * the LICENSE file in the top-level directory. * * * * SPDX-License-Identifier: BSD-3-Clause * ****************************************************************************/ #ifndef ARBORX_BOOST_RANGE_ADAPTERS_HPP #define ARBORX_BOOST_RANGE_ADAPTERS_HPP #include #include #include #include #include // is_same namespace boost { #define ARBORX_ASSERT_VIEW_COMPATIBLE(View) \ using Traits = typename View::traits; \ static_assert(Traits::rank == 1, \ "Adaptor to Boost.Range only available for Views of rank 1"); \ static_assert( \ ArborX::Details::KokkosExt::is_accessible_from_host::value, \ "Adaptor to Boost.Range only available when View memory space is " \ "accessible from host"); // Adapt Kokkos::View to Boost.Range template struct range_iterator> { using View = Kokkos::View; ARBORX_ASSERT_VIEW_COMPATIBLE(View) using type = std::add_pointer_t::value_type>; }; template struct range_const_iterator> { using View = Kokkos::View; ARBORX_ASSERT_VIEW_COMPATIBLE(View) using type = std::add_pointer_t< typename Kokkos::ViewTraits::const_value_type>; }; template struct range_value> { using View = Kokkos::View; ARBORX_ASSERT_VIEW_COMPATIBLE(View) using type = typename Kokkos::ViewTraits::value_type; }; template struct range_reference> { using View = Kokkos::View; ARBORX_ASSERT_VIEW_COMPATIBLE(View) using type = typename Kokkos::ViewTraits::reference_type; }; template struct range_size> { using View = Kokkos::View; ARBORX_ASSERT_VIEW_COMPATIBLE(View) using type = typename Kokkos::ViewTraits::size_type; }; } // namespace boost namespace Kokkos { template inline typename boost::range_iterator>::type range_begin(Kokkos::View &v) { using View = Kokkos::View; ARBORX_ASSERT_VIEW_COMPATIBLE(View) return v.data(); } template inline typename boost::range_const_iterator>::type range_begin(Kokkos::View const &v) { using View = Kokkos::View; ARBORX_ASSERT_VIEW_COMPATIBLE(View) return v.data(); } template inline typename boost::range_iterator>::type range_end(Kokkos::View &v) { using View = Kokkos::View; ARBORX_ASSERT_VIEW_COMPATIBLE(View) ARBORX_ASSERT(v.span_is_contiguous()); return v.data() + v.span(); } template inline typename boost::range_const_iterator>::type range_end(Kokkos::View const &v) { using View = Kokkos::View; ARBORX_ASSERT_VIEW_COMPATIBLE(View) ARBORX_ASSERT(v.span_is_contiguous()); return v.data() + v.span(); } // optional template inline typename boost::range_size>::type range_calculate_size(Kokkos::View const &v) { using View = Kokkos::View; ARBORX_ASSERT_VIEW_COMPATIBLE(View) return v.extent(0); } #undef ARBORX_ASSERT_VIEW_COMPATIBLE } // namespace Kokkos #endif