Jpp 21.0.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JTOOLS::JArray< N, T > Struct Template Reference

Wrapper data structure around std::array. More...

#include <JArray.hh>

Inheritance diagram for JTOOLS::JArray< N, T >:
std::array< T, N > JMATH::JMath< JFirst_t, JSecond_t > JLANG::JEquals< JFirst_t, JSecond_t >

Public Types

typedef std::array< T, N > array_type
 
typedef JClass< T >::argument_type argument_type
 
typedef std::conditional< std::is_const< T >::value, typenamestd::remove_const< T >::type, typenamestd::add_const< T >::type >::type U
 

Public Member Functions

 JArray ()
 Default constructor.
 
template<unsigned int M>
 JArray (const JArray< M, T > &array)
 Copy constructor.
 
template<unsigned int M>
 JArray (const JArray< M, U > &array)
 Copy constructor.
 
template<class ... Args>
 JArray (argument_type value, const Args &...args)
 Assemble constructor.
 
 JArray (const T *p)
 Multi-copy constructor.
 
template<size_t M>
 JArray (const std::array< T, M > &first, const std::array< T, N-M > &second)
 Combine constructor.
 
template<size_t M, class ... Args>
 JArray (const std::array< T, M > &array, argument_type value, const Args &...args)
 Copy and assemble constructor.
 
template<size_t M, class ... Args>
 JArray (const std::array< U, M > &array, argument_type value, const Args &...args)
 Copy and assemble constructor.
 
 JArray (const JMultiKey< N, T > &key)
 Convert constructor.
 
 JArray (const JMultiKey< N, U > &key)
 Convert constructor.
 
template<unsigned int M>
 JArray (const JMultiKey< M, T > &key, const std::array< std::remove_const_t< T >, N-M > &array)
 Convert and combine constructor.
 
template<unsigned int M>
 JArray (const JMultiKey< M, U > &key, const std::array< std::remove_const_t< T >, N-M > &array)
 Convert and combine constructor.
 
template<unsigned int M, class ... Args>
 JArray (const JMultiKey< M, T > &key, argument_type value, const Args &...args)
 Convert and assemble constructor.
 
template<unsigned int M, class ... Args>
 JArray (const JMultiKey< M, U > &key, argument_type value, const Args &...args)
 Convert and assemble constructor.
 
JArray< N-1, T > pop_front () const
 Make a copy in which the first element is removed.
 
JArray< N-1, T > pop_back () const
 Make a copy in which the last element is removed.
 
JArray< N+1, T > push_back (argument_type value) const
 Make a copy and push back value.
 
JArraynegate ()
 Negate array.
 
JArrayadd (const JArray &array)
 Add array.
 
JArraysub (const JArray &array)
 Subtract array.
 
JArraymul (const double factor)
 Scale array.
 
JArraydiv (const double factor)
 Scale array.
 
bool equals (const JArray< N, T > &array) const
 Check equality.
 
JFirst_t & mul (const JSecond_t &object)
 Multiply with object.
 

Protected Member Functions

template<size_t ... i>
JArray< sizeof...(i), T > pop_back (const std::index_sequence< i... > &ls) const
 Auxiliary method to pop back array.
 
template<size_t ... i>
JArray< N-1, T > pop_front (const std::index_sequence< i... > &ls) const
 Auxiliary method to pop front array.
 
template<size_t ... i>
JArray< N+1, T > push_back (argument_type value, const std::index_sequence< i... > &ls) const
 Push back array.
 

Static Protected Member Functions

template<size_t M, size_t ... i>
static std::array< T, N > match (const std::array< T, M > &array, const std::index_sequence< i... > &ls)
 Auxiliary method to match array.
 
template<size_t M>
static std::array< T, N > match (const std::array< T, M > &array)
 Match array.
 
template<size_t ... i>
static std::array< T, sizeof...(i)> convert (const std::array< U, sizeof...(i)> &array, const std::index_sequence< i... > &ls)
 Auxiliary method to convert array.
 
template<size_t M>
static std::array< T, M > convert (const std::array< U, M > &array)
 Convert array.
 
template<size_t ... iv, size_t ... iw>
static std::array< T, N > combine (const std::array< T, sizeof...(iv)> &v, const std::index_sequence< iv... > &lv, const std::array< T, sizeof...(iw)> &w, const std::index_sequence< iw... > &lw)
 Auxiliary method combine arrays.
 
template<size_t M>
static std::array< T, N > combine (const std::array< T, M > &first, const std::array< T, N-M > &second)
 Combine two arrays.
 
