DATAKIT API  V2025.2
Dtk_tab< T > Class Template Reference

This is a high level array class. More...

Public Types

typedef const_pointer const_iterator
 
typedef T const * const_pointer
 
typedef pointer iterator
 
typedef T * pointer
 
typedef T value_type
 

Public Member Functions

T & at (Dtk_Size_t k)
 
const T & at (Dtk_Size_t k) const
 
T & back ()
 Return the elements at the end of the array. More...
 
const T & back () const
 Return the elements at the end of the array. More...
 
iterator begin ()
 
const_iterator begin () const
 
Dtk_Size_t capacity () const
 Returns the size of the storage space currently allocated for the array, expressed in terms of elements. More...
 
const_iterator cbegin () const
 
const_iterator cend () const
 
void clear (int no_delete=0)
 Resets the Dtk_tab content. More...
 
T * data ()
 
T const * data () const
 
 Dtk_tab ()
 Default constructor. More...
 
 Dtk_tab (const Dtk_tab< T > &t)
 
 Dtk_tab (Dtk_Size_t initreservesize, int resize=0)
 
 Dtk_tab (Dtk_tab< T > &&t) DTK_NOEXCEPT
 Move constructor. More...
 
iterator end ()
 
const_iterator end () const
 
int find (const T &e) const
 
template<typename comp >
int find (const T &e, const comp &C) const
 
T & front ()
 Return the elements at the beginning of the array. More...
 
const T & front () const
 Return the elements at the beginning of the array. More...
 
const T * GetArray () const
 Returns array of T elements. More...
 
Dtk_Size_t GetSize () const
 
max_element () const
 
Dtk_Size_t max_ithelement ()
 
min_element () const
 
Dtk_Size_t min_ithelement ()
 
Dtk_taboperator+= (const Dtk_tab &t)
 
Dtk_taboperator+= (Dtk_tab &&t)
 
int operator< (const Dtk_tab< T > &t) const
 
Dtk_taboperator= (const Dtk_tab< T > &t)
 
Dtk_tab< T > & operator= (Dtk_tab< T > &&t) DTK_NOEXCEPT
 Move assignment operator. More...
 
int operator== (const Dtk_tab< T > &t) const
 
T & operator[] (Dtk_Size_t k)
 Accesses the ith element - like a classic array -. More...
 
const T & operator[] (Dtk_Size_t k) const
 
void pop_back ()
 Removes the last element. More...
 
void push_back (const T &x)
 Inserts an element at the end of the array. More...
 
void push_back (T &&x)
 Inserts an element by moving it at the end of the array. More...
 
void reduce ()
 
void remove (const T &a)
 Removes the first element with the value a. More...
 
void reserve (Dtk_Size_t n)
 
void resize (Dtk_Size_t n)
 
void resize (Dtk_Size_t n, const T &t)
 Resizes the array. More...
 
void reverse ()
 
Dtk_Size_t size () const
 Returns the size of the array. More...
 
void sort ()
 Swap two elements. More...
 
template<typename comp >
void sort (const comp &C)
 Sorts the array with custom sorting. More...
 
Dtk_tab subtab (Dtk_Size_t a, Dtk_Size_t b)
 
void swap (const Dtk_Size_t inA, const Dtk_Size_t inB)
 Sorts the array. More...
 
 ~Dtk_tab ()
 

Friends

std::ostream & operator<< (std::ostream &o, const Dtk_tab &d)
 

Detailed Description

template<typename T>
class Dtk_tab< T >

This is a high level array class.

This class lets you use optimized arrays.

Member Typedef Documentation

◆ const_iterator

template<typename T >
typedef const_pointer Dtk_tab< T >::const_iterator

◆ const_pointer

template<typename T >
typedef T const* Dtk_tab< T >::const_pointer

◆ iterator

template<typename T >
typedef pointer Dtk_tab< T >::iterator

◆ pointer

