1

Following is my code snippet:

struct TestPMR
{
    std::vector<int> a;
    std::vector<int> b;
};

I would like to use my own memory resource for vectors a and b. Something like a std::pmr::new_delete_resource(). Following code is the example for what exactly I would like to implement:

auto mr = std::pmr::new_delete_resource();
std::pmr::vector<int> a(mr);

Above code works well when used within the function like:

void dummy_fn(){
     auto mr = std::pmr::new_delete_resource();
     std::pmr::vector<int> a(mr);
     another_dummy_fn(a);
}

void another_dummy_fn(std::pmr::vector<int> v){
...
}

How can I use the same inside structure TestPMR so that all instances of this structure allocates memory in the given memory resource? I tried std::pmr::vector<int> a(std::pmr::new_delete_resource()) and error occurs saying std::pmr::new_delete_resource() is not a type name

typedef function is not a type name? This link did not answer my question.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
SNR_BT
  • 133
  • 5
  • Just use braces: `struct TestPMR { std::pmr::vector a{std::pmr::new_delete_resource()}; std::pmr::vector b{std::pmr::new_delete_resource()}; };` I don't see the point though - that's just a very elaborate way to declare normal, plain vanilla vectors. – Igor Tandetnik May 30 '20 at 15:56

0 Answers0