template<class ... Args>
static JArray< N-1, T > pop_front (argument_type value, const Args &...args)
 Auxiliary method to pop front array.
 

Friends

std::istream & operator>> (std::istream &in, JArray &array)
 Read array from input stream.
 
std::ostream & operator<< (std::ostream &out, const JArray &array)
 Write array to output stream.
 
JReaderoperator>> (JReader &in, JArray &buffer)
 Read array from input.
 
JWriteroperator<< (JWriter &out, const JArray &buffer)
 Write array to output.
 

Detailed Description

template<unsigned int N, class T>
struct JTOOLS::JArray< N, T >

Wrapper data structure around std::array.

Definition at line 39 of file JArray.hh.

Member Typedef Documentation

◆ array_type

template<unsigned int N, class T >
std::array<T, N> JTOOLS::JArray< N, T >::array_type

Definition at line 46 of file JArray.hh.

◆ argument_type

template<unsigned int N, class T >
JClass<T>::argument_type JTOOLS::JArray< N, T >::argument_type

Definition at line 60 of file JArray.hh.

◆ U

template<unsigned int N, class T >
std::conditional<std::is_const<T>::value,typenamestd::remove_const<T>::type,typenamestd::add_const<T>::type>::type JTOOLS::JArray< N, T >::U

Definition at line 64 of file JArray.hh.

Constructor & Destructor Documentation

◆ JArray() [1/14]

template<unsigned int N, class T >
JTOOLS::JArray< N, T >::JArray ( )
inline

Default constructor.

Definition at line 70 of file JArray.hh.

70 :
72 {}

◆ JArray() [2/14]

template<unsigned int N, class T >
template<unsigned int M>
JTOOLS::JArray< N, T >::JArray ( const JArray< M, T > & array)
inline

Copy constructor.

Parameters
arrayarray

Definition at line 81 of file JArray.hh.

81 :
83 {}
static std::array< T, N > match(const std::array< T, M > &array, const std::index_sequence< i... > &ls)
Auxiliary method to match array.
Definition JArray.hh:437

◆ JArray() [3/14]

template<unsigned int N, class T >
template<unsigned int M>
JTOOLS::JArray< N, T >::JArray ( const JArray< M, U > & array)
inline

Copy constructor.

Parameters
arrayarray

Definition at line 92 of file JArray.hh.

92 :
94 {}
static std::array< T, sizeof...(i)> convert(const std::array< U, sizeof...(i)> &array, const std::index_sequence< i... > &ls)
Auxiliary method to convert array.
Definition JArray.hh:464

◆ JArray() [4/14]

template<unsigned int N, class T >
template<class ... Args>
JTOOLS::JArray< N, T >::JArray ( argument_type value,
const Args &... args )
inline

Assemble constructor.

Parameters
valuevalue
argsargument list

Definition at line 104 of file JArray.hh.

104 :
105 std::array<T, N>({value, args...})
106 {}

◆ JArray() [5/14]

template<unsigned int N, class T >
JTOOLS::JArray< N, T >::JArray ( const T * p)
inline

Multi-copy constructor.

Parameters
ppointer to data

Definition at line 114 of file JArray.hh.

115 {
116 std::copy_n(p, N, this->data());
117 }

◆ JArray() [6/14]

template<unsigned int N, class T >
template<size_t M>
JTOOLS::JArray< N, T >::JArray ( const std::array< T, M > & first,
const std::array< T, N-M > & second )
inline

Combine constructor.

Parameters
firstfirst array
secondsecond array

Definition at line 127 of file JArray.hh.

127 :
128 std::array<T, N>(combine(first, second))
129 {}
static std::array< T, N > combine(const std::array< T, sizeof...(iv)> &v, const std::index_sequence< iv... > &lv, const std::array< T, sizeof...(iw)> &w, const std::index_sequence< iw... > &lw)
Auxiliary method combine arrays.
Definition JArray.hh:492

◆ JArray() [7/14]

template<unsigned int N, class T >
template<size_t M, class ... Args>
JTOOLS::JArray< N, T >::JArray ( const std::array< T, M > & array,
argument_type value,
const Args &... args )
inline

Copy and assemble constructor.

Parameters
arrayarray
valuevalue
argsargument list

Definition at line 140 of file JArray.hh.

140 :
141 JArray(array, std::array<T, N-M>({value, args...}))
142 {}
JArray()
Default constructor.
Definition JArray.hh:70

◆ JArray() [8/14]