template<typename T >
typedef T* Dtk_tab< T >::pointer

◆ value_type

template<typename T >
typedef T Dtk_tab< T >::value_type

Constructor & Destructor Documentation

◆ Dtk_tab() [1/4]

template<typename T >
Dtk_tab< T >::Dtk_tab ( )

Default constructor.

Remarks
create an empty array
216  {
217  nb=0;
218  rsv=0;
219  v=NULL;
220  }

◆ Dtk_tab() [2/4]

template<typename T >
Dtk_tab< T >::Dtk_tab ( Dtk_Size_t  initreservesize,
int  resize = 0 
)
222  {
223  Pdtk_Assert(initreservesize>0); // forbidden : at least one element on reserve.
224  rsv=initreservesize;
225  nb=0;
226  if (resize)
227  nb = rsv;
228  if (rsv>0)
229  v=new T[rsv];
230  else
231  v=NULL;
232  }

◆ ~Dtk_tab()

template<typename T >
Dtk_tab< T >::~Dtk_tab ( )
234  {
235  if (v!=NULL)
236  {
237  delete [] v;
238  v=NULL;
239  }
240  }

◆ Dtk_tab() [3/4]

template<typename T >
Dtk_tab< T >::Dtk_tab ( const Dtk_tab< T > &  t)
250  {
251 //#ifdef DTK_DEBUG_STL_TRACE
252 // FILE* F = fopen("/stltrace.txt","a");
253 // fprintf(F,"Dtk_tab copy constructor size : %d ; elemsize : %d\n",t.size(),sizeof(T));
254 // fclose(F);
255 //#endif
256  nb=t.nb;
257  rsv=t.nb; // shrink_to_fit while copy
258  if (rsv>0)
259  {
260  Pdtk_Assert(nb > 0);
261  v=new T[nb];
262  for(Dtk_Size_t i=0;i<nb;i++)
263  v[i] = t.v[i];
264  }
265  else
266  v=NULL;
267  }

◆ Dtk_tab() [4/4]

template<typename T >
Dtk_tab< T >::Dtk_tab ( Dtk_tab< T > &&  t)

Move constructor.

Parameters
tthe Dtk_tab to move
299  : v(t.v), nb(t.nb), rsv(t.rsv)
300  {
301  t.v = 0;
302  t.nb = 0;
303  t.rsv = 0;
304  }

Member Function Documentation

◆ at() [1/2]

template<typename T >
T& Dtk_tab< T >::at ( Dtk_Size_t  k)
399  {
400  return operator[](k);
401  }

◆ at() [2/2]

template<typename T >
const T& Dtk_tab< T >::at ( Dtk_Size_t  k) const
403  {
404  return operator[](k);
405  }

◆ back() [1/2]

template<typename T >
T& Dtk_tab< T >::back ( )

Return the elements at the end of the array.

Sample:

Dtk_tab<int> L; //we construct an array of int.
L.push_back(5);
L.push_back(35);
L.push_back(8); // array is now : 5 - 35 - 8
int a = L.back(); // a is 8
540  {
541  Pdtk_Assert(nb!=0);
542  return v[nb - 1];
543  }

◆ back() [2/2]

template<typename T >
const T& Dtk_tab< T >::back ( ) const

Return the elements at the end of the array.

Sample:

Dtk_tab<int> L; //we construct an array of int.
L.push_back(5);
L.push_back(35);
L.push_back(8); // array is now : 5 - 35 - 8
int a = L.back(); // a is 8
555  {
556  Pdtk_Assert(nb!=0);
557  return v[nb - 1];
558  }

◆ begin() [1/2]

template<typename T >
iterator Dtk_tab< T >::begin ( )
890  {
891  return v;
892  }

◆ begin() [2/2]

template<typename T >
const_iterator Dtk_tab< T >::begin ( ) const
894  {
895  return v;
896  }

◆ capacity()

