Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Exceptions

Exceptions are used when there is a danger of a runaway or illegal operations on an empty list.

The key example is to take the length of a non-terminating list, e.g.

length(enum_from(1))

This is protected using an exception:

lazy_exception

Note that this is implemented such that defining

BOOST_PHOENIX_NO_LAZY_EXCEPTIONS

will enable the user to turn off the exceptions at their own risk.

BOOST_PHOENIX_FUNCTION_MAX_LAZY_LIST_LENGTH

is currently defined as 1000 and again the user can define their own value.

In the length function this how it is implemented:

        struct Length {
          template <typename Sig> struct result;

          template <typename This, typename L>
          struct result<This(L)>
          {
             typedef size_t type;
          };

          template <class L>
          size_t operator()( const L& ll ) const {
            typename L::delay_result_type l = delay(ll);
            size_t x = 0;
            while( !null(l)() ) {
                l = tail(l);
                ++x;
                if (x > BOOST_PHOENIX_FUNCTION_MAX_LAZY_LIST_LENGTH)
                   break;
            }
#ifndef BOOST_PHOENIX_NO_LAZY_EXCEPTIONS
            if (x > BOOST_PHOENIX_FUNCTION_MAX_LAZY_LIST_LENGTH)
                 throw lazy_exception("Your list is too long!!");
#endif
            return x;
          }
        };

PrevUpHomeNext