Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class generator

#include <boost/coroutine/generator.hpp>

template<
    typename Result,
    typename Allocator = ctx::stack_allocator
>
class generator
{
public:
    class self_t
    {
    public:
        void yield( R);

        void yield_break();
    };

    generator();

    template< typename Fn >
    generator( Fn fn,
               std::size_t size = ctx::default_stacksize(),
               flag_unwind_t do_unwind = stack_unwind,
               bool preserve_fpu = true,
               Allocator alloc = Allocator() );

    template< typename Fn >
    generator( Fn && fn,
               std::size_t size = ctx::default_stacksize(),
               flag_unwind_t do_unwind = stack_unwind,
               bool preserve_fpu = true,
               Allocator alloc = Allocator() );

    generator( generator && other);

    generator & operator=( generator && other);

    operator unspecified-bool-type() const;

    bool operator!() const;

    void swap( generator & other);

    Result operator()();
};

void swap( generator & l, generator & r);
generator()

Effects:

Creates a generator representing a not-a-generator.

Throws:

Nothing.

template< typename Fn > generator( Fn fn, std::size_t size, flag_unwind_t do_unwind, bool preserve_fpu, Allocator alloc)

Preconditions:

size > ctx::minimum_stacksize(), size < ctx::maximum_stacksize() when ! ctx::is_stack_unbound().

Effects:

Creates a generator which will execute fn. If do_unwind is stack_unwind the destructor of *this unwinds the stack before destructing it. If preserve_fpu is true the floating-point registers are preserved between context switches.

Throws:

invalid_argument if a precondition is not satisfied.

generator( generator && other)

Effects:

Moves the internal data of other to *this. other becomes not-a-generator.

Throws:

Nothing.

generator & operator=( generator && other)

Effects:

Destroys the internal data of *this and moves the internal data of other to *this. other becomes not-a-generator.

Throws:

Nothing.

operator unspecified-bool-type() const

Returns:

If *this refers to not-a-generator, the function returns false. Otherwise true.

Throws:

Nothing.

bool operator!() const

Returns:

If *this refers not to not-a-generator, the function returns true. Otherwise false.

Throws:

Nothing.

void swap( generator & other)

Effects:

Swaps the internal data from *this with the values of other.

Throws:

Nothing.

Result operator()()

Preconditions:

*this is not a not-a-generator, ! is_complete().

Effects:

The return value is the argument passed to generator<>::self_t::yield().

Throws:

Re-throws exceptions exceptions thrown inside generator-function.

void self_t::yield( Result)

Effects:

Gives execution control back to calling context by returning a value of type Result. The return type of this function is a boost::tuple<> containing the arguments passed to generator<>::operator()().

Throws:

Nothing.

void self_t::yield_break()

Effects:

Gives execution control back to calling context and sets the generator to be complete. generator<>::operator()() in the other generator throws exception coroutine_terminated.

Postconditions:

*this is complete, which is operator unspecified-bool-type() returns false.

Non-member function swap()
void swap( generator & l, generator & r);

Effects:

As if 'l.swap( r)'.


PrevUpHomeNext