template<typename T >
Dtk_Size_t Dtk_tab< T >::capacity ( ) const

Returns the size of the storage space currently allocated for the array, expressed in terms of elements.

This capacity is not necessarily equal to the size. It can be equal or greater. The capacity of the Dtk_tab can be explicitly altered by calling member Dtk_tab::reserve.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.reserve(5); //we reserve 5 element of type int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
Dtk_Size_t size = tab.size(); //size is equal to 3
Dtk_Size_t capacity = tab.capacity(); //capacity is equal to 5
525  {
526  return rsv;
527  }

◆ cbegin()

template<typename T >
const_iterator Dtk_tab< T >::cbegin ( ) const
898  {
899  return v;
900  }

◆ cend()

template<typename T >
const_iterator Dtk_tab< T >::cend ( ) const
910  {
911  return v + nb;
912  }

◆ clear()

template<typename T >
void Dtk_tab< T >::clear ( int  no_delete = 0)

Resets the Dtk_tab content.

Remarks
If the Dtk_tab has pointers, theses ones aren't deleted.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
Now tab has 3 elements...
tab.clear(); //Now tab hasn't any element.
354  {
355  if (v==NULL)
356  return;
357  if (no_delete)
358  {
359  nb=0;
360  return;
361  }
362  delete [] v;
363  nb=0;
364  rsv=0;
365  v=NULL;
366  }

◆ data() [1/2]

template<typename T >
T* Dtk_tab< T >::data ( )
247 { return v; }

◆ data() [2/2]

template<typename T >
T const* Dtk_tab< T >::data ( ) const
248 { return v; }

◆ end() [1/2]

template<typename T >
iterator Dtk_tab< T >::end ( )
902  {
903  return v + nb;
904  }

◆ end() [2/2]

template<typename T >
const_iterator Dtk_tab< T >::end ( ) const
906  {
907  return v + nb;
908  }

◆ find() [1/2]

template<typename T >
int Dtk_tab< T >::find ( const T &  e) const
745  {
746  for(Dtk_Size_t i=0;i<nb;i++)
747  if (v[i]==e)
748  return (int)i;
749  return -1;
750  }

◆ find() [2/2]

template<typename T >
template<typename comp >
int Dtk_tab< T >::find ( const T &  e,
const comp &  C 
) const
753  {
754  for(Dtk_Size_t i=0;i<nb;i++)
755  if (!C(v[i],e) && !C(e,v[i]))
756  return (int)i;
757  return -1;
758  }

◆ front() [1/2]

template<typename T >
T& Dtk_tab< T >::front ( )

Return the elements at the beginning of the array.

Sample:

Dtk_tab<int> L; //we construct a list of array.
L.push_back(5);
L.push_back(35);
L.push_back(8); // array is now : 5 - 35 - 8
int a = L.front(); // a is 5
570  {
571  Pdtk_Assert(nb!=0);
572  return v[0];
573  }

◆ front() [2/2]

template<typename T >
const T& Dtk_tab< T >::front ( ) const

Return the elements at the beginning of the array.

Sample:

Dtk_tab<int> L; //we construct a list of array.
L.push_back(5);
L.push_back(35);
L.push_back(8); // array is now : 5 - 35 - 8
int a = L.front(); // a is 5
585  {
586  Pdtk_Assert(nb!=0);
587  return v[0];
588  }

◆ GetArray()

template<typename T >
const T* Dtk_tab< T >::GetArray ( ) const

Returns array of T elements.

Remarks
You should call size () method to know returned array size.
244  {
245  return this->v;
246  }

◆ GetSize()

template<typename T >
Dtk_Size_t Dtk_tab< T >::GetSize ( ) const
874  {
875  return 2*sizeof(Dtk_Size_t) + sizeof(T*) + rsv * sizeof(T);
876  }

◆ max_element()

