Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:52:42

0001 //  (C) Copyright Eric Niebler 2004-2005
0002 //  (C) Copyright Gennadiy Rozental 2001.
0003 //  Distributed under the Boost Software License, Version 1.0.
0004 //  (See accompanying file LICENSE_1_0.txt or copy at
0005 //  http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 //  See http://www.boost.org/libs/test for the library home page.
0008 //
0009 //  File        : $RCSfile$
0010 //
0011 //  Version     : $Revision$
0012 //
0013 //  Description : this is an abridged version of an excelent BOOST_FOREACH facility
0014 //  presented by Eric Niebler. I am so fond of it so I can't wait till it
0015 //  going to be accepted into Boost. Also I need version with less number of dependencies
0016 //  and more portable. This version doesn't support rvalues and will reeveluate it's
0017 //  parameters, but should be good enough for my purposes.
0018 // ***************************************************************************
0019 
0020 #ifndef BOOST_TEST_UTILS_FOREACH_HPP
0021 #define BOOST_TEST_UTILS_FOREACH_HPP
0022 
0023 // Boost.Test
0024 #include <boost/test/detail/config.hpp>
0025 
0026 // Boost
0027 #include <boost/type.hpp>
0028 #include <boost/mpl/bool.hpp>
0029 
0030 #include <boost/type_traits/is_const.hpp>
0031 
0032 #include <boost/test/detail/suppress_warnings.hpp>
0033 
0034 //____________________________________________________________________________//
0035 
0036 namespace boost {
0037 namespace unit_test {
0038 namespace for_each {
0039 
0040 // ************************************************************************** //
0041 // **************                  static_any                  ************** //
0042 // ************************************************************************** //
0043 
0044 struct static_any_base
0045 {
0046     operator bool() const { return false; }
0047 };
0048 
0049 //____________________________________________________________________________//
0050 
0051 template<typename Iter>
0052 struct static_any : static_any_base
0053 {
0054     static_any( Iter const& t ) : m_it( t ) {}
0055 
0056     mutable Iter m_it;
0057 };
0058 
0059 //____________________________________________________________________________//
0060 
0061 typedef static_any_base const& static_any_t;
0062 
0063 //____________________________________________________________________________//
0064 
0065 template<typename Iter>
0066 inline Iter&
0067 static_any_cast( static_any_t a, Iter* = 0 )
0068 {
0069     return static_cast<Iter&>( static_cast<static_any<Iter> const&>( a ).m_it );
0070 }
0071 
0072 //____________________________________________________________________________//
0073 
0074 // ************************************************************************** //
0075 // **************                   is_const                   ************** //
0076 // ************************************************************************** //
0077 
0078 template<typename C>
0079 inline is_const<C>
0080 is_const_coll( C& )
0081 {
0082     return is_const<C>();
0083 }
0084 
0085 //____________________________________________________________________________//
0086 
0087 // ************************************************************************** //
0088 // **************                     begin                    ************** //
0089 // ************************************************************************** //
0090 
0091 template<typename C>
0092 inline static_any<BOOST_DEDUCED_TYPENAME C::iterator>
0093 begin( C& t, mpl::false_ )
0094 {
0095     return static_any<BOOST_DEDUCED_TYPENAME C::iterator>( t.begin() );
0096 }
0097 
0098 //____________________________________________________________________________//
0099 
0100 template<typename C>
0101 inline static_any<BOOST_DEDUCED_TYPENAME C::const_iterator>
0102 begin( C const& t, mpl::true_ )
0103 {
0104     return static_any<BOOST_DEDUCED_TYPENAME C::const_iterator>( t.begin() );
0105 }
0106 
0107 //____________________________________________________________________________//
0108 
0109 // ************************************************************************** //
0110 // **************                      end                     ************** //
0111 // ************************************************************************** //
0112 
0113 template<typename C>
0114 inline static_any<BOOST_DEDUCED_TYPENAME C::iterator>
0115 end( C& t, mpl::false_ )
0116 {
0117     return static_any<BOOST_DEDUCED_TYPENAME C::iterator>( t.end() );
0118 }
0119 
0120 //____________________________________________________________________________//
0121 
0122 template<typename C>
0123 inline static_any<BOOST_DEDUCED_TYPENAME C::const_iterator>
0124 end( C const& t, mpl::true_ )
0125 {
0126     return static_any<BOOST_DEDUCED_TYPENAME C::const_iterator>( t.end() );
0127 }
0128 
0129 //____________________________________________________________________________//
0130 
0131 // ************************************************************************** //
0132 // **************                      done                    ************** //
0133 // ************************************************************************** //
0134 
0135 template<typename C>
0136 inline bool
0137 done( static_any_t cur, static_any_t end, C&, mpl::false_ )
0138 {
0139     return  static_any_cast<BOOST_DEDUCED_TYPENAME C::iterator>( cur ) ==
0140             static_any_cast<BOOST_DEDUCED_TYPENAME C::iterator>( end );
0141 }
0142 
0143 //____________________________________________________________________________//
0144 
0145 template<typename C>
0146 inline bool
0147 done( static_any_t cur, static_any_t end, C const&, mpl::true_ )
0148 {
0149     return  static_any_cast<BOOST_DEDUCED_TYPENAME C::const_iterator>( cur ) ==
0150             static_any_cast<BOOST_DEDUCED_TYPENAME C::const_iterator>( end );
0151 }
0152 
0153 //____________________________________________________________________________//
0154 
0155 // ************************************************************************** //
0156 // **************                      next                    ************** //
0157 // ************************************************************************** //
0158 
0159 template<typename C>
0160 inline void
0161 next( static_any_t cur, C&, mpl::false_ )
0162 {
0163     ++static_any_cast<BOOST_DEDUCED_TYPENAME C::iterator>( cur );
0164 }
0165 
0166 //____________________________________________________________________________//
0167 
0168 template<typename C>
0169 inline void
0170 next( static_any_t cur, C const&, mpl::true_ )
0171 {
0172     ++static_any_cast<BOOST_DEDUCED_TYPENAME C::const_iterator>( cur );
0173 }
0174 
0175 //____________________________________________________________________________//
0176 
0177 // ************************************************************************** //
0178 // **************                      prev                    ************** //
0179 // ************************************************************************** //
0180 
0181 template<typename C>
0182 inline void
0183 prev( static_any_t cur, C&, mpl::false_ )
0184 {
0185     --static_any_cast<BOOST_DEDUCED_TYPENAME C::iterator>( cur );
0186 }
0187 
0188 //____________________________________________________________________________//
0189 
0190 template<typename C>
0191 inline void
0192 prev( static_any_t cur, C const&, mpl::true_ )
0193 {
0194     --static_any_cast<BOOST_DEDUCED_TYPENAME C::const_iterator>( cur );
0195 }
0196 
0197 //____________________________________________________________________________//
0198 
0199 // ************************************************************************** //
0200 // **************                      deref                   ************** //
0201 // ************************************************************************** //
0202 
0203 template<class RefType,typename C>
0204 inline RefType
0205 deref( static_any_t cur, C&, ::boost::type<RefType>, mpl::false_ )
0206 {
0207     return *static_any_cast<BOOST_DEDUCED_TYPENAME C::iterator>( cur );
0208 }
0209 
0210 //____________________________________________________________________________//
0211 
0212 template<class RefType,typename C>
0213 inline RefType
0214 deref( static_any_t cur, C const&, ::boost::type<RefType>, mpl::true_ )
0215 {
0216     return *static_any_cast<BOOST_DEDUCED_TYPENAME C::const_iterator>( cur );
0217 }
0218 
0219 //____________________________________________________________________________//
0220 
0221 // ************************************************************************** //
0222 // **************              BOOST_TEST_FOREACH              ************** //
0223 // ************************************************************************** //
0224 
0225 #define BOOST_TEST_FE_ANY                   ::boost::unit_test::for_each::static_any_t
0226 #define BOOST_TEST_FE_IS_CONST( COL )       ::boost::unit_test::for_each::is_const_coll( COL )
0227 
0228 #define BOOST_TEST_FE_BEG( COL )            \
0229     ::boost::unit_test::for_each::begin(    \
0230         COL,                                \
0231         BOOST_TEST_FE_IS_CONST( COL ) )     \
0232 /**/
0233 
0234 #define BOOST_TEST_FE_END( COL )            \
0235     ::boost::unit_test::for_each::end(      \
0236         COL,                                \
0237         BOOST_TEST_FE_IS_CONST( COL ) )     \
0238 /**/
0239 
0240 #define BOOST_TEST_FE_DONE( COL )           \
0241     ::boost::unit_test::for_each::done(     \
0242         BOOST_TEST_FE_CUR_VAR,              \
0243         BOOST_TEST_FE_END_VAR,              \
0244         COL,                                \
0245         BOOST_TEST_FE_IS_CONST( COL ) )     \
0246 /**/
0247 
0248 #define BOOST_TEST_FE_NEXT( COL )           \
0249     ::boost::unit_test::for_each::next(     \
0250         BOOST_TEST_FE_CUR_VAR,              \
0251         COL,                                \
0252         BOOST_TEST_FE_IS_CONST( COL ) )     \
0253 /**/
0254 
0255 #define BOOST_TEST_FE_PREV( COL )           \
0256     ::boost::unit_test::for_each::prev(     \
0257         BOOST_TEST_FE_CUR_VAR,              \
0258         COL,                                \
0259         BOOST_TEST_FE_IS_CONST( COL ) )     \
0260 /**/
0261 
0262 #define BOOST_FOREACH_NOOP(COL)             \
0263     ((void)&(COL))
0264 
0265 #define BOOST_TEST_FE_DEREF( COL, RefType ) \
0266     ::boost::unit_test::for_each::deref(    \
0267         BOOST_TEST_FE_CUR_VAR,              \
0268         COL,                                \
0269         ::boost::type<RefType >(),          \
0270         BOOST_TEST_FE_IS_CONST( COL ) )     \
0271 /**/
0272 
0273 #if BOOST_WORKAROUND( BOOST_MSVC, == 1310 )
0274 #define BOOST_TEST_LINE_NUM
0275 #else
0276 #define BOOST_TEST_LINE_NUM     __LINE__
0277 #endif
0278 
0279 #define BOOST_TEST_FE_CUR_VAR   BOOST_JOIN( _fe_cur_, BOOST_TEST_LINE_NUM )
0280 #define BOOST_TEST_FE_END_VAR   BOOST_JOIN( _fe_end_, BOOST_TEST_LINE_NUM )
0281 #define BOOST_TEST_FE_CON_VAR   BOOST_JOIN( _fe_con_, BOOST_TEST_LINE_NUM )
0282 
0283 #define BOOST_TEST_FOREACH( RefType, var, COL )                                             \
0284 if( BOOST_TEST_FE_ANY BOOST_TEST_FE_CUR_VAR = BOOST_TEST_FE_BEG( COL ) ) {} else            \
0285 if( BOOST_TEST_FE_ANY BOOST_TEST_FE_END_VAR = BOOST_TEST_FE_END( COL ) ) {} else            \
0286 for( bool BOOST_TEST_FE_CON_VAR = true;                                                     \
0287           BOOST_TEST_FE_CON_VAR && !BOOST_TEST_FE_DONE( COL );                              \
0288           BOOST_TEST_FE_CON_VAR ? BOOST_TEST_FE_NEXT( COL ) : BOOST_FOREACH_NOOP( COL ))    \
0289                                                                                             \
0290     if( (BOOST_TEST_FE_CON_VAR = false, false) ) {} else                                    \
0291     for( RefType var = BOOST_TEST_FE_DEREF( COL, RefType );                                 \
0292          !BOOST_TEST_FE_CON_VAR; BOOST_TEST_FE_CON_VAR = true )                             \
0293 /**/
0294 
0295 #define BOOST_TEST_REVERSE_FOREACH( RefType, var, COL )                                     \
0296 if( BOOST_TEST_FE_ANY BOOST_TEST_FE_CUR_VAR = BOOST_TEST_FE_END( COL ) ) {} else            \
0297 if( BOOST_TEST_FE_ANY BOOST_TEST_FE_END_VAR = BOOST_TEST_FE_BEG( COL ) ) {} else            \
0298 for( bool BOOST_TEST_FE_CON_VAR = true;                                                     \
0299           BOOST_TEST_FE_CON_VAR && !BOOST_TEST_FE_DONE( COL ); )                            \
0300                                                                                             \
0301     if( (BOOST_TEST_FE_CON_VAR = false, false) ) {} else                                    \
0302     if( (BOOST_TEST_FE_PREV( COL ), false) ) {} else                                        \
0303     for( RefType var = BOOST_TEST_FE_DEREF( COL, RefType );                                 \
0304          !BOOST_TEST_FE_CON_VAR; BOOST_TEST_FE_CON_VAR = true )                             \
0305 /**/
0306 
0307 //____________________________________________________________________________//
0308 
0309 } // namespace for_each
0310 } // namespace unit_test
0311 } // namespace boost
0312 
0313 #include <boost/test/detail/enable_warnings.hpp>
0314 
0315 #endif // BOOST_TEST_UTILS_FOREACH_HPP