single_view initial check in

[SVN r16280]
This commit is contained in:
Aleksey Gurtovoy
2002-11-16 10:48:39 +00:00
parent 4b7c2ef23b
commit 9e5b6ee85c
3 changed files with 203 additions and 0 deletions

View File

@@ -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<N> position;
template< typename D >
struct BOOST_MPL_AUX_ITERATOR_ADVANCE
{
typedef plus< int_c<N>,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<N>
>::type type;
};
};
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template< typename T >
struct single_element_iter<T,0>
: single_iter_base<T,0>
{
typedef single_element_iter<T,1> next;
typedef T type;
};
template< typename T >
struct single_element_iter<T,1>
: single_iter_base<T,1>
{
typedef single_element_iter<T,0> 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<T,0>
{
typedef single_element_iter<T,1> next;
typedef T type;
};
};
template<>
struct single_iter_impl<1>
{
template< typename T > struct result_
: single_iter_base<T,1>
{
typedef single_element_iter<T,0> prior;
};
};
template< typename T, int N >
struct single_element_iter
: single_iter_impl<N>::template result_<T>
{
};
#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

View File

@@ -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<T,0>
, aux::single_element_iter<T,1>
>
{
};
BOOST_MPL_AUX_VOID_SPEC(1, single_view)
} // namespace mpl
} // namespace boost
#endif // BOOST_MPL_SINGLE_VIEW_HPP_INCLUDED

38
test/single_view.cpp Normal file
View File

@@ -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<int> view;
typedef begin<view>::type first;
typedef end<view>::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<view>::type::value == 1);
return 0;
}