template<unsigned int N, class T >
template<size_t M, class ... Args>
JTOOLS::JArray< N, T >::JArray ( const std::array< U, M > & array,
argument_type value,
const Args &... args )
inline

Copy and assemble constructor.

Parameters
arrayarray
valuevalue
argsargument list

Definition at line 153 of file JArray.hh.

153 :
154 JArray(convert(array), std::array<T, N-M>({value, args...}))
155 {}

◆ JArray() [9/14]

template<unsigned int N, class T >
JTOOLS::JArray< N, T >::JArray ( const JMultiKey< N, T > & key)
inline

Convert constructor.

Parameters
keykey

Definition at line 163 of file JArray.hh.

163 :
165 {}

◆ JArray() [10/14]

template<unsigned int N, class T >
JTOOLS::JArray< N, T >::JArray ( const JMultiKey< N, U > & key)
inline

Convert constructor.

Parameters
keykey

Definition at line 173 of file JArray.hh.

173 :
175 {}

◆ JArray() [11/14]

template<unsigned int N, class T >
template<unsigned int M>
JTOOLS::JArray< N, T >::JArray ( const JMultiKey< M, T > & key,
const std::array< std::remove_const_t< T >, N-M > & array )
inline

Convert and combine constructor.

Parameters
keykey
arrayarray

Definition at line 185 of file JArray.hh.

185 :
186 JArray((std::array<T, M>) key, array)
187 {}

◆ JArray() [12/14]

template<unsigned int N, class T >
template<unsigned int M>
JTOOLS::JArray< N, T >::JArray ( const JMultiKey< M, U > & key,
const std::array< std::remove_const_t< T >, N-M > & array )
inline

Convert and combine constructor.

Parameters
keykey
arrayarray

Definition at line 197 of file JArray.hh.

197 :
198 JArray(convert((std::array<U, M>) key), array)
199 {}

◆ JArray() [13/14]

template<unsigned int N, class T >
template<unsigned int M, class ... Args>
JTOOLS::JArray< N, T >::JArray ( const JMultiKey< M, T > & key,
argument_type value,
const Args &... args )
inline

Convert and assemble constructor.

Parameters
keykey
valuevalue
argsargument list

Definition at line 210 of file JArray.hh.

210 :
211 JArray(key, std::array<T, N-M>({value, args...}))
212 {}

◆ JArray() [14/14]

template<unsigned int N, class T >
template<unsigned int M, class ... Args>
JTOOLS::JArray< N, T >::JArray ( const JMultiKey< M, U > & key,
argument_type value,
const Args &... args )
inline

Convert and assemble constructor.

Parameters
keykey
valuevalue
argsargument list

Definition at line 223 of file JArray.hh.

223 :
224 JArray(key, std::array<T, N-M>({value, args...}))
225 {}

Member Function Documentation

◆ pop_front() [1/3]

template<unsigned int N, class T >
JArray< N-1, T > JTOOLS::JArray< N, T >::pop_front ( ) const
inline

Make a copy in which the first element is removed.

Returns
array

Definition at line 233 of file JArray.hh.

234 {
235 return pop_front(std::make_index_sequence<N>{});
236 }
JArray< N-1, T > pop_front() const
Make a copy in which the first element is removed.
Definition JArray.hh:233

◆ pop_back() [1/2]

template<unsigned int N, class T >
JArray< N-1, T > JTOOLS::JArray< N, T >::pop_back ( ) const
inline

Make a copy in which the last element is removed.

Returns
array

Definition at line 244 of file JArray.hh.

245 {
246 return pop_back(std::make_index_sequence<N-1>{});
247 }
JArray< N-1, T > pop_back() const
Make a copy in which the last element is removed.
Definition JArray.hh:244

◆ push_back() [1/2]

template<unsigned int N, class T >
JArray< N+1, T > JTOOLS::JArray< N, T >::push_back ( argument_type value) const
inline

Make a copy and push back value.

Parameters
valuevalue
Returns
array

Definition at line 256 of file JArray.hh.

257 {
258 return push_back(value, std::make_index_sequence<N>{});
259 }
JArray< N+1, T > push_back(argument_type value) const
Make a copy and push back value.
Definition JArray.hh:256

◆ negate()

template<unsigned int N, class T >
JArray & JTOOLS::JArray< N, T >::negate ( )
inline

Negate array.

Returns
this array

Definition at line 267 of file JArray.hh.

268 {
269 for (int i = 0; i != N; ++i) {
270 (*this)[i] = -(*this)[i];
271 }
272
273 return *this;
274 }

◆ add()

template<unsigned int N, class T >
JArray & JTOOLS::JArray< N, T >::add ( const JArray< N, T > & array)
inline

