tgen
Loading...
Searching...
No Matches

List value. More...

Inheritance diagram for tgen::list< T >::value:

Public Member Functions

 value (const std::vector< T > &vec)
 Creates a list value from a std::vector.
int size () const
 Returns the size of the list value.
T & operator[] (int idx)
 Accesses the value at some position of the value.
valuesort ()
 Sorts the value in non-decreasing order.
valuereverse ()
 Reverses the value.
valueseparator (char sep)
 Sets separator for printing.
value operator+ (const value &rhs)
 Concatenates two values.
auto to_std () const
 Converts the value to a std::vector.
Public Member Functions inherited from tgen::gen_value_base< value >
bool operator< (const value &rhs) const

Friends

std::ostream & operator<< (std::ostream &out, const value &inst)
 Prints the value to a std::ostream.

Detailed Description

template<typename T>
struct tgen::list< T >::value

List value.

It can be deterministically operated upon (see Generator Value Operations for random operations) and printed through std::cout.

Definition at line 1320 of file tgen.h.

Constructor & Destructor Documentation

◆ value()

template<typename T>
tgen::list< T >::value::value ( const std::vector< T > & vec)
inline

Creates a list value from a std::vector.

Parameters
vecThe std::vector representing the value.

Examples

// Creates and prints a value from a std::vector.
std::vector<int> v = {1, 2, 3};
std::cout << inst << std::endl; // Prints "1 2 3".
// Also works with std::initializer_list<T>.
inst = {5, 4};
std::cout << inst << std::endl; // Prints "5 4".
List value.
Definition tgen.h:1320

Definition at line 1329 of file tgen.h.

Member Function Documentation

◆ operator+()

template<typename T>
value tgen::list< T >::value::operator+ ( const value & rhs)
inline

Concatenates two values.

Parameters
rhsThe right-hand side.
Returns
The concatenation.

Complexity

Linear.

Examples

// Concatenates and prints two values.
std::cout << s.gen() + s.gen() << std::endl;
List generator.
Definition tgen.h:1190
list & all_different()
Restricts generator s.t. all values are different.
Definition tgen.h:1312
value gen() const
Generates a random value from the set of valid lists.
Definition tgen.h:1452

Definition at line 1370 of file tgen.h.

◆ operator[]()

template<typename T>
T & tgen::list< T >::value::operator[] ( int idx)
inline

Accesses the value at some position of the value.

Parameters
idxIndex to be accessed.
Returns
The value at index idx.

Examples

// Changes and prints a position of a value.
tgen::list<int>::value inst = {1, 2, 3};
++inst[1];
std::cout << inst[1] << std::endl; // Prints "3".

Definition at line 1336 of file tgen.h.

◆ reverse()

template<typename T>
value & tgen::list< T >::value::reverse ( )
inline

Reverses the value.

Complexity

O(n).

Examples

// Reverses and prints a value.
tgen::list<int>::value inst = {3, 1, 2};
std::cout << inst.reverse() << std::endl; // Prints "2 1 3".
value & reverse()
Reverses the value.
Definition tgen.h:1356

Definition at line 1356 of file tgen.h.

◆ separator()

template<typename T>
value & tgen::list< T >::value::separator ( char sep)
inline

Sets separator for printing.

Complexity

O(1).

Examples

// Prints a value, separated by commas.
tgen::list<int>::value inst = {3, 1, 2};
std::cout << inst.separator(',') << std::endl; // Prints "3,1,2".
value & separator(char sep)
Sets separator for printing.
Definition tgen.h:1363

Definition at line 1363 of file tgen.h.

◆ size()

template<typename T>
int tgen::list< T >::value::size ( ) const
inline

Returns the size of the list value.

Returns
The size (number of elements) of the list value.

Examples

// Prints the size of a value.
tgen::list<int>::value inst = {1, 2, 3};
std::cout << inst.size() << std::endl; // Prints "3".
int size() const
Returns the size of the list value.
Definition tgen.h:1333

Definition at line 1333 of file tgen.h.

◆ sort()

template<typename T>
value & tgen::list< T >::value::sort ( )
inline

Sorts the value in non-decreasing order.

Complexity

O(n log n).

Examples

// Sorts and prints a value.
tgen::list<int>::value inst = {3, 1, 2};
std::cout << inst.sort() << std::endl; // Prints "1 2 3".
value & sort()
Sorts the value in non-decreasing order.
Definition tgen.h:1349

Definition at line 1349 of file tgen.h.

◆ to_std()

template<typename T>
auto tgen::list< T >::value::to_std ( ) const
inline

Converts the value to a std::vector.

Returns
A std::vector representing the value.

Examples

// Convoluted way to reverse a vector.
std::vector<int> v = {3, 1, 2};
// v = {2, 1, 3}.
auto to_std() const
Converts the value to a std::vector.
Definition tgen.h:1388

Definition at line 1388 of file tgen.h.

◆ operator<<

template<typename T>
std::ostream & operator<< ( std::ostream & out,
const value & inst )
friend

Prints the value to a std::ostream.

The values are printed with one space as a separator by default, and with no end of line.

Examples

// Prints a value.
std::cout << tgen::list<int>::value({3, 1, 2}) << std::endl; // Prints "3 1 2".

Definition at line 1378 of file tgen.h.


The documentation for this struct was generated from the following files:
  • /home/runner/work/tgen/tgen/single_include/tgen.h
  • list.dox