template<typename T >
T Dtk_tab< T >::max_element ( ) const
824  {
825  if (nb==0)
826  return T();
827  T max = v[0];
828  for(Dtk_Size_t i=0;i<nb;i++)
829  if (v[i]>max)
830  max=v[i];
831  return max;
832  }

◆ max_ithelement()

template<typename T >
Dtk_Size_t Dtk_tab< T >::max_ithelement ( )
848  {
849  if (nb==0)
850  return 0;
851  Dtk_Size_t imax = 0;
852  T max = v[0];
853  for(Dtk_Size_t i=0;i<nb;i++)
854  if (v[i]>max)
855  {
856  max=v[i];
857  imax = i;
858  }
859  return imax;
860  }

◆ min_element()

template<typename T >
T Dtk_tab< T >::min_element ( ) const
814  {
815  if (nb==0)
816  return T();
817  T min = v[0];
818  for(Dtk_Size_t i=0;i<nb;i++)
819  if (v[i]<min)
820  min=v[i];
821  return min;
822  }

◆ min_ithelement()

template<typename T >
Dtk_Size_t Dtk_tab< T >::min_ithelement ( )
834  {
835  if (nb==0)
836  return 0;
837  Dtk_Size_t imin = 0;
838  T min = v[0];
839  for(Dtk_Size_t i=0;i<nb;i++)
840  if (v[i]<min)
841  {
842  min=v[i];
843  imin = i;
844  }
845  return imin;
846  }

◆ operator+=() [1/2]

template<typename T >
Dtk_tab& Dtk_tab< T >::operator+= ( const Dtk_tab< T > &  t)
761  {
762  if (t.nb==0) // empty 2nd
763  return *this;
764  rsv=nb+t.nb;
765  if (v==NULL)
766  v = new T[rsv];
767  else
768  delete [] _dtk_doublerealloc(rsv);
769  for(Dtk_Size_t i=0;i<t.nb;i++)
770  v[i+nb] = t.v[i];
771  nb=nb+t.nb;
772  return *this;
773  }

◆ operator+=() [2/2]

template<typename T >
Dtk_tab& Dtk_tab< T >::operator+= ( Dtk_tab< T > &&  t)
776  {
777  if( t.nb == 0 )
778  return *this;
779  rsv = nb + t.nb;
780  if( v == nullptr )
781  v = new T[ rsv ];
782  else
783  delete[] _dtk_doublerealloc( rsv );
784  for( Dtk_Size_t i = 0; i < t.nb; i++ )
785  v[ i + nb ] = std::move( t.v[ i ] );
786  nb = nb + t.nb;
787  return *this;
788  }

◆ operator<()

template<typename T >
int Dtk_tab< T >::operator< ( const Dtk_tab< T > &  t) const
326  {
327  Dtk_Size_t i;
328  if (size()<t.size())
329  return 1;
330  if (t.size()<size())
331  return 0;
332  for(i=0;i<size();i++)
333  {
334  if ((v[i]<t.v[i]))
335  return 1;
336  if ((t.v[i]<v[i]))
337  return 0;
338  }
339  return 0;
340  }

◆ operator=() [1/2]

template<typename T >
Dtk_tab& Dtk_tab< T >::operator= ( const Dtk_tab< T > &  t)
269  {
270  if (&t!=this)
271  {
272  if (v!=NULL)
273  {
274  Pdtk_Assert(rsv>0);
275  delete [] v;
276  }
277  v=NULL;
278  nb=t.nb;
279  rsv=t.nb;
280  if (t.v!=NULL && nb > 0)
281  {
282  v=new T[nb];
283  for(Dtk_Size_t i=0;i<nb;i++)
284  v[i] = t.v[i];
285  }
286  }
287  return *this;
288  }

◆ operator=() [2/2]

template<typename T >
Dtk_tab<T>& Dtk_tab< T >::operator= ( Dtk_tab< T > &&  t)

Move assignment operator.

Parameters
tthe Dtk_tab to move
309  {
310  if(this != &t)
311  {
312  delete [] v;
313  v = t.v;
314  nb = t.nb;
315  rsv = t.rsv;
316  t.v = 0;
317  t.nb = 0;
318  t.rsv = 0;
319  }
320 
321  return *this;
322  }

◆ operator==()

template<typename T >
int Dtk_tab< T >::operator== ( const Dtk_tab< T > &  t) const
290  {
291  if (t<*this || *this<t)
292  return 0;
293  return 1;
294  }

◆ operator[]() [1/2]

template<typename T >
T& Dtk_tab< T >::operator[] ( Dtk_Size_t  k)

Accesses the ith element - like a classic array -.

Parameters
[in]k: The element position.
Warning
There isn't any check for the element position validity !!!

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
// tab is {0,2,1}
int elt = tab[2]; //elt is equal to 1
tab[1] = 5; // tab is {0,5,1}
tab[5] = 5; // Error !!! The program will crash :(
383  {
384 #ifdef _DEBUG_DTK
385  if (k>=nb)
387 #endif
388  return v[k];
389  }

◆ operator[]() [2/2]

template<typename T >
const T& Dtk_tab< T >::operator[] ( Dtk_Size_t  k) const
391  {
392 #ifdef _DEBUG_DTK
393  if (k>=nb)
395 #endif
396  return v[k];
397  }

◆ pop_back()

template<typename T >
void Dtk_tab< T >::pop_back ( )

Removes the last element.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
Now tab is {0,2,1}...
488  {
489  Pdtk_Assert(nb!=0);
490  if( nb == 0 ) { Dtk_ThrowOverflowException(); }
491  nb--;
492  } // extent : liberation a 1/3.

◆ push_back() [1/2]

template<typename T >
void Dtk_tab< T >::push_back ( const T &  x)

Inserts an element at the end of the array.

Parameters
[in]xThe element to insert.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
Now tab is {0,2,1}...
418  {
419  if (nb==rsv)
420  {
421  if (nb==0)
422  {
423  rsv=1;
424  v = new T[1];
425  v[nb++]=x;
426  }
427  else
428  {
429  rsv*=2;
430  T to_add;
431  to_add = x;
432  T* ex = _dtk_doublerealloc(rsv);
433  //v[nb++]=x;
434  v[ nb++ ] = to_add;
435  delete [] ex;
436  }
437  }
438  else
439  v[nb++]=x;
440  }

◆ push_back() [2/2]

template<typename T >
void Dtk_tab< T >::push_back ( T &&  x)

Inserts an element by moving it at the end of the array.

Parameters
[in]xThe element to insert.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
Now tab is {0,2,1}...
455  {
456  if (nb==rsv)
457  {
458  if (nb==0)
459  {
460  rsv=1;
461  v = new T[1];
462  v[nb++]=std::move(x);
463  }
464  else
465  {
466  rsv*=2;
467  T* ex = _dtk_doublerealloc(rsv);
468  v[nb++]= std::move(x);
469  delete [] ex;
470  }
471  }
472  else
473  v[nb++]=std::move(x);
474  }

◆ reduce()

template<typename T >
void Dtk_tab< T >::reduce ( )
878  {
879  if (rsv>nb)
880  {
881  rsv = nb;
882  if (rsv==0)
883  rsv = 1;
884  delete [] _dtk_doublerealloc(rsv);
885  }
886  }

◆ remove()

template<typename T >
void Dtk_tab< T >::remove ( const T &  a)

Removes the first element with the value a.

Parameters
[in]aThe value of the element that should be removed
Remarks
: The order of the elements of the tab won't be conserved, the last element is moved to the old position of the removed element

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(1); //we insert '1'
tab.push_back(2); //we insert '2'
tab.push_back(3); //we insert '3'
tab.remove(1); //Now tab is {0,3,2}
tab.remove(2); //Now tab is {0,3}
693  {
694  int pos = find( a );
695  if( pos >= 0)
696  {
697  swap( pos, nb - 1 );
698  pop_back();
699  }
700  }

◆ reserve()

template<typename T >
void Dtk_tab< T >::reserve ( Dtk_Size_t  n)
800  {
801  if (n<=rsv)
802  return;
803  if (v==NULL)
804  {
805  Pdtk_Assert(rsv==0);
806  v = new T[n];
807  rsv = n;
808  return;
809  }
810  rsv = n;
811  delete [] _dtk_doublerealloc(rsv);
812  }

◆ resize() [1/2]

template<typename T >
void Dtk_tab< T >::resize ( Dtk_Size_t  n)
629  {
630  if (n<=nb)
631  {
632  nb=n;
633  return;
634  }
635  if (n<=0)
636  {
637  clear();
638  return;
639  }
640  if (n<rsv) // cas ou n>nb && n<rsv
641  {
642  nb = n;
643  return;
644  }
645  if (v==NULL)
646  {
647  Pdtk_Assert(rsv==0);
648  v = new T[n];
649  }
650  else
651  delete [] _dtk_doublerealloc(n);
652 
653  nb=rsv=n;
654  }

◆ resize() [2/2]

template<typename T >
void Dtk_tab< T >::resize ( Dtk_Size_t  n,
const T &  t 
)

Resizes the array.

Parameters
[in]nThe new size.
[in]tThe filling element.
Remarks
If the new size is lower than the old one, the last elements are removed.
If the new size is greater than the old one, inserts t in the new elements.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
tab.resize(2); //Now tab is {0,2}
tab.resize(5,6); //Now tab is {0,2,6,6,6}
606  {
607  if (n<=nb)
608  {
609  nb=n;
610  return;
611  }
612  if (n<=0)
613  {
614  clear();
615  return;
616  }
617  if (v==NULL)
618  {
619  Pdtk_Assert(rsv==0 && n>0);
620  v = new T[n];
621  }
622  else
623  delete [] _dtk_doublerealloc(n);
624  for(Dtk_Size_t i=nb;i<n;i++)
625  v[i]=t;
626  nb=rsv=n;
627  }

◆ reverse()

template<typename T >
void Dtk_tab< T >::reverse ( )
887 {Dtk_Size_t i;for(i=0;i<nb/2;i++) Dtk_swap(v[i],v[nb-i-1]);}

◆ size()

template<typename T >
Dtk_Size_t Dtk_tab< T >::size ( ) const

Returns the size of the array.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
int size = tab.size(); //size is equal to 3
505  {
506  return nb;
507  }

◆ sort() [1/2]

template<typename T >
void Dtk_tab< T >::sort ( )

Swap two elements.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
//tab is {0,2,1}
tab.swap(tab[0],tab[1]);
//tab is {2,0,1}
714  {
715  sort(Dtk_less<T>());
716  }

◆ sort() [2/2]

template<typename T >
template<typename comp >
void Dtk_tab< T >::sort ( const comp &  C)

Sorts the array with custom sorting.

Parameters
[in]CComparison Functor
Remarks
Comparison functor need to be instanciated with default : use (). See sample.
Use a custom functor or one of the two internal functors available : Dtk_less (default) and Dtk_greater

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
//tab is {0,2,1}
//tab is {2,1,0}
734  {
735  if(nb > 0 )
736  {
737  //_quicksort((int)0,(int)(nb-1),C);
738  T* tmp = new T[nb];
739  _mergesort(tmp,(int)0,(int)(nb-1),C);
740  delete [] tmp;
741  }
742  }

◆ subtab()

template<typename T >
Dtk_tab Dtk_tab< T >::subtab ( Dtk_Size_t  a,
Dtk_Size_t  b 
)
791  {
792  Pdtk_Assert(a<nb && b<nb && b>=a);
793  Dtk_tab<T> res;
794  res.resize(b-a+1);
795  for(Dtk_Size_t i=0;i<res.rsv;i++)
796  res.v[i] = v[a+i];
797  return res;
798  }

