diff --git a/doc/reference/adaptors/filtered.qbk b/doc/reference/adaptors/filtered.qbk index 3f84c94..0340ed1 100644 --- a/doc/reference/adaptors/filtered.qbk +++ b/doc/reference/adaptors/filtered.qbk @@ -15,7 +15,7 @@ * [*Postcondition:] For all adjacent elements `[x]` in the returned range, `pred(x)` is `true`. * [*Throws:] Whatever the copy constructor of `pred` might throw. * [*Range Category:] __forward_range__ -* [*Range Return Type:] `boost::filtered_range` +* [*Range Return Type:] `boost::filtered_range` * [*Returned Range Category:] The minimum of the range category of `rng` and __bidirectional_range__ [section:filtered_example filtered example] diff --git a/doc/reference/adaptors/indexed.qbk b/doc/reference/adaptors/indexed.qbk index 117e1e3..d4ee91f 100644 --- a/doc/reference/adaptors/indexed.qbk +++ b/doc/reference/adaptors/indexed.qbk @@ -13,7 +13,7 @@ * [*Returns:] A range adapted to return both the element and the associated index. The returned range consists of iterators that have in addition to the usual iterator member functions an `index()` member function that returns the appropriate index for the element in the sequence corresponding with the iterator. * [*Range Category:] __single_pass_range__ -* [*Range Return Type:] `boost::indexed_range` +* [*Range Return Type:] `boost::indexed_range` * [*Returned Range Category:] The range category of `rng` [section:indexed_example indexed example] diff --git a/doc/reference/adaptors/indirected.qbk b/doc/reference/adaptors/indirected.qbk index 437a547..3d6f416 100644 --- a/doc/reference/adaptors/indirected.qbk +++ b/doc/reference/adaptors/indirected.qbk @@ -14,7 +14,7 @@ * [*Precondition:] The `value_type` of the range defines unary `operator*()` * [*Postcondition:] For all elements `x` in the returned range, `x` is the result of `*y` where `y` is the corresponding element in the original range. * [*Range Category:] __single_pass_range__ -* [*Range Return Type:] `boost::indirected_range` +* [*Range Return Type:] `boost::indirected_range` * [*Returned Range Category:] The range category of `rng` [section:indirected_example indirected example] diff --git a/doc/reference/adaptors/map_keys.qbk b/doc/reference/adaptors/map_keys.qbk index f9fbb9a..e70b4b8 100644 --- a/doc/reference/adaptors/map_keys.qbk +++ b/doc/reference/adaptors/map_keys.qbk @@ -14,7 +14,7 @@ * [*Precondition:] The `value_type` of the range is an instantiation of `std::pair`. * [*Postcondition:] For all elements `x` in the returned range, `x` is the result of `y.first` where `y` is the corresponding element in the original range. * [*Range Category:] __single_pass_range__ -* [*Range Return Type:] `boost::select_first_range` +* [*Range Return Type:] `boost::select_first_range` * [*Returned Range Category:] The range category of `rng`. [section:map_keys_example map_keys example] diff --git a/doc/reference/adaptors/map_values.qbk b/doc/reference/adaptors/map_values.qbk index 7941f47..845c9e8 100644 --- a/doc/reference/adaptors/map_values.qbk +++ b/doc/reference/adaptors/map_values.qbk @@ -14,7 +14,7 @@ * [*Precondition:] The `value_type` of the range is an instantiation of `std::pair`. * [*Postcondition:] For all elements `x` in the returned range, `x` is the result of `y.second` where `y` is the corresponding element in the original range. * [*Range Category:] __single_pass_range__ -* [*Range Return Type:] for constant ranges, `boost::select_second_const` otherwise `boost:select_second_mutable` +* [*Range Return Type:] for constant ranges, `boost::select_second_const` otherwise `boost:select_second_mutable` * [*Returned Range Category:] The range category of `rng`. [section:map_values_example map_values example] diff --git a/doc/reference/adaptors/replaced.qbk b/doc/reference/adaptors/replaced.qbk index aae4ece..3afb2c5 100644 --- a/doc/reference/adaptors/replaced.qbk +++ b/doc/reference/adaptors/replaced.qbk @@ -15,8 +15,8 @@ * `new_value` is convertible to the `value_type` of the range. * `old_value` is convertible to the `value_type` of the range. * [*Postcondition:] For all elements `x` in the returned range, the value `x` is equal to the value of `(y == old_value) ? new_value : y` where `y` is the corresponding element in the original range. -* [*Range Category:] __forward_range__ -* [*Range Return Type:] `boost::replaced_range` +* [*Range Category:] __single_pass_range__ +* [*Range Return Type:] `boost::replaced_range` * [*Returned Range Category:] The range category of `rng`. [section:replaced_example replaced example] diff --git a/doc/reference/adaptors/replaced_if.qbk b/doc/reference/adaptors/replaced_if.qbk index f00c46a..99c1ed8 100644 --- a/doc/reference/adaptors/replaced_if.qbk +++ b/doc/reference/adaptors/replaced_if.qbk @@ -15,8 +15,8 @@ * The range `value_type` is convertible to the argument type of `pred`. * `new_value` is convertible to the `value_type` of the range. * [*Postconditions:] For all elements `x` in the returned range, the value `x` is equal to the value of `pred(y) ? new_value : y` where `y` is the corresponding element in the original range. -* [*Range Category:] __forward_range__ -* [*Range Return Type:] `boost::replaced_if_range` +* [*Range Category:] __single_pass_range__ +* [*Range Return Type:] `boost::replaced_if_range` * [*Returned Range Category:] The range category of `rng`. [section:replaced_if_example replaced_if example] diff --git a/doc/reference/adaptors/reversed.qbk b/doc/reference/adaptors/reversed.qbk index 42f8e73..8fe813f 100644 --- a/doc/reference/adaptors/reversed.qbk +++ b/doc/reference/adaptors/reversed.qbk @@ -13,7 +13,7 @@ * [*Returns:] A range whose iterators behave as if they were the original iterators wrapped in `reverse_iterator`. * [*Range Category:] __bidirectional_range__ -* [*Range Return Type:] `boost::reversed_range` +* [*Range Return Type:] `boost::reversed_range` * [*Returned Range Category:] The range category of `rng`. [section:reversed_example reversed example] diff --git a/doc/reference/adaptors/sliced.qbk b/doc/reference/adaptors/sliced.qbk index e67ae30..81b4a16 100644 --- a/doc/reference/adaptors/sliced.qbk +++ b/doc/reference/adaptors/sliced.qbk @@ -14,7 +14,7 @@ * [*Precondition:] `0 <= n && n <= m && m < distance(rng)` * [*Returns:] `make_range(rng, n, m)` * [*Range Category:] __random_access_range__ -* [*Range Return Type:] `boost::sliced_range` +* [*Range Return Type:] `boost::sliced_range` * [*Returned Range Category:] __random_access_range__ [section:sliced_example sliced example] diff --git a/doc/reference/adaptors/tokenized.qbk b/doc/reference/adaptors/tokenized.qbk index 0a480d4..2105323 100644 --- a/doc/reference/adaptors/tokenized.qbk +++ b/doc/reference/adaptors/tokenized.qbk @@ -41,7 +41,7 @@ * [*Returns:] A range whose iterators behave as if they were the original iterators wrapped in `regex_token_iterator`. The first iterator in the range would be constructed by forwarding all the arguments of `tokenized()` to the `regex_token_iterator` constructor. * [*Throws:] Whatever constructing and copying equivalent `regex_token_iterator`s might throw. * [*Range Category:] __random_access_range__ -* [*Range Return Type:] `boost::tokenized_range` +* [*Range Return Type:] `boost::tokenized_range` * [*Returned Range Category:] __random_access_range__ [section:tokenized_example tokenized_example] diff --git a/doc/reference/adaptors/transformed.qbk b/doc/reference/adaptors/transformed.qbk index c53cfd7..0c71e8d 100644 --- a/doc/reference/adaptors/transformed.qbk +++ b/doc/reference/adaptors/transformed.qbk @@ -15,7 +15,7 @@ * [*Postcondition:] For all elements `x` in the returned range, `x` is the result of `fun(y)` where `y` is the corresponding element in the original range. * [*Throws:] Whatever the copy-constructor of `fun` might throw. * [*Range Category:] __single_pass_range__ -* [*Range Return Type:] `boost::transformed_range` +* [*Range Return Type:] `boost::transformed_range` * [*Returned Range Category:] The range category of `rng`. [section:transformed_example transformed example] diff --git a/doc/reference/adaptors/uniqued.qbk b/doc/reference/adaptors/uniqued.qbk index 5b8e7f2..3fb38d7 100644 --- a/doc/reference/adaptors/uniqued.qbk +++ b/doc/reference/adaptors/uniqued.qbk @@ -14,7 +14,7 @@ * [*Precondition:] The `value_type` of the range is comparable with `operator==()`. * [*Postcondition:] For all adjacent elements `[x,y]` in the returned range, `x==y` is false. * [*Range Category:] __forward_range__ -* [*Range Return Type:] `boost::uniqued_range` +* [*Range Return Type:] `boost::uniqued_range` * [*Returned Range Category:] The minimum of the range concept of `rng` and __forward_range__. [section:uniqued_example uniqued example] diff --git a/include/boost/range/adaptor/adjacent_filtered.hpp b/include/boost/range/adaptor/adjacent_filtered.hpp index 159d8ee..287a4ae 100644 --- a/include/boost/range/adaptor/adjacent_filtered.hpp +++ b/include/boost/range/adaptor/adjacent_filtered.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -154,6 +155,8 @@ namespace boost operator|( ForwardRng& r, const adjacent_holder& f ) { + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + return adjacent_filtered_range( f.val, r ); } @@ -162,6 +165,8 @@ namespace boost operator|( const ForwardRng& r, const adjacent_holder& f ) { + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + return adjacent_filtered_range( f.val, r ); } @@ -171,6 +176,7 @@ namespace boost operator|( ForwardRng& r, const adjacent_excl_holder& f ) { + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); return adjacent_filtered_range( f.val, r ); } @@ -179,6 +185,7 @@ namespace boost operator|( const ForwardRng& r, const adjacent_excl_holder& f ) { + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); return adjacent_filtered_range( f.val, r ); } @@ -207,6 +214,7 @@ namespace boost inline adjacent_filtered_range adjacent_filter(ForwardRng& rng, BinPredicate filter_pred) { + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); return adjacent_filtered_range(filter_pred, rng); } @@ -214,6 +222,7 @@ namespace boost inline adjacent_filtered_range adjacent_filter(const ForwardRng& rng, BinPredicate filter_pred) { + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); return adjacent_filtered_range(filter_pred, rng); } diff --git a/include/boost/range/adaptor/copied.hpp b/include/boost/range/adaptor/copied.hpp index f4cf2d1..f7dfbcd 100755 --- a/include/boost/range/adaptor/copied.hpp +++ b/include/boost/range/adaptor/copied.hpp @@ -1,6 +1,6 @@ // Boost.Range library // -// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. Use, modification and +// Copyright Thorsten Ottosen, Neil Groves 2006. Use, modification and // distribution is subject to 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) @@ -15,6 +15,7 @@ #include #include #include +#include namespace boost { @@ -29,25 +30,34 @@ namespace boost std::size_t u; }; - template< class CopyableRandomAccessRng > - inline CopyableRandomAccessRng - operator|( const CopyableRandomAccessRng& r, const copied& f ) + template + inline CopyableRandomAccessRange + operator|(const CopyableRandomAccessRange& r, const copied& f) { + BOOST_RANGE_CONCEPT_ASSERT(( + RandomAccessRangeConcept)); + iterator_range< - BOOST_DEDUCED_TYPENAME range_iterator::type > - temp( adaptors::slice( r, f.t, f.u ) ); - return CopyableRandomAccessRng( temp.begin(), temp.end() ); + BOOST_DEDUCED_TYPENAME range_iterator< + const CopyableRandomAccessRange + >::type + > temp(adaptors::slice(r, f.t, f.u)); + + return CopyableRandomAccessRange(temp.begin(), temp.end()); } template inline CopyableRandomAccessRange copy(const CopyableRandomAccessRange& rng, std::size_t t, std::size_t u) { + BOOST_RANGE_CONCEPT_ASSERT(( + RandomAccessRangeConcept)); + iterator_range< - BOOST_DEDUCED_TYPENAME range_iterator::type> temp( - adaptors::slice(rng, t, u)); + BOOST_DEDUCED_TYPENAME range_iterator< + const CopyableRandomAccessRange + >::type + > temp(adaptors::slice(rng, t, u)); return CopyableRandomAccessRange( temp.begin(), temp.end() ); } @@ -55,4 +65,4 @@ namespace boost } -#endif +#endif // include guard diff --git a/include/boost/range/adaptor/filtered.hpp b/include/boost/range/adaptor/filtered.hpp index d9315bd..9e050a6 100755 --- a/include/boost/range/adaptor/filtered.hpp +++ b/include/boost/range/adaptor/filtered.hpp @@ -13,6 +13,7 @@ #include #include +#include #include namespace boost @@ -47,20 +48,23 @@ namespace boost { } }; - template< class InputRng, class Predicate > - inline filtered_range - operator|( InputRng& r, - const filter_holder& f ) + template< class ForwardRange, class Predicate > + inline filtered_range + operator|(ForwardRange& r, + const filter_holder& f) { - return filtered_range( f.val, r ); + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + return filtered_range( f.val, r ); } - template< class InputRng, class Predicate > - inline filtered_range - operator|( const InputRng& r, - const filter_holder& f ) + template< class ForwardRange, class Predicate > + inline filtered_range + operator|(const ForwardRange& r, + const filter_holder& f ) { - return filtered_range( f.val, r ); + BOOST_RANGE_CONCEPT_ASSERT(( + ForwardRangeConcept)); + return filtered_range( f.val, r ); } } // 'range_detail' @@ -81,18 +85,23 @@ namespace boost range_detail::forwarder(); } - template - inline filtered_range - filter(InputRange& rng, Predicate filter_pred) + template + inline filtered_range + filter(ForwardRange& rng, Predicate filter_pred) { - return range_detail::filtered_range( filter_pred, rng ); + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + + return range_detail::filtered_range( filter_pred, rng ); } - template - inline filtered_range - filter(const InputRange& rng, Predicate filter_pred) + template + inline filtered_range + filter(const ForwardRange& rng, Predicate filter_pred) { - return range_detail::filtered_range( filter_pred, rng ); + BOOST_RANGE_CONCEPT_ASSERT(( + ForwardRangeConcept)); + + return range_detail::filtered_range( filter_pred, rng ); } } // 'adaptors' diff --git a/include/boost/range/adaptor/indexed.hpp b/include/boost/range/adaptor/indexed.hpp index cb2c127..cafedf1 100644 --- a/include/boost/range/adaptor/indexed.hpp +++ b/include/boost/range/adaptor/indexed.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -124,6 +125,9 @@ namespace boost operator|( SinglePassRange& r, const indexed& f ) { + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + return indexed_range( f.val, r ); } @@ -132,6 +136,9 @@ namespace boost operator|( const SinglePassRange& r, const indexed& f ) { + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + return indexed_range( f.val, r ); } @@ -139,6 +146,9 @@ namespace boost inline indexed_range index(SinglePassRange& rng, Index index_value) { + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + return indexed_range(index_value, rng); } @@ -146,6 +156,9 @@ namespace boost inline indexed_range index(const SinglePassRange& rng, Index index_value) { + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + return indexed_range(index_value, rng); } } // 'adaptors' diff --git a/include/boost/range/adaptor/indirected.hpp b/include/boost/range/adaptor/indirected.hpp index d7edc18..e741f17 100644 --- a/include/boost/range/adaptor/indirected.hpp +++ b/include/boost/range/adaptor/indirected.hpp @@ -12,6 +12,7 @@ #define BOOST_RANGE_ADAPTOR_INDIRECTED_HPP #include +#include #include namespace boost @@ -42,18 +43,24 @@ namespace boost struct indirect_forwarder {}; - template< class InputRng > - inline indirected_range - operator|( InputRng& r, indirect_forwarder ) + template< class SinglePassRange > + inline indirected_range + operator|( SinglePassRange& r, indirect_forwarder ) { - return indirected_range( r ); + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + + return indirected_range( r ); } - template< class InputRng > - inline indirected_range - operator|( const InputRng& r, indirect_forwarder ) + template< class SinglePassRange > + inline indirected_range + operator|( const SinglePassRange& r, indirect_forwarder ) { - return indirected_range( r ); + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + + return indirected_range( r ); } } // 'range_detail' @@ -68,18 +75,23 @@ namespace boost range_detail::indirect_forwarder(); } - template - inline indirected_range - indirect(InputRange& rng) + template + inline indirected_range + indirect(SinglePassRange& rng) { - return indirected_range(rng); + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + return indirected_range(rng); } - template - inline indirected_range - indirect(const InputRange& rng) + template + inline indirected_range + indirect(const SinglePassRange& rng) { - return indirected_range(rng); + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + + return indirected_range(rng); } } // 'adaptors' diff --git a/include/boost/range/adaptor/map.hpp b/include/boost/range/adaptor/map.hpp index ff8b97e..2d922ea 100755 --- a/include/boost/range/adaptor/map.hpp +++ b/include/boost/range/adaptor/map.hpp @@ -15,6 +15,7 @@ #include #include #include +#include namespace boost { @@ -120,6 +121,9 @@ namespace boost inline select_first_range operator|( const StdPairRng& r, map_keys_forwarder ) { + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + return operator|( r, boost::adaptors::transformed( select_first() ) ); } @@ -128,6 +132,8 @@ namespace boost inline select_second_mutable_range operator|( StdPairRng& r, map_values_forwarder ) { + BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept)); + return operator|( r, boost::adaptors::transformed( select_second_mutable() ) ); } @@ -136,6 +142,9 @@ namespace boost inline select_second_const_range operator|( const StdPairRng& r, map_values_forwarder ) { + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + return operator|( r, boost::adaptors::transformed( select_second_const() ) ); } @@ -161,6 +170,9 @@ namespace boost inline select_first_range keys(const StdPairRange& rng) { + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + return select_first_range( range_detail::select_first(), rng ); } @@ -169,6 +181,9 @@ namespace boost inline select_second_const_range values(const StdPairRange& rng) { + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + return select_second_const_range( range_detail::select_second_const(), rng ); } @@ -177,6 +192,8 @@ namespace boost inline select_second_mutable_range values(StdPairRange& rng) { + BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept)); + return select_second_mutable_range( range_detail::select_second_mutable(), rng ); } diff --git a/include/boost/range/adaptor/replaced.hpp b/include/boost/range/adaptor/replaced.hpp index deeb8da..2a6ab56 100644 --- a/include/boost/range/adaptor/replaced.hpp +++ b/include/boost/range/adaptor/replaced.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -82,20 +83,30 @@ namespace boost void operator=(const replace_holder&); }; - template< class InputRng > - inline replaced_range - operator|( InputRng& r, - const replace_holder::type>& f ) + template< class SinglePassRange > + inline replaced_range + operator|( + SinglePassRange& r, + const replace_holder< + BOOST_DEDUCED_TYPENAME range_value::type>& f ) { - return replaced_range(r, f.val1, f.val2); + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + + return replaced_range(r, f.val1, f.val2); } - template< class InputRng > - inline replaced_range - operator|( const InputRng& r, - const replace_holder::type>& f ) + template< class SinglePassRange > + inline replaced_range + operator|( + const SinglePassRange& r, + const replace_holder< + BOOST_DEDUCED_TYPENAME range_value::type>& f) { - return replaced_range(r, f.val1, f.val2); + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + + return replaced_range(r, f.val1, f.val2); } } // 'range_detail' @@ -110,22 +121,28 @@ namespace boost range_detail::forwarder2(); } - template - inline replaced_range - replace(InputRange& rng, - BOOST_DEDUCED_TYPENAME range_value::type from, - BOOST_DEDUCED_TYPENAME range_value::type to) + template + inline replaced_range + replace(SinglePassRange& rng, + BOOST_DEDUCED_TYPENAME range_value::type from, + BOOST_DEDUCED_TYPENAME range_value::type to) { - return replaced_range(rng, from, to); + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + + return replaced_range(rng, from, to); } - template - inline replaced_range - replace(const InputRange& rng, - BOOST_DEDUCED_TYPENAME range_value::type from, - BOOST_DEDUCED_TYPENAME range_value::type to) + template + inline replaced_range + replace(const SinglePassRange& rng, + BOOST_DEDUCED_TYPENAME range_value::type from, + BOOST_DEDUCED_TYPENAME range_value::type to) { - return replaced_range(rng, from ,to); + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + + return replaced_range(rng, from ,to); } } // 'adaptors' diff --git a/include/boost/range/adaptor/replaced_if.hpp b/include/boost/range/adaptor/replaced_if.hpp index b514354..b9f73ae 100644 --- a/include/boost/range/adaptor/replaced_if.hpp +++ b/include/boost/range/adaptor/replaced_if.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -86,20 +87,34 @@ namespace boost T m_to; }; - template< class Pred, class InputRng > - inline replaced_if_range - operator|( InputRng& r, - const replace_if_holder::type>& f ) + template< class Pred, class SinglePassRange > + inline replaced_if_range + operator|( + SinglePassRange& r, + const replace_if_holder< + Pred, + BOOST_DEDUCED_TYPENAME range_value::type>& f) { - return replaced_if_range(r, f.pred(), f.to()); + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + + return replaced_if_range( + r, f.pred(), f.to()); } - template< class Pred, class InputRng > - inline replaced_if_range - operator|( const InputRng& r, - const replace_if_holder::type>& f ) + template< class Pred, class SinglePassRange > + inline replaced_if_range + operator|( + const SinglePassRange& r, + const replace_if_holder< + Pred, + BOOST_DEDUCED_TYPENAME range_value::type>& f) { - return replaced_if_range(r, f.pred(), f.to()); + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + + return replaced_if_range( + r, f.pred(), f.to()); } } // 'range_detail' @@ -113,24 +128,34 @@ namespace boost replaced_if = range_detail::forwarder2TU(); } - - template - inline replaced_if_range - replace_if(InputRange& rng, Pred pred, - BOOST_DEDUCED_TYPENAME range_value::type to) + + template + inline replaced_if_range + replace_if(SinglePassRange& rng, Pred pred, + BOOST_DEDUCED_TYPENAME range_value::type to) { - return range_detail::replaced_if_range(rng, pred, to); + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + + return range_detail::replaced_if_range( + rng, pred, to); } - template - inline replaced_if_range - replace_if(const InputRange& rng, Pred pred, - BOOST_DEDUCED_TYPENAME range_value::type to) + template + inline replaced_if_range + replace_if( + const SinglePassRange& rng, + Pred pred, + BOOST_DEDUCED_TYPENAME range_value::type to) { - return range_detail::replaced_if_range(rng, pred, to); + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + + return range_detail::replaced_if_range( + rng, pred, to); } } // 'adaptors' - + } // 'boost' #endif // include guard diff --git a/include/boost/range/adaptor/reversed.hpp b/include/boost/range/adaptor/reversed.hpp index c85eda8..944fbff 100755 --- a/include/boost/range/adaptor/reversed.hpp +++ b/include/boost/range/adaptor/reversed.hpp @@ -12,6 +12,7 @@ #define BOOST_RANGE_ADAPTOR_REVERSED_HPP #include +#include #include namespace boost @@ -44,18 +45,24 @@ namespace boost struct reverse_forwarder {}; - template< class BidirectionalRng > - inline reversed_range - operator|( BidirectionalRng& r, reverse_forwarder ) + template< class BidirectionalRange > + inline reversed_range + operator|( BidirectionalRange& r, reverse_forwarder ) { - return reversed_range( r ); + BOOST_RANGE_CONCEPT_ASSERT(( + BidirectionalRangeConcept)); + + return reversed_range( r ); } - - template< class BidirectionalRng > - inline reversed_range - operator|( const BidirectionalRng& r, reverse_forwarder ) + + template< class BidirectionalRange > + inline reversed_range + operator|( const BidirectionalRange& r, reverse_forwarder ) { - return reversed_range( r ); + BOOST_RANGE_CONCEPT_ASSERT(( + BidirectionalRangeConcept)); + + return reversed_range( r ); } } // 'range_detail' @@ -74,6 +81,9 @@ namespace boost inline reversed_range reverse(BidirectionalRange& rng) { + BOOST_RANGE_CONCEPT_ASSERT(( + BidirectionalRangeConcept)); + return reversed_range(rng); } @@ -81,6 +91,9 @@ namespace boost inline reversed_range reverse(const BidirectionalRange& rng) { + BOOST_RANGE_CONCEPT_ASSERT(( + BidirectionalRangeConcept)); + return reversed_range(rng); } } // 'adaptors' diff --git a/include/boost/range/adaptor/sliced.hpp b/include/boost/range/adaptor/sliced.hpp index b88597d..a09cbd0 100755 --- a/include/boost/range/adaptor/sliced.hpp +++ b/include/boost/range/adaptor/sliced.hpp @@ -14,6 +14,7 @@ #include #include #include +#include namespace boost { @@ -44,6 +45,9 @@ namespace boost inline sliced_range slice( RandomAccessRange& rng, std::size_t t, std::size_t u ) { + BOOST_RANGE_CONCEPT_ASSERT(( + RandomAccessRangeConcept)); + BOOST_ASSERT( t <= u && "error in slice indices" ); BOOST_ASSERT( static_cast(boost::size(rng)) >= u && "second slice index out of bounds" ); @@ -55,6 +59,9 @@ namespace boost inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > slice( const RandomAccessRange& rng, std::size_t t, std::size_t u ) { + BOOST_RANGE_CONCEPT_ASSERT(( + RandomAccessRangeConcept)); + BOOST_ASSERT( t <= u && "error in slice indices" ); BOOST_ASSERT( static_cast(boost::size(rng)) >= u && "second slice index out of bounds" ); @@ -66,6 +73,9 @@ namespace boost inline sliced_range operator|( RandomAccessRange& r, const sliced& f ) { + BOOST_RANGE_CONCEPT_ASSERT(( + RandomAccessRangeConcept)); + return sliced_range( r, f.t, f.u ); } @@ -73,6 +83,9 @@ namespace boost inline sliced_range operator|( const RandomAccessRange& r, const sliced& f ) { + BOOST_RANGE_CONCEPT_ASSERT(( + RandomAccessRangeConcept)); + return sliced_range( r, f.t, f.u ); } diff --git a/include/boost/range/adaptor/transformed.hpp b/include/boost/range/adaptor/transformed.hpp index d18c73c..9edd27c 100755 --- a/include/boost/range/adaptor/transformed.hpp +++ b/include/boost/range/adaptor/transformed.hpp @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -57,20 +58,27 @@ namespace boost } }; - template< class InputRng, class UnaryFunction > - inline transformed_range - operator|( InputRng& r, + template< class SinglePassRange, class UnaryFunction > + inline transformed_range + operator|( SinglePassRange& r, const transform_holder& f ) { - return transformed_range( f.val, r ); + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + + return transformed_range( f.val, r ); } - template< class InputRng, class UnaryFunction > - inline transformed_range - operator|( const InputRng& r, + template< class SinglePassRange, class UnaryFunction > + inline transformed_range + operator|( const SinglePassRange& r, const transform_holder& f ) { - return transformed_range( f.val, r ); + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + + return transformed_range( + f.val, r); } } // 'range_detail' @@ -86,18 +94,25 @@ namespace boost range_detail::forwarder(); } - template - inline transformed_range - transform(InputRange& rng, UnaryFunction fn) + template + inline transformed_range + transform(SinglePassRange& rng, UnaryFunction fn) { - return transformed_range(fn, rng); + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + + return transformed_range(fn, rng); } - template - inline transformed_range - transform(const InputRange& rng, UnaryFunction fn) + template + inline transformed_range + transform(const SinglePassRange& rng, UnaryFunction fn) { - return transformed_range(fn, rng); + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + + return transformed_range( + fn, rng); } } // 'adaptors' diff --git a/include/boost/range/adaptor/type_erased.hpp b/include/boost/range/adaptor/type_erased.hpp index 80bc712..2298de6 100644 --- a/include/boost/range/adaptor/type_erased.hpp +++ b/include/boost/range/adaptor/type_erased.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include namespace boost @@ -56,6 +57,9 @@ namespace boost , Buffer >) { + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + typedef typename any_range_type_generator< SinglePassRange , Value @@ -92,6 +96,9 @@ namespace boost , Buffer >) { + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + typedef typename any_range_type_generator< const SinglePassRange , Value @@ -129,6 +136,9 @@ namespace boost > = type_erased<>() ) { + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + typedef typename any_range_type_generator< SinglePassRange , Value @@ -167,6 +177,9 @@ namespace boost > = type_erased<>() ) { + BOOST_RANGE_CONCEPT_ASSERT(( + SinglePassRangeConcept)); + typedef typename any_range_type_generator< const SinglePassRange , Value diff --git a/include/boost/range/adaptor/uniqued.hpp b/include/boost/range/adaptor/uniqued.hpp index 40c8249..29101d3 100755 --- a/include/boost/range/adaptor/uniqued.hpp +++ b/include/boost/range/adaptor/uniqued.hpp @@ -12,6 +12,7 @@ #define BOOST_RANGE_ADAPTOR_UNIQUED_IMPL_HPP #include +#include namespace boost { @@ -47,6 +48,7 @@ namespace boost operator|( ForwardRng& r, unique_forwarder ) { + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); return uniqued_range(r); } @@ -55,6 +57,7 @@ namespace boost operator|( const ForwardRng& r, unique_forwarder ) { + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); return uniqued_range(r); } @@ -74,6 +77,7 @@ namespace boost inline uniqued_range unique(ForwardRange& rng) { + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); return uniqued_range(rng); } @@ -81,6 +85,9 @@ namespace boost inline uniqued_range unique(const ForwardRange& rng) { + BOOST_RANGE_CONCEPT_ASSERT(( + ForwardRangeConcept)); + return uniqued_range(rng); } } // 'adaptors' diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 4354c3f..187b78d 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -32,6 +32,30 @@ rule range-test ( name : includes * ) test-suite range : [ compile-fail compile_fail/iterator_range1.cpp ] + [ compile-fail compile_fail/adaptor/adjacent_filtered_concept.cpp ] + [ compile-fail compile_fail/adaptor/adjacent_filtered_concept2.cpp ] + [ compile-fail compile_fail/adaptor/adjacent_filtered_concept3.cpp ] + [ compile-fail compile_fail/adaptor/adjacent_filtered_concept4.cpp ] + [ compile-fail compile_fail/adaptor/copied_concept.cpp ] + [ compile-fail compile_fail/adaptor/copied_concept2.cpp ] + [ compile-fail compile_fail/adaptor/copied_concept3.cpp ] + [ compile-fail compile_fail/adaptor/copied_concept4.cpp ] + [ compile-fail compile_fail/adaptor/filtered_concept.cpp ] + [ compile-fail compile_fail/adaptor/filtered_concept2.cpp ] + [ compile-fail compile_fail/adaptor/filtered_concept3.cpp ] + [ compile-fail compile_fail/adaptor/filtered_concept4.cpp ] + [ compile-fail compile_fail/adaptor/reversed_concept.cpp ] + [ compile-fail compile_fail/adaptor/reversed_concept2.cpp ] + [ compile-fail compile_fail/adaptor/reversed_concept3.cpp ] + [ compile-fail compile_fail/adaptor/reversed_concept4.cpp ] + [ compile-fail compile_fail/adaptor/sliced_concept.cpp ] + [ compile-fail compile_fail/adaptor/sliced_concept2.cpp ] + [ compile-fail compile_fail/adaptor/sliced_concept3.cpp ] + [ compile-fail compile_fail/adaptor/sliced_concept4.cpp ] + [ compile-fail compile_fail/adaptor/uniqued_concept.cpp ] + [ compile-fail compile_fail/adaptor/uniqued_concept2.cpp ] + [ compile-fail compile_fail/adaptor/uniqued_concept3.cpp ] + [ compile-fail compile_fail/adaptor/uniqued_concept4.cpp ] [ range-test adaptor_test/adjacent_filtered ] [ range-test adaptor_test/copied ] [ range-test adaptor_test/filtered ] diff --git a/test/compile_fail/adaptor/adjacent_filtered_concept.cpp b/test/compile_fail/adaptor/adjacent_filtered_concept.cpp new file mode 100644 index 0000000..e67215d --- /dev/null +++ b/test/compile_fail/adaptor/adjacent_filtered_concept.cpp @@ -0,0 +1,39 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +namespace +{ + +struct always_true +{ + typedef bool result_type; + + bool operator()(int, int) const + { + return true; + } +}; + +} // anonymous namespace + +int main(int, const char**) +{ + using boost::range::unit_test::mock_range; + using boost::adaptors::adjacent_filtered; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adjacent_filtered adaptor takes at least a + // ForwardRange. + return (mock_range() | + adjacent_filtered(always_true())).front(); +} diff --git a/test/compile_fail/adaptor/adjacent_filtered_concept2.cpp b/test/compile_fail/adaptor/adjacent_filtered_concept2.cpp new file mode 100644 index 0000000..160f7c9 --- /dev/null +++ b/test/compile_fail/adaptor/adjacent_filtered_concept2.cpp @@ -0,0 +1,39 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +namespace +{ + +struct always_true +{ + typedef bool result_type; + + bool operator()(int, int) const + { + return true; + } +}; + +} // anonymous namespace + +int main(int, const char**) +{ + using boost::range::unit_test::mock_const_range; + using boost::adaptors::adjacent_filtered; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adjacent_filtered adaptor takes at least a + // ForwardRange. + return (mock_const_range() | + adjacent_filtered(always_true())).front(); +} diff --git a/test/compile_fail/adaptor/adjacent_filtered_concept3.cpp b/test/compile_fail/adaptor/adjacent_filtered_concept3.cpp new file mode 100644 index 0000000..310ac21 --- /dev/null +++ b/test/compile_fail/adaptor/adjacent_filtered_concept3.cpp @@ -0,0 +1,40 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +namespace +{ + +struct always_true +{ + typedef bool result_type; + + bool operator()(int, int) const + { + return true; + } +}; + +} // anonymous namespace + +int main(int, const char**) +{ + using boost::range::unit_test::mock_range; + using boost::adaptors::adjacent_filter; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adjacent_filtered adaptor takes at least a + // ForwardRange. + return adjacent_filter( + mock_range(), + always_true()).front(); +} diff --git a/test/compile_fail/adaptor/adjacent_filtered_concept4.cpp b/test/compile_fail/adaptor/adjacent_filtered_concept4.cpp new file mode 100644 index 0000000..f84b31e --- /dev/null +++ b/test/compile_fail/adaptor/adjacent_filtered_concept4.cpp @@ -0,0 +1,40 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +namespace +{ + +struct always_true +{ + typedef bool result_type; + + bool operator()(int, int) const + { + return true; + } +}; + +} // anonymous namespace + +int main(int, const char**) +{ + using boost::range::unit_test::mock_const_range; + using boost::adaptors::adjacent_filter; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adjacent_filtered adaptor takes at least a + // ForwardRange. + return adjacent_filter( + mock_const_range(), + always_true()).front(); +} diff --git a/test/compile_fail/adaptor/copied_concept.cpp b/test/compile_fail/adaptor/copied_concept.cpp new file mode 100644 index 0000000..27e7f72 --- /dev/null +++ b/test/compile_fail/adaptor/copied_concept.cpp @@ -0,0 +1,24 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include +#include + +int main(int, const char**) +{ + using boost::range::unit_test::mock_range; + using boost::adaptors::copied; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adaptor takes at least a RandomAccessRange. + return (mock_range() | + copied(0,1)).front(); +} diff --git a/test/compile_fail/adaptor/copied_concept2.cpp b/test/compile_fail/adaptor/copied_concept2.cpp new file mode 100644 index 0000000..5df8ab6 --- /dev/null +++ b/test/compile_fail/adaptor/copied_concept2.cpp @@ -0,0 +1,24 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include +#include + +int main(int, const char**) +{ + using boost::range::unit_test::mock_const_range; + using boost::adaptors::copied; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adaptor takes at least a RandomAccessRange. + return (mock_const_range() | + copied(0,1)).front(); +} diff --git a/test/compile_fail/adaptor/copied_concept3.cpp b/test/compile_fail/adaptor/copied_concept3.cpp new file mode 100644 index 0000000..da1659f --- /dev/null +++ b/test/compile_fail/adaptor/copied_concept3.cpp @@ -0,0 +1,23 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include +#include + +int main(int, const char**) +{ + using boost::range::unit_test::mock_range; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adaptor takes at least a RandomAccessRange. + return boost::adaptors::copy( + mock_range(), 0, 1).front(); +} diff --git a/test/compile_fail/adaptor/copied_concept4.cpp b/test/compile_fail/adaptor/copied_concept4.cpp new file mode 100644 index 0000000..3df0a6c --- /dev/null +++ b/test/compile_fail/adaptor/copied_concept4.cpp @@ -0,0 +1,24 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include +#include + +int main(int, const char**) +{ + using boost::range::unit_test::mock_const_range; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adaptor takes at least a RandomAccessRange. + return boost::adaptors::copy( + mock_const_range(), + 0, 1).front(); +} diff --git a/test/compile_fail/adaptor/filtered_concept.cpp b/test/compile_fail/adaptor/filtered_concept.cpp new file mode 100644 index 0000000..4242d3c --- /dev/null +++ b/test/compile_fail/adaptor/filtered_concept.cpp @@ -0,0 +1,38 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +namespace +{ + +struct always_true +{ + typedef bool result_type; + + bool operator()(int) const + { + return true; + } +}; + +} // anonymous namespace + +int main(int, const char**) +{ + using boost::range::unit_test::mock_range; + using boost::adaptors::filtered; + + // This next line should fail when Boost.Range concept checking is + // enabled since the filtered adaptor takes at least a ForwardRange. + return (mock_range() | + filtered(always_true())).front(); +} diff --git a/test/compile_fail/adaptor/filtered_concept2.cpp b/test/compile_fail/adaptor/filtered_concept2.cpp new file mode 100644 index 0000000..d184eb0 --- /dev/null +++ b/test/compile_fail/adaptor/filtered_concept2.cpp @@ -0,0 +1,38 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +namespace +{ + +struct always_true +{ + typedef bool result_type; + + bool operator()(int) const + { + return true; + } +}; + +} // anonymous namespace + +int main(int, const char**) +{ + using boost::range::unit_test::mock_const_range; + using boost::adaptors::filtered; + + // This next line should fail when Boost.Range concept checking is + // enabled since the filtered adaptor takes at least a ForwardRange. + return (mock_const_range() | + filtered(always_true())).front(); +} diff --git a/test/compile_fail/adaptor/filtered_concept3.cpp b/test/compile_fail/adaptor/filtered_concept3.cpp new file mode 100644 index 0000000..6a30185 --- /dev/null +++ b/test/compile_fail/adaptor/filtered_concept3.cpp @@ -0,0 +1,38 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +namespace +{ + +struct always_true +{ + typedef bool result_type; + + bool operator()(int) const + { + return true; + } +}; + +} // anonymous namespace + +int main(int, const char**) +{ + using boost::range::unit_test::mock_range; + + // This next line should fail when Boost.Range concept checking is + // enabled since the filtered adaptor takes at least a ForwardRange. + return boost::adaptors::filter( + mock_range(), + always_true()).front(); +} diff --git a/test/compile_fail/adaptor/filtered_concept4.cpp b/test/compile_fail/adaptor/filtered_concept4.cpp new file mode 100644 index 0000000..8d21bba --- /dev/null +++ b/test/compile_fail/adaptor/filtered_concept4.cpp @@ -0,0 +1,38 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +namespace +{ + +struct always_true +{ + typedef bool result_type; + + bool operator()(int) const + { + return true; + } +}; + +} // anonymous namespace + +int main(int, const char**) +{ + using boost::range::unit_test::mock_const_range; + + // This next line should fail when Boost.Range concept checking is + // enabled since the filtered adaptor takes at least a ForwardRange. + return boost::adaptors::filter( + mock_const_range(), + always_true()).front(); +} diff --git a/test/compile_fail/adaptor/mock_iterator.hpp b/test/compile_fail/adaptor/mock_iterator.hpp new file mode 100644 index 0000000..97f67a9 --- /dev/null +++ b/test/compile_fail/adaptor/mock_iterator.hpp @@ -0,0 +1,82 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// +#ifndef BOOST_RANGE_UNIT_TEST_ADAPTOR_MOCK_ITERATOR_HPP_INCLUDED +#define BOOST_RANGE_UNIT_TEST_ADAPTOR_MOCK_ITERATOR_HPP_INCLUDED + +#include + +namespace boost +{ + namespace range + { + namespace unit_test + { + +template +class mock_iterator + : public boost::iterator_facade< + mock_iterator, + int, + TraversalTag, + const int& + > +{ +public: + mock_iterator() + : m_value(0) + { + } + + explicit mock_iterator(int value) + : m_value(value) + { + } + +private: + + void increment() + { + ++m_value; + } + + void decrement() + { + --m_value; + } + + bool equal(const mock_iterator& other) const + { + return m_value == other.m_value; + } + + void advance(std::ptrdiff_t offset) + { + m_value += offset; + } + + std::ptrdiff_t distance_to(const mock_iterator& other) const + { + return other.m_value - m_value; + } + + const int& dereference() const + { + return m_value; + } + + int m_value; + friend class boost::iterator_core_access; +}; + + } // namespace unit_test + } // namespace range +} // namespace boost + +#endif // include guard diff --git a/test/compile_fail/adaptor/mock_range.hpp b/test/compile_fail/adaptor/mock_range.hpp new file mode 100644 index 0000000..18fe2fa --- /dev/null +++ b/test/compile_fail/adaptor/mock_range.hpp @@ -0,0 +1,50 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// +#ifndef BOOST_RANGE_UNIT_TEST_ADAPTOR_MOCK_RANGE_HPP_INCLUDED +#define BOOST_RANGE_UNIT_TEST_ADAPTOR_MOCK_RANGE_HPP_INCLUDED + +#include "mock_iterator.hpp" +#include + +namespace boost +{ + namespace range + { + namespace unit_test + { + +// Make a non-empty range that models the corresponding range concept. +// This is only useful in unit tests. It is main use is to help test concepts +// assertions are present. +template +iterator_range >& + mock_range() +{ + static iterator_range > instance( + mock_iterator(0), + mock_iterator(1)); + return instance; +} + +template +const iterator_range >& + mock_const_range() +{ + static iterator_range > instance( + mock_iterator(0), + mock_iterator(1)); + return instance; +} + + } // namespace unit_test + } // namespace range +} // namespace boost + +#endif // include guard diff --git a/test/compile_fail/adaptor/reversed_concept.cpp b/test/compile_fail/adaptor/reversed_concept.cpp new file mode 100644 index 0000000..5ad0041 --- /dev/null +++ b/test/compile_fail/adaptor/reversed_concept.cpp @@ -0,0 +1,23 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +int main(int, const char**) +{ + using boost::range::unit_test::mock_range; + using boost::adaptors::reversed; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adaptor takes at least a BidirectionalRange. + return (mock_range() | reversed).front(); +} + diff --git a/test/compile_fail/adaptor/reversed_concept2.cpp b/test/compile_fail/adaptor/reversed_concept2.cpp new file mode 100644 index 0000000..e2b8cb6 --- /dev/null +++ b/test/compile_fail/adaptor/reversed_concept2.cpp @@ -0,0 +1,23 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +int main(int, const char**) +{ + using boost::range::unit_test::mock_const_range; + using boost::adaptors::reversed; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adaptor takes at least a BidirectionalRange. + return (mock_const_range() | reversed).front(); +} + diff --git a/test/compile_fail/adaptor/reversed_concept3.cpp b/test/compile_fail/adaptor/reversed_concept3.cpp new file mode 100644 index 0000000..619dfa8 --- /dev/null +++ b/test/compile_fail/adaptor/reversed_concept3.cpp @@ -0,0 +1,23 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +int main(int, const char**) +{ + using boost::range::unit_test::mock_range; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adaptor takes at least a BidirectionalRange. + return boost::adaptors::reverse( + mock_range()).front(); +} + diff --git a/test/compile_fail/adaptor/reversed_concept4.cpp b/test/compile_fail/adaptor/reversed_concept4.cpp new file mode 100644 index 0000000..0e183ee --- /dev/null +++ b/test/compile_fail/adaptor/reversed_concept4.cpp @@ -0,0 +1,23 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +int main(int, const char**) +{ + using boost::range::unit_test::mock_const_range; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adaptor takes at least a BidirectionalRange. + return boost::adaptors::reverse( + mock_const_range()).front(); +} + diff --git a/test/compile_fail/adaptor/sliced_concept.cpp b/test/compile_fail/adaptor/sliced_concept.cpp new file mode 100644 index 0000000..08a653f --- /dev/null +++ b/test/compile_fail/adaptor/sliced_concept.cpp @@ -0,0 +1,23 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +int main(int, const char**) +{ + using boost::range::unit_test::mock_range; + using boost::adaptors::sliced; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adaptor takes at least a RandomAccessRange. + return (mock_range() | + sliced(0,1)).front(); +} diff --git a/test/compile_fail/adaptor/sliced_concept2.cpp b/test/compile_fail/adaptor/sliced_concept2.cpp new file mode 100644 index 0000000..9965020 --- /dev/null +++ b/test/compile_fail/adaptor/sliced_concept2.cpp @@ -0,0 +1,23 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +int main(int, const char**) +{ + using boost::range::unit_test::mock_const_range; + using boost::adaptors::sliced; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adaptor takes at least a RandomAccessRange. + return (mock_const_range() | + sliced(0,1)).front(); +} diff --git a/test/compile_fail/adaptor/sliced_concept3.cpp b/test/compile_fail/adaptor/sliced_concept3.cpp new file mode 100644 index 0000000..1274911 --- /dev/null +++ b/test/compile_fail/adaptor/sliced_concept3.cpp @@ -0,0 +1,22 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +int main(int, const char**) +{ + using boost::range::unit_test::mock_range; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adaptor takes at least a RandomAccessRange. + return boost::adaptors::slice( + mock_range(), 0, 1).front(); +} diff --git a/test/compile_fail/adaptor/sliced_concept4.cpp b/test/compile_fail/adaptor/sliced_concept4.cpp new file mode 100644 index 0000000..c7f8206 --- /dev/null +++ b/test/compile_fail/adaptor/sliced_concept4.cpp @@ -0,0 +1,22 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +int main(int, const char**) +{ + using boost::range::unit_test::mock_const_range; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adaptor takes at least a RandomAccessRange. + return boost::adaptors::slice( + mock_const_range(), 0, 1).front(); +} diff --git a/test/compile_fail/adaptor/uniqued_concept.cpp b/test/compile_fail/adaptor/uniqued_concept.cpp new file mode 100644 index 0000000..bbaaf11 --- /dev/null +++ b/test/compile_fail/adaptor/uniqued_concept.cpp @@ -0,0 +1,22 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +int main(int, const char**) +{ + using boost::range::unit_test::mock_range; + using boost::adaptors::uniqued; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adaptor takes at least a ForwardRange. + return (mock_range() | uniqued).front(); +} diff --git a/test/compile_fail/adaptor/uniqued_concept2.cpp b/test/compile_fail/adaptor/uniqued_concept2.cpp new file mode 100644 index 0000000..a390d13 --- /dev/null +++ b/test/compile_fail/adaptor/uniqued_concept2.cpp @@ -0,0 +1,23 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +int main(int, const char**) +{ + using boost::range::unit_test::mock_const_range; + using boost::adaptors::uniqued; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adaptor takes at least a ForwardRange. + return (mock_const_range() | + uniqued).front(); +} diff --git a/test/compile_fail/adaptor/uniqued_concept3.cpp b/test/compile_fail/adaptor/uniqued_concept3.cpp new file mode 100644 index 0000000..fea058c --- /dev/null +++ b/test/compile_fail/adaptor/uniqued_concept3.cpp @@ -0,0 +1,22 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +int main(int, const char**) +{ + using boost::range::unit_test::mock_range; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adaptor takes at least a ForwardRange. + return boost::adaptors::unique( + mock_range()).front(); +} diff --git a/test/compile_fail/adaptor/uniqued_concept4.cpp b/test/compile_fail/adaptor/uniqued_concept4.cpp new file mode 100644 index 0000000..1e02390 --- /dev/null +++ b/test/compile_fail/adaptor/uniqued_concept4.cpp @@ -0,0 +1,22 @@ +// Boost.Range library +// +// Copyright Neil Groves 2014. Use, modification and distribution is subject +// to 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) +// +// For more information, see http://www.boost.org/libs/range +// + +#include "mock_range.hpp" +#include + +int main(int, const char**) +{ + using boost::range::unit_test::mock_const_range; + + // This next line should fail when Boost.Range concept checking is + // enabled since the adaptor takes at least a ForwardRange. + return boost::adaptors::unique( + mock_const_range()).front(); +}