ATLAS Offline Software
Loading...
Searching...
No Matches
JaggedVecConversions.icc
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration.
3 */
4/**
5 * @file AthContainers/tools/JaggedVecConversions.icc
6 * @author scott snyder <snyder@bnl.gov>
7 * @date Jul, 2024
8 * @brief Conversions for accessing jagged vector variables.
9 */
10
11
12#include "CxxUtils/throw_out_of_range.h"
13
14
15namespace SG { namespace detail {
16
17
18/**
19 * @brief Constructor.
20 * @param elts Start of the element vector.
21 * @param payload Span over the payload vector.
22 */
23template <class PAYLOAD_T>
24inline
25JaggedVecConstConverter<PAYLOAD_T>::JaggedVecConstConverter (const JaggedVecEltBase* elts,
26 const_Payload_span payload)
27 : m_elts (elts),
28 m_payload (payload)
29{
30}
31
32
33/**
34 * @brief Convert to a span.
35 * @param elt The jagged vector element to transform.
36 */
37template <class PAYLOAD_T>
38inline
39auto JaggedVecConstConverter<PAYLOAD_T>::operator() (const JaggedVecEltBase& elt) const
40 -> const element_type
41{
42 size_t beg = elt.begin(&elt - m_elts);
43 size_t end = elt.end();
44 if (beg > end || end > m_payload.size()) {
45 CxxUtils::throw_out_of_range (__PRETTY_FUNCTION__, end, m_payload.size(), this);
46 }
47 const Payload_t* payload = m_payload.data();
48 return element_type (payload + beg, payload + end);
49}
50
51
52//****************************************************************************
53
54
55/**
56 * @brief Constructor.
57 * @param elts The elements of the jagged vector.
58 * @param container The container holding this variable.
59 * @param auxid The aux ID of this variable.
60 */
61inline
62JaggedVecProxyBase::JaggedVecProxyBase (const AuxDataSpanBase& elts,
63 AuxVectorData& container,
64 SG::auxid_t auxid)
65 : m_elts (reinterpret_cast<Elt_t*> (elts.beg), elts.size),
66 m_container (container),
67 m_linkedVec (auxid)
68{
69}
70
71
72/**
73 * @brief Return one jagged vector element (non-const).
74 * @param elt_index The index of the element.
75 */
76inline
77auto JaggedVecProxyBase::elt (size_t elt_index) noexcept -> Elt_t&
78{
79 return m_elts[elt_index];
80}
81
82
83/**
84 * @brief Return one jagged vector element (const).
85 * @param elt_index The index of the element.
86 */
87inline
88auto JaggedVecProxyBase::elt (size_t elt_index) const noexcept -> const Elt_t&
89{
90 return m_elts[elt_index];
91}
92
93
94//****************************************************************************
95
96
97/**
98 * @brief Constructor.
99 * @param elts The elements of the jagged vector.
100 * @param container The container holding this variable.
101 * @param auxid The aux ID of this variable.
102 */
103inline
104JaggedVecProxyValBase::JaggedVecProxyValBase (const AuxDataSpanBase& elts,
105 AuxVectorData& container,
106 SG::auxid_t auxid)
107 : m_base (elts, container, auxid)
108{
109}
110
111
112/**
113 * @brief Constructor.
114 * @param base The base information.
115 */
116inline
117JaggedVecProxyRefBase::JaggedVecProxyRefBase (JaggedVecProxyBase& base)
118 : m_base (base)
119{
120}
121
122
123//****************************************************************************
124
125
126/**
127 * @brief Constructor.
128 * @param elt_index Index of the jagged vector element.
129 * @param payload Reference to a range over the payload vector.
130 * @param elts The elements of the jagged vector.
131 * @param container The container holding this variable.
132 * @param auxid The aux ID of this variable.
133 */
134template <class PAYLOAD_T, class BASE>
135inline
136JaggedVecProxyT<PAYLOAD_T, BASE>::JaggedVecProxyT (size_t elt_index,
137 Payload_span payload,
138 const AuxDataSpanBase& elts,
139 AuxVectorData& container,
140 SG::auxid_t auxid)
141 : BASE (elts, container, auxid),
142 m_index (elt_index),
143 m_payload (payload)
144{
145}
146
147
148/**
149 * @brief Constructor.
150 * @param elt_index Index of the jagged vector element.
151 * @param payload Reference to a range over the payload vector.
152 * @param base The base information.
153 */
154template <class PAYLOAD_T, class BASE>
155inline
156JaggedVecProxyT<PAYLOAD_T, BASE>::JaggedVecProxyT (size_t elt_index,
157 Payload_span payload,
158 JaggedVecProxyBase& base)
159 : BASE (base),
160 m_index (elt_index),
161 m_payload (payload)
162{
163}
164
165
166/**
167 * @brief Return the size of this jagged vector element.
168 */
169template <class PAYLOAD_T, class BASE>
170inline
171size_t JaggedVecProxyT<PAYLOAD_T, BASE>::size() const noexcept
172{
173 return elt_end() - elt_begin();
174}
175
176
177/**
178 * @brief Test if this jagged vector element is empty.
179 */
180template <class PAYLOAD_T, class BASE>
181inline
182bool JaggedVecProxyT<PAYLOAD_T, BASE>::empty() const noexcept
183{
184 return size() == 0;
185}
186
187
188/**
189 * @brief Element access (non-const).
190 * @param i Index within this element's payload.
191 */
192template <class PAYLOAD_T, class BASE>
193inline
194auto JaggedVecProxyT<PAYLOAD_T, BASE>::operator[] (size_t i) noexcept
195 -> reference
196{
197 return m_payload[elt_begin()+i];
198}
199
200
201/**
202 * @brief Element access (const).
203 * @param i Index within this element's payload.
204 */
205template <class PAYLOAD_T, class BASE>
206inline
207auto JaggedVecProxyT<PAYLOAD_T, BASE>::operator[] (size_t i) const noexcept
208 -> const_reference
209{
210 return m_payload[elt_begin()+i];
211}
212
213
214/**
215 * @brief Element access (non-const, bounds-checked).
216 * @param i Index within this element's payload.
217 */
218template <class PAYLOAD_T, class BASE>
219inline
220auto JaggedVecProxyT<PAYLOAD_T, BASE>::at (size_t i) -> reference
221{
222 size_t beg = this->elt_begin();
223 size_t end = this->elt_end();
224 if (i >= (end-beg)) CxxUtils::throw_out_of_range (__PRETTY_FUNCTION__, i, end-beg, this);
225 return m_payload[i+beg];
226}
227
228
229/**
230 * @brief Element access (const, bounds-checked).
231 * @param i Index within this element's payload.
232 */
233template <class PAYLOAD_T, class BASE>
234inline
235auto JaggedVecProxyT<PAYLOAD_T, BASE>::at (size_t i) const -> const_reference
236{
237 size_t beg = this->elt_begin();
238 size_t end = this->elt_end();
239 if (i >= (end-beg)) CxxUtils::throw_out_of_range (__PRETTY_FUNCTION__, i, end-beg, this);
240 return m_payload[i+beg];
241}
242
243
244/**
245 * @brief Return a reference to the first item in this element's payload.
246 */
247template <class PAYLOAD_T, class BASE>
248inline
249auto JaggedVecProxyT<PAYLOAD_T, BASE>::front() noexcept -> reference
250{
251 return m_payload[this->elt_begin()];
252}
253
254
255/**
256 * @brief Return the first item in this element's payload.
257 */
258template <class PAYLOAD_T, class BASE>
259inline
260auto JaggedVecProxyT<PAYLOAD_T, BASE>::front() const noexcept -> const_reference
261{
262 return m_payload[this->elt_begin()];
263}
264
265
266/**
267 * @brief Return a reference to the last item in this element's payload.
268 */
269template <class PAYLOAD_T, class BASE>
270inline
271auto JaggedVecProxyT<PAYLOAD_T, BASE>::back() noexcept -> reference
272{
273 return m_payload[this->elt_end()-1];
274}
275
276
277/**
278 * @brief Return the last item in this element's payload.
279 */
280template <class PAYLOAD_T, class BASE>
281inline
282auto JaggedVecProxyT<PAYLOAD_T, BASE>::back() const noexcept -> const_reference
283{
284 return m_payload[this->elt_end()-1];
285}
286
287
288/**
289 * @brief Return a (non-const) begin iterator.
290 */
291template <class PAYLOAD_T, class BASE>
292inline
293auto JaggedVecProxyT<PAYLOAD_T, BASE>::begin() noexcept -> iterator
294{
295 return m_payload.data() + this->elt_begin();
296}
297
298
299/**
300 * @brief Return a (non-const) end iterator.
301 */
302template <class PAYLOAD_T, class BASE>
303inline
304auto JaggedVecProxyT<PAYLOAD_T, BASE>::end() noexcept -> iterator
305{
306 return m_payload.data() + this->elt_end();
307}
308
309
310/**
311 * @brief Return a (const) begin iterator.
312 */
313template <class PAYLOAD_T, class BASE>
314inline
315auto JaggedVecProxyT<PAYLOAD_T, BASE>::begin() const noexcept -> const_iterator
316{
317 return m_payload.data() + this->elt_begin();
318}
319
320
321/**
322 * @brief Return a (const) end iterator.
323 */
324template <class PAYLOAD_T, class BASE>
325inline
326auto JaggedVecProxyT<PAYLOAD_T, BASE>::end() const noexcept -> const_iterator
327{
328 return m_payload.data() + this->elt_end();
329}
330
331
332/**
333 * @brief Return a (const) begin iterator.
334 */
335template <class PAYLOAD_T, class BASE>
336inline
337auto JaggedVecProxyT<PAYLOAD_T, BASE>::cbegin() const noexcept -> const_iterator
338{
339 return m_payload.data() + this->elt_begin();
340}
341
342
343/**
344 * @brief Return a (const) end iterator.
345 */
346template <class PAYLOAD_T, class BASE>
347inline
348auto JaggedVecProxyT<PAYLOAD_T, BASE>::cend() const noexcept -> const_iterator
349{
350 return m_payload.data() + this->elt_end();
351}
352
353
354/**
355 * @brief Return a (non-const) begin reverse iterator.
356 */
357template <class PAYLOAD_T, class BASE>
358inline
359auto JaggedVecProxyT<PAYLOAD_T, BASE>::rbegin() noexcept -> reverse_iterator
360{
361 return reverse_iterator (end());
362}
363
364
365/**
366 * @brief Return a (non-const) end reverse iterator.
367 */
368template <class PAYLOAD_T, class BASE>
369inline
370auto JaggedVecProxyT<PAYLOAD_T, BASE>::rend() noexcept -> reverse_iterator
371{
372 return reverse_iterator (begin());
373}
374
375
376/**
377 * @brief Return a (const) begin reverse iterator.
378 */
379template <class PAYLOAD_T, class BASE>
380inline
381auto JaggedVecProxyT<PAYLOAD_T, BASE>::rbegin() const noexcept
382 -> const_reverse_iterator
383{
384 return const_reverse_iterator (end());
385}
386
387
388/**
389 * @brief Return a (const) end reverse iterator.
390 */
391template <class PAYLOAD_T, class BASE>
392inline
393auto JaggedVecProxyT<PAYLOAD_T, BASE>::rend() const noexcept
394 -> const_reverse_iterator
395{
396 return const_reverse_iterator (begin());
397}
398
399
400/**
401 * @brief Return a (const) begin reverse iterator.
402 */
403template <class PAYLOAD_T, class BASE>
404inline
405auto JaggedVecProxyT<PAYLOAD_T, BASE>::crbegin() const noexcept
406 -> const_reverse_iterator
407{
408 return const_reverse_iterator (end());
409}
410
411
412/**
413 * @brief Return a (const) end reverse iterator.
414 */
415template <class PAYLOAD_T, class BASE>
416inline
417auto JaggedVecProxyT<PAYLOAD_T, BASE>::crend() const noexcept
418 -> const_reverse_iterator
419{
420 return const_reverse_iterator (begin());
421}
422
423
424/**
425 * @brief Assign this jagged vector element from a range.
426 * @param range The range from which to assign.
427 */
428template <class PAYLOAD_T, class BASE>
429template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
430JaggedVecProxyT<PAYLOAD_T, BASE>&
431JaggedVecProxyT<PAYLOAD_T, BASE>::operator= (const RANGE& range)
432{
433 this->m_base.resize1 (m_index, std::size(range));
434 std::copy (range.begin(), range.end(), begin());
435 return *this;
436}
437
438
439/**
440 * @brief Convert this jagged vector element to a vector.
441 */
442template <class PAYLOAD_T, class BASE>
443auto JaggedVecProxyT<PAYLOAD_T, BASE>::asVector() const
444 -> std::vector<Payload_t>
445{
446 return std::vector<Payload_t> (this->begin(), this->end());
447}
448
449
450/**
451 * @brief Convert this jagged vector element to a vector.
452 */
453template <class PAYLOAD_T, class BASE>
454template <class VALLOC>
455JaggedVecProxyT<PAYLOAD_T, BASE>::operator std::vector<Payload_t, VALLOC>() const
456{
457 return std::vector<Payload_t, VALLOC> (this->begin(), this->end());
458}
459
460
461/**
462 * @brief Add an item to the end of this jagged vector element.
463 * @param x The item to add.
464 */
465template <class PAYLOAD_T, class BASE>
466void JaggedVecProxyT<PAYLOAD_T, BASE>::push_back (const Payload_t& x)
467{
468 this->m_base.adjust1 (m_index, size(), 1);
469 back() = x;
470}
471
472
473/**
474 * @brief Clear this jagged vector element.
475 */
476template <class PAYLOAD_T, class BASE>
477void JaggedVecProxyT<PAYLOAD_T, BASE>::clear()
478{
479 this->m_base.resize1 (m_index, 0);
480}
481
482
483/**
484 * @brief Resize this jagged vector element.
485 * @param n New size for the element.
486 * @param x If the element is being enlarged, initialize the new
487 * elements with this value.
488 */
489template <class PAYLOAD_T, class BASE>
490void JaggedVecProxyT<PAYLOAD_T, BASE>::resize (size_t n,
491 const Payload_t& x /*= Payload_t()*/)
492{
493 size_t sz = size();
494 this->m_base.adjust1 (m_index, sz, n - sz);
495 if (n > sz) {
496 std::fill_n (begin()+sz, n-sz, x);
497 }
498}
499
500
501/**
502 * @brief Erase one item from this jagged vector element.
503 * @param pos Position within the element of the item to erase.
504 */
505template <class PAYLOAD_T, class BASE>
506void JaggedVecProxyT<PAYLOAD_T, BASE>::erase (nonnull_iterator pos)
507{
508 this->m_base.adjust1 (m_index, pos-begin()+1, -1);
509}
510
511
512/**
513 * @brief Erase one item from this jagged vector element.
514 * @param pos Index within the element of the item to erase.
515 */
516template <class PAYLOAD_T, class BASE>
517void JaggedVecProxyT<PAYLOAD_T, BASE>::erase (index_type pos)
518{
519 this->m_base.adjust1 (m_index, pos+1, -1);
520}
521
522
523/**
524 * @brief Erase a range of items from this jagged vector element.
525 * @param first Position within the element of the first item to erase.
526 * @param last One past the position within the element of the last item to erase.
527 */
528template <class PAYLOAD_T, class BASE>
529void JaggedVecProxyT<PAYLOAD_T, BASE>::erase (nonnull_iterator first,
530 nonnull_iterator last)
531{
532 this->m_base.adjust1 (m_index, last - begin(), -(last - first));
533}
534
535
536/**
537 * @brief Erase a range of items from this jagged vector element.
538 * @param first Index within the element of the first item to erase.
539 * @param last One past the index within the element of the last item to erase.
540 */
541template <class PAYLOAD_T, class BASE>
542void JaggedVecProxyT<PAYLOAD_T, BASE>::erase (index_type first, index_type last)
543{
544 this->m_base.adjust1 (m_index, last, -(last - first));
545}
546
547
548/**
549 * @brief Insert an item into this jagged vector element.
550 * @param pos Position within the element at which to insert.
551 * @param x The item to insert.
552 */
553template <class PAYLOAD_T, class BASE>
554void JaggedVecProxyT<PAYLOAD_T, BASE>::insert (nonnull_iterator pos,
555 const Payload_t& x)
556{
557 insert (pos, 1, x);
558}
559
560/**
561 * @brief Insert an item into this jagged vector element.
562 * @param pos Index within the element at which to insert.
563 * @param x The item to insert.
564 */
565template <class PAYLOAD_T, class BASE>
566void JaggedVecProxyT<PAYLOAD_T, BASE>::insert (index_type pos,
567 const Payload_t& x)
568{
569 insert (pos, 1, x);
570}
571
572
573/**
574 * @brief Insert a number of items into this jagged vector element.
575 * @param pos Position within the element at which to insert.
576 * @param n The number of items to insert.
577 * @param x The value to insert.
578 */
579template <class PAYLOAD_T, class BASE>
580void JaggedVecProxyT<PAYLOAD_T, BASE>::insert (nonnull_iterator pos,
581 size_t n,
582 const Payload_t& x)
583{
584 size_t i = pos - begin();
585 this->m_base.adjust1 (m_index, i, n);
586 std::fill_n (begin()+i, n, x);
587}
588
589
590/**
591 * @brief Insert a number of items into this jagged vector element.
592 * @param pos Index within the element at which to insert.
593 * @param n The number of items to insert.
594 * @param x The value to insert.
595 */
596template <class PAYLOAD_T, class BASE>
597void JaggedVecProxyT<PAYLOAD_T, BASE>::insert (index_type pos,
598 size_t n,
599 const Payload_t& x)
600{
601 this->m_base.adjust1 (m_index, pos, n);
602 std::fill_n (begin()+pos, n, x);
603}
604
605/**
606 * @brief Insert a range of items into this jagged vector element.
607 * @param pos Position within the element at which to insert.
608 * @param first Start of the range to insert.
609 * @param last End of the range to insert.
610 */
611template <class PAYLOAD_T, class BASE>
612template <CxxUtils::detail::InputValIterator<PAYLOAD_T> ITERATOR>
613void JaggedVecProxyT<PAYLOAD_T, BASE>::insert (nonnull_iterator pos,
614 ITERATOR first,
615 ITERATOR last)
616{
617 size_t i = pos - begin();
618 size_t n_new = last - first;
619 this->m_base.adjust1 (m_index, i, n_new);
620 std::copy (first, last, begin()+i);
621}
622
623
624/**
625 * @brief Insert a range of items into this jagged vector element.
626 * @param pos Index within the element at which to insert.
627 * @param first Start of the range to insert.
628 * @param last End of the range to insert.
629 */
630template <class PAYLOAD_T, class BASE>
631template <CxxUtils::detail::InputValIterator<PAYLOAD_T> ITERATOR>
632void JaggedVecProxyT<PAYLOAD_T, BASE>::insert (index_type pos,
633 ITERATOR first,
634 ITERATOR last)
635{
636 size_t n_new = last - first;
637 this->m_base.adjust1 (m_index, pos, n_new);
638 std::copy (first, last, begin()+pos);
639}
640
641
642/**
643 * @brief Insert a range of items into this jagged vector element.
644 * @param pos Position within the element at which to insert.
645 * @param range The range to insert.
646 */
647template <class PAYLOAD_T, class BASE>
648template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
649void JaggedVecProxyT<PAYLOAD_T, BASE>::insert_range (nonnull_iterator pos,
650 const RANGE& range)
651{
652 size_t i = pos - begin();
653 size_t n_new = std::size (range);
654 this->m_base.adjust1 (m_index, i, n_new);
655 std::copy (range.begin(), range.end(), begin()+i);
656}
657
658
659/**
660 * @brief Insert a range of items into this jagged vector element.
661 * @param pos Index within the element at which to insert.
662 * @param range The range to insert.
663 */
664template <class PAYLOAD_T, class BASE>
665template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
666void JaggedVecProxyT<PAYLOAD_T, BASE>::insert_range (index_type pos,
667 const RANGE& range)
668{
669 size_t n_new = std::size (range);
670 this->m_base.adjust1 (m_index, pos, n_new);
671 std::copy (range.begin(), range.end(), begin()+pos);
672}
673
674
675/**
676 * @brief Append a range of items to the end of this jagged vector element.
677 * @param range The range to append.
678 */
679template <class PAYLOAD_T, class BASE>
680template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
681void JaggedVecProxyT<PAYLOAD_T, BASE>::append_range (const RANGE& range)
682{
683 size_t sz = size();
684 size_t n_new = std::size (range);
685 this->m_base.adjust1 (m_index, sz, n_new);
686 std::copy (range.begin(), range.end(), begin()+sz);
687}
688
689
690/**
691 * @brief Remove the last item from this jagged vector element.
692 */
693template <class PAYLOAD_T, class BASE>
694void JaggedVecProxyT<PAYLOAD_T, BASE>::pop_back()
695{
696 this->m_base.adjust1 (m_index, size(), -1);
697}
698
699
700/**
701 * @brief Set this jagged vector element to a number of items.
702 * @param n The number of items to assign.
703 * @param x The value to assign.
704 */
705template <class PAYLOAD_T, class BASE>
706void JaggedVecProxyT<PAYLOAD_T, BASE>::assign (size_t n, const Payload_t& x)
707{
708 this->m_base.resize1 (m_index, n);
709 std::fill_n (begin(), n, x);
710}
711
712
713/**
714 * @brief Assign this jagged vector element from a range.
715 * @param first Start of the range to assign.
716 * @param last End of the range to assign.
717 */
718template <class PAYLOAD_T, class BASE>
719template <CxxUtils::detail::InputValIterator<PAYLOAD_T> ITERATOR>
720void JaggedVecProxyT<PAYLOAD_T, BASE>::assign (ITERATOR first, ITERATOR last)
721{
722 this->m_base.resize1 (m_index, last-first);
723 std::copy (first, last, begin());
724}
725
726
727/**
728 * @brief Assign this jagged vector element from a range.
729 * @param range The range from which to assign.
730 */
731template <class PAYLOAD_T, class BASE>
732template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
733void JaggedVecProxyT<PAYLOAD_T, BASE>::assign_range (const RANGE& range)
734{
735 this->m_base.resize1 (m_index, std::size (range));
736 std::copy (range.begin(), range.end(), begin());
737}
738
739
740/**
741 * @brief Return a reference to this proxy's element.
742 */
743template <class PAYLOAD_T, class BASE>
744inline
745auto JaggedVecProxyT<PAYLOAD_T, BASE>::elt() noexcept -> Elt_t&
746{
747 return this->m_base.elt (m_index);
748}
749
750
751/**
752 * @brief Return a (const) reference to this proxy's element.
753 */
754template <class PAYLOAD_T, class BASE>
755inline
756auto JaggedVecProxyT<PAYLOAD_T, BASE>::elt() const noexcept -> const Elt_t&
757{
758 const JaggedVecProxyBase& base = this->m_base;
759 return base.elt (m_index);
760}
761
762
763/**
764 * @brief Return the begin payload index of this proxy's element.
765 */
766template <class PAYLOAD_T, class BASE>
767inline
768size_t JaggedVecProxyT<PAYLOAD_T, BASE>::elt_begin() const noexcept
769{
770 if (m_index == 0) return 0;
771 const JaggedVecProxyBase& base = this->m_base;
772 return base.elt (m_index-1).end();
773}
774
775
776/**
777 * @brief Return the end payload index of this proxy's element.
778 */
779template <class PAYLOAD_T, class BASE>
780inline
781size_t JaggedVecProxyT<PAYLOAD_T, BASE>::elt_end() const noexcept
782{
783 const JaggedVecProxyBase& base = this->m_base;
784 return base.elt (m_index).end();
785}
786
787
788//****************************************************************************
789
790
791/**
792 * @brief Constructor.
793 * @param container The container holding this variable.
794 * @param auxid The aux ID of this variable.
795 * @param linked_auxid The aux ID for the linked payload variable.
796 */
797template <class PAYLOAD_T>
798inline
799JaggedVecConverter<PAYLOAD_T>::JaggedVecConverter (AuxVectorData& container,
800 auxid_t auxid,
801 auxid_t linked_auxid)
802 : m_base (*container.getDataSpan (auxid), container, auxid),
803 m_payload (*container.getDataSpan (linked_auxid))
804{
805}
806
807
808/**
809 * @brief Convert to a (read-only) span.
810 * @param elt The jagged vector element to transform.
811 */
812template <class PAYLOAD_T>
813inline
814auto JaggedVecConverter<PAYLOAD_T>::operator() (const SG::JaggedVecEltBase& elt) const
815 -> const element_type
816{
817 size_t idx = &elt - &m_base.elt(0);
818 size_t beg = elt.begin(idx);
819 size_t end = elt.end();
820 if (beg > end || end > m_payload.size()) {
821 CxxUtils::throw_out_of_range (__PRETTY_FUNCTION__, end, m_payload.size(), this);
822 }
823 const Payload_t* payload = m_payload.data();
824 return element_type (payload + beg, payload + end);
825}
826
827
828/**
829 * @brief Convert to a (writable) span.
830 * @param elt The jagged vector element to transform.
831 */
832template <class PAYLOAD_T>
833inline
834auto JaggedVecConverter<PAYLOAD_T>::operator() (SG::JaggedVecEltBase& elt)
835 -> value_type
836{
837 return value_type (&elt - &m_base.elt(0),
838 m_payload,
839 m_base);
840}
841
842
843} } // namespace SG::detail