template<typename _Container, typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
class CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >
A Counter allows looping over many incrementing variables in one loop.
- Template Parameters
-
Container | The type of container containing the variables begin looped over. Container should be fully specified, so 'std::vector<int>', not 'std::vector'. |
value_type | The type of variable contained by the Container. Must have valid operators '+=' and '+'. |
size_type | The type of the index into the Container. |
Access | A Functor or function with signature 'value_type& Access::operator()(Container &, size_type);', which provides a reference to a element of the Container. |
Compare | A Functor or function with signature 'bool Compare::operator()(const value_type& A, const value_type& B);', which provides a less than comparison, like 'operator<'. |
Default container access using the CASM_TMP::BracketAccess functor is identical to 'container[index]'. Parentheses access, like 'container(index)', can be obtained by setting the Access parameter using the CASM_TMP::ParenthesesAccess functor.
Default value_type comparison is as 'value_type < value_type'. Custom comparison can be provided using the Compare functor.
Several typedefs are provided:
The first element of the container is the inner loop, and the last element of the container is the outer loop.
Example:
std::vector<int>
final(
size, 1);
do {
for( int i=0; i<counter.size(); i++) {
std::cout << counter()[i] << " ";
}
std::cout << std::endl;
} while(counter++);
const Container & increment() const
const Container & initial() const
Output:
0 0 0
1 0 0
0 1 0
1 1 0
0 0 1
1 0 1
0 1 1
1 1 1
Definition at line 107 of file Counter.hh.
template<typename _Container , typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
typedef _Access CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::Access |
template<typename _Container , typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
template<typename _Container , typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
template<typename _Container , typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
template<typename _Container , typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
template<typename _Container , typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
template<typename _Container , typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
template<typename _Container , typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
Construct a Counter-type object.
- Parameters
-
_initial | the initial Container values |
_final | the final valid Container values |
_increment | the amount to increment each Container value by |
Definition at line 143 of file Counter.hh.
template<typename _Container , typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
bool CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::_compute_validity |
( |
| ) |
|
|
inlineprivate |
template<typename _Container , typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
void CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::_init |
( |
| ) |
|
|
inlineprivate |
Called from the constructor to set m_lower and m_upper appropriately.
Definition at line 192 of file Counter.hh.
template<typename _Container , typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
template<typename _Container , typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
void CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::operator++ |
( |
int |
| ) |
|
|
inline |
template<typename _Container , typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
void CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::reset |
( |
| ) |
|
|
inline |
Reset the current value of the Counter to the initial value.
Definition at line 184 of file Counter.hh.
template<typename _Container , typename _value_type = typename _Container::value_type, typename _size_type = typename _Container::size_type, typename _Access = CASM_TMP::BracketAccess<_Container, _value_type, _size_type>, typename _Compare = CASM_TMP::MuchLessThan<_value_type>>
void CASM::Counter< _Container, _value_type, _size_type, _Access, _Compare >::set_current |
( |
const Container & |
new_current | ) |
|
|
inline |