Add array.

Parameters
arrayarray
Returns
this array

Definition at line 283 of file JArray.hh.

284 {
285 for (int i = 0; i != N; ++i) {
286 (*this)[i] += array[i];
287 }
288
289 return *this;
290 }

◆ sub()

template<unsigned int N, class T >
JArray & JTOOLS::JArray< N, T >::sub ( const JArray< N, T > & array)
inline

Subtract array.

Parameters
arrayarray
Returns
this array

Definition at line 299 of file JArray.hh.

300 {
301 for (int i = 0; i != N; ++i) {
302 (*this)[i] -= array[i];
303 }
304
305 return *this;
306 }

◆ mul() [1/2]

template<unsigned int N, class T >
JArray & JTOOLS::JArray< N, T >::mul ( const double factor)
inline

Scale array.

Parameters
factormultiplication factor
Returns
this array

Definition at line 315 of file JArray.hh.

316 {
317 for (int i = 0; i != N; ++i) {
318 (*this)[i] *= factor;
319 }
320
321 return *this;
322 }

◆ div()

template<unsigned int N, class T >
JArray & JTOOLS::JArray< N, T >::div ( const double factor)
inline

Scale array.

Parameters
factordivision factor
Returns
this array

Definition at line 331 of file JArray.hh.

332 {
333 for (int i = 0; i != N; ++i) {
334 (*this)[i] /= factor;
335 }
336
337 return *this;
338 }

◆ equals()

template<unsigned int N, class T >
bool JTOOLS::JArray< N, T >::equals ( const JArray< N, T > & array) const
inline

Check equality.

Parameters
arrayarray
Returns
true if arrays are equal; else false

Definition at line 347 of file JArray.hh.

348 {
349 for (int i = 0; i != N; ++i) {
350 if ((*this)[i] != array[i]) {
351 return false;
352 }
353 }
354
355 return true;
356 }

◆ match() [1/2]

template<unsigned int N, class T >
template<size_t M, size_t ... i>
static std::array< T, N > JTOOLS::JArray< N, T >::match ( const std::array< T, M > & array,
const std::index_sequence< i... > & ls )
inlinestaticprotected

Auxiliary method to match array.

Parameters
arrayarray
lsindices of array
Returns
array

Definition at line 437 of file JArray.hh.

438 {
439 return {array[i]...};
440 };

◆ match() [2/2]

template<unsigned int N, class T >
template<size_t M>
static std::array< T, N > JTOOLS::JArray< N, T >::match ( const std::array< T, M > & array)
inlinestaticprotected

Match array.

Parameters
arrayarray
Returns
array

Definition at line 450 of file JArray.hh.

451 {
452 return match(array, std::make_index_sequence<N>{});
453 };

◆ convert() [1/2]

template<unsigned int N, class T >
template<size_t ... i>
static std::array< T, sizeof...(i)> JTOOLS::JArray< N, T >::convert ( const std::array< U, sizeof...(i)> & array,
const std::index_sequence< i... > & ls )
inlinestaticprotected

Auxiliary method to convert array.

Parameters
arrayarray
lsindices of array
Returns
array

Definition at line 464 of file JArray.hh.

465 {
466 return {array[i]...};
467 };

◆ convert() [2/2]

template<unsigned int N, class T >
template<size_t M>
static std::array< T, M > JTOOLS::JArray< N, T >::convert ( const std::array< U, M > & array)
inlinestaticprotected

Convert array.

Parameters
arrayarray
Returns
array

Definition at line 477 of file JArray.hh.

478 {
479 return convert(array, std::make_index_sequence<M>{});
480 };

◆ combine() [1/2]

template<unsigned int N, class T >
template<size_t ... iv, size_t ... iw>
static std::array< T, N > JTOOLS::JArray< N, T >::combine ( const std::array< T, sizeof...(iv)> & v,
const std::index_sequence< iv... > & lv,
const std::array< T, sizeof...(iw)> & w,
const std::index_sequence< iw... > & lw )
inlinestaticprotected

Auxiliary method combine arrays.

Parameters
vfirst array
lvindices of first array
wsecond array
lwindices of second array

Definition at line 492 of file JArray.hh.

494 {
495 return { v[iv]..., w[iw]... };
496 };

◆ combine() [2/2]

template<unsigned int N, class T >
template<size_t M>
static std::array< T, N > JTOOLS::JArray< N, T >::combine ( const std::array< T, M > & first,
const std::array< T, N-M > & second )
inlinestaticprotected