◆ swap()

template<typename T >
void Dtk_tab< T >::swap ( const Dtk_Size_t  inA,
const Dtk_Size_t  inB 
)

Sorts the array.

Sample:

Dtk_tab<int> tab; //we construct an array of int.
tab.push_back(0); //we insert '0'
tab.push_back(2); //we insert '2'
tab.push_back(1); //we insert '1'
//tab is {0,2,1}
tab.sort();
//tab is {0,1,2}
668  {
669 #ifdef _DEBUG_DTK
670  if ( inA >= nb || inB >= nb )
672 #endif
673  const T Tmp = v[ inA ];
674  v[ inA ] = v[ inB ];
675  v[ inB ] = Tmp;
676  }

Friends And Related Function Documentation

◆ operator<<

template<typename T >
std::ostream& operator<< ( std::ostream &  o,
const Dtk_tab< T > &  d 
)
friend
863  {
864  o<<"<Tab><Size>"<<d.size()<<"</Size>"<<std::endl;
865  Dtk_Size_t i;
866  for(i=0;i<d.size();i++)
867  {
868  o<<"<Elem_"<<i<<">"<< d[i] <<"</Elem_"<<i<<">"<<std::endl;
869  }
870  o << "</Tab>"<<std::endl;
871  return o;
872  }
Dtk_greater
Functor comparison object.
Definition: util_stl_dtk.hpp:27
Dtk_tab::capacity
Dtk_Size_t capacity() const
Returns the size of the storage space currently allocated for the array, expressed in terms of elemen...
Definition: util_stl_dtk.hpp:524
Dtk_tab::pop_back
void pop_back()
Removes the last element.
Definition: util_stl_dtk.hpp:487
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:712
Dtk_tab::sort
void sort()
Swap two elements.
Definition: util_stl_dtk.hpp:713
Dtk_less
Functor comparison object.
Definition: util_stl_dtk.hpp:41
Dtk_tab::back
T & back()
Return the elements at the end of the array.
Definition: util_stl_dtk.hpp:539
Dtk_tab::remove
void remove(const T &a)
Removes the first element with the value a.
Definition: util_stl_dtk.hpp:692
Dtk_tab::operator[]
T & operator[](Dtk_Size_t k)
Accesses the ith element - like a classic array -.
Definition: util_stl_dtk.hpp:382
Dtk_tab::find
int find(const T &e) const
Definition: util_stl_dtk.hpp:744
Pdtk_Assert
#define Pdtk_Assert(X)
Definition: define.h:742
Dtk_tab::front
T & front()
Return the elements at the beginning of the array.
Definition: util_stl_dtk.hpp:569
Dtk_tab::resize
void resize(Dtk_Size_t n, const T &t)
Resizes the array.
Definition: util_stl_dtk.hpp:605
Dtk_tab::reserve
void reserve(Dtk_Size_t n)
Definition: util_stl_dtk.hpp:799
Dtk_ThrowOverflowException
void Dtk_ThrowOverflowException()
Dtk_tab< int >
Dtk_tab::size
Dtk_Size_t size() const
Returns the size of the array.
Definition: util_stl_dtk.hpp:504
Dtk_tab::swap
void swap(const Dtk_Size_t inA, const Dtk_Size_t inB)
Sorts the array.
Definition: util_stl_dtk.hpp:667
Dtk_swap
void Dtk_swap(T &a, T &b)
Swap any type of data.
Definition: util_stl_dtk.hpp:71
Dtk_tab::push_back
void push_back(const T &x)
Inserts an element at the end of the array.
Definition: util_stl_dtk.hpp:417
Dtk_tab::clear
void clear(int no_delete=0)
Resets the Dtk_tab content.
Definition: util_stl_dtk.hpp:353