Skip to content
Snippets Groups Projects
Commit 374be4cc authored by Enrico Guiraud's avatar Enrico Guiraud Committed by Danilo Piparo
Browse files

[VecOps] Make RAdoptAllocator<T> rebindable to RAdoptAllocator<bool>

...and viceversa. Only non-adopting RAdoptAllocators can be rebound.
This makes it possible to copy-construct RVec<bool>'s from other
RVec<bool>'s.
parent 78e4befd
No related branches found
No related tags found
No related merge requests found
......@@ -50,6 +50,8 @@ now the vector *v* owns its memory as a regular vector.
template <typename T>
class RAdoptAllocator {
public:
friend class RAdoptAllocator<bool>;
using propagate_on_container_move_assignment = std::true_type;
using propagate_on_container_swap = std::true_type;
using StdAlloc_t = std::allocator<T>;
......@@ -80,7 +82,7 @@ public:
RAdoptAllocator(RAdoptAllocator &&) = default;
RAdoptAllocator &operator=(const RAdoptAllocator &) = default;
RAdoptAllocator &operator=(RAdoptAllocator &&) = default;
RAdoptAllocator(const RAdoptAllocator<bool> &) : RAdoptAllocator() {}
RAdoptAllocator(const RAdoptAllocator<bool> &);
/// Construct an object at a certain memory address
/// \tparam U The type of the memory address at which the object needs to be constructed
......@@ -166,7 +168,13 @@ public:
RAdoptAllocator() = default;
RAdoptAllocator(const RAdoptAllocator &) = default;
RAdoptAllocator(pointer) {}
template <typename U>
RAdoptAllocator(const RAdoptAllocator<U> &o) : fStdAllocator(o.fStdAllocator)
{
if (o.fAllocType != RAdoptAllocator<U>::EAllocType::kOwning)
throw std::runtime_error("Cannot rebind owning RAdoptAllocator");
}
bool *allocate(std::size_t n) { return fStdAllocator.allocate(n); }
......@@ -189,6 +197,9 @@ public:
bool operator!=(const RAdoptAllocator &) { return false; }
};
template <typename T>
RAdoptAllocator<T>::RAdoptAllocator(const RAdoptAllocator<bool> &o) : fStdAllocator(o.fStdAllocator) {}
} // End NS VecOps
} // End NS Detail
} // End NS ROOT
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment