Skip to content

Commit

Permalink
Merge pull request #6 from correaa/move-memory-resource
Browse files Browse the repository at this point in the history
move pmr out of core headers
  • Loading branch information
correaa authored Apr 20, 2024
2 parents 2343066 + a3c9ed1 commit d38bbf4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 deletions.
16 changes: 0 additions & 16 deletions include/boost/multi/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
#include <type_traits> // for std::common_reference
#include <utility> // for std::move

#if(not defined(__GLIBCXX__) or (__GLIBCXX__ >= 20210601)) and (not defined(_LIBCPP_VERSION) or (_LIBCPP_VERSION > 14000))
#include <memory_resource>
#endif

namespace boost::multi {

template<class Allocator>
Expand Down Expand Up @@ -1316,18 +1312,6 @@ template<class T, boost::multi::dimensionality_type D, class... A> struct std::c
template<class T, boost::multi::dimensionality_type D, class... A> struct std::common_reference<typename ::boost::multi::array<T, D, A...>::basic_const_array, ::boost::multi::array<T, D, A...>&> { using type = typename ::boost::multi::array<T, D, A...>::basic_const_array; };
#endif

#if(defined(__cpp_lib_memory_resource) && (__cpp_lib_memory_resource >= 201603))
namespace boost::multi::pmr {
template<class T, boost::multi::dimensionality_type D>
using array = boost::multi::array<T, D, std::pmr::polymorphic_allocator<T>>;
} // end namespace boost::multi::pmr
#else
namespace boost::multi::pmr {
template<class T, boost::multi::dimensionality_type D>
struct [[deprecated("no PMR allocator")]] array; // your version of C++ doesn't provide polymorphic_allocators
} // end namespace boost::multi::pmr
#endif

namespace boost::serialization {

template<typename T, boost::multi::dimensionality_type D, class A>
Expand Down
26 changes: 26 additions & 0 deletions include/boost/multi/pmr.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2018-2024 Alfredo A. Correa

#ifndef MULTI_ARRAY_PMR_HPP_
#define MULTI_ARRAY_PMR_HPP_

#include <multi/array.hpp>

#if(!defined(__GLIBCXX__) || (__GLIBCXX__ >= 20210601)) && (!defined(_LIBCPP_VERSION) || (_LIBCPP_VERSION > 14000))
#include <memory_resource>
#endif

#if(defined(__cpp_lib_memory_resource) && (__cpp_lib_memory_resource >= 201603))
namespace boost::multi::pmr {

template<class T, boost::multi::dimensionality_type D>
using array = boost::multi::array<T, D, std::pmr::polymorphic_allocator<T>>;

} // end namespace boost::multi::pmr
#else
namespace boost::multi::pmr {
template<class T, boost::multi::dimensionality_type D>
struct [[deprecated("no PMR allocator")]] array; // your version of C++ doesn't provide polymorphic_allocators
} // end namespace boost::multi::pmr
#endif

#endif
6 changes: 6 additions & 0 deletions test/allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
#include <boost/test/unit_test.hpp>

#include <multi/array.hpp>
#include <multi/pmr.hpp>

#include <multi/detail/static_allocator.hpp>

#include <vector>

#if(not defined(__GLIBCXX__) or (__GLIBCXX__ >= 20210601)) and (not defined(_LIBCPP_VERSION) or (_LIBCPP_VERSION > 14000))
#include <memory_resource>
#endif

namespace multi = boost::multi;

BOOST_AUTO_TEST_CASE(empty_stride) {
Expand Down
5 changes: 5 additions & 0 deletions test/fix_complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
#include <boost/test/unit_test.hpp>

#include <multi/array.hpp>
#include <multi/pmr.hpp>

#include <complex>
#include <vector>

#if(not defined(__GLIBCXX__) or (__GLIBCXX__ >= 20210601)) and (not defined(_LIBCPP_VERSION) or (_LIBCPP_VERSION > 14000))
#include <memory_resource>
#endif

namespace multi = boost::multi;

#ifdef __NVCC__
Expand Down
5 changes: 5 additions & 0 deletions test/pmr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
#include<boost/test/unit_test.hpp>

#include <multi/array.hpp>
#include <multi/pmr.hpp>

#include <numeric>

#if(not defined(__GLIBCXX__) or (__GLIBCXX__ >= 20210601)) and (not defined(_LIBCPP_VERSION) or (_LIBCPP_VERSION > 14000))
#include <memory_resource>
#endif

namespace multi = boost::multi;

BOOST_AUTO_TEST_CASE(pmr_partially_formed) {
Expand Down

0 comments on commit d38bbf4

Please sign in to comment.