1// Dear emacs, this is -*- c++ -*-
3 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
6 * @file AthContainers/ConstDataVector.icc
7 * @author scott snyder <snyder@bnl.gov>
9 * @brief @c DataVector adapter that acts like it holds const pointers.
13#include "CxxUtils/checker_macros.h"
14#include "CxxUtils/throw_out_of_range.h"
19namespace ConstDataVector_detail {
22/// Functional to cast const away.
27 T* operator() (const T* p) const {
28 T* pp ATLAS_THREAD_SAFE = const_cast<T*> (p);
34} // namespace ConstDataVector_detail
37//=== Constructors, destructors, assignment.
41 * @brief Default constructor.
42 * @param ownPolicy The ownership mode for the container.
44 * By default, a @c DataVector will own its elements.
45 * To avoid this, pass @c SG::VIEW_ELEMENTS for @a ownPolicy.
49ConstDataVector<DV>::ConstDataVector
50 (SG::OwnershipPolicy ownPolicy /*= SG::OWN_ELEMENTS*/)
53 base_data_vector::clear (ownPolicy, SG::NEVER_TRACK_INDICES);
58 * @brief Constructor with argument forwarding.
59 * @param ownPolicy The ownership mode for the container.
61 * All arguments are forwarded to the base class constructor.
64template <typename... ARGS>
66ConstDataVector<DV>::ConstDataVector (SG::OwnershipPolicy ownPolicy,
68 : DV (ownPolicy, std::forward<ARGS>(args)...)
70 base_data_vector::clear (ownPolicy, SG::NEVER_TRACK_INDICES);
75 * @brief Sized constructor.
76 * @param n The size of the container.
77 * @param ownPolicy The ownership mode for the container.
79 * Note that unlike the standard vector constructor, you can't specify
80 * an initial value here. The container will be initialized with 0's.
82 * By default, a @c DataVector will own its elements.
83 * To avoid this, pass @c SG::VIEW_ELEMENTS for @a ownPolicy.
87ConstDataVector<DV>::ConstDataVector
89 SG::OwnershipPolicy ownPolicy /*= SG::OWN_ELEMENTS*/)
92 base_data_vector::clear (ownPolicy, SG::NEVER_TRACK_INDICES);
98 * @brief Constructor from iterators.
99 * @param first The start of the range to put in the new container.
100 * @param last The end of the range to put in the new container.
101 * @param ownPolicy The ownership mode for the container.
103 * By default, a @c DataVector will own its elements (and take ownership
104 * of the pointers passed to this constructor).
105 * To avoid this, pass @c SG::VIEW_ELEMENTS for @a ownPolicy.
108template <class InputIterator>
110ConstDataVector<DV>::ConstDataVector
111 (InputIterator first,
113 SG::OwnershipPolicy ownPolicy /*= SG::VIEW_ELEMENTS*/)
116 base_data_vector::clear (ownPolicy, SG::NEVER_TRACK_INDICES);
117 reserve (std::distance (first, last));
118 while (first != last)
119 push_back (*first++);
124 * @brief Move constructor.
125 * @param rhs The container from which to move.
127 * Any auxiliary data will be moved along with the container contents.
131ConstDataVector<DV>::ConstDataVector (ConstDataVector&& rhs)
132 : DV (std::move (rhs))
138 * @brief Constructor from an initializer list.
139 * @param l An initializer list.
140 * @param last The end of the range to put in the new container.
141 * @param ownPolicy The ownership mode for the container.
143 * By default, a @c DataVector will own its elements (and take ownership
144 * of the pointers passed to this constructor).
145 * To avoid this, pass @c SG::VIEW_ELEMENTS for @a ownPolicy.
149ConstDataVector<DV>::ConstDataVector
150 (std::initializer_list<value_type> l,
151 SG::OwnershipPolicy ownPolicy /*= SG::VIEW_ELEMENTS*/)
152 : ConstDataVector (l.begin(), l.end(), ownPolicy)
158 * @brief Constructor from a vector of ElementLinks.
159 * @param v The vector from which to initialize.
161 * This will make a view container.
164template <class CONTAINER>
165ConstDataVector<DV>::ConstDataVector
166 (const std::vector<ElementLink<CONTAINER> >& v)
167 : DV (SG::VIEW_ELEMENTS)
169 this->reserve (v.size());
170 for (const ElementLink<CONTAINER>& el : v)
171 this->push_back (*el);
176 * @brief Assignment operator.
177 * @param rhs The DataVector from which to assign.
178 * @return This object.
180 * This is a `shallow' copy; after the completion of this, the DataVector
181 * will not own its elements. Any elements it owned prior to this call
184 * Note: this method may only be called using the most derived
185 * @c DataVector in the hierarchy.
190ConstDataVector<DV>::operator= (const ConstDataVector& rhs)
192 *static_cast<DV*>(this) = rhs;
198 * @brief Move assignment.
199 * @param rhs The container from which to move.
201 * Any auxiliary data will be moved along with the container contents.
206ConstDataVector<DV>::operator= (ConstDataVector&& rhs)
209 DV::operator= (std::move (rhs));
216 * @brief Assignment operator, from an initializer list.
217 * @param l An initializer list.
218 * @return This object.
220 * This is equivalent to @c assign.
221 * Any existing owned elements will be released.
222 * The @c DataVector's ownership policy determines whether it will take
223 * ownership of the new elements.
228ConstDataVector<DV>::operator= (std::initializer_list<value_type> l)
230 this->assign (l.begin(), l.end());
236 * @brief Assign from iterators.
237 * @param first The start of the range to put in the container.
238 * @param last The end of the range to put in the container.
240 * Any existing owned elements will be released.
241 * The @c DataVector's ownership policy determines whether it will take
242 * ownership of the new elements.
245template <class InputIterator>
247void ConstDataVector<DV>::assign(InputIterator first, InputIterator last)
250 reserve (std::distance (first, last));
251 while (first != last)
252 push_back (*first++);
257 * @brief Assign from an initializer list.
258 * @param l An initializer list.
260 * Any existing owned elements will be released.
261 * The @c DataVector's ownership policy determines whether it will take
262 * ownership of the new elements.
266void ConstDataVector<DV>::assign(std::initializer_list<value_type> l)
268 this->assign (l.begin(), l.end());
273 * @brief Assign from a vector of ElementLinks.
274 * @param v The vector from which to initialize.
276 * This will change the container to a view container.
279template <class CONTAINER>
280void ConstDataVector<DV>::assign (const std::vector<ElementLink<CONTAINER> >& v)
282 this->clear(SG::VIEW_ELEMENTS);
283 this->reserve (v.size());
284 for (const ElementLink<CONTAINER>& el : v)
285 this->push_back (*el);
293 * @brief Access an element, as an lvalue.
294 * @param n Array index to access.
295 * @return Proxy to the element at @a n.
297 * No bounds checking is done.
298 * Note that we return a proxy object rather than a reference;
299 * the proxy will handle deleting an owned element if it's assigned to.
303typename ConstDataVector<DV>::ElementProxy
304ConstDataVector<DV>::operator[] (size_type n)
306 return to_element_proxy (this->m_pCont.begin() + n);
311 * @brief Access an element, as an lvalue.
312 * @param n Array index to access.
313 * @return Proxy to the element at @a n.
315 * Will raise @c std::out_of_range if the index is out-of-bounds.
316 * Note that we return a proxy object rather than a reference;
317 * the proxy will handle deleting an owned element if it's assigned to.
321typename ConstDataVector<DV>::ElementProxy
322ConstDataVector<DV>::at (size_type n)
324 if (n >= this->size())
325 CxxUtils::throw_out_of_range (__PRETTY_FUNCTION__, n, this->size(), this);
326 return to_element_proxy (this->m_pCont.begin() + n);
331 * @brief Access the first element in the collection as an lvalue.
332 * @return Proxy to the first element in the collection.
334 * No checking is done to ensure that the container is not empty.
335 * Note that we return a proxy object rather than a reference;
336 * the proxy will handle deleting an owned element if it's assigned to.
340typename ConstDataVector<DV>::ElementProxy
341ConstDataVector<DV>::front ()
343 return to_element_proxy (this->m_pCont.begin());
348 * @brief Access the last element in the collection as an lvalue.
349 * @return Proxy to the last element in the collection.
351 * No checking is done to ensure that the container is not empty.
352 * Note that we return a proxy object rather than a reference;
353 * the proxy will handle deleting an owned element if it's assigned to.
357typename ConstDataVector<DV>::ElementProxy
358ConstDataVector<DV>::back ()
360 return to_element_proxy (this->m_pCont.end()-1);
364//=== Iterator creation.
368 * @brief Return an @c iterator pointing at the beginning
370 * @return An @c iterator.
372 * Note that dereferencing the iterator will yield a proxy rather
373 * than a reference; the proxy will handle deleting an owned element
374 * if it's assigned to.
378typename ConstDataVector<DV>::iterator
379ConstDataVector<DV>::begin() noexcept
381 return to_my_iterator (DV::begin());
386 * @brief Return an @c iterator pointing past the end
388 * @return An @c iterator.
390 * Note that dereferencing the iterator will yield a proxy rather
391 * than a reference; the proxy will handle deleting an owned element
392 * if it's assigned to.
396typename ConstDataVector<DV>::iterator
397ConstDataVector<DV>::end() noexcept
399 return to_my_iterator (DV::end());
404 * @brief Return a @c reverse_iterator pointing past the end
406 * @return A @c reverse_iterator.
408 * Note that dereferencing the iterator will yield a proxy rather
409 * than a reference; the proxy will handle deleting an owned element
410 * if it's assigned to.
414typename ConstDataVector<DV>::reverse_iterator
415ConstDataVector<DV>::rbegin() noexcept
417 return reverse_iterator (to_my_iterator (DV::end()));
422 * @brief Return a @c reverse_iterator pointing at the beginning
424 * @return A @c reverse_iterator.
426 * Note that dereferencing the iterator will yield a proxy rather
427 * than a reference; the proxy will handle deleting an owned element
428 * if it's assigned to.
432typename ConstDataVector<DV>::reverse_iterator
433ConstDataVector<DV>::rend() noexcept
435 return reverse_iterator (to_my_iterator (DV::begin()));
439//=== Insertion operations.
443 * @brief Add an element to the end of the collection.
444 * @param pElem The element to add to the collection.
446 * The container's ownership policy will determine if it takes ownership
447 * of the new element.
449 * Note: this method may only be called using the most derived
450 * @c DataVector in the hierarchy.
452 * Returns the pushed pointer.
456typename ConstDataVector<DV>::value_type
457ConstDataVector<DV>::push_back(value_type pElem)
459 typename DV::value_type p ATLAS_THREAD_SAFE = const_cast<typename DV::value_type> (pElem);
466 * @brief Add an element to the end of the collection.
467 * @param pElem The element to add to the collection.
469 * The container's ownership policy will determine if it takes ownership
470 * of the new element.
472 * Note: this method may only be called using the most derived
473 * @c DataVector in the hierarchy.
475 * For @c DataVector, this is like the same as @c push_back, and
476 * it returns the pushed element.
477 * It's included just for interface compatibility with `std::vector`.
481typename ConstDataVector<DV>::value_type
482ConstDataVector<DV>::emplace_back(value_type pElem)
484 this->push_back (pElem);
490 * @brief Add a new element to the collection.
491 * @param position Iterator before which the element will be added.
492 * @param pElem The element to add to the collection.
493 * @return An iterator that points to the inserted data.
495 * The container's ownership policy will determine if it takes ownership
496 * of the new element.
498 * Note: this method may only be called using the most derived
499 * @c DataVector in the hierarchy.
503typename ConstDataVector<DV>::iterator
504ConstDataVector<DV>::insert(iterator position, value_type pElem)
506 typename DV::value_type p ATLAS_THREAD_SAFE = const_cast<typename DV::value_type> (pElem);
507 return to_my_iterator
508 (DV::insert (to_base_iterator (position), p));
513 * @brief Add a new element to the collection.
514 * @param position Iterator before which the element will be added.
515 * @param pElem The element to add to the collection.
516 * @return An iterator that points to the inserted data.
518 * The container's ownership policy will determine if it takes ownership
519 * of the new element.
521 * Note: this method may only be called using the most derived
522 * @c DataVector in the hierarchy.
524 * For @c DataVector, this is just the same as @c insert.
525 * It's included just for interface compatibility with `std::vector`.
529typename ConstDataVector<DV>::iterator
530ConstDataVector<DV>::emplace(iterator position, value_type pElem)
532 return this->insert (position, pElem);
537 * @brief Add a group of new elements to the collection.
538 * @param position Iterator before which the element will be added.
539 * @param first The start of the range to put in the container.
540 * @param last The end of the range to put in the container.
542 * The container's ownership policy will determine if it takes ownership
543 * of the new element.
545 * Note: this method may only be called using the most derived
546 * @c DataVector in the hierarchy.
549template <class InputIterator>
551void ConstDataVector<DV>::insert (iterator position,
555 ConstDataVector_detail::remove_const<typename DV::base_value_type> cast;
556 auto view = std::ranges::subrange(first, last) | std::views::transform(cast);
557 DV::insert(to_base_iterator(position), view.begin(), view.end());
562 * @brief Add an element to the end of the collection.
563 * @param pElem The element to add to the collection.
565 * The container must be an owning container.
567 * Note: this method may only be called using the most derived
568 * @c DataVector in the hierarchy.
570 * Returns the pushed pointer.
574typename ConstDataVector<DV>::value_type
575ConstDataVector<DV>::push_back(std::unique_ptr<const base_value_type> pElem)
577 typename DV::value_type ptmp ATLAS_THREAD_SAFE =
578 const_cast<typename DV::value_type> (pElem.release());
579 std::unique_ptr<typename DV::base_value_type> ptr (ptmp);
580 DV::push_back (std::move (ptr));
586 * @brief Add a new element to the collection.
587 * @param position Iterator before which the element will be added.
588 * @param pElem The element to add to the collection.
589 * @return An iterator that points to the inserted data.
591 * The container must be an owning container.
593 * Note: this method may only be called using the most derived
594 * @c DataVector in the hierarchy.
598typename ConstDataVector<DV>::iterator
599ConstDataVector<DV>::insert(iterator position,
600 std::unique_ptr<const base_value_type> pElem)
602 typename DV::value_type ptmp ATLAS_THREAD_SAFE =
603 const_cast<typename DV::value_type> (pElem.release());
604 std::unique_ptr<typename DV::base_value_type> ptr (ptmp);
605 return to_my_iterator
606 (DV::insert (to_base_iterator (position), std::move (ptr)));
611 * @brief Add a group of new elements to the collection.
612 * @param position Iterator before which the element will be added.
613 * @param l An initializer list.
615 * The container's ownership policy will determine if it takes ownership
616 * of the new element.
618 * Note: this method may only be called using the most derived
619 * @c DataVector in the hierarchy.
623void ConstDataVector<DV>::insert (iterator position,
624 std::initializer_list<value_type> l)
626 this->insert (position, l.begin(), l.end());
630//=== Erasure operations.
634 * @brief Remove element at a given position.
635 * @param position Iterator pointing to the element to be removed.
636 * @return An iterator pointing to the next element (or @c end()).
638 * If the container owns its elements, then the pointed-to element
643typename ConstDataVector<DV>::iterator
644ConstDataVector<DV>::erase(iterator position)
646 return to_my_iterator (DV::erase (to_base_iterator (position)));
651 * @brief Remove a range of elements.
652 * @param first Iterator pointing to the first element to be removed.
653 * @param last Iterator pointing one past the last element to be removed.
654 * @return An iterator pointing to the element pointed to by @a last
655 * prior to erasing (or @c end()).
657 * If the container owns its elements, then the removed elements
658 * will be deleted. Any duplicates will be removed in this process,
659 * but don't rely on this.
663typename ConstDataVector<DV>::iterator
664ConstDataVector<DV>::erase(iterator first, iterator last)
666 return to_my_iterator
667 (DV::erase (to_base_iterator (first),
668 to_base_iterator (last)));
674 * @brief Erase all the elements in the collection.
676 * If the container owns its elements, then the removed elements
677 * will be deleted. Any duplicates will be removed in this process,
678 * but don't rely on this.
682void ConstDataVector<DV>::clear()
689 * @brief Swap this collection with another.
690 * @param rhs The collection with which to swap.
692 * Ownership is swapped along with the collection content.
694 * Note: this method may only be called using the most-derived
695 * @c DataVector in the hierarchy. The @a rhs must also be
696 * referenced using the most-derived @c DataVector.
700void ConstDataVector<DV>::swap (ConstDataVector& rhs)
707 * @brief Swap the referents of two @c DataVector iterators.
708 * @param a The first iterator for the swap.
709 * @param b The second iterator for the swap.
713void ConstDataVector<DV>::iter_swap (iterator a, iterator b)
715 DV::iter_swap (to_base_iterator (a),
716 to_base_iterator (b));
720//=== Non-standard operations.
724 * @brief Swap one element out of the container.
725 * @param index Index of the element in the container to swap.
726 * @param newElem New element to put in the container.
728 * @param oldElem Reference to receive the element removed from the
731 * Reference @a oldElem is initialized with element @a index of the
732 * collection (no bounds checking). Then element @a index is set
733 * to @c newElem. If the collection owns its elements, then it will
734 * take ownership of @a newElem and release (without deleting)
735 * the element returned through @a oldElem.
737 * Note: this method may only be called using the most derived
738 * @c DataVector in the hierarchy.
743ConstDataVector<DV>::swapElement (size_type index,
747 typename DV::value_type pnew ATLAS_THREAD_SAFE = const_cast<typename DV::value_type>(newElem);
748 typename DV::reference rold ATLAS_THREAD_SAFE = const_cast<typename DV::reference>(oldElem);
749 DV::swapElement (index, pnew, rold);
754 * @brief Swap one element out of the container.
755 * @param pos The element in the container to swap.
756 * @param newElem New element to put in the container.
758 * @param oldElem Reference to receive the element removed from the
761 * Reference @a oldElem is initialized with element @a pos of the
762 * collection (no bounds checking). Then element @a index is set
763 * to @c newElem. If the collection owns its elements, then it will
764 * take ownership of @a newElem and release (without deleting)
765 * the element returned through @a oldElem.
767 * Note: this method may only be called using the most derived
768 * @c DataList in the hierarchy.
773ConstDataVector<DV>::swapElement (iterator pos,
777 typename DV::value_type pnew ATLAS_THREAD_SAFE = const_cast<typename DV::value_type>(newElem);
778 typename DV::reference rold ATLAS_THREAD_SAFE = const_cast<typename DV::reference>(oldElem);
779 DV::swapElement (to_base_iterator(pos), pnew, rold);
784 * @brief Swap one element out of the container.
785 * @param index Index of the element in the container to swap.
786 * @param newElem New element to put in the container.
788 * @param oldElem Reference to receive the element removed from the
791 * Reference @a oldElem is initialized with element @a index of the
792 * collection (no bounds checking). Then element @a index is set
795 * The collection must own its elements to use its interface.
796 * The collection will take ownership of @c newElem and will return
797 * ownership of @c oldElem.
799 * Note: this method may only be called using the most derived
800 * @c DataVector in the hierarchy.
805ConstDataVector<DV>::swapElement (size_type index,
806 std::unique_ptr<const base_value_type> newElem,
807 std::unique_ptr<const base_value_type>& oldElem)
809 typename DV::value_type pelem ATLAS_THREAD_SAFE =
810 const_cast<typename DV::value_type> (newElem.release());
811 std::unique_ptr<typename DV::base_value_type> new_u (pelem);
812 std::unique_ptr<typename DV::base_value_type> old_u;
813 DV::swapElement (index, std::move(new_u), old_u);
814 oldElem = std::move (old_u);
819 * @brief Swap one element out of the container.
820 * @param pos The element in the container to swap.
821 * @param newElem New element to put in the container.
823 * @param oldElem Reference to receive the element removed from the
826 * Reference @a oldElem is initialized with element @a pos of the
827 * collection (no bounds checking). Then element @a index is set
830 * The collection must own its elements to use its interface.
831 * The collection will take ownership of @c newElem and will return
832 * ownership of @c oldElem.
834 * Note: this method may only be called using the most derived
835 * @c DataList in the hierarchy.
840ConstDataVector<DV>::swapElement (iterator pos,
841 std::unique_ptr<const base_value_type> newElem,
842 std::unique_ptr<const base_value_type>& oldElem)
844 typename DV::value_type pelem ATLAS_THREAD_SAFE =
845 const_cast<typename DV::value_type> (newElem.release());
846 std::unique_ptr<typename DV::base_value_type> new_u (pelem);
847 std::unique_ptr<typename DV::base_value_type> old_u;
848 DV::swapElement (to_base_iterator(pos), std::move(new_u), old_u);
849 oldElem = std::move (old_u);
854 * @brief Return a pointer to this object, as a const @c DataVector.
859ConstDataVector<DV>::asDataVector() const
861 return static_cast<const DV*>(this);
866 * @brief Cast from a @c DataVector to a @c ConstDataVector.
867 * @param dv Pointer to object to cast.
869 * Return @c DV cast to a @c ConstDataVector.
872const ConstDataVector<DV>* ConstDataVector<DV>::fromDataVector (const DV* dv)
874 if (typeid (*dv) == typeid (ConstDataVector))
875 return static_cast<const ConstDataVector*> (dv);
881 * @brief Reset indices / reorder aux data after elements have been permuted.
882 * @param beg Start of the range of elements to process.
883 * @param end End of the range of elements to process.
885 * This is a no-op for @c ConstDataVector.
889void ConstDataVector<DV>::resortAux (iterator /*beg*/, iterator /*end*/)
895 * @brief Erase all the elements in the collection, and reset
896 * the ownership mode.
897 * @param ownPolicy The new ownership policy of the container.
899 * If the container owns its elements, then the removed elements
900 * will be deleted. Any duplicates will be removed in this process,
901 * but don't rely on this.
905void ConstDataVector<DV>::clear (SG::OwnershipPolicy ownPolicy)
907 DV::clear (ownPolicy, SG::NEVER_TRACK_INDICES);
913 * @brief Erase all the elements in the collection, and reset
914 * the ownership mode.
915 * @param ownPolicy The new ownership policy of the container.
916 * @param trackIndices The index tracking policy.
918 * If the container owns its elements, then the removed elements
919 * will be deleted. Any duplicates will be removed in this process,
920 * but don't rely on this.
924void ConstDataVector<DV>::clear (SG::OwnershipPolicy ownPolicy,
925 SG::IndexTrackingPolicy trackIndices)
927 DV::clear (ownPolicy, trackIndices);
928 if (DV::trackIndices()) std::abort();
933 * @brief Convert to @c AuxVectorBase.
935 * Needed to get @x AuxVectorBase from a @c ConstDataVector.
936 * Present in @c DataVector as well for consistency.
940const SG::AuxVectorBase& ConstDataVector<DV>::auxbase() const
946//=== Relational operators.
950 * @brief Vector ordering relation.
951 * @param b A @c ConstDataVector of the same type as @a *this.
952 * @return True iff @a *this is lexicographically less than @a b.
954 * This is a total ordering relation. It is linear in the size of the
955 * vectors. Comparisons are done on the pointer values of the elements.
957 * See @c std::lexicographical_compare() for how the determination is made.
961bool ConstDataVector<DV>::operator< (const ConstDataVector& b) const
963 return static_cast<const DV&>(*this) < static_cast<const DV&>(b);
967/// Based on operator<
970bool ConstDataVector<DV>::operator> (const ConstDataVector& b) const
972 return static_cast<const DV&>(*this) > static_cast<const DV&>(b);
976/// Based on operator<
979bool ConstDataVector<DV>::operator<= (const ConstDataVector& b) const
981 return static_cast<const DV&>(*this) <= static_cast<const DV&>(b);
985/// Based on operator<
988bool ConstDataVector<DV>::operator>= (const ConstDataVector& b) const
990 return static_cast<const DV&>(*this) >= static_cast<const DV&>(b);
995 * @brief Vector equality comparison.
996 * @param b A @c ConstDataVector of the same type as @a *this.
997 * @return True iff the size and elements of the vectors are equal.
999 * This is an equivalence relation. It is linear in the size of the
1000 * vectors. Vectors are considered equivalent if their sizes are equal,
1001 * and if corresponding elements compare equal.
1005bool ConstDataVector<DV>::operator== (const ConstDataVector& b) const
1007 return static_cast<const DV&>(*this) == static_cast<const DV&>(b);
1011/// Based on operator==
1014bool ConstDataVector<DV>::operator!= (const ConstDataVector& b) const
1016 return static_cast<const DV&>(*this) != static_cast<const DV&>(b);
1020//=== Private helpers.
1024 * @brief Handle element assignment.
1025 * @param pos Position in the container to assign.
1026 * @param newElem The new element to assign.
1028 * The old element is freed if this container owns elements.
1029 * Auxiliary data are copied if appropriate.
1034ConstDataVector<DV>::assignElement (typename BaseContainer::iterator pos,
1037 typename DV::value_type pelem ATLAS_THREAD_SAFE =
1038 const_cast<typename DV::value_type> (newElem);
1039 DV::assignElement (pos, pelem);
1044 * @brief Handle element assignment.
1045 * @param pos Position in the container to assign.
1046 * @param newElem The new element to assign.
1048 * The container must own its elements.
1049 * Auxiliary data are copied if appropriate.
1054ConstDataVector<DV>::assignElement (typename BaseContainer::iterator pos,
1055 std::unique_ptr<const base_value_type> newElem)
1057 typename DV::value_type pelem ATLAS_THREAD_SAFE =
1058 const_cast<typename DV::value_type> (newElem.release());
1059 std::unique_ptr<typename DV::base_value_type> new_u (pelem);
1060 DV::assignElement (pos, std::move(new_u));
1065 * @brief Handle element assignment from a base pointer.
1066 * @param pos Position in the container to assign.
1067 * @param newElem The new element to assign.
1069 * The old element is freed if this container owns elements.
1070 * Auxiliary data are copied if appropriate.
1075ConstDataVector<DV>::assignBaseElement (typename BaseContainer::iterator pos,
1076 typename BaseContainer::value_type newElem)
1078 DV::assignBaseElement (pos, newElem);
1083 * @brief Convert a @c ConstDataVector::iterator to an iterator
1084 * of the base @c DataVector.
1085 * @param it The @c ConstDataVector::iterator to convert.
1089typename DV::iterator
1090ConstDataVector<DV>::to_base_iterator (iterator it)
1092 return typename DV::iterator (it.base(), it.container());
1097 * @brief Convert an iterator of the base @c DataVector to
1098 * a @c ConstDataVector::iterator.
1099 * @param it The base @c DataVector iterator to convert.
1103typename ConstDataVector<DV>::iterator
1104ConstDataVector<DV>::to_my_iterator (typename DV::iterator it)
1106 return iterator (it.base(), this);
1111 * @brief Convert an iterator of the base @c vector
1112 * an @c ElementProxy for the @c ConstDataVector.
1113 * @param it The base @c vector iterator to convert.
1117typename ConstDataVector<DV>::ElementProxy
1118ConstDataVector<DV>::to_element_proxy (typename BaseContainer::iterator i)
1120 return ElementProxy (i, this);
1124//=== Other helper classes.
1127#ifndef XAOD_STANDALONE
1131 * @brief Constructor from a payload object.
1132 * @param data Object to hold in the bucket.
1138DVLConstDataVectorBucket<DV>::DVLConstDataVectorBucket
1139 (ConstDataVector<DV>* data)
1141 ([] (const DV* dv) { DV* dv_nc ATLAS_THREAD_SAFE = const_cast<DV*> (dv);
1143 (data->asDataVector()))
1149 * @brief Constructor from a payload object.
1150 * @param data Object to hold in the bucket.
1153DVLConstDataVectorBucket<DV>::DVLConstDataVectorBucket
1154 (std::unique_ptr<ConstDataVector<DV> > data)
1155 : DVLDataBucket<DV> (std::unique_ptr<DV>
1156 ([] (const DV* dv) { DV* dv_nc ATLAS_THREAD_SAFE = const_cast<DV*> (dv);
1158 (data.release()->asDataVector())))
1166#endif // not XAOD_STANDALONE