pstade

PrevUpHomeNext

Extending Boost.Range

Concept-like extension
ATL extension
MFC extension
WTL extension

Pending section...

Description

Oven emulates a Concept-like extension way for Boost.Range.

Header
  • <pstade/oven/extension.hpp>
Notation
  • X is a type extending Boost.Range.
  • x is an object of (possibly const-qualified) X.
  • ER is ::pstade_oven_extension::Range<X>.
  • XS is a Boost.Preprocessor Sequence of typename X.
  • N is the number of template arguments of X, only valid if all template arguments are typenames.
  • S is a sequence of template arguments of X.
Effects
  • X becomes a model of Range.
Preconditions
  • ER::associate<X>::mutable_iterator is the mutable iterator type of X.
  • ER::associate<X>::constant_iterator is the constant iterator type of X.
  • ER::begin<_iter_of<typeof(x)>::type>(x) is a valid expression which returns the begin iterator.
  • ER::end<_iter_of<typeof(x)>::type>(x) is a valid expression which returns the end iterator.
  • If X is a type, PSTADE_OVEN_EXTENSION_OF_TYPE(X) is placed in the global namespace.
  • If X is a template, PSTADE_OVEN_EXTENSION_OF_TEMPLATE(XS, N) or PSTADE_OVEN_EXTENSION_OF_TEMPLATE(XS, S) is placed in the global namespace.
Example
namespace Foo {

    template< class T >
    struct Pair
    {
        T first, last;
    };

} // namespace Foo

namespace pstade_oven_extension {

    template< class T >
    struct Range< Foo::Pair<T> >
    {
        // X == Foo::Pair<T>
        template< class X >
        struct associate
        {
            typedef T mutable_iterator;
            typedef T constant_iterator;
        };

        // if X is not const, Iterator == mutable_iterator;
        // otherwise, Iterator == constant_iterator.
        template< class Iterator, class X >
        Iterator begin(X& x)
        {
            return x.first;
        }

        template< class Iterator, class X >
        Iterator end(X& x)
        {
            return x.last;
        }
    };

} // namespace pstade_oven_extension

PSTADE_OVEN_EXTENSION_OF_TEMPLATE((Foo)(Pair), (class))
// PSTADE_OVEN_EXTENSION_OF_TEMPLATE((Foo)(Pair), 1) // also ok.
See also
Header
  • <pstade/oven/atl.hpp>
See
Header
  • <pstade/oven/mfc.hpp>
See
Header
  • <pstade/oven/wtl.hpp>
Copyright 2005 -2007 Shunsuke Sogame

PrevUpHomeNext