UList.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2025 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::UList
29 
30 Description
31  A 1D vector of objects of type <T>, where the size of the vector is
32  known and can be used for subscript bounds checking, etc.
33 
34  Storage is not allocated during construction or use but is supplied to
35  the constructor as an argument. This type of list is particularly useful
36  for lists that refer to parts of existing lists such as SubList.
37 
38 SourceFiles
39  UList.C
40  UListI.H
41  UListIO.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef Foam_UList_H
46 #define Foam_UList_H
47 
48 #include "bool.H"
49 #include "label.H"
50 #include "uLabel.H"
51 #include "zero.H"
52 #include "one.H"
53 #include "stdFoam.H"
54 #include "nullObject.H"
55 #include "Hash.H"
56 #include "ListPolicy.H" // Also includes "contiguous"
57 
58 #include <vector> // i.e, std::vector
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
62 namespace Foam
63 {
64 
65 // Forward Declarations
66 class labelRange;
67 
68 template<class T> class List;
69 template<class T> class SubList;
70 template<class T> class UList;
71 template<class T> class IndirectList;
72 template<class T> class UIndirectList;
73 template<class T, class Addr> class IndirectListBase;
74 
75 template<class T> Istream& operator>>(Istream&, UList<T>&);
76 template<class T> Ostream& operator<<(Ostream&, const UList<T>&);
77 
78 // Common list types
79 typedef UList<bool> boolUList;
80 typedef UList<char> charUList;
81 typedef UList<label> labelUList;
82 
83 
84 /*---------------------------------------------------------------------------*\
85  Class UList Declaration
86 \*---------------------------------------------------------------------------*/
87 
88 template<class T>
89 class UList
90 {
91  // Private Data
92 
93  //- Number of elements in UList
94  label size_;
95 
96  //- Vector of values of type T
97  T* __restrict__ v_;
98 
99 
100 protected:
101 
102  // Protected Member Functions
103 
104  //- Set addressed size to be inconsistent with allocated storage.
105  // Use with care
106  inline void setAddressableSize(const label n) noexcept;
107 
108  //- Older name for setAddressableSize
109  FOAM_DEPRECATED_FOR(2021-01, "setAddressableSize(label) method")
110  void size(const label n) { this->setAddressableSize(n); }
111 
112  //- Write the UList with its compound type
113  void writeEntry(Ostream& os) const;
115  //- Return a validated (start,size) subset range, which means that it
116  //- always addresses a valid section of the list.
117  labelRange validateRange(const labelRange& requestedRange) const;
118 
119  //- Assign all entries to the given value
120  // Caution: method name subject to change
121  inline void fill_uniform(const T& val);
122 
123  //- Assign all entries to zero
124  // Caution: method name subject to change
125  inline void fill_uniform(Foam::zero);
126 
127 
128 public:
129 
130  // STL type definitions
131 
132  //- The value type the list contains
133  typedef T value_type;
134 
135  //- The pointer type for non-const access to value_type items
136  typedef T* pointer;
137 
138  //- The pointer type for const access to value_type items
139  typedef const T* const_pointer;
140 
141  //- The type used for storing into value_type objects
142  typedef T& reference;
143 
144  //- The type used for reading from constant value_type objects.
145  typedef const T& const_reference;
146 
147  //- Random access iterator for traversing a UList
148  typedef T* iterator;
150  //- Random access iterator for traversing a UList
151  typedef const T* const_iterator;
152 
153  //- The type to represent the size of a UList
154  typedef label size_type;
155 
156  //- The difference between iterator objects
157  typedef label difference_type;
158 
159  //- Reverse iterator (non-const access)
160  typedef std::reverse_iterator<iterator> reverse_iterator;
161 
162  //- Reverse iterator (const access)
163  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
165 
166  // Related types
167 
168  //- Declare friendship with the List class
169  friend class List<T>;
170 
171  //- Declare friendship with the SubList class
172  friend class SubList<T>;
173 
175  // Static Functions
176 
177  //- Return a null UList (reference to a nullObject).
178  //- Behaves like an empty UList.
179  static const UList<T>& null() noexcept
180  {
181  return NullObjectRef<UList<T>>();
182  }
183 
185  // Public Classes
186 
187  //- A list compare binary predicate for normal sort
188  struct less
189  {
190  const UList<T>& values;
191 
192  less(const UList<T>& list)
193  :
194  values(list)
195  {}
196 
197  bool operator()(const label a, const label b) const
198  {
199  return (values[a] < values[b]);
200  }
201  };
202 
203  //- A list compare binary predicate for reverse sort
204  struct greater
205  {
206  const UList<T>& values;
208  greater(const UList<T>& list)
209  :
210  values(list)
211  {}
213  bool operator()(const label a, const label b) const
214  {
215  return (values[b] < values[a]);
216  }
217  };
218 
219 
220  // Generated Methods
222  //- Copy construct, shallow copy
223  UList(const UList<T>&) noexcept = default;
224 
225  //- Move construct, shallow copy
226  UList(UList<T>&&) noexcept = default;
227 
228  //- No copy assignment (default: shallow copy)
229  // Assignment may need to be shallow (copy pointer)
230  // or deep (copy elements) depending on context or type of list.
231  // Disallow default assignment and provide separate 'shallowCopy' and
232  // 'deepCopy' member functions.
233  UList<T>& operator=(const UList<T>&) = delete;
235  //- Move assignment, shallow copy.
236  // No ambiguity between shallow or deep copying in this form.
237  UList<T>& operator=(UList<T>&&) noexcept = default;
238 
239 
240  // Constructors
242  //- Default construct, zero-sized and nullptr
243  inline constexpr UList() noexcept;
244 
245  //- Construct from components
246  inline UList(T* __restrict__ ptr, const label len) noexcept;
247 
248  //- Move construct from a SubList, shallow copy
249  UList(SubList<T>&&) noexcept;
251 
252  // Member Functions
253 
254  // Access
255 
256  //- The forward circular index. The next index in the list
257  //- which returns to the first at the end of the list
258  inline label fcIndex(const label i) const noexcept;
260  //- The reverse circular index. The previous index in the list
261  //- which returns to the last at the beginning of the list
262  inline label rcIndex(const label i) const noexcept;
263 
264  //- Return forward circular value (ie, next value in the list)
265  inline const T& fcValue(const label i) const;
266 
267  //- Return forward circular value (ie, next value in the list)
268  inline T& fcValue(const label i);
269 
270  //- Return reverse circular value (ie, previous value in the list)
271  inline const T& rcValue(const label i) const;
272 
273  //- Return reverse circular value (ie, previous value in the list)
274  inline T& rcValue(const label i);
275 
276  //- Return pointer to the underlying array serving as data storage.
277  inline const T* cdata() const noexcept;
278 
279  //- Return pointer to the underlying array serving as data storage.
280  inline T* data() noexcept;
281 
282  //- Return pointer to the underlying array serving as data storage,
283  // reinterpreted as byte data
284  // \note Only meaningful for contiguous data
285  inline const char* cdata_bytes() const noexcept;
286 
287  //- Return pointer to the underlying array serving as data storage,
288  // reinterpreted as byte data
289  // \note Only meaningful for contiguous data
290  inline char* data_bytes() noexcept;
291 
292  //- Access first element of the list, position [0]
293  inline T& front();
294 
295  //- Access first element of the list
296  inline const T& front() const;
297 
298  //- Access last element of the list, position [size()-1]
299  inline T& back();
300 
301  //- Access last element of the list, position [size()-1]
302  inline const T& back() const;
303 
304  //- Number of contiguous bytes for the List data.
305  // \note Only meaningful for contiguous data
306  inline std::streamsize size_bytes() const noexcept;
307 
308  //- Number of contiguous bytes for the List data,
309  //- runtime FatalError if type is not contiguous
310  std::streamsize byteSize() const;
311 
312 
313  // Check
314 
315  //- Check start is within valid range [0,size)
316  inline void checkStart(const label start) const;
317 
318  //- Check size is within valid range [0,size]
319  inline void checkSize(const label size) const;
320 
321  //- Check that start and length define a valid range
322  inline void checkRange(const label start, const label len) const;
323 
324  //- Check index is within valid range [0,size)
325  inline void checkIndex(const label i) const;
326 
327  //- True if all entries have identical values, and list is non-empty
328  inline bool uniform() const;
329 
330 
331  // Search
332 
333  //- True if the value is contained in the list.
334  inline bool contains(const T& val) const;
335 
336  //- Is the value contained in the list?
337  // \param val The value to search for
338  // \param pos The first position to examine (no-op if -ve)
339  // \param len The length of the search region (-ve until the end)
340  // \return true if found.
341  inline bool contains(const T& val, label pos, label len = -1) const;
342 
343  //- Find index of the first occurrence of the value.
344  // \param val The value to search for
345  // \return position in list or -1 if not found.
346  label find(const T& val) const;
347 
348  //- Find index of the first occurrence of the value.
349  // \param val The value to search for
350  // \param pos The first position to examine (no-op if -ve)
351  // \param len The length of the search region (-ve until the end)
352  // \return position in list or -1 if not found.
353  label find(const T& val, label pos, label len = -1) const;
354 
355  //- Find index of the last occurrence of the value.
356  // Any occurrences after the end pos are ignored.
357  // Linear search.
358  // \return position in list or -1 if not found.
359  label rfind(const T& val, label pos = -1) const;
360 
361 
362  // Edit
363 
364  //- Move element to the first position.
365  void moveFirst(const label i);
366 
367  //- Move element to the last position.
368  void moveLast(const label i);
369 
370  //- Swap element with the first element. Fatal on an empty list.
371  void swapFirst(const label i);
372 
373  //- Swap element with the last element. Fatal on an empty list.
374  void swapLast(const label i);
375 
376 
377  // Copy
378 
379  //- Copy the pointer and size
380  inline void shallowCopy(T* __restrict__ ptr, const label len) noexcept;
381 
382  //- Copy nullptr and zero size
383  inline void shallowCopy(std::nullptr_t) noexcept;
384 
385  //- Copy the pointer and size held by the given UList
386  inline void shallowCopy(const UList<T>& list) noexcept;
387 
388  //- Copy elements of the given UList. Sizes must match!
389  void deepCopy(const UList<T>& list);
390 
391  //- Copy elements of the given indirect list. Sizes must match!
392  template<class Addr>
393  void deepCopy(const IndirectListBase<T, Addr>& list);
394 
395 
396  // Other Access
397 
398  //- Return SubList slice (non-const access) - no range checking
399  SubList<T> slice(const label pos, label len = -1);
400 
401  //- Return SubList slice (const access) - no range checking
402  const SubList<T> slice(const label pos, label len = -1) const;
403 
404  //- Return SubList slice (non-const access) - with range checking.
405  // The range is subsetted with the list size itself to ensure that the
406  // result always addresses a valid section of the list.
407  SubList<T> slice(const labelRange& range);
408 
409  //- Return SubList slice (const access) - with range checking.
410  // The range is subsetted with the list size itself to ensure that the
411  // result always addresses a valid section of the list.
412  const SubList<T> slice(const labelRange& range) const;
413 
414 
415  // Member Operators
416 
417  //- Return element of UList
418  inline T& operator[](const label i);
419 
420  //- Return element of constant UList
421  // \note bool specialization adds lazy evaluation so reading an
422  // out-of-range element returns false without ill-effects
423  inline const T& operator[](const label i) const;
424 
425  //- Allow cast to a const List<T>&.
426  // \note Marked as "strictly" deprecated.
427  // Currently (2025-04) code still depends on this cast.
428  FOAM_DEPRECATED_STRICTER(2025-04, "dereference as UList, not List?")
429  operator const Foam::List<T>&() const
430  {
431  return *reinterpret_cast<const List<T>*>(this);
432  }
433 
434  //- Assignment of all entries to the given value
435  inline void operator=(const T& val);
436 
437  //- Assignment of all entries to zero
438  void operator=(Foam::zero);
439 
440 
441  // Random access iterator (non-const)
442 
443  //- Return an iterator to begin traversing the UList
444  inline iterator begin() noexcept;
445 
446  //- Return an iterator to end traversing the UList
447  inline iterator end() noexcept;
448 
449  //- Return iterator at offset i from begin,
450  //- clamped to [0,size] range
451  inline iterator begin(const label i) noexcept;
452 
453 
454  // Random access iterator (const)
455 
456  //- Return const_iterator to begin traversing the constant UList
457  inline const_iterator cbegin() const noexcept;
458 
459  //- Return const_iterator to end traversing the constant UList
460  inline const_iterator cend() const noexcept;
461 
462  //- Return const_iterator to begin traversing the constant UList
463  inline const_iterator begin() const noexcept;
464 
465  //- Return const_iterator to end traversing the constant UList
466  inline const_iterator end() const noexcept;
467 
468  //- Return const_iterator at offset i from begin,
469  //- clamped to [0,size] range
470  inline const_iterator cbegin(const label i) const noexcept;
471 
472  //- Return const_iterator at offset i from begin,
473  //- clamped to [0,size] range
474  inline const_iterator begin(const label i) const noexcept;
475 
476 
477  // Reverse iterators (non-const)
478 
479  //- Return reverse_iterator to begin reverse traversing the UList
480  inline reverse_iterator rbegin();
481 
482  //- Return reverse_iterator to end reverse traversing the UList
483  inline reverse_iterator rend();
484 
485 
486  // Reverse iterators (const)
487 
488  //- Return const_reverse_iterator to begin reverse traversing the UList
489  inline const_reverse_iterator crbegin() const;
490 
491  //- Return const_reverse_iterator to end reverse traversing the UList
492  inline const_reverse_iterator crend() const;
493 
494  //- Return const_reverse_iterator to begin reverse traversing the UList
495  inline const_reverse_iterator rbegin() const;
496 
497  //- Return const_reverse_iterator to end reverse traversing the UList
498  inline const_reverse_iterator rend() const;
499 
500 
501  // STL member functions
502 
503  //- True if List is empty (ie, size() is zero)
504  bool empty() const noexcept { return !size_; }
505 
506  //- The number of elements in the container
507  label size() const noexcept { return size_; }
508 
509  //- Size of the underlying storage.
510  label capacity() const noexcept { return size_; }
511 
512  //- The size of the largest possible UList
513  static constexpr label max_size() noexcept { return labelMax; }
514 
515  //- Swap content with another UList of the same type in constant time
516  inline void swap(UList<T>& list) noexcept;
517 
518 
519  // STL member operators
520 
521  //- Equality operation on ULists of the same type.
522  // Returns true when the ULists are element-wise equal
523  // (using UList::value_type::operator==). Takes linear time
524  bool operator==(const UList<T>& list) const;
525 
526  //- The opposite of the equality operation. Takes linear time
527  bool operator!=(const UList<T>& list) const;
528 
529  //- Compare two ULists lexicographically. Takes linear time
530  bool operator<(const UList<T>& list) const;
531 
532  //- Compare two ULists lexicographically. Takes linear time
533  bool operator>(const UList<T>& list) const;
534 
535  //- Return true if !(a > b). Takes linear time
536  bool operator<=(const UList<T>& list) const;
537 
538  //- Return true if !(a < b). Takes linear time
539  bool operator>=(const UList<T>& list) const;
540 
541 
542  // Reading/writing
543 
544  //- Read List contents from Istream.
545  // The List must have the proper size before calling
546  Istream& readList(Istream& is);
547 
548  //- Write the List as a dictionary entry with keyword
549  void writeEntry(const word& keyword, Ostream& os) const;
550 
551  //- Write List, with line-breaks in ASCII when length exceeds shortLen.
552  // Using '0' suppresses line-breaks entirely.
553  Ostream& writeList(Ostream& os, const label shortLen=0) const;
554 
555 
556  // IOstream Operators
557 
558  //- Use the readList() method to read contents from Istream.
559  friend Istream& operator>> <T>
560  (
561  Istream& os,
562  UList<T>& list
563  );
564 
565 
566  // Special Methods
567 
568  //- Test \c bool value at specified position,
569  //- always false for out-of-range access.
570  // \note Method name compatibility with bitSet, HashSet
571  template<class TypeT = T>
572  std::enable_if_t<std::is_same_v<bool, TypeT>, bool>
573  inline test(const label i) const
574  {
575  return (i >= 0 && i < size_ && v_[i]);
576  }
577 
578  //- Return \c bool value at specified position,
579  //- always false for out-of-range access.
580  // \note Method name compatibility with bitSet
581  template<class TypeT = T>
582  std::enable_if_t<std::is_same_v<bool, TypeT>, bool>
583  inline get(const label i) const
584  {
585  return (i >= 0 && i < size_ && v_[i]);
586  }
587 
588  //- Unset the \c bool entry at specified position,
589  //- always false for out-of-range access.
590  // \return True if value changed and was not out-of-range
591  // \note Method name compatibility with bitSet
592  template<class TypeT = T>
593  std::enable_if_t<std::is_same_v<bool, TypeT>, bool>
594  inline unset(const label i)
595  {
596  if (i >= 0 && i < size_ && v_[i])
597  {
598  v_[i] = false;
599  return true;
600  }
601  return false;
602  }
603 
604 
605  // Hashing
606 
607  //- Hashing functor for UList
608  struct hasher
609  {
610  inline unsigned operator()
611  (
612  const UList<T>& obj,
613  unsigned seed=0
614  ) const
615  {
616  if constexpr (is_contiguous_v<T>)
617  {
618  return Foam::Hasher(obj.cdata(), obj.size_bytes(), seed);
619  }
620  else
621  {
622  Foam::Hash<T> op;
623  for (const T& val : obj)
624  {
625  seed = op(val, seed);
626  }
627  return seed;
628  }
629  }
630  };
631 
632  //- Deprecated(2021-04) hashing functor. Use hasher()
633  // \deprecated(2021-04) - use hasher() functor
634  template<class Unused=bool>
635  struct Hash : UList<T>::hasher
636  {
637  FOAM_DEPRECATED_FOR(2021-04, "hasher()") Hash() {}
638  };
639 
640 
641  // Housekeeping
642 
643  //- Access first element of the list, position [0]
644  //FOAM_DEPRECATED_FOR(2022-10, "front()")
645  T& first() { return front(); }
646 
647  //- Access first element of the list
648  //FOAM_DEPRECATED_FOR(2022-10, "front()")
649  const T& first() const { return front(); };
650 
651  //- Access last element of the list, position [size()-1]
652  //FOAM_DEPRECATED_FOR(2022-10, "back()")
653  T& last() { return back(); }
654 
655  //- Access last element of the list, position [size()-1]
656  //FOAM_DEPRECATED_FOR(2022-10, "back()")
657  const T& last() const { return back(); };
658 
659  //- Same as contains()
660  bool found(const T& val, label pos = 0) const
661  {
662  return this->contains(val, pos);
663  }
664 };
665 
666 
667 // * * * * * * * * * * * * Template Specializations * * * * * * * * * * * * //
668 
669 //- Character list writeEntry
670 template<>
671 void UList<char>::writeEntry(Ostream& os) const;
672 
673 //- Character list assign zero - avoids Foam::zero casting ambiguities
674 template<>
676 
677 
678 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
679 
680 //- Read List contents from Istream, list must have the proper size!
681 template<class T>
682 Istream& operator>>(Istream& is, UList<T>& list)
683 {
684  return list.readList(is);
685 }
686 
687 
688 //- Write List to Ostream, as per UList::writeList() with default length.
689 // The default short-length is given by Foam::ListPolicy::short_length
690 template<class T>
691 Ostream& operator<<(Ostream& os, const UList<T>& list)
692 {
693  return list.writeList(os, Foam::ListPolicy::short_length<T>::value);
694 }
695 
696 //- Write std::vector to Ostream. ASCII only, no line-breaks
697 template<class T>
698 Ostream& operator<<(Ostream& os, const std::vector<T>& list);
699 
700 
701 // * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
703 //- Fill an identity map with (map[i] == i), works like std::iota().
704 // Optionally with an alternative start index, so that (map[i] == i+start)
705 void identity(UList<int32_t>& map, int32_t start = 0);
706 
707 //- Fill an identity map with (map[i] == i), works like std::iota().
708 // Optionally with an alternative start index, so that (map[i] == i+start)
709 void identity(UList<int64_t>& map, int64_t start = 0);
710 
711 //- Sort the list
712 template<class T>
713 void sort(UList<T>& list);
714 
715 //- Sort the list with the specified comparator
716 template<class T, class Compare>
717 void sort(UList<T>& list, const Compare& comp);
718 
719 //- Stable sort the list
720 template<class T>
721 void stableSort(UList<T>& list);
722 
723 //- Stable sort the list with the specified comparator
724 template<class T, class Compare>
725 void stableSort(UList<T>& list, const Compare& comp);
726 
727 //- Randomise the list order
728 template<class T>
729 void shuffle(UList<T>& list);
730 
731 //- Reverse the first n elements of the list
732 template<class T>
733 inline void reverse(UList<T>& list, const label n);
734 
735 //- Reverse all elements of the list
736 template<class T>
737 inline void reverse(UList<T>& list);
738 
739 
740 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
741 
742 //- Hashing for List data
743 template<class T>
744 struct Hash<UList<T>> : UList<T>::hasher {};
745 
746 
747 //- Object access operator or list access operator (default is pass-through)
748 //- \sa ListListOps::combine()
749 template<class T>
750 struct accessOp
751 {
752  const T& operator()(const T& obj) const { return obj; }
753 };
754 
755 
756 //- Test if object is empty, typically using its empty() method.
757 template<class T>
758 struct emptyOp
759 {
760  bool operator()(const T& obj) const { return obj.empty(); }
761 };
762 
763 
764 //- Extract size (as label) from an object, typically using its size() method.
765 template<class T>
766 struct sizeOp
767 {
768  label operator()(const T& obj) const { return obj.size(); }
769 };
770 
771 
772 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
773 
774 } // End namespace Foam
775 
776 
777 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
778 
779 // Does not need std::swap or Foam::Swap() specialization
780 // since UList is MoveConstructible and MoveAssignable
781 
782 
783 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
784 
785 #include "UListI.H"
786 
787 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
788 
789 #ifdef NoRepository
790  #include "UList.C"
791  #include "UListIO.C"
792  #include "stdVectorIO.C"
793 #endif
794 
795 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
796 
797 #endif
798 
799 // ************************************************************************* //
void swap(UList< T > &list) noexcept
Swap content with another UList of the same type in constant time.
Definition: UListI.H:499
std::reverse_iterator< const_iterator > const_reverse_iterator
Reverse iterator (const access)
Definition: UList.H:199
const_iterator cend() const noexcept
Return const_iterator to end traversing the constant UList.
Definition: UListI.H:443
T * pointer
The pointer type for non-const access to value_type items.
Definition: UList.H:154
FOAM_DEPRECATED_FOR(2021-04, "hasher()") Hash()
Definition: UList.H:875
void swapLast(const label i)
Swap element with the last element. Fatal on an empty list.
Definition: UList.C:83
label operator()(const T &obj) const
Definition: UList.H:1059
void swapFirst(const label i)
Swap element with the first element. Fatal on an empty list.
Definition: UList.C:71
bool operator()(const label a, const label b) const
Definition: UList.H:241
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
const_reverse_iterator crbegin() const
Return const_reverse_iterator to begin reverse traversing the UList.
Definition: UListI.H:464
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:52
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const T * const_pointer
The pointer type for const access to value_type items.
Definition: UList.H:159
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:697
T * data() noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:265
T & front()
Access first element of the list, position [0].
Definition: UListI.H:230
T & first()
Access first element of the list, position [0].
Definition: UList.H:886
Object access operator or list access operator (default is pass-through)
Definition: UList.H:1037
bool found(const T &val, label pos=0) const
Same as contains()
Definition: UList.H:912
T * iterator
Random access iterator for traversing a UList.
Definition: UList.H:174
void stableSort(UList< T > &list)
Stable sort the list.
Definition: UList.C:311
labelRange validateRange(const labelRange &requestedRange) const
Return a validated (start,size) subset range, which means that it always addresses a valid section of...
Definition: UList.C:31
void setAddressableSize(const label n) noexcept
Set addressed size to be inconsistent with allocated storage.
Definition: UListI.H:492
std::enable_if_t< std::is_same_v< bool, TypeT >, bool > test(const label i) const
Test bool value at specified position, always false for out-of-range access.
Definition: UList.H:800
Base for lists with indirect addressing, templated on the list contents type and the addressing type...
UList< bool > boolUList
A UList of bools.
Definition: UList.H:74
bool contains(const T &val) const
True if the value is contained in the list.
Definition: UListI.H:293
static bool less(const vector &x, const vector &y)
To compare normals.
char * data_bytes() noexcept
Return pointer to the underlying array serving as data storage,.
Definition: UListI.H:279
Istream & readList(Istream &is)
Read List contents from Istream.
Definition: UListIO.C:174
scalar range
UList< label > labelUList
A UList of labels.
Definition: UList.H:76
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:65
const_reverse_iterator crend() const
Return const_reverse_iterator to end reverse traversing the UList.
Definition: UListI.H:485
const char * cdata_bytes() const noexcept
Return pointer to the underlying array serving as data storage,.
Definition: UListI.H:272
label difference_type
The difference between iterator objects.
Definition: UList.H:189
label fcIndex(const label i) const noexcept
The forward circular index. The next index in the list which returns to the first at the end of the l...
Definition: UListI.H:90
reverse_iterator rbegin()
Return reverse_iterator to begin reverse traversing the UList.
Definition: UListI.H:450
UList< T > & operator=(const UList< T > &)=delete
No copy assignment (default: shallow copy)
reverse_iterator rend()
Return reverse_iterator to end reverse traversing the UList.
Definition: UListI.H:471
dimensionedScalar pos(const dimensionedScalar &ds)
Ostream & writeList(Ostream &os, const label shortLen=0) const
Write List, with line-breaks in ASCII when length exceeds shortLen.
Definition: UListIO.C:75
A non-owning sub-view of a List (allocated or unallocated storage).
Definition: SubList.H:46
const UList< T > & values
Definition: UList.H:234
void fill_uniform(const T &val)
Assign all entries to the given value.
Definition: UListI.H:46
const T & fcValue(const label i) const
Return forward circular value (ie, next value in the list)
Definition: UListI.H:104
label capacity() const noexcept
Size of the underlying storage.
Definition: UList.H:707
SubList< T > slice(const label pos, label len=-1)
Return SubList slice (non-const access) - no range checking.
Definition: SubList.H:259
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
Definition: labelLists.C:44
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:295
Istream & operator>>(Istream &, directionInfo &)
bool operator==(const UList< T > &list) const
Equality operation on ULists of the same type.
Definition: UList.C:237
#define FOAM_DEPRECATED_STRICTER(since, replacement)
Definition: stdFoam.H:56
bool operator!=(const UList< T > &list) const
The opposite of the equality operation. Takes linear time.
Definition: UList.C:251
label rfind(const T &val, label pos=-1) const
Find index of the last occurrence of the value.
Definition: UList.C:211
void reverse(UList< T > &list, const label n)
Reverse the first n elements of the list.
Definition: UListI.H:514
std::reverse_iterator< iterator > reverse_iterator
Reverse iterator (non-const access)
Definition: UList.H:194
bool operator()(const T &obj) const
Definition: UList.H:1049
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition: UListI.H:385
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
label find(const T &val) const
Find index of the first occurrence of the value.
Definition: UList.C:172
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: scalarImpl.H:255
UList< char > charUList
A UList of chars.
Definition: UList.H:75
label size() const noexcept
The number of elements in the container.
Definition: UList.H:702
const UList< T > & values
Definition: UList.H:252
OBJstream os(runTime.globalPath()/outputName)
T & reference
The type used for storing into value_type objects.
Definition: UList.H:164
std::enable_if_t< std::is_same_v< bool, TypeT >, bool > unset(const label i)
Unset the bool entry at specified position, always false for out-of-range access. ...
Definition: UList.H:827
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
static constexpr label max_size() noexcept
The size of the largest possible UList.
Definition: UList.H:712
void moveLast(const label i)
Move element to the last position.
Definition: UList.C:59
T & last()
Access last element of the list, position [size()-1].
Definition: UList.H:900
label size_type
The type to represent the size of a UList.
Definition: UList.H:184
void checkRange(const label start, const label len) const
Check that start and length define a valid range.
Definition: UListI.H:160
unsigned Hasher(const void *data, size_t len, unsigned seed=0)
Bob Jenkins&#39;s 96-bit mixer hashing function (lookup3)
Definition: Hasher.C:575
constexpr UList() noexcept
Default construct, zero-sized and nullptr.
Definition: UListI.H:28
const T * const_iterator
Random access iterator for traversing a UList.
Definition: UList.H:179
Hash function class. The default definition is for primitives. Non-primitives used to hash entries on...
Definition: Hash.H:47
std::streamsize byteSize() const
Number of contiguous bytes for the List data, runtime FatalError if type is not contiguous.
Definition: UList.C:159
bool operator()(const label a, const label b) const
Definition: UList.H:259
void shallowCopy(T *__restrict__ ptr, const label len) noexcept
Copy the pointer and size.
Definition: UListI.H:309
greater(const UList< T > &list)
Definition: UList.H:254
static const UList< T > & null() noexcept
Return a null UList (reference to a nullObject). Behaves like an empty UList.
Definition: UList.H:221
T & back()
Access last element of the list, position [size()-1].
Definition: UListI.H:244
Includes some common C++ headers, defines global macros and templates used in multiple places by Open...
constexpr label labelMax
Definition: label.H:55
const T & const_reference
The type used for reading from constant value_type objects.
Definition: UList.H:169
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing the constant UList.
Definition: UListI.H:399
void checkSize(const label size) const
Check size is within valid range [0,size].
Definition: UListI.H:146
label n
void writeEntry(Ostream &os) const
Write the UList with its compound type.
Definition: UListIO.C:29
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:258
void deepCopy(const UList< T > &list)
Copy elements of the given UList. Sizes must match!
Definition: UList.C:97
Number of items before requiring line-breaks in the list output.
Definition: ListPolicy.H:55
iterator end() noexcept
Return an iterator to end traversing the UList.
Definition: UListI.H:429
label rcIndex(const label i) const noexcept
The reverse circular index. The previous index in the list which returns to the last at the beginning...
Definition: UListI.H:97
void shuffle(UList< T > &list)
Randomise the list order.
Definition: UList.C:327
void moveFirst(const label i)
Move element to the first position.
Definition: UList.C:47
void checkStart(const label start) const
Check start is within valid range [0,size)
Definition: UListI.H:132
const T & operator()(const T &obj) const
Definition: UList.H:1039
void checkIndex(const label i) const
Check index is within valid range [0,size)
Definition: UListI.H:189
T value_type
The value type the list contains.
Definition: UList.H:149
const T & rcValue(const label i) const
Return reverse circular value (ie, previous value in the list)
Definition: UListI.H:118
std::streamsize size_bytes() const noexcept
Number of contiguous bytes for the List data.
Definition: UListI.H:286
bool operator>=(const UList< T > &list) const
Return true if !(a < b). Takes linear time.
Definition: UList.C:286
System bool.
Namespace for OpenFOAM.
less(const UList< T > &list)
Definition: UList.H:236
bool operator>(const UList< T > &list) const
Compare two ULists lexicographically. Takes linear time.
Definition: UList.C:272