Combine two arrays.

Parameters
firstfirst array
secondsecond array
Returns
array

Definition at line 507 of file JArray.hh.

508 {
509 return combine(first, std::make_index_sequence< M >{},
510 second, std::make_index_sequence<N-M>{});
511 }

◆ pop_back() [2/2]

template<unsigned int N, class T >
template<size_t ... i>
JArray< sizeof...(i), T > JTOOLS::JArray< N, T >::pop_back ( const std::index_sequence< i... > & ls) const
inlineprotected

Auxiliary method to pop back array.

Parameters
lsindices of array
Returns
array

Definition at line 521 of file JArray.hh.

522 {
523 return {(*this)[i]...};
524 };

◆ pop_front() [2/3]

template<unsigned int N, class T >
template<class ... Args>
static JArray< N-1, T > JTOOLS::JArray< N, T >::pop_front ( argument_type value,
const Args &... args )
inlinestaticprotected

Auxiliary method to pop front array.

Parameters
valuevalue
argsargument list
Returns
array

Definition at line 535 of file JArray.hh.

536 {
537 return {args...};
538 };

◆ pop_front() [3/3]

template<unsigned int N, class T >
template<size_t ... i>
JArray< N-1, T > JTOOLS::JArray< N, T >::pop_front ( const std::index_sequence< i... > & ls) const
inlineprotected

Auxiliary method to pop front array.

Parameters
lsindices of array
Returns
array

Definition at line 548 of file JArray.hh.

549 {
550 return pop_front((*this)[i]...);
551 };

◆ push_back() [2/2]

template<unsigned int N, class T >
template<size_t ... i>
JArray< N+1, T > JTOOLS::JArray< N, T >::push_back ( argument_type value,
const std::index_sequence< i... > & ls ) const
inlineprotected

Push back array.

Parameters
valuevalue
lsindices of array
Returns
array

Definition at line 562 of file JArray.hh.

563 {
564 return {value, (*this)[i]...};
565 };

◆ mul() [2/2]

template<class JFirst_t , class JSecond_t >
JFirst_t & JMATH::JMath< JFirst_t, JSecond_t >::mul ( const JSecond_t & object)
inlineinherited

Multiply with object.

Parameters
objectobject
Returns
result object

Definition at line 354 of file JMath.hh.

355 {
356 return static_cast<JFirst_t&>(*this) = JFirst_t().mul(static_cast<const JFirst_t&>(*this), object);
357 }

Friends And Related Symbol Documentation

◆ operator>> [1/2]

template<unsigned int N, class T >
std::istream & operator>> ( std::istream & in,
JArray< N, T > & array )
friend

Read array from input stream.

Parameters
ininput stream
arrayarray
Returns
input stream

Definition at line 366 of file JArray.hh.

367 {
368 for (iterator i = array.begin(); i != array.end(); ++i) {
369 in >> *i;
370 }
371
372 return in;
373 }

◆ operator<< [1/2]

template<unsigned int N, class T >
std::ostream & operator<< ( std::ostream & out,
const JArray< N, T > & array )
friend

Write array to output stream.

Parameters
outoutput stream
arrayarray
Returns
output stream

Definition at line 383 of file JArray.hh.

384 {
385 const JFormat format(out, getFormat<JArray>(JFormat_t(10, 3, std::ios::fixed | std::ios::showpos)));
386
387 for (const_iterator i = array.begin(); i != array.end(); ++i) {
388 out << ' ' << format << *i;
389 }
390
391 return out;
392 }
JFormat_t & getFormat()
Get format for given type.
Definition JManip.hh:682
Data structure for format specifications.
Definition JManip.hh:524
Auxiliary class to temporarily define format specifications.
Definition JManip.hh:636

◆ operator>> [2/2]

template<unsigned int N, class T >
JReader & operator>> ( JReader & in,
JArray< N, T > & buffer )
friend

Read array from input.

Parameters
inreader
bufferarray
Returns
reader

Definition at line 402 of file JArray.hh.

403 {
404 for (iterator i = buffer.begin(); i != buffer.end(); ++i) {
405 in >> *i;
406 }
407
408 return in;
409 }

◆ operator<< [2/2]

template<unsigned int N, class T >
JWriter & operator<< ( JWriter & out,
const JArray< N, T > & buffer )
friend

Write array to output.

Parameters
outwriter
bufferarray
Returns
writer

Definition at line 419 of file JArray.hh.

420 {
421 for (const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
422 out << *i;
423 }
424
425 return out;
426 }

The documentation for this struct was generated from the following file: