/////////////////////////////////////////////////////////////////////////////// // width_of.hpp // // Copyright 2004 Eric Niebler. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_WIDTH_OF_HPP_EAN_10_04_2005 #define BOOST_XPRESSIVE_DETAIL_STATIC_WIDTH_OF_HPP_EAN_10_04_2005 // MS compatible compilers support #pragma once #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace xpressive { namespace detail { /////////////////////////////////////////////////////////////////////////////// // add_width template struct add_width : mpl::eval_if < mpl::or_ < mpl::equal_to , mpl::equal_to > , mpl::identity , mpl::plus >::type { }; /////////////////////////////////////////////////////////////////////////////// // mult_width template struct mult_width : mpl::eval_if < mpl::or_ < mpl::equal_to , mpl::equal_to > , mpl::identity , mpl::times >::type { }; /////////////////////////////////////////////////////////////////////////////// // equal_width template struct equal_width : mpl::if_ < mpl::equal_to , X , unknown_width >::type { }; /////////////////////////////////////////////////////////////////////////////// // width_of // template struct width_of; template<> struct width_of : mpl::size_t<0> { }; template struct width_of > : as_matcher_type::type::width { }; template struct width_of > : add_width, width_of > { }; template struct width_of > : equal_width, width_of > { }; template struct width_of > : width_of { }; template struct width_of > : mpl::size_t<1> { }; template struct width_of > : width_of { }; template struct width_of > > : mpl::size_t<0> { }; template struct width_of > > : mpl::size_t<0> { }; template struct width_of > : width_of { }; template struct width_of > : add_width > { }; template struct width_of const> > : unknown_width { }; template struct width_of const> > > : unknown_width { }; template struct width_of, proto::noop_tag> > : unknown_width { }; template struct width_of const>, proto::noop_tag> > : unknown_width { }; template struct width_of > : unknown_width { }; template struct width_of > : unknown_width { }; template struct width_of > : unknown_width { }; template struct width_of > > : mpl::if_c, mpl::size_t >, unknown_width>::type { }; template struct width_of > : width_of { }; // when complementing a set or an assertion, the width is that of the set (1) or the assertion (0) template struct width_of > : width_of { }; // The comma is used in list-initialized sets, and the width of sets are 1 template struct width_of > : mpl::size_t<1> { }; // The subscript operator[] is used for sets, as in set['a' | range('b','h')], // or for actions as in (any >> expr)[ action ] template struct width_of > : mpl::if_, mpl::size_t<1>, width_of >::type { // If Left is "set" then make sure that Right has a width_of 1 BOOST_MPL_ASSERT (( mpl::or_ < mpl::not_ > , mpl::equal_to, mpl::size_t<1> > > )); }; // The width of a list of alternates is N if all the alternates have width N, otherwise unknown_width template struct alt_width_of : mpl::fold < Widths , typename mpl::front::type , equal_width >::type { }; template struct width_of > : alt_width_of > > { }; template struct width_of > : width_of { }; }}} // namespace boost::xpressive::detail #endif