diff --git a/include/boost/mpl/aux_/single_element_iter.hpp b/include/boost/mpl/aux_/single_element_iter.hpp new file mode 100644 index 0000000..15cca4a --- /dev/null +++ b/include/boost/mpl/aux_/single_element_iter.hpp @@ -0,0 +1,122 @@ +//----------------------------------------------------------------------------- +// boost mpl/aux_/single_element_iter.hpp header file +// See http://www.boost.org for updates, documentation, and revision history. +//----------------------------------------------------------------------------- +// +// Copyright (c) 2000-02 +// Aleksey Gurtovoy +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appears in all copies and +// that both the copyright notice and this permission notice appear in +// supporting documentation. No representations are made about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. + +#ifndef BOOST_MPL_AUX_SINGLE_ELEMENT_ITER_HPP_INCLUDED +#define BOOST_MPL_AUX_SINGLE_ELEMENT_ITER_HPP_INCLUDED + +#include "boost/mpl/iterator_tag.hpp" +#include "boost/mpl/arithmetic/plus.hpp" +#include "boost/mpl/arithmetic/minus.hpp" +#include "boost/mpl/int_c.hpp" +#include "boost/mpl/aux_/value_wknd.hpp" +#include "boost/mpl/aux_/iterator_names.hpp" +#include "boost/mpl/aux_/lambda_spec.hpp" +#include "boost/mpl/aux_/config/ctps.hpp" + +namespace boost { namespace mpl { + +namespace aux { + +template< typename T, int N > +struct single_element_iter; + +// random access support +template< typename T, int N > +struct single_iter_base +{ + typedef ra_iter_tag_ category; + typedef int_c position; + + template< typename D > + struct BOOST_MPL_AUX_ITERATOR_ADVANCE + { + typedef plus< int_c,D > n_; + typedef single_element_iter< + T + , BOOST_MPL_AUX_VALUE_WKND(n_)::value + > type; + }; + + template< typename U > + struct BOOST_MPL_AUX_ITERATOR_DISTANCE + { + typedef typename minus< + typename U::position + , int_c + >::type type; + }; +}; + +#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) + +template< typename T > +struct single_element_iter + : single_iter_base +{ + typedef single_element_iter next; + typedef T type; +}; + +template< typename T > +struct single_element_iter + : single_iter_base +{ + typedef single_element_iter prior; +}; + +#else + +template< int N > struct single_iter_impl +{ + template< typename T > struct result_; +}; + +template<> +struct single_iter_impl<0> +{ + template< typename T > struct result_ + : single_iter_base + { + typedef single_element_iter next; + typedef T type; + }; +}; + +template<> +struct single_iter_impl<1> +{ + template< typename T > struct result_ + : single_iter_base + { + typedef single_element_iter prior; + }; +}; + +template< typename T, int N > +struct single_element_iter + : single_iter_impl::template result_ +{ +}; + +#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + +} // namespace aux + +//BOOST_MPL_AUX_PASS_THROUGH_LAMBDA_SPEC(1, aux::single_element_iter) + +}} // namespace boost::mpl + +#endif // BOOST_MPL_AUX_SINGLE_ELEMENT_ITER_HPP_INCLUDED diff --git a/include/boost/mpl/single_view.hpp b/include/boost/mpl/single_view.hpp new file mode 100644 index 0000000..58e8295 --- /dev/null +++ b/include/boost/mpl/single_view.hpp @@ -0,0 +1,43 @@ +//----------------------------------------------------------------------------- +// boost mpl/single_view.hpp header file +// See http://www.boost.org for updates, documentation, and revision history. +//----------------------------------------------------------------------------- +// +// Copyright (c) 2000-02 +// Aleksey Gurtovoy +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appears in all copies and +// that both the copyright notice and this permission notice appear in +// supporting documentation. No representations are made about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. + +#ifndef BOOST_MPL_SINGLE_VIEW_HPP_INCLUDED +#define BOOST_MPL_SINGLE_VIEW_HPP_INCLUDED + +#include "boost/mpl/aux_/single_element_iter.hpp" +#include "boost/mpl/iterator_range.hpp" +#include "boost/mpl/aux_/void_spec.hpp" + +namespace boost { +namespace mpl { + +template< + typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T) + > +struct single_view + : iterator_range< + aux::single_element_iter + , aux::single_element_iter + > +{ +}; + +BOOST_MPL_AUX_VOID_SPEC(1, single_view) + +} // namespace mpl +} // namespace boost + +#endif // BOOST_MPL_SINGLE_VIEW_HPP_INCLUDED diff --git a/test/single_view.cpp b/test/single_view.cpp new file mode 100644 index 0000000..74c9125 --- /dev/null +++ b/test/single_view.cpp @@ -0,0 +1,38 @@ +//----------------------------------------------------------------------------- +// boost mpl/test/single_view.cpp source file +// See http://www.boost.org for updates, documentation, and revision history. +//----------------------------------------------------------------------------- +// +// Copyright (c) 2001-02 +// Aleksey Gurtovoy +// +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appears in all copies and +// that both the copyright notice and this permission notice appear in +// supporting documentation. No representations are made about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. + +#include "boost/mpl/single_view.hpp" +#include "boost/mpl/size.hpp" +#include "boost/mpl/begin_end.hpp" +#include "boost/mpl/assert_is_same.hpp" +#include "boost/static_assert.hpp" + +using namespace boost::mpl; + +int main() +{ + typedef single_view view; + typedef begin::type first; + typedef end::type last; + + BOOST_MPL_ASSERT_IS_SAME(first::type,int); + BOOST_MPL_ASSERT_IS_SAME(first::next,last); + BOOST_MPL_ASSERT_IS_SAME(last::prior,first); + + BOOST_STATIC_ASSERT(size::type::value == 1); + + return 0; +}