Go to the source code of this file.
Classes | |
struct | AnyType< T > |
struct | AnyTypeBase |
struct | EvalTypeIf< bool, ZeroClass, OneClass > |
Define a member typedef that is either ZeroClass or OneClass based on the value of the bool. Note that effect is accomplished using specialization, not here in this base class. see below. More... | |
struct | EvalTypeIf< 0, ZeroClass, OneClass > |
struct | EvalTypeIf< 1, ZeroClass, OneClass > |
struct | IteratorReferent< Container > |
Given a container as a template parameter, determine the return data type of its "iterator" -- particularly the constness thereof. Define a nested member typedef, type, which maps to the return value type of. More... | |
struct | IteratorReferent< const Container[N]> |
struct | IteratorReferent< Container[N]> |
struct | iteratorReturnsConst< Container > |
Define a nested constant, value, which is true if the specified Container type has an iterator which returns a const version of Container::value_type. Set for example has no non-const iterator. If std::set is the Container passed in then the value will be true. It will be false for most normal containers. More... | |
struct | IteratorWrapper< T > |
struct | IteratorWrapper< T * > |
A wrapper around a pointer, which is an iterator to a normal C++ array. More... | |
Namespaces | |
namespace | cxxtls |
The namespace that encapsulates most of the functionality in the CXX toolkit. | |
namespace | cxxtls::foreach_helpers |
Defines | |
#define | CXXTLS_FENS(n) cxxtls::foreach_helpers::n |
Puts the appropriate namespace on the specified symbol name. | |
#define | CXXTLS_FEV(n) cxxtls_foreach_var_##n |
Puts the appropriate namespace on the specified variable name. | |
#define | CXXTLS_FOREACH(loopVar, bag) |
CXXTLS_FOREACH implements a generic "foreach" feature in the c++ language. The ideas in its design are stolen right out of boost. They did good on this! | |
#define | CXXTLS_NULL_TYPE_PTR(bag) (true?0 : &bag) |
CXXTLS_NULL_TYPE_PTR(expression) returns a 0 which is cast to be pointer to whatever the type of the expression is. For example: | |
Typedefs | |
typedef unsigned long long | size_t |
Functions | |
template<class T , size_t N> | |
bool | continuing (AnyTypeBase const ¤t, AnyTypeBase const &last, T const (*)[N]) |
Given foreach loop variables, "current" and "last", return true if current is not equal to last. | |
template<class Container > | |
bool | continuing (AnyTypeBase const ¤t, AnyTypeBase const &last, Container const *) |
Given foreach loop variables, "current" and "last", return true if current is not equal to last. | |
template<class T , size_t N> | |
T & | deref (AnyTypeBase const ¤t, T(*)[N]) |
Given a reference to an iterator into the specified mutable C++ container, return a reference to the object it refers to. | |
template<class T , size_t N> | |
T const & | deref (AnyTypeBase const ¤t, T const (*)[N]) |
Given a reference to an iterator into the specified const C++ array, return a reference to the object it refers to. | |
template<class Container > | |
const Container::value_type & | deref (AnyTypeBase const ¤t, Container const *) |
Given a reference to an iterator into the specified "const" container, return a reference to the object it refers to. | |
template<class Container > | |
IteratorReferent< Container > ::type & | deref (AnyTypeBase const ¤t, Container *) |
Given a reference to an iterator into the specified container, return a reference to the object it refers to. | |
template<class T , size_t N> | |
AnyType< IteratorWrapper< T * > > | getBegin (AnyTypeBase const &b, T const (*)[N]) |
Given a reference to a C++ array, return an AnyType<> object that is a wrapper for a pointer to the first object in the container. The wrapper's sole purpose is to make the contents accessible as an AnyType object. | |
template<class T > | |
AnyType< IteratorWrapper< T > > | getBegin (AnyTypeBase const &b, T const *) |
Given a reference to an STL container, return an AnyType<> object that is a wrapper for an iterator to the first object in the container. The wrapper's sole purpose is to make the contents accessible as an AnyType object. | |
template<class T , size_t N> | |
AnyType< T const * > | getContainer (T const (&v)[N]) |
Given a reference to a C++ array, return an AnyType<> object that is a reference to said container. | |
template<class T > | |
AnyType< T & > | getContainer (T const &v) |
Given a reference to an STL container, return an AnyType<> object that is a reference to said container. | |
template<class T , size_t N> | |
AnyType< IteratorWrapper< T * > > | getEnd (AnyTypeBase const &b, T const (*)[N]) |
Given a reference to a C++ array, return an AnyType<> object that is a wrapper for an iterator to the "end" object in the container. The wrapper's sole purpose is to make the contents accessible as an AnyType object. | |
template<class T > | |
AnyType< IteratorWrapper< T > > | getEnd (AnyTypeBase const &b, T const *) |
Given a reference to an STL container, return an AnyType<> object that is a wrapper for an iterator to the "end" object in the container. The wrapper's sole purpose is to make the contents accessible as an AnyType object. | |
template<class T , size_t N> | |
bool | next (AnyTypeBase const ¤t, AnyTypeBase const &last, T const (*)[N]) |
Given foreach loop variables, "current" and "last", if current is not equal to last, increment it. | |
template<class Container > | |
bool | next (AnyTypeBase const ¤t, AnyTypeBase const &last, Container const *) |
Given foreach loop variables, "current" and "last", if current is not equal to last, increment it. |
#define CXXTLS_FENS | ( | n | ) | cxxtls::foreach_helpers::n |
#define CXXTLS_FEV | ( | n | ) | cxxtls_foreach_var_##n |
#define CXXTLS_FOREACH | ( | loopVar, | |||
bag | ) |
if( CXXTLS_FENS(AnyTypeBase) const & CXXTLS_FEV(cnt) = \ CXXTLS_FENS(getContainer)(bag) ) {} else \ if( CXXTLS_FENS(AnyTypeBase) const & CXXTLS_FEV(cur) = \ CXXTLS_FENS(getBegin)(CXXTLS_FEV(cnt), CXXTLS_NULL_TYPE_PTR(bag))) {} else \ if( CXXTLS_FENS(AnyTypeBase) const & CXXTLS_FEV(end) = \ CXXTLS_FENS(getEnd)(CXXTLS_FEV(cnt), CXXTLS_NULL_TYPE_PTR(bag))) {} else \ for( bool fcCnTiNuE=true; \ fcCnTiNuE && CXXTLS_FENS(continuing)(CXXTLS_FEV(cur), CXXTLS_FEV(end), CXXTLS_NULL_TYPE_PTR(bag)); \ (fcCnTiNuE? CXXTLS_FENS(next)(CXXTLS_FEV(cur), CXXTLS_FEV(end), CXXTLS_NULL_TYPE_PTR(bag)) : 0 ) \ ) \ if((fcCnTiNuE=false)) {} else \ for( loopVar = CXXTLS_FENS(deref)( CXXTLS_FEV(cur), CXXTLS_NULL_TYPE_PTR(bag)); \ !fcCnTiNuE; \ fcCnTiNuE=true \ )
CXXTLS_FOREACH implements a generic "foreach" feature in the c++ language. The ideas in its design are stolen right out of boost. They did good on this!
The macro lets you iterate over arrays and stl containers like this:
CXXTLS_FOREACH(int x, someVectorOfInt) cout << "i is " << x << endl;
When using an stl container, you must must declare a proper loop variable. The loop variable to iterate over a map must be reference or variable of type map::value_type.
WARNING: At the time of this writing, "break;" doesn't workin a CXXTLS_FOREACH() loop. It doesn't cause an error, it just doesn't break! I need to tinker with the macro to make that work...
#define CXXTLS_NULL_TYPE_PTR | ( | bag | ) | (true?0 : &bag) |
CXXTLS_NULL_TYPE_PTR(expression) returns a 0 which is cast to be pointer to whatever the type of the expression is. For example:
int a;
int *aptr = CXXTLS_NULL_TYPE_PTR(a);
Will compile succcessfully and aptr will be zero.