diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index fd54f7a..e286110 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -9,25 +9,36 @@ #// -use-project boost : $(BOOST_ROOT) ; - +#use-project boost : $(BOOST_ROOT) ; +project boost/libs/range/doc ; import boostbook : boostbook ; -import quickbook ; +#import quickbook ; +using quickbook ; -xml boost_range : boost_range.qbk ; +path-constant images_location : html ; -boostbook standalone +#xml boost_range : boost_range.qbk ; + +#boostbook standalone + +boostbook quickbook : - boost_range + boost_range.qbk : - toc.max.depth=2 - toc.section.depth=4 - chunk.section.depth=2 + boost.root=../../../.. + boost.libraries=../../../libraries.htm + html.stylesheet=../../../../doc/html/boostbook.css + chunk.section.depth=4 + chunk.first.sections=1 + toc.section.depth=3 + toc.max.depth=3 + generate.section.toc.level=4 # generate.section.toc.level=4 # chunk.first.sections=7 # toc.section.depth=10 pdf:boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html + pdf:img.src.path=$(images_location)/ ; diff --git a/doc/boost_range.qbk b/doc/boost_range.qbk index 80b5c8c..45af6c4 100644 --- a/doc/boost_range.qbk +++ b/doc/boost_range.qbk @@ -1,7 +1,16 @@ -[article Boost.Range Documentation - [quickbook 1.3] - [id boost.range] - [copyright 2003-2007 Thorsten Ottosen] +[/============================================================================== + Copyright (C) 2003-2010 Thorsten Ottosen, Neil Groves + + 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 +==============================================================================/] +[library Range + [quickbook 1.5] + [version 2.0] + [authors [Ottosen, Thorsten], [Groves, Neil]] + [copyright 2003-2010 Thorsten Ottosen, Neil Groves] + [purpose Half-open range library] [license Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -11,19 +20,49 @@ [/ Converted to Quickbook format by Darren Garvey, 2007] -[def __ranges__ [link boost.range.concepts Ranges]] -[def __range_concepts__ [link boost.range.concepts Range concepts]] -[def __forward_range__ [link boost.range.concepts.forward_range Forward Range]] -[def __single_pass_range__ [link boost.range.concepts.single_pass_range Single Pass Range]] -[def __bidirectional_range__ [link boost.range.concepts.bidirectional_range Bidirectional Range]] -[def __random_access_range__ [link boost.range.concepts.random_access_range Random Access Range]] +[def __note__ [$images/note.png]] +[def __alert__ [$images/alert.png]] +[def __tip__ [$images/tip.png]] +[def __caution__ [$images/caution.png]] -[def __iterator_range__ [link boost.range.utilities.iterator_range `iterator_range`]] -[def __sub_range__ [link boost.range.utilities.sub_range `sub_range`]] -[def __minimal_interface__ [link boost.range.reference.extending minimal interface]] -[def __range_result_iterator__ [link boost.range.reference.semantics.metafunctions `range_result_iterator`]] -[def __implementation_of_metafunctions__ [link boost.range.reference.semantics.metafunctions implementation of metafunctions]] -[def __implementation_of_functions__ [link boost.range.reference.semantics.functions implementation of functions]] +[def __boost_range_home__ [link range Boost.Range]] +[def __ranges__ [link range.concepts Ranges]] +[def __range_concepts__ [link range.concepts Range concepts]] +[def __forward_range__ [link range.concepts.forward_range Forward Range]] +[def __single_pass_range__ [link range.concepts.single_pass_range Single Pass Range]] +[def __bidirectional_range__ [link range.concepts.bidirectional_range Bidirectional Range]] +[def __random_access_range__ [link range.concepts.random_access_range Random Access Range]] + +[def __iterator_range__ [link range.utilities.iterator_range `iterator_range`]] +[def __sub_range__ [link range.utilities.sub_range `sub_range`]] +[def __minimal_interface__ [link range.reference.extending minimal interface]] +[def __range_result_iterator__ [link range.reference.semantics.metafunctions `range_result_iterator`]] +[def __extending_for_udts__ [link range.reference.extending Extending the library for UDTs]] +[def __implementation_of_metafunctions__ [link range.reference.semantics.metafunctions Implementation of metafunctions]] +[def __implementation_of_functions__ [link range.reference.semantics.functions Implementation of functions]] + +[def __range_value__ [link range.reference.semantics.metafunctions `range_value`]] +[def __range_iterator__ [link range.reference.semantics.metafunctions `range_iterator`]] +[def __range_difference__ [link range.reference.semantics.metafunctions `range_difference`]] +[def __range_pointer__ [link range.reference.semantics.metafunctions `range_pointer`]] +[def __range_category__ [link range.reference.semantics.metafunctions `range_category`]] +[def __range_reverse_iterator__ [link range.reference.semantics.metafunctions `range_reverse_iterator`]] +[def __begin__ [link range.reference.semantics.functions `begin`]] +[def __const_begin__ [link range.reference.semantics.functions `const_begin`]] +[def __end__ [link range.reference.semantics.functions `end`]] +[def __const_end__ [link range.reference.semantics.functions `const_end`]] +[def __empty__ [link range.reference.semantics.functions `empty`]] +[def __distance__ [link range.reference.semantics.functions `distance`]] +[def __size__ [link range.reference.semantics.functions `size`]] +[def __rbegin__ [link range.reference.semantics.functions `rbegin`]] +[def __const_rbegin__ [link range.reference.semantics.functions `const_rbegin`]] +[def __rend__ [link range.reference.semantics.functions `rend`]] +[def __const_rend__ [link range.reference.semantics.functions `const_rend`]] +[def __as_array__ [link range.reference.semantics.functions `as_array`]] +[def __as_literal__ [link range.reference.semantics.functions `as_literal`]] + +[def __range_adaptors__ [link range.reference.adaptors Range adaptors]] +[def __range_algorithms__ [link range.reference.algorithms Range algorithms]] [def __single_pass_iterator__ [@../../libs/iterator/doc/new-iter-concepts.html#singls-pass-iterators-lib-single-pass-iterators Single Pass Iterator]] [def __forward_traversal_iterator__ [@../../libs/iterator/doc/new-iter-concepts.html#forward-traversal-iterators-lib-forward-traversal-iterators Forward Traversal Iterator]] @@ -38,1197 +77,20 @@ [def __boost_array__ [@../../libs/array/index.html boost::array]] [def __the_forwarding_problem__ [@http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2002/n1385.htm The Forwarding Problem]] +[def __sgi_inner_product__ [@http://www.sgi.com/tech/stl/inner_product.html inner_product]] +[def __sgi_partial_sum__ [@http://www.sgi.com/tech/stl/partial_sum.html partial_sum]] Boost.Range is a collection of concepts and utilities that are particularly useful for specifying and implementing generic algorithms. +[include introduction.qbk] +[include concepts.qbk] +[include reference.qbk] +[include utilities.qbk] +[include style.qbk] +[include headers.qbk] +[include examples.qbk] +[include mfc_atl.qbk] +[include upgrade.qbk] +[include portability.qbk] +[include faq.qbk] +[include history_ack.qbk] - -[section Introduction] - -Generic algorithms have so far been specified in terms of two or more iterators. Two iterators would together form a range of values that the algorithm could work on. This leads to a very general interface, but also to a somewhat clumsy use of the algorithms with redundant specification of container names. Therefore we would like to raise the abstraction level for algorithms so they specify their interface in terms of __ranges__ as much as possible. - -The most common form of ranges we are used to work with is standard library containers. However, one often finds it desirable to extend that code to work with other types that offer enough functionality to satisfy the needs of the generic code if a suitable layer of indirection is applied . For example, raw arrays are often suitable for use with generic code that works with containers, provided a suitable adapter is used. Likewise, null terminated strings can be treated as containers of characters, if suitably adapted. - -This library therefore provides the means to adapt standard-like containers, null terminated strings, `std::pairs` of iterators, and raw arrays (and more), such that the same generic code can work with them all. The basic idea is to add another layer of indirection using __metafunctions__ and free-standing functions so syntactic and/or semantic differences can be removed. - -The main advantages are - -* simpler implementation and specification of generic range algorithms -* more flexible, compact and maintainable client code -* correct handling of null-terminated strings - -[:[*Warning: support for null-terminated strings is deprecated and will disappear in the next Boost release (1.34).]] - -* safe use of built-in arrays (for legacy code; why else would you use built-in arrays?) - -Below are given a small example (the complete example can be found [@http://www.boost.org/libs/range/test/algorithm_example.cpp here] ): - -`` - // - // example: extracting bounds in a generic algorithm - // - template< class ForwardReadableRange, class T > - inline typename boost::range_iterator< ForwardReadableRange >::type - find( ForwardReadableRange& c, const T& value ) - { - return std::find( boost::begin( c ), boost::end( c ), value ); - } - - template< class ForwardReadableRange, class T > - inline typename boost::range_const_iterator< ForwardReadableRange >::type - find( const ForwardReadableRange& c, const T& value ) - { - return std::find( boost::begin( c ), boost::end( c ), value ); - } - - // - // replace first value and return its index - // - template< class ForwardReadableWriteableRange, class T > - inline typename boost::range_size< ForwardReadableWriteableRange >::type - my_generic_replace( ForwardReadableWriteableRange& c, const T& value, const T& replacement ) - { - typename boost::range_iterator< ForwardReadableWriteableRange >::type found = find( c, value ); - - if( found != boost::end( c ) ) - *found = replacement; - return std::distance( boost::begin( c ), found ); - } - - // - // usage - // - const int N = 5; - std::vector my_vector; - int values[] = { 1,2,3,4,5,6,7,8,9 }; - - my_vector.assign( values, boost::end( values ) ); - typedef std::vector::iterator iterator; - std::pair my_view( boost::begin( my_vector ), - boost::begin( my_vector ) + N ); - char str_val[] = "a string"; - char* str = str_val; - - std::cout << my_generic_replace( my_vector, 4, 2 ); - std::cout << my_generic_replace( my_view, 4, 2 ); - std::cout << my_generic_replace( str, 'a', 'b' ); - - // prints '3', '5' and '0' -`` - -By using the free-standing functions and __metafunctions__, the code automatically works for all the types supported by this library; now and in the future. Notice that we have to provide two version of `find()` since we cannot forward a non-const rvalue with reference arguments (see this article about __the_forwarding_problem__ ). - -[endsect] - - - -[section:concepts Range Concepts] - -[section Overview] - -A Range is a ['concept] similar to the STL [@http://www.sgi.com/Technology/STL/Container.html Container] concept. A Range provides iterators for accessing a half-open range `[first,one_past_last)` of elements and provides information about the number of elements in the Range. However, a Range has fewer requirements than a Container. - -The motivation for the Range concept is that there are many useful Container-like types that do not meet the full requirements of Container, and many algorithms that can be written with this reduced set of requirements. In particular, a Range does not necessarily - -* own the elements that can be accessed through it, -* have copy semantics, - -Because of the second requirement, a Range object must be passed by (const or non-const) reference in generic code. - -The operations that can be performed on a Range is dependent on the [@../../iterator/doc/new-iter-concepts.html#iterator-traversal-concepts-lib-iterator-traversal traversal category] of the underlying iterator type. Therefore the range concepts are named to reflect which traversal category its iterators support. See also terminology and style guidelines. for more information about naming of ranges. - -The concepts described below specifies associated types as [@../../libs/mpl/doc/refmanual/metafunction.html metafunctions] and all functions as free-standing functions to allow for a layer of indirection. - -[endsect] - - -[section Single Pass Range] - -[h4 Notation] - -`X` A type that is a model of __single_pass_range__. -`a` Object of type X. - -[h4 Description] - -A range `X` where `boost::range_iterator::type` is a model of __single_pass_iterator__. - -[h4 Associated types] - -[table - [] - [[Value type ] [`boost::range_value::type` ] [The type of the object stored in a Range.]] - [[Iterator type ] [`boost::range_iterator::type` ] [The type of iterator used to iterate through a Range's elements. The iterator's value type is expected to be the Range's value type. A conversion from the iterator type to the `const` iterator type must exist.]] - [[Const iterator type] [`boost::range_const_iterator::type`] [A type of iterator that may be used to examine, but not to modify, a Range's elements.]] -] - -[h4 Valid expressions] - -The following expressions must be valid. - -[table - [[Name ] [Expression ] [Return type ]] - [[Beginning of range] [`boost::begin(a)`] [`boost::range_iterator::type` if `a` is mutable,[br] `boost::range_const_iterator::type` otherwise]] - [[End of range ] [`boost::end(a)` ] [`boost::range_iterator::type` if `a` is mutable,[br] `boost::range_const_iterator::type` otherwise]] - [[Is range empty? ] [boost::empty(a) ] [Convertible to bool]] -] - -[h4 Expression semantics] - -[table - [[Expression ] [Semantics ] [Postcondition]] - [[`boost::begin(a)`] [Returns an iterator pointing to the first element in the Range. ] [`boost::begin(a)` is either dereferenceable or past-the-end. It is past-the-end if and only if `boost::size(a) == 0`.]] - [[`boost::end(a)` ] [Returns an iterator pointing one past the last element in the Range. ] [`boost::end(a)` is past-the-end.]] - [[`boost::empty(a)`] [Equivalent to `boost::begin(a) == boost::end(a)`. (But possibly faster.)] [- ]] -] - -[h4 Complexity guarantees] - -All three functions are at most amortized linear time. For most practical purposes, one can expect `boost::begin(a)`, `boost::end(a)` and `boost::empty(a)` to be amortized constant time. - -[h4 Invariants] - -[table - [] - [[Valid range ] [For any Range `a`, `[boost::begin(a),boost::end(a))` is a valid range, that is, `boost::end(a)` is reachable from `boost::begin(a)` in a finite number of increments.]] - - [[Completeness] [An algorithm that iterates through the range `[boost::begin(a),boost::end(a))` will pass through every element of `a`.]] -] - -[h4 See also] - -__container__ - -__implementation_of_metafunctions__ - -__implementation_of_functions__ - -[endsect] - - -[section Forward Range] - -[h4 Notation] - -`X` A type that is a model of __forward_range__. -`a` Object of type X. - -[h4 Description] - -A range `X` where `boost::range_iterator::type` is a model of __forward_traversal_iterator__. - -[h4 Refinement of] - -__single_pass_range__ - -[h4 Associated types] - -[table - [] - [[Distance type] [`boost::range_difference::type`] [A signed integral type used to represent the distance between two of the Range's iterators. This type must be the same as the iterator's distance type.]] - [[Size type ] [`boost::range_size::type` ] [An unsigned integral type that can represent any nonnegative value of the Range's distance type.]] -] - -[h4 Valid expressions] - -[table - [[Name ] [Expression ] [Return type ]] - [[Size of range] [`boost::size(a)`] [`boost::range_size::type`]] -] - -[h4 Expression semantics] - -[table - [[Expression ] [Semantics] [Postcondition]] - [[`boost::size(a)`] [Returns the size of the Range, that is, its number of elements. Note `boost::size(a) == 0u` is equivalent to `boost::empty(a)`.] [`boost::size(a) >= 0`]] -] - -[h4 Complexity guarantees] - -`boost::size(a)` is at most amortized linear time. - -[h4 Invariants] - -[table - [] - [[Range size] [`boost::size(a)` is equal to the distance from `boost::begin(a)` to `boost::end(a)`.]] -] - -[h4 See also] - -__implementation_of_metafunctions__ - -__implementation_of_functions__ - -[endsect] - - -[section Bidirectional Range] - -[h4 Notation] - -`X` A type that is a model of __bidirectional_range__. -`a` Object of type X. - -[h4 Description] - -This concept provides access to iterators that traverse in both directions (forward and reverse). The `boost::range_iterator::type` iterator must meet all of the requirements of __bidirectional_traversal_iterator__. - -[h4 Refinement of] - -__forward_range__ - -[h4 Associated types] - -[table - [] - [[Reverse Iterator type ] [`boost::range_reverse_iterator::type` ] [The type of iterator used to iterate through a Range's elements in reverse order. The iterator's value type is expected to be the Range's value type. A conversion from the reverse iterator type to the const reverse iterator type must exist.]] - - [[Const reverse iterator type] [`boost::range_const_reverse_iterator::type`] [A type of reverse iterator that may be used to examine, but not to modify, a Range's elements.]] -] - -[h4 Valid expressions] - -[table - [[Name ] [Expression ] [Return type] [Semantics]] - [[Beginning of range] [`boost::rbegin(a)`] [`boost::range_reverse_iterator::type` if `a` is mutable[br] `boost::range_const_reverse_iterator::type` otherwise.] [Equivalent to `boost::range_reverse_iterator::type(boost::end(a))`.]] - - [[End of range ] [`boost::rend(a)` ] [`boost::range_reverse_iterator::type` if `a` is mutable,[br] `boost::range_const_reverse_iterator::type` otherwise.] [Equivalent to `boost::range_reverse_iterator::type(boost::begin(a))`.]] -] - -[h4 Complexity guarantees] - -`boost::rbegin(a)` has the same complexity as `boost::end(a)` and `boost::rend(a)` has the same complexity as `boost::begin(a)` from __forward_range__. - -[h4 Invariants] - -[table - [] - [[Valid reverse range] [For any Bidirectional Range a, `[boost::rbegin(a),boost::rend(a))` is a valid range, that is, `boost::rend(a)` is reachable from `boost::rbegin(a)` in a finite number of increments.]] - - [[Completeness ] [`An algorithm that iterates through the range `[boost::rbegin(a),boost::rend(a))` will pass through every element of `a`.]] -] - -[h4 See also] - -__implementation_of_metafunctions__ - -__implementation_of_functions__ - -[endsect] - - -[section Random Access Range] - -[h4 Description] - -A range `X` where `boost::range_iterator::type` is a model of __random_access_traversal_iterator__. - -[h4 Refinement of] - -__bidirectional_range__ - -[endsect] - - -[section Concept Checking] - -Each of the range concepts has a corresponding concept checking class in the file [@../../boost/range/concepts.hpp `boost/range/concepts.hpp`]. These classes may be used in conjunction with the __concept_check__ to insure that the type of a template parameter is compatible with a range concept. If not, a meaningful compile time error is generated. Checks are provided for the range concepts related to iterator traversal categories. For example, the following line checks that the type `T` models the __forward_range__ concept. - -`` -function_requires >(); -`` - -An additional concept check is required for the value access property of the range based on the range's iterator type. For example to check for a ForwardReadableRange, the following code is required. - -`` -function_requires >(); - function_requires< - ReadableIteratorConcept< - typename range_iterator::type - > - >(); -`` - -The following range concept checking classes are provided. - -* Class SinglePassRangeConcept checks for __single_pass_range__ -* Class ForwardRangeConcept checks for __forward_range__ -* Class BidirectionalRangeConcept checks for __bidirectional_range__ -* Class RandomAccessRangeConcept checks for __random_access_range__ - -[h4 See also] - -[link boost.range.style_guide Range Terminology and style guidelines] - -__iterator_concepts__ - -__concept_check__ - -[endsect] - -[endsect] - - - -[section Reference] - -[section Overview] - -Four types of objects are currently supported by the library: - -* standard-like containers -* `std::pair` -* null terminated strings (this includes `char[]`,`wchar_t[]`, `char*`, and `wchar_t*`) - -[:[*Warning: ['support for null-terminated strings is deprecated and will disappear in the next Boost release (1.34).]]] - -* built-in arrays - -Even though the behavior of the primary templates are exactly such that standard containers will be supported by default, the requirements are much lower than the standard container requirements. For example, the utility class __iterator_range__ implements the __minimal_interface__ required to make the class a __forward_range__. - -Please also see __range_concepts__ for more details. - -[endsect] - - -[section Synopsis] - -`` -namespace boost -{ - // - // Single Pass Range metafunctions - // - - template< class T > - struct range_value; - - template< class T > - struct range_iterator; - - template< class T > - struct range_const_iterator; - - // - // Forward Range metafunctions - // - - template< class T > - struct range_difference; - - template< class T > - struct range_size; - - // - // Bidirectional Range metafunctions - // - - template< class T > - struct range_reverse_iterator; - - template< class T > - struct range_const_reverse_iterator; - - // - // Special metafunctions - // - - template< class T > - struct range_result_iterator; - - template< class T > - struct range_reverse_result_iterator; - - // - // Single Pass Range functions - // - - template< class T > - typename range_iterator::type - begin( T& c ); - - template< class T > - typename range_const_iterator::type - begin( const T& c ); - - template< class T > - typename range_iterator::type - end( T& c ); - - template< class T > - typename range_const_iterator::type - end( const T& c ); - - template< class T > - bool - empty( const T& c ); - - // - // Forward Range functions - // - - template< class T > - typename range_size::type - size( const T& c ); - - // - // Bidirectional Range functions - // - - template< class T > - typename range_reverse_iterator::type - rbegin( T& c ); - - template< class T > - typename range_const_reverse_iterator::type - rbegin( const T& c ); - - template< class T > - typename range_reverse_iterator::type - rend( T& c ); - - template< class T > - typename range_const_reverse_iterator::type - rend( const T& c ); - - // - // Special const Range functions - // - - template< class T > - typename range_const_iterator::type - const_begin( const T& r ); - - template< class T > - typename range_const_iterator::type - const_end( const T& r ); - - template< class T > - typename range_const_reverse_iterator::type - const_rbegin( const T& r ); - - template< class T > - typename range_const_reverse_iterator::type - const_rend( const T& r ); - -} // namespace 'boost' -`` - -[endsect] - - -[section Semantics] - -[h5 notation] - -[table - [[Type ] [Object] [Describes ]] - [[`X` ] [`x` ] [any type ]] - [[`T` ] [`t` ] [denotes behavior of the primary templates]] - [[`P` ] [`p` ] [denotes `std::pair` ]] - [[`A[sz]`] [`a` ] [denotes an array of type `A` of size `sz`]] - [[`Char*`] [`s` ] [denotes either `char*` or `wchar_t*` ]] -] - -Please notice in tables below that when four lines appear in a cell, the first line will describe the primary template, the second line pairs of iterators, the third line arrays and the last line null-terminated strings. - -[section Metafunctions] - -[table - [[Expression] [Return type] [Complexity]] - [[`range_value::type`] [`T::value_type`[br] -`boost::iterator_value::type`[br] -`A`[br] -`Char`] [compile time]] - [[`range_iterator::type`] [`T::iterator`[br] -`P::first_type`[br] -`A*`[br] -`Char*`] [compile time]] - [[`range_const_iterator::type`] [`T::const_iterator`[br] -`P::first_type`[br] -`const A*`[br] -`const Char*`] [compile time]] - [[`range_difference::type`] [`T::difference_type`[br] -`boost::iterator_difference::type`[br] -`std::ptrdiff_t`[br] -`std::ptrdiff_t`] [compile time]] - [[`range_size::type`] [`T::size_type`[br] -`std::size_t`[br] -`std::size_t`[br] -`std::size_t`] [compile time]] - [[`range_result_iterator::type`] [`range_const_iterator::type` if `X` is `const`[br] -`range_iterator::type` otherwise] [compile time]] - [[`range_reverse_iterator::type`] [`boost::reverse_iterator< typename range_iterator::type >`] [compile time]] - [[`range_const_reverse_iterator::type`] [`boost::reverse_iterator< typename range_const_iterator::type >`] [compile time]] - [[`range_reverse_result_iterator::type`] [`boost::reverse_iterator< typename range_result_iterator::type >`] [compile time]] -] - -The special metafunctions `range_result_iterator` and `range_reverse_result_iterator` are not part of any Range concept, but they are very useful when implementing certain Range classes like __sub_range__ because of their ability to select iterators based on constness. - -[endsect] - -[section Functions] - -[table - [[Expression] [Return type] [Returns] [Complexity]] - - [[`begin(x)`] [`range_result_iterator::type`] [`p.first` if `p` is of type `std::pair`[br] -`a` if `a` is an array[br] -`s` if `s` is a string literal[br] -`boost_range_begin(x)` if that expression would invoke a function found by ADL[br] -`t.begin()` otherwise] [constant time]] - - [[`end(x)`] [`range_result_iterator::type`] [`p.second` if `p` is of type `std::pair`[br] -`a + sz` if `a` is an array of size `sz`[br] -`s + std::char_traits::length( s )` if `s` is a `Char*`[br] -`s + sz - 1` if `s` is a string literal of size `sz`[br] -`boost_range_end(x)` if that expression would invoke a function found by ADL[br] -`t.end()` otherwise] [linear if `X` is `Char*` -constant time otherwise]] - - [[`empty(x)`] [`bool`] [`begin(x) == end( x )`] [linear if `X` is `Char*`[br] -constant time otherwise]] - - [[`size(x)`] [`range_size::type`] [`std::distance(p.first,p.second)` if `p` is of type `std::pair`[br] -`sz` if `a` is an array of size `sz`[br] -`end(s) - s` if `s` is a string literal or a `Char*`[br] -`boost_range_size(x)` if that expression would invoke a function found by ADL[br] -`t.size()` otherwise] [linear if `X` is `Char*` or if `std::distance()` is linear[br] -constant time otherwise]] - - [[`rbegin(x)`] [`range_reverse_result_iterator::type`] [`range_reverse_result_iterator::type( end(x) )`] [same as `end(x)`]] - - [[`rend(x)`] [`range_reverse_result_iterator::type`] [`range_reverse_result_iterator::type( begin(x) )`] [same as `begin(x)`]] - - [[`const_begin(x)`] [`range_const_iterator::type`] [`range_const_iterator::type( begin(x) )`] [same as `begin(x)`]] - - [[`const_end(x)`] [`range_const_iterator::type`] [`range_const_iterator::type( end(x) )`] [same as `end(x)`]] - - [[`const_rbegin(x)`] [`range_const_reverse_iterator::type`] [`range_const_reverse_iterator::type( rbegin(x) )`] [same as `rbegin(x)`]] - - [[`const_rend(x)`] [`range_const_reverse_iterator::type`] [`range_const_reverse_iterator::type( rend(x) )`] [same as `rend(x)`]] -] - -The special const functions are not part of any Range concept, but are very useful when you want to document clearly that your code is read-only. - -[endsect] - -[endsect] - -[section:extending Extending the library] - -[section:method_1 Method 1: provide member functions and nested types] - -This procedure assumes that you have control over the types that should be made conformant to a Range concept. If not, see [link boost.range.reference.extending.method_2 method 2]. - -The primary templates in this library are implemented such that standard containers will work automatically and so will __boost_array__. Below is given an overview of which member functions and member types a class must specify to be useable as a certain Range concept. - -[table - [[Member function] [Related concept ]] - [[`begin()` ] [__single_pass_range__]] - [[`end()` ] [__single_pass_range__]] - [[`size()` ] [__forward_range__ ]] -] - -Notice that `rbegin()` and `rend()` member functions are not needed even though the container can support bidirectional iteration. - -The required member types are: - -[table - [[Member type ] [Related concept ]] - [[`iterator` ] [__single_pass_range__]] - [[`const_iterator`] [__single_pass_range__]] - [[`size_type` ] [__forward_range__ ]] -] - -Again one should notice that member types `reverse_iterator` and `const_reverse_iterator` are not needed. - -[endsect] - -[section:method_2 Method 2: provide free-standing functions and specialize metafunctions] - -This procedure assumes that you cannot (or do not wish to) change the types that should be made conformant to a Range concept. If this is not true, see [link boost.range.reference.extending.method_1 method 1]. - -The primary templates in this library are implemented such that certain functions are found via argument-dependent-lookup (ADL). Below is given an overview of which free-standing functions a class must specify to be useable as a certain Range concept. Let `x` be a variable (`const` or `mutable`) of the class in question. - -[table - [[Function ] [Related concept ]] - [[`boost_range_begin(x)`] [__single_pass_range__]] - [[`boost_range_end(x)` ] [__single_pass_range__]] - [[`boost_range_size(x)` ] [__forward_range__ ]] -] - -`boost_range_begin()` and `boost_range_end()` must be overloaded for both `const` and `mutable` reference arguments. - -You must also specialize 3 metafunctions for your type `X`: - -[table - [[Metafunction ] [Related concept ]] - [[`boost::range_iterator` ] [__single_pass_range__]] - [[`boost::range_const_iterator`] [__single_pass_range__]] - [[`boost::range_size` ] [__forward_range__ ]] -] - -A complete example is given here: - -`` - #include - #include // for std::iterator_traits, std::distance() - - namespace Foo - { - // - // Our sample UDT. A 'Pair' - // will work as a range when the stored - // elements are iterators. - // - template< class T > - struct Pair - { - T first, last; - }; - - } // namespace 'Foo' - - namespace boost - { - // - // Specialize metafunctions. We must include the range.hpp header. - // We must open the 'boost' namespace. - // - - template< class T > - struct range_iterator< Foo::Pair > - { - typedef T type; - }; - - template< class T > - struct range_const_iterator< Foo::Pair > - { - // - // Remark: this is defined similar to 'range_iterator' - // because the 'Pair' type does not distinguish - // between an iterator and a const_iterator. - // - typedef T type; - }; - - template< class T > - struct range_size< Foo::Pair > - { - - typedef std::size_t type; - }; - - } // namespace 'boost' - - namespace Foo - { - // - // The required functions. These should be defined in - // the same namespace as 'Pair', in this case - // in namespace 'Foo'. - // - - template< class T > - inline T boost_range_begin( Pair& x ) - { - return x.first; - } - - template< class T > - inline T boost_range_begin( const Pair& x ) - { - return x.first; - } - - template< class T > - inline T boost_range_end( Pair& x ) - { - return x.last; - } - - template< class T > - inline T boost_range_end( const Pair& x ) - { - return x.last; - } - - template< class T > - inline typename boost::range_size< Pair >::type - boost_range_size( const Pair& x ) - { - return std::distance(x.first,x.last); - } - - } // namespace 'Foo' - - #include - - int main() - { - typedef std::vector::iterator iter; - std::vector vec; - Foo::Pair pair = { vec.begin(), vec.end() }; - const Foo::Pair& cpair = pair; - // - // Notice that we call 'begin' etc with qualification. - // - iter i = boost::begin( pair ); - iter e = boost::end( pair ); - i = boost::begin( cpair ); - e = boost::end( cpair ); - boost::range_size< Foo::Pair >::type s = boost::size( pair ); - s = boost::size( cpair ); - boost::range_const_reverse_iterator< Foo::Pair >::type - ri = boost::rbegin( cpair ), - re = boost::rend( cpair ); - } -`` - -[endsect] - -[endsect] - -[endsect] - - - -[section Utilities] - -Having an abstraction that encapsulates a pair of iterators is very useful. The standard library uses `std::pair` in some circumstances, but that class is cumbersome to use because we need to specify two template arguments, and for all range algorithm purposes we must enforce the two template arguments to be the same. Moreover, `std::pair` is hardly self-documenting whereas more domain specific class names are. Therefore these two classes are provided: - -* Class `iterator_range` -* Class `sub_range` - -The `iterator_range` class is templated on an __forward_traversal_iterator__ and should be used whenever fairly general code is needed. The `sub_range` class is templated on an __forward_range__ and it is less general, but a bit easier to use since its template argument is easier to specify. The biggest difference is, however, that a `sub_range` can propagate constness because it knows what a corresponding `const_iterator` is. - -Both classes can be used as ranges since they implement the __minimal_interface__ required for this to work automatically. - -[section:iterator_range Class `iterator_range`] - -The intention of the `iterator_range` class is to encapsulate two iterators so they fulfill the __forward_range__ concept. A few other functions are also provided for convenience. - -If the template argument is not a model of __forward_traversal_iterator__, one can still use a subset of the interface. In particular, `size()` requires Forward Traversal Iterators whereas `empty()` only requires Single Pass Iterators. - -Recall that many default constructed iterators are singular and hence can only be assigned, but not compared or incremented or anything. However, if one creates a default constructed `iterator_range`, then one can still call all its member functions. This means that the `iterator_range` will still be usable in many contexts even though the iterators underneath are not. - -[h4 Synopsis] - -`` -namespace boost -{ - template< class ForwardTraversalIterator > - class iterator_range - { - public: // Forward Range types - typedef ... value_type; - typedef ... difference_type; - typedef ... size_type; - typedef ForwardTraversalIterator iterator; - typedef ForwardTraversalIterator const_iterator; - - public: // construction, assignment - template< class ForwardTraversalIterator2 > - iterator_range( ForwardTraversalIterator2 Begin, ForwardTraversalIterator2 End ); - - template< class ForwardRange > - iterator_range( ForwardRange& r ); - - template< class ForwardRange > - iterator_range( const ForwardRange& r ); - - template< class ForwardRange > - iterator_range& operator=( ForwardRange& r ); - - template< class ForwardRange > - iterator_range& operator=( const ForwardRange& r ); - - public: // Forward Range functions - iterator begin() const; - iterator end() const; - size_type size() const; - bool empty() const; - - public: // convenience - operator unspecified_bool_type() const; - bool equal( const iterator_range& ) const; - value_type& front() const; - value_type& back() const; - // for Random Access Range only: - value_type& operator[]( size_type at ) const; - }; - - // stream output - template< class ForwardTraversalIterator, class T, class Traits > - std::basic_ostream& - operator<<( std::basic_ostream& Os, - const iterator_range& r ); - - // comparison - template< class ForwardTraversalIterator, class ForwardTraversalIterator2 > - bool operator==( const iterator_range& l, - const iterator_range& r ); - - template< class ForwardTraversalIterator, class ForwardRange > - bool operator==( const iterator_range& l, - const ForwardRange& r ); - - template< class ForwardTraversalIterator, class ForwardRange > - bool operator==( const ForwardRange& l, - const iterator_range& r ); - - template< class ForwardTraversalIterator, class ForwardTraversalIterator2 > - bool operator!=( const iterator_range& l, - const iterator_range& r ); - - template< class ForwardTraversalIterator, class ForwardRange > - bool operator!=( const iterator_range& l, - const ForwardRange& r ); - - template< class ForwardTraversalIterator, class ForwardRange > - bool operator!=( const ForwardRange& l, - const iterator_range& r ); - - template< class ForwardTraversalIterator, class ForwardTraversalIterator2 > - bool operator<( const iterator_range& l, - const iterator_range& r ); - - template< class ForwardTraversalIterator, class ForwardRange > - bool operator<( const iterator_range& l, - const ForwardRange& r ); - - template< class ForwardTraversalIterator, class ForwardRange > - bool operator<( const ForwardRange& l, - const iterator_range& r ); - - // external construction - template< class ForwardTraversalIterator > - iterator_range< ForwardTraversalIterator > - make_iterator_range( ForwardTraversalIterator Begin, - ForwardTraversalIterator End ); - - template< class ForwardRange > - iterator_range< typename iterator_of::type > - make_iterator_range( ForwardRange& r ); - - template< class ForwardRange > - iterator_range< typename const_iterator_of::type > - make_iterator_range( const ForwardRange& r ); - - template< class Range > - iterator_range< typename range_iterator::type > - make_iterator_range( Range& r, - typename range_difference::type advance_begin, - typename range_difference::type advance_end ); - - template< class Range > - iterator_range< typename range_const_iterator::type > - make_iterator_range( const Range& r, - typename range_difference::type advance_begin, - typename range_difference::type advance_end ); - - // convenience - template< class Sequence, class ForwardRange > - Sequence copy_range( const ForwardRange& r ); - -} // namespace 'boost' -`` - -If an instance of `iterator_range` is constructed by a client with two iterators, the client must ensure that the two iterators delimit a valid closed-open range [begin,end). - -It is worth noticing that the templated constructors and assignment operators allow conversion from `iterator_range` to `iterator_range`. Similarly, since the comparison operators have two template arguments, we can compare ranges whenever the iterators are comparable; for example when we are dealing with const and non-const iterators from the same container. - -[h4 Details member functions] - -`operator unspecified_bool_type() const;` - -[:['[*Returns]] `!empty();`] - -`bool equal( iterator_range& r ) const;` - -[:['[*Returns]] `begin() == r.begin() && end() == r.end();`] - -[h4 Details functions] - -`bool operator==( const ForwardRange1& l, const ForwardRange2& r );` - -[:['[*Returns]] `size(l) != size(r) ? false : std::equal( begin(l), end(l), begin(r) );`] - -`bool operator!=( const ForwardRange1& l, const ForwardRange2& r );` - -[:['[*Returns]] `!( l == r );`] - -`bool operator<( const ForwardRange1& l, const ForwardRange2& r );` - -[:['[*Returns]] `std::lexicographical_compare( begin(l), end(l), begin(r), end(r) );`] - -`` -iterator_range make_iterator_range( Range& r, - typename range_difference::type advance_begin, - typename range_difference::type advance_end ); -`` - -[:['[*Effects:]]] - -`` - iterator new_begin = begin( r ), - iterator new_end = end( r ); - std::advance( new_begin, advance_begin ); - std::advance( new_end, advance_end ); - return make_iterator_range( new_begin, new_end ); -`` - -`Sequence copy_range( const ForwardRange& r );` - -[:['[*Returns]] `Sequence( begin(r), end(r) );`] - -[endsect] - -[section:sub_range Class `sub_range`] - -The `sub_range` class inherits all its functionality from the __iterator_range__ class. The `sub_range` class is often easier to use because one must specify the __forward_range__ template argument instead of an iterator. Moreover, the sub_range class can propagate constness since it knows what a corresponding `const_iterator` is. - -[h4 Synopsis] - -`` -namespace boost -{ - template< class ForwardRange > - class sub_range : public iterator_range< typename range_result_iterator::type > - { - public: - typedef typename range_result_iterator::type iterator; - typedef typename range_const_iterator::type const_iterator; - - public: // construction, assignment - template< class ForwardTraversalIterator > - sub_range( ForwardTraversalIterator Begin, ForwardTraversalIterator End ); - - template< class ForwardRange2 > - sub_range( ForwardRange2& r ); - - template< class ForwardRange2 > - sub_range( const Range2& r ); - - template< class ForwardRange2 > - sub_range& operator=( ForwardRange2& r ); - - template< class ForwardRange2 > - sub_range& operator=( const ForwardRange2& r ); - - public: // Forward Range functions - iterator begin(); - const_iterator begin() const; - iterator end(); - const_iterator end() const; - - public: // convenience - value_type& front(); - const value_type& front() const; - value_type& back(); - const value_type& back() const; - // for Random Access Range only: - value_type& operator[]( size_type at ); - const value_type& operator[]( size_type at ) const; - - public: - // rest of interface inherited from iterator_range - }; - -} // namespace 'boost' -`` - -The class should be trivial to use as seen below. Imagine that we have an algorithm that searches for a sub-string in a string. The result is an iterator_range, that delimits the match. We need to store the result from this algorithm. Here is an example of how we can do it with and without `sub_range` - -`` -std::string str("hello"); -iterator_range ir = find_first( str, "ll" ); -sub_range sub = find_first( str, "ll" ); -`` - -[endsect] - -[endsect] - - - -[section:style_guide Terminology and style guidelines] - -The use of a consistent terminology is as important for __ranges__ and range-based algorithms as it is for iterators and iterator-based algorithms. If a conventional set of names are adopted, we can avoid misunderstandings and write generic function prototypes that are ['self-documenting]. - -Since ranges are characterized by a specific underlying iterator type, we get a type of range for each type of iterator. Hence we can speak of the following types of ranges: - -* ['Value access] category: - * Readable Range - * Writeable Range - * Swappable Range - * Lvalue Range -* ['Traversal] category: - * __single_pass_range__ - * __forward_range__ - * __bidirectional_range__ - * __random_access_range__ - -Notice how we have used the categories from the __new_style_iterators__. - -Notice that an iterator (and therefore an range) has one ['traversal] property and one or more properties from the ['value access] category. So in reality we will mostly talk about mixtures such as - -* Random Access Readable Writeable Range -* Forward Lvalue Range - -By convention, we should always specify the ['traversal] property first as done above. This seems reasonable since there will only be one ['traversal] property, but perhaps many ['value access] properties. - -It might, however, be reasonable to specify only one category if the other category does not matter. For example, the __iterator_range__ can be constructed from a Forward Range. This means that we do not care about what ['value access] properties the Range has. Similarly, a Readable Range will be one that has the lowest possible ['traversal] property (Single Pass). - -As another example, consider how we specify the interface of `std::sort()`. Algorithms are usually more cumbersome to specify the interface of since both traversal and value access properties must be exactly defined. The iterator-based version looks like this: - -`` - template< class RandomAccessTraversalReadableWritableIterator > - void sort( RandomAccessTraversalReadableWritableIterator first, - RandomAccessTraversalReadableWritableIterator last ); -`` - -For ranges the interface becomes - -`` - template< class RandomAccessReadableWritableRange > - void sort( RandomAccessReadableWritableRange& r ); -`` - -[endsect] - - - -[section Library Headers] - -[table - [[Header ] [Includes ] [Related Concept ]] - [[`` ] [everything ] [- ]] - [[`` ] [every metafunction ] [- ]] - [[`` ] [every function ] [- ]] - [[`` ] [`range_value` ] [__single_pass_range__ ]] - [[`` ] [`range_iterator` ] [__single_pass_range__ ]] - [[`` ] [`range_const_iterator` ] [__single_pass_range__ ]] - [[`` ] [`range_difference` ] [__forward_range__ ]] - [[`` ] [`range_size` ] [__forward_range__ ]] - [[`` ] [`range_result_iterator` ] [- ]] - [[``] [`range_reverse_iterator` ] [__bidirectional_range__ ]] - [[``] - [`range_const_reverse_iterator`] - [_bidirectional_range__ ]] - [[``] - [`range_reverse_result_iterator`] - [- ]] - [[`` ] [`begin` and `const_begin` ] [__single_pass_range__ ]] - [[`` ] [`end` and `const_end` ] [__single_pass_range__ ]] - [[`` ] [`empty` ] [__single_pass_range__ ]] - [[`` ] [`size` ] [__forward_range__ ]] - [[`` ] [`rbegin` and `const_rbegin`] [__bidirectional_range__ ]] - [[`` ] [`rend` and `const_rend` ] [__bidirectional_range__ ]] - [[`` ] [`iterator_range` ] [- ]] - [[`` ] [`sub_range` ] [- ]] - [[`` ] [`concept checks` ] [- ]] -] - -[endsect] - - - -[section Examples] - -Some examples are given in the accompanying test files: - -* [@http://www.boost.org/libs/range/test/string.cpp string.cpp][br] -shows how to implement a container version of `std::find()` that works with `char[]`,`wchar_t[]`,`char*`,`wchar_t*`. - -[:[*Warning: ['support for null-terminated strings is deprecated and will disappear in the next Boost release (1.34).]]] - -* [@http://www.boost.org/libs/range/test/algorithm_example.cpp algorithm_example.cpp][br]shows the replace example from the introduction. - -* [@http://www.boost.org/libs/range/test/iterator_range.cpp iterator_range.cpp] - -* [@http://www.boost.org/libs/range/test/sub_range.cpp sub_range.cpp] - -* [@http://www.boost.org/libs/range/test/iterator_pair.cpp iterator_pair.cpp] - -* [@http://www.boost.org/libs/range/test/reversible_range.cpp reversible_range.cpp] - -* [@http://www.boost.org/libs/range/test/std_container.cpp std_container.cpp] - -* [@http://www.boost.org/libs/range/test/array.cpp array.cpp] - -[endsect] - - - -[section Portability] - -A huge effort has been made to port the library to as many compilers as possible. - -Full support for built-in arrays require that the compiler supports class template partial specialization. For non-conforming compilers there might be a chance that it works anyway thanks to workarounds in the type traits library. -Visual C++ 6/7.0 has a limited support for arrays: as long as the arrays are of built-in type it should work. - -Notice also that some compilers cannot do function template ordering properly. In that case one must rely of __range_result_iterator__ and a single function definition instead of overloaded versions for const and non-const arguments. So if one cares about old compilers, one should not pass rvalues to the functions. - -For maximum portability you should follow these guidelines: - -# do not use built-in arrays, -# do not pass rvalues to `begin()`, `end()` and `iterator_range` Range constructors and assignment operators, -# use `const_begin()` and `const_end()` whenever your code by intention is read-only; this will also solve most rvalue problems, -# do not rely on ADL: - * if you overload functions, include that header before the headers in this library, - * put all overloads in namespace boost. - - - -[endsect] - - - -[section FAQ] - -1. ['[*Why is there no difference between `range_iterator::type` and `range_const_iterator::type` for `std::pair`?]] - -[:In general it is not possible nor desirable to find a corresponding `const_iterator`. When it is possible to come up with one, the client might choose to construct a `std::pair` object.] - -[:Note that an __iterator_range__ is somewhat more convenient than a `pair` and that a __sub_range__ does propagate const-ness.] - -2. ['[*Why is there not supplied more types or more functions?]] - -[:The library has been kept small because its current interface will serve most purposes. If and when a genuine need arises for more functionality, it can be implemented.] - -3. ['[*How should I implement generic algorithms for ranges?]] - -[:One should always start with a generic algorithm that takes two iterators (or more) as input. Then use Boost.Range to build handier versions on top of the iterator based algorithm. Please notice that once the range version of the algorithm is done, it makes sense not to expose the iterator version in the public interface.] - -4. ['[*Why is there no Incrementable Range concept?]] - -[:Even though we speak of incrementable iterators, it would not make much sense for ranges; for example, we cannot determine the size and emptiness of a range since we cannot even compare its iterators.] - -[:Note also that incrementable iterators are derived from output iterators and so there exist no output range.] - -[endsect] - -[section:history_ack History and Acknowledgement] - -The library have been under way for a long time. Dietmar Kühl originally intended to submit an `array_traits` class template which had most of the functionality present now, but only for arrays and standard containers. - -Meanwhile work on algorithms for containers in various contexts showed the need for handling pairs of iterators, and string libraries needed special treatment of character arrays. In the end it made sense to formalize the minimal requirements of these similar concepts. And the results are the Range concepts found in this library. - -The term Range was adopted because of paragraph 24.1/7 from the C++ standard: - -Most of the library's algorithmic templates that operate on data structures have interfaces that use ranges. A range is a pair of iterators that designate the beginning and end of the computation. A range [i, i) is an empty range; in general, a range [i, j) refers to the elements in the data structure starting with the one pointed to by i and up to but not including the one pointed to by j. Range [i, j) is valid if and only if j is reachable from i. The result of the application of functions in the library to invalid ranges is undefined. - -Special thanks goes to - -* Pavol Droba for help with documentation and implementation -* Pavel Vozenilek for help with porting the library -* Jonathan Turkanis and John Torjo for help with documentation -* Hartmut Kaiser for being review manager -* Jonathan Turkanis for porting the lib (as far sa possible) to vc6 and vc7. - -The concept checks and their documentation was provided by Daniel Walker. - -[endsect] \ No newline at end of file diff --git a/doc/concepts.qbk b/doc/concepts.qbk new file mode 100644 index 0000000..cc6fd23 --- /dev/null +++ b/doc/concepts.qbk @@ -0,0 +1,251 @@ +[section:concepts Range Concepts] + +[section Overview] + +A Range is a [*/concept/] similar to the STL [@http://www.sgi.com/Technology/STL/Container.html Container] concept. A Range provides iterators for accessing a half-open range `[first,one_past_last)` of elements and provides information about the number of elements in the Range. However, a Range has fewer requirements than a Container. + +The motivation for the Range concept is that there are many useful Container-like types that do not meet the full requirements of Container, and many algorithms that can be written with this reduced set of requirements. In particular, a Range does not necessarily + +* own the elements that can be accessed through it, +* have copy semantics, + +Because of the second requirement, a Range object must be passed by (const or non-const) reference in generic code. + +The operations that can be performed on a Range is dependent on the [@../../iterator/doc/new-iter-concepts.html#iterator-traversal-concepts-lib-iterator-traversal traversal category] of the underlying iterator type. Therefore the range concepts are named to reflect which traversal category its iterators support. See also terminology and style guidelines. for more information about naming of ranges. + +The concepts described below specifies associated types as [@../../libs/mpl/doc/refmanual/metafunction.html metafunctions] and all functions as free-standing functions to allow for a layer of indirection. + +[endsect] + + +[section Single Pass Range] + +[heading Notation] + +[table + [] + [[`X`] [A type that is a model of __single_pass_range__.]] + [[`a`] [Object of type X.]] +] + +[heading Description] + +A range `X` where `boost::range_iterator::type` is a model of __single_pass_iterator__. + +[heading Associated types] + +[table + [] + [[Iterator type ] [`boost::range_iterator::type` ] [The type of iterator used to iterate through a Range's elements. The iterator's value type is expected to be the Range's value type. A conversion from the iterator type to the `const` iterator type must exist.]] + [[Const iterator type] [`boost::range_iterator::type`] [A type of iterator that may be used to examine, but not to modify, a Range's elements.]] +] + +[heading Valid expressions] + +The following expressions must be valid. + +[table + [[Name ] [Expression ] [Return type ]] + [[Beginning of range] [`boost::begin(a)`] [`boost::range_iterator::type` if `a` is mutable, `boost::range_iterator::type` otherwise]] + [[End of range ] [`boost::end(a)` ] [`boost::range_iterator::type` if `a` is mutable, `boost::range_iterator::type` otherwise]] +] + +[heading Expression semantics] + +[table + [[Expression ] [Semantics ] [Postcondition]] + [[`boost::begin(a)`] [Returns an iterator pointing to the first element in the Range. ] [`boost::begin(a)` is either dereferenceable or past-the-end. It is past-the-end if and only if `boost::distance(a) == 0`.]] + [[`boost::end(a)` ] [Returns an iterator pointing one past the last element in the Range. ] [`boost::end(a)` is past-the-end.]] +] + +[heading Complexity guarantees] + +`boost::end(a)` is at most amortized linear time, `boost::begin(a)` is amortized constant time. For most practical purposes, one can expect both to be amortized constant time. + +[heading Invariants] + +[table + [] + [[Valid range ] [For any Range `a`, `[boost::begin(a),boost::end(a))` is a valid range, that is, `boost::end(a)` is reachable from `boost::begin(a)` in a finite number of increments.]] + + [[Completeness] [An algorithm that iterates through the range `[boost::begin(a),boost::end(a))` will pass through every element of `a`.]] +] + +[heading See also] + +__extending_for_udts__ + +__implementation_of_metafunctions__ + +__implementation_of_functions__ + +__container__ + +[endsect] + + +[section Forward Range] + +[heading Notation] + +[table + [] + [[`X`] [A type that is a model of __forward_range__.]] + [[`a`] [Object of type X.]] +] + +[heading Description] + +A range `X` where `boost::range_iterator::type` is a model of __forward_traversal_iterator__. + +[heading Refinement of] + +__single_pass_range__ + +[heading Associated types] + +[table + [] + [[Distance type] [`boost::range_difference::type`] [A signed integral type used to represent the distance between two of the Range's iterators. This type must be the same as the iterator's distance type.]] + [[Size type ] [`boost::range_size::type` ] [An unsigned integral type that can represent any nonnegative value of the Range's distance type.]] +] + +[heading See also] + +__implementation_of_metafunctions__ + +__implementation_of_functions__ + +[endsect] + + +[section Bidirectional Range] + +[heading Notation] + +[table + [] + [[`X`] [A type that is a model of __bidirectional_range__.]] + [[`a`] [Object of type X.]] +] + +[heading Description] + +This concept provides access to iterators that traverse in both directions (forward and reverse). The `boost::range_iterator::type` iterator must meet all of the requirements of __bidirectional_traversal_iterator__. + +[heading Refinement of] + +__forward_range__ + +[heading Associated types] + +[table + [] + [[Reverse Iterator type ] [`boost::range_reverse_iterator::type` ] [The type of iterator used to iterate through a Range's elements in reverse order. The iterator's value type is expected to be the Range's value type. A conversion from the reverse iterator type to the const reverse iterator type must exist.]] + + [[Const reverse iterator type] [`boost::range_reverse_iterator::type`] [A type of reverse iterator that may be used to examine, but not to modify, a Range's elements.]] +] + +[heading Valid expressions] + +[table + [[Name ] [Expression ] [Return type] [Semantics]] + [[Beginning of range] [`boost::rbegin(a)`] [`boost::range_reverse_iterator::type` if `a` is mutable `boost::range_reverse_iterator::type` otherwise.] [Equivalent to `boost::range_reverse_iterator::type(boost::end(a))`.]] + + [[End of range ] [`boost::rend(a)` ] [`boost::range_reverse_iterator::type` if `a` is mutable, `boost::range_reverse_iterator::type` otherwise.] [Equivalent to `boost::range_reverse_iterator::type(boost::begin(a))`.]] +] + +[heading Complexity guarantees] + +`boost::rbegin(a)` has the same complexity as `boost::end(a)` and `boost::rend(a)` has the same complexity as `boost::begin(a)` from __forward_range__. + +[heading Invariants] + +[table + [] + [[Valid reverse range] [For any Bidirectional Range a, `[boost::rbegin(a),boost::rend(a))` is a valid range, that is, `boost::rend(a)` is reachable from `boost::rbegin(a)` in a finite number of increments.]] + + [[Completeness ] [An algorithm that iterates through the range `[boost::rbegin(a),boost::rend(a))` will pass through every element of `a`.]] +] + +[heading See also] + +__implementation_of_metafunctions__ + +__implementation_of_functions__ + +[endsect] + + +[section Random Access Range] + +[heading Description] + +A range `X` where `boost::range_iterator::type` is a model of __random_access_traversal_iterator__. + +[heading Refinement of] + +__bidirectional_range__ + +[heading Valid expressions] + +[table + [[Name ] [Expression ] [Return type ]] + [[Size of range] [`boost::size(a)`] [`boost::range_size::type`]] +] + +[heading Expression semantics] + +[table + [[Expression ] [Semantics] [Postcondition]] + [[`boost::size(a)`] [Returns the size of the Range, that is, its number of elements. Note `boost::size(a) == 0u` is equivalent to `boost::empty(a)`.] [`boost::size(a) >= 0`]] +] + +[heading Complexity guarantees] + +`boost::size(a)` completes in amortized constant time. + +[heading Invariants] + +[table + [] + [[Range size] [`boost::size(a)` is equal to the `boost::end(a)` - `boost::begin(a)`.]] +] + +[endsect] + + +[section Concept Checking] + +Each of the range concepts has a corresponding concept checking class in the file [@../../boost/range/concepts.hpp ``]. These classes may be used in conjunction with the __concept_check__ to ensure that the type of a template parameter is compatible with a range concept. If not, a meaningful compile time error is generated. Checks are provided for the range concepts related to iterator traversal categories. For example, the following line checks that the type `T` models the __forward_range__ concept. + +`` +BOOST_CONCEPT_ASSERT(( ForwardRangeConcept )); +`` + +An additional concept check is required for the value access property of the range based on the range's iterator type. For example to check for a ForwardReadableRange, the following code is required. + +`` +BOOST_CONCEPT_ASSERT(( ForwardRangeConcept )); +BOOST_CONCEPT_ASSERT(( ReadableIteratorConcept::type> )); +`` + +The following range concept checking classes are provided. + +* Class SinglePassRangeConcept checks for __single_pass_range__ +* Class ForwardRangeConcept checks for __forward_range__ +* Class BidirectionalRangeConcept checks for __bidirectional_range__ +* Class RandomAccessRangeConcept checks for __random_access_range__ + +[heading See also] + +[link range.style_guide Range Terminology and style guidelines] + +__iterator_concepts__ + +__concept_check__ + +[endsect] + +[endsect] + diff --git a/doc/counting_range.html b/doc/counting_range.html new file mode 100755 index 0000000..c44edcc --- /dev/null +++ b/doc/counting_range.html @@ -0,0 +1,70 @@ + + + + + + Boost.Range Utilities + + + + + + + + + +

Boost.Range

+

Function counting_range

+

+ The intention of the counting_range function is to construct + a new range with iterators that are wrapped in a + counting_iterator (from Boost.Iterator) +

+ +

Synopsis

+ +
namespace boost
+{
+    template< class Incrementable > inline
+    range< counting_iterator<Incrementable> >
+    counting_range(Incrementable first, Incrementable last);
+
+    template< class SinglePassRange > inline
+    range< counting_iterator<typename range_iterator<SinglePassRange>::type >
+    counting_range(const Range& rng);
+
+    template< class SinglePassRange > inline
+    range< counting_iterator<typename range_iterator<SinglePassRange>::type >
+    counting_range(Range& rng);
+            
+} // namespace 'boost'
+    
+ +

+ © Copyright Neil Groves 2009. +

+ +

+ Distributed under the Boost Software License, Version 1.0. (See + accompanying file LICENSE_1_0.txt or copy + at www.boost.org/LICENSE_1_0.txt) +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + + + diff --git a/doc/examples.qbk b/doc/examples.qbk new file mode 100644 index 0000000..bea16e2 --- /dev/null +++ b/doc/examples.qbk @@ -0,0 +1,23 @@ +[section Examples] + +Some examples are given in the accompanying test files: + +* [@http://www.boost.org/libs/range/test/string.cpp string.cpp] shows how to implement a container version of `std::find()` that works with `char[]`,`wchar_t[]`,`char*`,`wchar_t*`. + +* [@http://www.boost.org/libs/range/test/algorithm_example.cpp algorithm_example.cpp] shows the replace example from the introduction. + +* [@http://www.boost.org/libs/range/test/iterator_range.cpp iterator_range.cpp] + +* [@http://www.boost.org/libs/range/test/sub_range.cpp sub_range.cpp] + +* [@http://www.boost.org/libs/range/test/iterator_pair.cpp iterator_pair.cpp] + +* [@http://www.boost.org/libs/range/test/reversible_range.cpp reversible_range.cpp] + +* [@http://www.boost.org/libs/range/test/std_container.cpp std_container.cpp] + +* [@http://www.boost.org/libs/range/test/array.cpp array.cpp] + +[endsect] + + diff --git a/doc/faq.qbk b/doc/faq.qbk new file mode 100644 index 0000000..f01ffe8 --- /dev/null +++ b/doc/faq.qbk @@ -0,0 +1,25 @@ +[section FAQ] + +1. ['[*Why is there no difference between `range_iterator::type` and `range_const_iterator::type` for `std::pair`?]] + +[:In general it is not possible nor desirable to find a corresponding `const_iterator`. When it is possible to come up with one, the client might choose to construct a `std::pair` object.] + +[:Note that an __iterator_range__ is somewhat more convenient than a `pair` and that a __sub_range__ does propagate const-ness.] + +2. ['[*Why is there not supplied more types or more functions?]] + +[:The library has been kept small because its current interface will serve most purposes. If and when a genuine need arises for more functionality, it can be implemented.] + +3. ['[*How should I implement generic algorithms for ranges?]] + +[:One should always start with a generic algorithm that takes two iterators (or more) as input. Then use Boost.Range to build handier versions on top of the iterator based algorithm. Please notice that once the range version of the algorithm is done, it makes sense not to expose the iterator version in the public interface.] + +4. ['[*Why is there no Incrementable Range concept?]] + +[:Even though we speak of incrementable iterators, it would not make much sense for ranges; for example, we cannot determine the size and emptiness of a range since we cannot even compare its iterators.] + +[:Note also that incrementable iterators are derived from output iterators and so there exist no output range.] + +[endsect] + + diff --git a/doc/headers.qbk b/doc/headers.qbk new file mode 100644 index 0000000..6edefbd --- /dev/null +++ b/doc/headers.qbk @@ -0,0 +1,29 @@ +[section Library Headers] + +[table + [[Header ] [Includes ] [Related Concept ]] + [[`` ] [everything ] [- ]] + [[`` ] [every metafunction ] [- ]] + [[`` ] [every function ] [- ]] + [[`` ] [__range_value__ ] [__single_pass_range__ ]] + [[`` ] [__range_iterator__ ] [__single_pass_range__ ]] + [[`` ] [__range_difference__ ] [__forward_range__ ]] + [[`` ] [__range_pointer__ ] [-]] + [[`` ] [__range_category__ ] [-]] + [[``] [__range_reverse_iterator__ ] [__bidirectional_range__ ]] + [[`` ] [__begin__ and __const_begin__ ] [__single_pass_range__ ]] + [[`` ] [__end__ and __const_end__ ] [__single_pass_range__ ]] + [[`` ] [__empty__ ] [__single_pass_range__ ]] + [[`` ] [__distance__ ] [__forward_range__ ]] + [[`` ] [__size__ ] [__random_access_range__ ]] + [[`` ] [__rbegin__ and __const_rbegin__] [__bidirectional_range__ ]] + [[`` ] [__rend__ and __const_rend__ ] [__bidirectional_range__ ]] + [[`` ] [__as_array__ ] [- ]] + [[`` ] [__as_literal__ ] [- ]] + [[`` ] [__iterator_range__ ] [- ]] + [[`` ] [__sub_range__ ] [- ]] + [[`` ] [__range_concepts__ ] [- ]] +] + +[endsect] + diff --git a/doc/history_ack.qbk b/doc/history_ack.qbk new file mode 100644 index 0000000..4d4b103 --- /dev/null +++ b/doc/history_ack.qbk @@ -0,0 +1,22 @@ +[section:history_ack History and Acknowledgement] + +The library have been under way for a long time. Dietmar Kühl originally intended to submit an `array_traits` class template which had most of the functionality present now, but only for arrays and standard containers. + +Meanwhile work on algorithms for containers in various contexts showed the need for handling pairs of iterators, and string libraries needed special treatment of character arrays. In the end it made sense to formalize the minimal requirements of these similar concepts. And the results are the Range concepts found in this library. + +The term Range was adopted because of paragraph 24.1/7 from the C++ standard: + +Most of the library's algorithmic templates that operate on data structures have interfaces that use ranges. A range is a pair of iterators that designate the beginning and end of the computation. A range [i, i) is an empty range; in general, a range [i, j) refers to the elements in the data structure starting with the one pointed to by i and up to but not including the one pointed to by j. Range [i, j) is valid if and only if j is reachable from i. The result of the application of functions in the library to invalid ranges is undefined. + +Special thanks goes to + +* Pavol Droba for help with documentation and implementation +* Pavel Vozenilek for help with porting the library +* Jonathan Turkanis and John Torjo for help with documentation +* Hartmut Kaiser for being review manager +* Jonathan Turkanis for porting the lib (as far sa possible) to vc6 and vc7. + +The concept checks and their documentation was provided by Daniel Walker. + +[endsect] + diff --git a/doc/html/index.html b/doc/html/index.html new file mode 100644 index 0000000..4f1a4a1 --- /dev/null +++ b/doc/html/index.html @@ -0,0 +1,144 @@ + + + +Chapter 1. Range 2.0 + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
Next
+
+
+

+Chapter 1. Range 2.0

+

+Thorsten Ottosen +

+

+Neil Groves +

+
+
+

+ 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) +

+
+
+ +

+ Boost.Range is a collection of concepts and utilities that are particularly useful + for specifying and implementing generic algorithms. +

+
+ + + +

Last revised: April 03, 2010 at 08:56:46 GMT

+
+
Next
+ + diff --git a/doc/html/quickbook_HTML.manifest b/doc/html/quickbook_HTML.manifest new file mode 100644 index 0000000..b3be8f5 --- /dev/null +++ b/doc/html/quickbook_HTML.manifest @@ -0,0 +1,132 @@ +index.html +range/introduction.html +range/concepts.html +range/concepts/overview.html +range/concepts/single_pass_range.html +range/concepts/forward_range.html +range/concepts/bidirectional_range.html +range/concepts/random_access_range.html +range/concepts/concept_checking.html +range/reference.html +range/reference/overview.html +range/reference/synopsis.html +range/reference/semantics.html +range/reference/semantics/metafunctions.html +range/reference/semantics/functions.html +range/reference/adaptors.html +range/reference/adaptors/adaptors_introduction.html +range/reference/adaptors/adaptors_synopsis.html +range/reference/adaptors/adaptors_general_requirements.html +range/reference/adaptors/adaptors_reference.html +range/reference/adaptors/adaptors_reference/adjacent_filtered.html +range/reference/adaptors/adaptors_reference/copied.html +range/reference/adaptors/adaptors_reference/filtered.html +range/reference/adaptors/adaptors_reference/indexed.html +range/reference/adaptors/adaptors_reference/indirected.html +range/reference/adaptors/adaptors_reference/map_keys.html +range/reference/adaptors/adaptors_reference/map_values.html +range/reference/adaptors/adaptors_reference/replaced.html +range/reference/adaptors/adaptors_reference/replaced_if.html +range/reference/adaptors/adaptors_reference/reversed.html +range/reference/adaptors/adaptors_reference/sliced.html +range/reference/adaptors/adaptors_reference/strided.html +range/reference/adaptors/adaptors_reference/tokenized.html +range/reference/adaptors/adaptors_reference/transformed.html +range/reference/adaptors/adaptors_reference/uniqued.html +range/reference/algorithms.html +range/reference/algorithms/range_algorithm_introduction.html +range/reference/algorithms/range_algorithm_mutating_algorithms.html +range/reference/algorithms/range_algorithm_mutating_algorithms/copy.html +range/reference/algorithms/range_algorithm_mutating_algorithms/copy_backward.html +range/reference/algorithms/range_algorithm_mutating_algorithms/fill.html +range/reference/algorithms/range_algorithm_mutating_algorithms/generate.html +range/reference/algorithms/range_algorithm_mutating_algorithms/inplace_merge.html +range/reference/algorithms/range_algorithm_mutating_algorithms/merge.html +range/reference/algorithms/range_algorithm_mutating_algorithms/nth_element.html +range/reference/algorithms/range_algorithm_mutating_algorithms/partial_sort.html +range/reference/algorithms/range_algorithm_mutating_algorithms/partition.html +range/reference/algorithms/range_algorithm_mutating_algorithms/random_shuffle.html +range/reference/algorithms/range_algorithm_mutating_algorithms/remove.html +range/reference/algorithms/range_algorithm_mutating_algorithms/remove_if.html +range/reference/algorithms/range_algorithm_mutating_algorithms/replace.html +range/reference/algorithms/range_algorithm_mutating_algorithms/replace_if.html +range/reference/algorithms/range_algorithm_mutating_algorithms/rotate.html +range/reference/algorithms/range_algorithm_mutating_algorithms/sort.html +range/reference/algorithms/range_algorithm_mutating_algorithms/stable_partition.html +range/reference/algorithms/range_algorithm_mutating_algorithms/stable_sort.html +range/reference/algorithms/range_algorithm_mutating_algorithms/transform.html +range/reference/algorithms/range_algorithm_mutating_algorithms/unique.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/adjacent_find.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/binary_search.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/count.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/equal.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/equal_range.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/for_each.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/find.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/find_end.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/find_first_of.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/find_if.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/lexicographical_compare.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/lower_bound.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/max_element.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/min_element.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/mismatch.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/search.html +range/reference/algorithms/range_algorithm_non_mutating_algorithms/upper_bound.html +range/reference/algorithms/set_algorithms.html +range/reference/algorithms/set_algorithms/includes.html +range/reference/algorithms/set_algorithms/set_union.html +range/reference/algorithms/set_algorithms/set_intersection.html +range/reference/algorithms/set_algorithms/set_difference.html +range/reference/algorithms/set_algorithms/set_symmetric_difference.html +range/reference/algorithms/heap_algorithms.html +range/reference/algorithms/heap_algorithms/push_heap.html +range/reference/algorithms/heap_algorithms/pop_heap.html +range/reference/algorithms/heap_algorithms/make_heap.html +range/reference/algorithms/permutation_algorithms.html +range/reference/algorithms/permutation_algorithms/next_permutation.html +range/reference/algorithms/permutation_algorithms/prev_permutation.html +range/reference/algorithms/range_algorithm_new_algorithms.html +range/reference/algorithms/range_algorithm_new_algorithms/erase.html +range/reference/algorithms/range_algorithm_new_algorithms/for_each.html +range/reference/algorithms/range_algorithm_new_algorithms/insert.html +range/reference/algorithms/range_algorithm_new_algorithms/overwrite.html +range/reference/algorithms/range_algorithm_new_algorithms/push_back.html +range/reference/algorithms/range_algorithm_new_algorithms/push_front.html +range/reference/algorithms/range_algorithm_new_algorithms/remove_erase.html +range/reference/algorithms/range_algorithm_new_algorithms/remove_erase_if.html +range/reference/algorithms/range_numeric.html +range/reference/algorithms/range_numeric/accumulate.html +range/reference/algorithms/range_numeric/adjacent_difference.html +range/reference/algorithms/range_numeric/inner_product.html +range/reference/algorithms/range_numeric/partial_sum.html +range/reference/ranges.html +range/reference/ranges/counting_range.html +range/reference/ranges/istream_range.html +range/reference/ranges/irange.html +range/reference/extending.html +range/reference/extending/method_1.html +range/reference/extending/method_2.html +range/reference/extending/method_3.html +range/reference/extending/method_3/method_3_1.html +range/reference/extending/method_3/method_3_2.html +range/utilities.html +range/utilities/iterator_range.html +range/utilities/sub_range.html +range/utilities/join.html +range/style_guide.html +range/library_headers.html +range/examples.html +range/mfc_atl.html +range/mfc_atl/requirements.html +range/mfc_atl/mfc_ranges.html +range/mfc_atl/atl_ranges.html +range/mfc_atl/const_ranges.html +range/mfc_atl/references.html +range/upgrade.html +range/upgrade/upgrade_from_1_42.html +range/upgrade/upgrade_from_1_34.html +range/portability.html +range/faq.html +range/history_ack.html diff --git a/doc/html/range/concepts.html b/doc/html/range/concepts.html new file mode 100644 index 0000000..c384122 --- /dev/null +++ b/doc/html/range/concepts.html @@ -0,0 +1,51 @@ + + + +Range Concepts + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/concepts/bidirectional_range.html b/doc/html/range/concepts/bidirectional_range.html new file mode 100644 index 0000000..796ca14 --- /dev/null +++ b/doc/html/range/concepts/bidirectional_range.html @@ -0,0 +1,299 @@ + + + +Bidirectional Range + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Notation +
+
++++ + + + + + + + + + + + +
+

+ X +

+
+

+ A type that is a model of Bidirectional + Range. +

+
+

+ a +

+
+

+ Object of type X. +

+
+
+ + Description +
+

+ This concept provides access to iterators that traverse in both directions + (forward and reverse). The boost::range_iterator<X>::type iterator must meet all of the requirements + of Bidirectional + Traversal Iterator. +

+
+ + Refinement + of +
+

+ Forward Range +

+
+ + Associated + types +
+
+++++ + + + + + + + + + + + + + +
+

+ Reverse Iterator type +

+
+

+ boost::range_reverse_iterator<X>::type +

+
+

+ The type of iterator used to iterate through a Range's elements + in reverse order. The iterator's value type is expected to be the + Range's value type. A conversion from the reverse iterator type + to the const reverse iterator type must exist. +

+
+

+ Const reverse iterator type +

+
+

+ boost::range_reverse_iterator<const X>::type +

+
+

+ A type of reverse iterator that may be used to examine, but not + to modify, a Range's elements. +

+
+
+ + Valid + expressions +
+
++++++ + + + + + + + + + + + + + + + + + + + + +
+

+ Name +

+
+

+ Expression +

+
+

+ Return type +

+
+

+ Semantics +

+
+

+ Beginning of range +

+
+

+ boost::rbegin(a) +

+
+

+ boost::range_reverse_iterator<X>::type if a + is mutable boost::range_reverse_iterator<const + X>::type otherwise. +

+
+

+ Equivalent to boost::range_reverse_iterator<X>::type(boost::end(a)). +

+
+

+ End of range +

+
+

+ boost::rend(a) +

+
+

+ boost::range_reverse_iterator<X>::type if a + is mutable, boost::range_reverse_iterator<const + X>::type otherwise. +

+
+

+ Equivalent to boost::range_reverse_iterator<X>::type(boost::begin(a)). +

+
+
+ + Complexity + guarantees +
+

+ boost::rbegin(a) has + the same complexity as boost::end(a) and + boost::rend(a) has the same complexity as boost::begin(a) from + Forward Range. +

+
+ + Invariants +
+
++++ + + + + + + + + + + + +
+

+ Valid reverse range +

+
+

+ For any Bidirectional Range a, [boost::rbegin(a),boost::rend(a)) + is a valid range, that is, boost::rend(a) is reachable from boost::rbegin(a) + in a finite number of increments. +

+
+

+ Completeness +

+
+

+ An algorithm that iterates through the range [boost::rbegin(a),boost::rend(a)) + will pass through every element of a. +

+
+
+ + See also +
+

+ Implementation of + metafunctions +

+

+ Implementation of functions +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/concepts/concept_checking.html b/doc/html/range/concepts/concept_checking.html new file mode 100644 index 0000000..37175b4 --- /dev/null +++ b/doc/html/range/concepts/concept_checking.html @@ -0,0 +1,108 @@ + + + +Concept Checking + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ Each of the range concepts has a corresponding concept checking class in + the file <boost/range/concepts.hpp>. + These classes may be used in conjunction with the Boost + Concept Check library to ensure that the type of a template parameter + is compatible with a range concept. If not, a meaningful compile time error + is generated. Checks are provided for the range concepts related to iterator + traversal categories. For example, the following line checks that the type + T models the Forward + Range concept. +

+

+ +

+
BOOST_CONCEPT_ASSERT(( ForwardRangeConcept<T> ));
+
+

+

+

+ An additional concept check is required for the value access property of + the range based on the range's iterator type. For example to check for a + ForwardReadableRange, the following code is required. +

+

+ +

+
BOOST_CONCEPT_ASSERT(( ForwardRangeConcept<T> ));
+BOOST_CONCEPT_ASSERT(( ReadableIteratorConcept<typename range_iterator<T>::type> ));
+
+

+

+

+ The following range concept checking classes are provided. +

+
+
+ + See also +
+

+ Range Terminology and style guidelines +

+

+ Iterator concepts +

+

+ Boost Concept Check library +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/concepts/forward_range.html b/doc/html/range/concepts/forward_range.html new file mode 100644 index 0000000..9076b68 --- /dev/null +++ b/doc/html/range/concepts/forward_range.html @@ -0,0 +1,159 @@ + + + +Forward Range + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Notation +
+
++++ + + + + + + + + + + + +
+

+ X +

+
+

+ A type that is a model of Forward + Range. +

+
+

+ a +

+
+

+ Object of type X. +

+
+
+ + Description +
+

+ A range X where boost::range_iterator<X>::type is a model of Forward + Traversal Iterator. +

+
+ + Refinement of +
+

+ Single Pass Range +

+
+ + Associated + types +
+
+++++ + + + + + + + + + + + + + +
+

+ Distance type +

+
+

+ boost::range_difference<X>::type +

+
+

+ A signed integral type used to represent the distance between two + of the Range's iterators. This type must be the same as the iterator's + distance type. +

+
+

+ Size type +

+
+

+ boost::range_size<X>::type +

+
+

+ An unsigned integral type that can represent any nonnegative value + of the Range's distance type. +

+
+
+ + See also +
+

+ Implementation of + metafunctions +

+

+ Implementation of functions +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/concepts/overview.html b/doc/html/range/concepts/overview.html new file mode 100644 index 0000000..7cd19e8 --- /dev/null +++ b/doc/html/range/concepts/overview.html @@ -0,0 +1,79 @@ + + + +Overview + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ A Range is a concept + similar to the STL Container + concept. A Range provides iterators for accessing a half-open range [first,one_past_last) of elements and provides information about + the number of elements in the Range. However, a Range has fewer requirements + than a Container. +

+

+ The motivation for the Range concept is that there are many useful Container-like + types that do not meet the full requirements of Container, and many algorithms + that can be written with this reduced set of requirements. In particular, + a Range does not necessarily +

+
    +
  • + own the elements that can be accessed through it, +
  • +
  • + have copy semantics, +
  • +
+

+ Because of the second requirement, a Range object must be passed by (const + or non-const) reference in generic code. +

+

+ The operations that can be performed on a Range is dependent on the traversal + category of the underlying iterator type. Therefore the range concepts + are named to reflect which traversal category its iterators support. See + also terminology and style guidelines. for more information about naming + of ranges. +

+

+ The concepts described below specifies associated types as metafunctions + and all functions as free-standing functions to allow for a layer of indirection. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/concepts/random_access_range.html b/doc/html/range/concepts/random_access_range.html new file mode 100644 index 0000000..97b3171 --- /dev/null +++ b/doc/html/range/concepts/random_access_range.html @@ -0,0 +1,187 @@ + + + +Random Access Range + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Description +
+

+ A range X where boost::range_iterator<X>::type is a model of Random + Access Traversal Iterator. +

+
+ + Refinement + of +
+

+ Bidirectional Range +

+
+ + Valid + expressions +
+
+++++ + + + + + + + + + + +
+

+ Name +

+
+

+ Expression +

+
+

+ Return type +

+
+

+ Size of range +

+
+

+ boost::size(a) +

+
+

+ boost::range_size<X>::type +

+
+
+ + Expression + semantics +
+
+++++ + + + + + + + + + + +
+

+ Expression +

+
+

+ Semantics +

+
+

+ Postcondition +

+
+

+ boost::size(a) +

+
+

+ Returns the size of the Range, that is, its number of elements. + Note boost::size(a) + == 0u + is equivalent to boost::empty(a). +

+
+

+ boost::size(a) + >= 0 +

+
+
+ + Complexity + guarantees +
+

+ boost::size(a) completes in amortized constant time. +

+
+ + Invariants +
+
++++ + + + + + +
+

+ Range size +

+
+

+ boost::size(a) + is equal to the boost::end(a) - boost::begin(a). +

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/concepts/single_pass_range.html b/doc/html/range/concepts/single_pass_range.html new file mode 100644 index 0000000..10669d1 --- /dev/null +++ b/doc/html/range/concepts/single_pass_range.html @@ -0,0 +1,349 @@ + + + +Single Pass Range + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Notation +
+
++++ + + + + + + + + + + + +
+

+ X +

+
+

+ A type that is a model of Single + Pass Range. +

+
+

+ a +

+
+

+ Object of type X. +

+
+
+ + Description +
+

+ A range X where boost::range_iterator<X>::type is a model of Single + Pass Iterator. +

+
+ + Associated + types +
+
+++++ + + + + + + + + + + + + + +
+

+ Iterator type +

+
+

+ boost::range_iterator<X>::type +

+
+

+ The type of iterator used to iterate through a Range's elements. + The iterator's value type is expected to be the Range's value type. + A conversion from the iterator type to the const + iterator type must exist. +

+
+

+ Const iterator type +

+
+

+ boost::range_iterator<const X>::type +

+
+

+ A type of iterator that may be used to examine, but not to modify, + a Range's elements. +

+
+
+ + Valid + expressions +
+

+ The following expressions must be valid. +

+
+++++ + + + + + + + + + + + + + + + + + +
+

+ Name +

+
+

+ Expression +

+
+

+ Return type +

+
+

+ Beginning of range +

+
+

+ boost::begin(a) +

+
+

+ boost::range_iterator<X>::type if a + is mutable, boost::range_iterator<const + X>::type otherwise +

+
+

+ End of range +

+
+

+ boost::end(a) +

+
+

+ boost::range_iterator<X>::type if a + is mutable, boost::range_iterator<const + X>::type otherwise +

+
+
+ + Expression + semantics +
+
+++++ + + + + + + + + + + + + + + + + + +
+

+ Expression +

+
+

+ Semantics +

+
+

+ Postcondition +

+
+

+ boost::begin(a) +

+
+

+ Returns an iterator pointing to the first element in the Range. +

+
+

+ boost::begin(a) + is either dereferenceable or past-the-end. It is past-the-end if + and only if boost::distance(a) == 0. +

+
+

+ boost::end(a) +

+
+

+ Returns an iterator pointing one past the last element in the Range. +

+
+

+ boost::end(a) + is past-the-end. +

+
+
+ + Complexity + guarantees +
+

+ boost::end(a) is at most amortized linear time, boost::begin(a) is amortized + constant time. For most practical purposes, one can expect both to be amortized + constant time. +

+
+ + Invariants +
+
++++ + + + + + + + + + + + +
+

+ Valid range +

+
+

+ For any Range a, + [boost::begin(a),boost::end(a)) is a valid range, that is, boost::end(a) + is reachable from boost::begin(a) in a finite number of increments. +

+
+

+ Completeness +

+
+

+ An algorithm that iterates through the range [boost::begin(a),boost::end(a)) + will pass through every element of a. +

+
+
+ + See also +
+

+ Extending the library for UDTs +

+

+ Implementation of + metafunctions +

+

+ Implementation of functions +

+

+ Container +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/examples.html b/doc/html/range/examples.html new file mode 100644 index 0000000..b272df8 --- /dev/null +++ b/doc/html/range/examples.html @@ -0,0 +1,62 @@ + + + +Examples + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ Some examples are given in the accompanying test files: +

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/faq.html b/doc/html/range/faq.html new file mode 100644 index 0000000..0c9d40b --- /dev/null +++ b/doc/html/range/faq.html @@ -0,0 +1,127 @@ + + + +FAQ + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+

+FAQ +

+

+ 1. Why is there no difference between range_iterator<C>::type + and range_const_iterator<C>::type + for std::pair<iterator, iterator>? +

+
+

+

+

+ In general it is not possible nor desirable to find a corresponding const_iterator. When it is possible to + come up with one, the client might choose to construct a std::pair<const_iterator,const_iterator> + object. +

+

+

+
+
+

+

+

+ Note that an iterator_range is somewhat more + convenient than a pair + and that a sub_range + does propagate const-ness. +

+

+

+
+

+ 2. Why is there not supplied more types or + more functions? +

+
+

+

+

+ The library has been kept small because its current interface will serve + most purposes. If and when a genuine need arises for more functionality, + it can be implemented. +

+

+

+
+

+ 3. How should I implement generic algorithms + for ranges? +

+
+

+

+

+ One should always start with a generic algorithm that takes two iterators + (or more) as input. Then use Boost.Range to build handier versions on top + of the iterator based algorithm. Please notice that once the range version + of the algorithm is done, it makes sense not to expose the iterator version + in the public interface. +

+

+

+
+

+ 4. Why is there no Incrementable Range concept? +

+
+

+

+

+ Even though we speak of incrementable iterators, it would not make much + sense for ranges; for example, we cannot determine the size and emptiness + of a range since we cannot even compare its iterators. +

+

+

+
+
+

+

+

+ Note also that incrementable iterators are derived from output iterators + and so there exist no output range. +

+

+

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/history_ack.html b/doc/html/range/history_ack.html new file mode 100644 index 0000000..930b6b6 --- /dev/null +++ b/doc/html/range/history_ack.html @@ -0,0 +1,90 @@ + + + +History and Acknowledgement + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHome +
+
+ +

+ The library have been under way for a long time. Dietmar Kühl originally intended + to submit an array_traits class + template which had most of the functionality present now, but only for arrays + and standard containers. +

+

+ Meanwhile work on algorithms for containers in various contexts showed the + need for handling pairs of iterators, and string libraries needed special treatment + of character arrays. In the end it made sense to formalize the minimal requirements + of these similar concepts. And the results are the Range concepts found in + this library. +

+

+ The term Range was adopted because of paragraph 24.1/7 from the C++ standard: +

+

+ Most of the library's algorithmic templates that operate on data structures + have interfaces that use ranges. A range is a pair of iterators that designate + the beginning and end of the computation. A range [i, i) is an empty range; + in general, a range [i, j) refers to the elements in the data structure starting + with the one pointed to by i and up to but not including the one pointed to + by j. Range [i, j) is valid if and only if j is reachable from i. The result + of the application of functions in the library to invalid ranges is undefined. +

+

+ Special thanks goes to +

+
    +
  • + Pavol Droba for help with documentation and implementation +
  • +
  • + Pavel Vozenilek for help with porting the library +
  • +
  • + Jonathan Turkanis and John Torjo for help with documentation +
  • +
  • + Hartmut Kaiser for being review manager +
  • +
  • + Jonathan Turkanis for porting the lib (as far sa possible) to vc6 and vc7. +
  • +
+

+ The concept checks and their documentation was provided by Daniel Walker. +

+
+ + + +
+
+
+PrevUpHome +
+ + diff --git a/doc/html/range/introduction.html b/doc/html/range/introduction.html new file mode 100644 index 0000000..8bce31d --- /dev/null +++ b/doc/html/range/introduction.html @@ -0,0 +1,154 @@ + + + +Introduction + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ Generic algorithms have so far been specified in terms of two or more iterators. + Two iterators would together form a range of values that the algorithm could + work on. This leads to a very general interface, but also to a somewhat clumsy + use of the algorithms with redundant specification of container names. Therefore + we would like to raise the abstraction level for algorithms so they specify + their interface in terms of Ranges as + much as possible. +

+

+ The most common form of ranges used throughout the C++ community are standard + library containers. When writing algorithms however, one often finds it desirable + for the algorithm to accept other types that offer enough functionality to + satisfy the needs of the generic code if a + suitable layer of indirection is applied . For example, + raw arrays are often suitable for use with generic code that works with containers, + provided a suitable adapter is used. Likewise, null terminated strings can + be treated as containers of characters, if suitably adapted. +

+

+ This library therefore provides the means to adapt standard-like containers, + null terminated strings, std::pairs of + iterators, and raw arrays (and more), such that the same generic code can work + with them all. The basic idea is to add another layer of indirection using + metafunctions + and free-standing functions so syntactic and/or semantic differences can be + removed. +

+

+ The main advantages are +

+
    +
  • + simpler implementation and specification of generic range algorithms +
  • +
  • + more flexible, compact and maintainable client code +
  • +
  • + safe use of built-in arrays (for legacy code; why else would you use built-in + arrays?) +
  • +
+

+ Below are given a small example (the complete example can be found here + ): +

+

+ +

+
//
+// example: extracting bounds in a generic algorithm
+//
+template< class ForwardReadableRange, class T >
+inline typename boost::range_iterator< ForwardReadableRange >::type
+find( ForwardReadableRange& c, const T& value )
+{
+   return std::find( boost::begin( c ), boost::end( c ), value );
+}
+
+template< class ForwardReadableRange, class T >
+inline typename boost::range_iterator< const ForwardReadableRange >::type
+find( const ForwardReadableRange& c, const T& value )
+{
+   return std::find( boost::begin( c ), boost::end( c ), value );
+}
+
+//
+// replace first value and return its index
+//
+template< class ForwardReadableWriteableRange, class T >
+inline typename boost::range_size< ForwardReadableWriteableRange >::type
+my_generic_replace( ForwardReadableWriteableRange& c, const T& value, const T& replacement )
+{
+   typename boost::range_iterator< ForwardReadableWriteableRange >::type found = find( c, value );
+
+   if( found != boost::end( c ) )
+       *found = replacement;
+   return std::distance( boost::begin( c ), found );
+}
+
+//
+// usage
+//
+const int N = 5;
+std::vector<int> my_vector;
+int values[] = { 1,2,3,4,5,6,7,8,9 };
+
+my_vector.assign( values, boost::end( values ) );
+typedef std::vector<int>::iterator iterator;
+std::pair<iterator,iterator>       my_view( boost::begin( my_vector ),
+                                            boost::begin( my_vector ) + N );
+char  str_val[] = "a string";
+char* str       = str_val;
+
+std::cout << my_generic_replace( my_vector, 4, 2 );
+std::cout << my_generic_replace( my_view, 4, 2 );
+std::cout << my_generic_replace( str, 'a', 'b' );
+
+// prints '3', '5' and '0'
+
+

+

+

+ By using the free-standing functions and metafunctions, + the code automatically works for all the types supported by this library; now + and in the future. Notice that we have to provide two versions of find() since + we cannot forward a non-const rvalue with reference arguments (see this article + about The + Forwarding Problem ). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/library_headers.html b/doc/html/range/library_headers.html new file mode 100644 index 0000000..a5bd095 --- /dev/null +++ b/doc/html/range/library_headers.html @@ -0,0 +1,430 @@ + + + +Library Headers + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ Header +

+
+

+ Includes +

+
+

+ Related Concept +

+
+

+ <boost/range.hpp> +

+
+

+ everything +

+
+

+ - +

+
+

+ <boost/range/metafunctions.hpp> +

+
+

+ every metafunction +

+
+

+ - +

+
+

+ <boost/range/functions.hpp> +

+
+

+ every function +

+
+

+ - +

+
+

+ <boost/range/value_type.hpp> +

+
+

+ range_value +

+
+

+ Single Pass Range +

+
+

+ <boost/range/iterator.hpp> +

+
+

+ range_iterator +

+
+

+ Single Pass Range +

+
+

+ <boost/range/difference_type.hpp> +

+
+

+ range_difference +

+
+

+ Forward Range +

+
+

+ <boost/range/pointer.hpp> +

+
+

+ range_pointer +

+
+

+ - +

+
+

+ <boost/range/category.hpp> +

+
+

+ range_category +

+
+

+ - +

+
+

+ <boost/range/reverse_iterator.hpp> +

+
+

+ range_reverse_iterator +

+
+

+ Bidirectional + Range +

+
+

+ <boost/range/begin.hpp> +

+
+

+ begin and const_begin +

+
+

+ Single Pass Range +

+
+

+ <boost/range/end.hpp> +

+
+

+ end and const_end +

+
+

+ Single Pass Range +

+
+

+ <boost/range/empty.hpp> +

+
+

+ empty +

+
+

+ Single Pass Range +

+
+

+ <boost/range/distance.hpp> +

+
+

+ distance +

+
+

+ Forward Range +

+
+

+ <boost/range/size.hpp> +

+
+

+ size +

+
+

+ Random Access + Range +

+
+

+ <boost/range/rbegin.hpp> +

+
+

+ rbegin and const_rbegin +

+
+

+ Bidirectional + Range +

+
+

+ <boost/range/rend.hpp> +

+
+

+ rend and const_rend +

+
+

+ Bidirectional + Range +

+
+

+ <boost/range/as_array.hpp> +

+
+

+ as_array +

+
+

+ - +

+
+

+ <boost/range/as_literal.hpp> +

+
+

+ as_literal +

+
+

+ - +

+
+

+ <boost/range/iterator_range.hpp> +

+
+

+ iterator_range +

+
+

+ - +

+
+

+ <boost/range/sub_range.hpp> +

+
+

+ sub_range +

+
+

+ - +

+
+

+ <boost/range/concepts.hpp> +

+
+

+ Range concepts +

+
+

+ - +

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/mfc_atl.html b/doc/html/range/mfc_atl.html new file mode 100644 index 0000000..8d5ed19 --- /dev/null +++ b/doc/html/range/mfc_atl.html @@ -0,0 +1,141 @@ + + + +MFC/ATL (courtesy of Shunsuke Sogame) + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
+ + Introduction +
+

+ This implementation was kindly donated by Shunsuke Sogame. This header adapts + MFC and ATL containers to the appropriate Range concepts. +

+
++++ + + + + + + + + + + + + + + + + + + + +
+

+ Author: +

+
+

+ Shunsuke Sogame +

+
+

+ Contact: +

+
+

+ mb2act@yahoo.co.jp +

+
+

+ Date: +

+
+

+ 26th of May 2006 +

+
+

+ Copyright: +

+
+

+ Shunsuke Sogame 2005-2006. Use, modification and distribution is + subject to the Boost Software License, Version 1.0 +

+
+
+ + Overview +
+

+ Boost.Range MFC/ATL Extension provides Boost.Range support for MFC/ATL collection + and string types. +

+

+ +

+
CTypedPtrArray<CPtrArray, CList<CString> *> myArray;
+...
+BOOST_FOREACH (CList<CString> *theList, myArray)
+{
+    BOOST_FOREACH (CString& str, *theList)
+    {
+        boost::to_upper(str);
+        std::sort(boost::begin(str), boost::end(str));
+        ...
+    }
+}
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/mfc_atl/atl_ranges.html b/doc/html/range/mfc_atl/atl_ranges.html new file mode 100644 index 0000000..65ee355 --- /dev/null +++ b/doc/html/range/mfc_atl/atl_ranges.html @@ -0,0 +1,374 @@ + + + +ATL Ranges + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ If the <boost/range/atl.hpp> + is included before or after Boost.Range headers, the ATL collections and + strings become models of Range. The table below lists the Traversal Category + and range_reference of ATL + ranges. +

+
+++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ Range +

+
+

+ Traversal Category +

+
+

+ range_reference<Range>::type +

+
+

+ CAtlArray<E,ET> +

+
+

+ Random Access + Range +

+
+

+ E& +

+
+

+ CAutoPtrArray<E> +

+
+

+ Random Access + Range +

+
+

+ E& +

+
+

+ CInterfaceArray<I,pi> +

+
+

+ Random Access + Range +

+
+

+ CComQIPtr<I,pi>& +

+
+

+ CAtlList<E,ET> +

+
+

+ Bidirectional + Range +

+
+

+ E& +

+
+

+ CAutoPtrList<E> +

+
+

+ Bidirectional + Range +

+
+

+ E& +

+
+

+ CHeapPtrList<E,A> +

+
+

+ Bidirectional + Range +

+
+

+ E& +

+
+

+ CInterfaceList<I,pi> +

+
+

+ Bidirectional + Range +

+
+

+ CComQIPtr<I,pi>& +

+
+

+ CAtlMap<K,V,KT,VT> +

+
+

+ Forward Range +

+
+

+ Range::CPair& +

+
+

+ CRBTree<K,V,KT,VT> +

+
+

+ Bidirectional + Range +

+
+

+ Range::CPair& +

+
+

+ CRBMap<K,V,KT,VT> +

+
+

+ Bidirectional + Range +

+
+

+ Range::CPair& +

+
+

+ CRBMultiMap<K,V,KT,VT> +

+
+

+ Bidirectional + Range +

+
+

+ Range::CPair& +

+
+

+ CSimpleStringT<B,b> +

+
+

+ Random Access + Range +

+
+

+ B& +

+
+

+ CStringT<B,ST> +

+
+

+ Random Access + Range +

+
+

+ B& +

+
+

+ CFixedStringT<S,n> +

+
+

+ Random Access + Range +

+
+

+ range_reference<S>::type +

+
+

+ CComBSTR +

+
+

+ Random Access + Range +

+
+

+ OLECHAR& +

+
+

+ CSimpleArray<T,TE> +

+
+

+ Random Access + Range +

+
+

+ T& +

+
+

+ Other Boost.Range metafunctions are defined + by the following. Let Range + be any type listed above and Ref + be the same as range_reference<Range>::type. + range_value<Range>::type is the same as remove_reference<Ref>::type, + range_difference<Range>::type is the same as std::ptrdiff_t, + and range_pointer<Range>::type is the same as add_pointer<remove_reference<Ref>::type>::type. + As for const Range, + see below. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/mfc_atl/const_ranges.html b/doc/html/range/mfc_atl/const_ranges.html new file mode 100644 index 0000000..2e047f6 --- /dev/null +++ b/doc/html/range/mfc_atl/const_ranges.html @@ -0,0 +1,125 @@ + + + +const Ranges + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ range_reference<const Range>::type + is defined by the following algorithm. Let Range + be any type listed above and Ref + be the same as range_reference<Range>::type. +

+

+ +

+
if (Range is CObArray || Range is CObList)
+    return CObject const * &
+else if (Range is CPtrArray || Range is CPtrList)
+    return void const * &
+else if (there is a type X such that X& is the same as Ref)
+    return X const &
+else if (there is a type X such that X* const is the same as Ref)
+    return X const * const
+else
+    return Ref
+
+

+

+

+ Other Boost.Range metafunctions are defined by the following. +

+
++++ + + + + + + + + + + + + + + + + + + +
+

+ Range metafunction +

+
+

+ Result +

+
+

+ range_value<const Range>::type +

+
+

+ range_value<Range>::type +

+
+

+ range_difference<const + Range>::type +

+
+

+ std::ptrdiff_t +

+
+

+ range_pointer<const Range>::type +

+
+

+ add_pointer<remove_reference<range_reference<const Range>::type>::type>::type +

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/mfc_atl/mfc_ranges.html b/doc/html/range/mfc_atl/mfc_ranges.html new file mode 100644 index 0000000..af0c6e9 --- /dev/null +++ b/doc/html/range/mfc_atl/mfc_ranges.html @@ -0,0 +1,480 @@ + + + +MFC Ranges + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ If the <boost/range/mfc.hpp> + is included before or after Boost.Range headers, the MFC collections and + strings become models of Range. The table below lists the Traversal Category + and range_reference of MFC + ranges. +

+
+++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ Range +

+
+

+ Traversal Category +

+
+

+ range_reference<Range>::type +

+
+

+ CArray<T,A> +

+
+

+ Random Access + Range +

+
+

+ T& +

+
+

+ CList<T,A> +

+
+

+ Bidirectional + Range +

+
+

+ T& +

+
+

+ CMap<K,AK,M,AM> +

+
+

+ Forward Range +

+
+

+ Range::CPair& +

+
+

+ CTypedPtrArray<B,T*> +

+
+

+ Random Access + Range +

+
+

+ T* + const +

+
+

+ CTypedPtrList<B,T*> +

+
+

+ Bidirectional + Range +

+
+

+ T* + const +

+
+

+ CTypedPtrMap<B,T*,V*> +

+
+

+ Forward Range +

+
+

+ std::pair<T*,V*> + const +

+
+

+ CByteArray +

+
+

+ Random Access + Range +

+
+

+ BYTE& +

+
+

+ CDWordArray +

+
+

+ Random Access + Range +

+
+

+ DWORD& +

+
+

+ CObArray +

+
+

+ Random Access + Range +

+
+

+ CObject*& +

+
+

+ CPtrArray +

+
+

+ Random Access + Range +

+
+

+ void*& +

+
+

+ CStringArray +

+
+

+ Random Access + Range +

+
+

+ CString& +

+
+

+ CUIntArray +

+
+

+ Random Access + Range +

+
+

+ UINT& +

+
+

+ CWordArray +

+
+

+ Random Access + Range +

+
+

+ WORD& +

+
+

+ CObList +

+
+

+ Bidirectional + Range +

+
+

+ CObject*& +

+
+

+ CPtrList +

+
+

+ Bidirectional + Range +

+
+

+ void*& +

+
+

+ CStringList +

+
+

+ Bidirectional + Range +

+
+

+ CString& +

+
+

+ CMapPtrToWord +

+
+

+ Forward Range +

+
+

+ std::pair<void*,WORD> + const +

+
+

+ CMapPtrToPtr +

+
+

+ Forward Range +

+
+

+ std::pair<void*,void*> + const +

+
+

+ CMapStringToOb +

+
+

+ Forward Range +

+
+

+ std::pair<String,CObject*> + const +

+
+

+ CMapStringToString +

+
+

+ Forward Range +

+
+

+ Range::CPair& +

+
+

+ CMapWordToOb +

+
+

+ Forward Range +

+
+

+ std::pair<WORD,CObject*> + const +

+
+

+ CMapWordToPtr +

+
+

+ Forward Range +

+
+

+ std::pair<WORD,void*> + const +

+
+

+ Other Boost.Range metafunctions are defined by the following. Let Range be any type listed above and Ref be the same as range_reference<Range>::type. + range_value<Range>::type is the same as remove_reference<remove_const<Ref>::type>::type, + range_difference<Range>::type is the same as std::ptrdiff_t, + and range_pointer<Range>::type is the same as add_pointer<remove_reference<Ref>::type>::type. + As for const Range, + see below. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/mfc_atl/references.html b/doc/html/range/mfc_atl/references.html new file mode 100644 index 0000000..124a538 --- /dev/null +++ b/doc/html/range/mfc_atl/references.html @@ -0,0 +1,50 @@ + + + +References + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/mfc_atl/requirements.html b/doc/html/range/mfc_atl/requirements.html new file mode 100644 index 0000000..131433f --- /dev/null +++ b/doc/html/range/mfc_atl/requirements.html @@ -0,0 +1,51 @@ + + + +Requirements + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
    +
  • + Boost C++ Libraries Version 1.34.0 or later (no compilation required) +
  • +
  • + Visual C++ 7.1 or later (for MFC and ATL) +
  • +
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/portability.html b/doc/html/range/portability.html new file mode 100644 index 0000000..901e0b1 --- /dev/null +++ b/doc/html/range/portability.html @@ -0,0 +1,89 @@ + + + +Portability + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ A huge effort has been made to port the library to as many compilers as possible. +

+

+ Full support for built-in arrays require that the compiler supports class template + partial specialization. For non-conforming compilers there might be a chance + that it works anyway thanks to workarounds in the type traits library. Visual + C++ 6/7.0 has a limited support for arrays: as long as the arrays are of built-in + type it should work. +

+

+ Notice also that some compilers cannot do function template ordering properly. + In that case one must rely of range_iterator and a single function + definition instead of overloaded versions for const and non-const arguments. + So if one cares about old compilers, one should not pass rvalues to the functions. +

+

+ For maximum portability you should follow these guidelines: +

+
    +
  1. + do not use built-in arrays, +
  2. +
  3. + do not pass rvalues to begin(), + end() and iterator_range Range constructors + and assignment operators, +
  4. +
  5. + use const_begin() and const_end() + whenever your code by intention is read-only; this will also solve most rvalue + problems, +
  6. +
  7. + do not rely on ADL: +
      +
    • + if you overload functions, include that header before the headers in + this library, +
    • +
    • + put all overloads in namespace boost. +
    • +
    +
  8. +
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference.html b/doc/html/range/reference.html new file mode 100644 index 0000000..70c17dc --- /dev/null +++ b/doc/html/range/reference.html @@ -0,0 +1,93 @@ + + + +Reference + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors.html b/doc/html/range/reference/adaptors.html new file mode 100644 index 0000000..5ab0ecd --- /dev/null +++ b/doc/html/range/reference/adaptors.html @@ -0,0 +1,51 @@ + + + +Range Adaptors + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_general_requirements.html b/doc/html/range/reference/adaptors/adaptors_general_requirements.html new file mode 100644 index 0000000..a815bae --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_general_requirements.html @@ -0,0 +1,141 @@ + + + +General Requirements + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ In the description of generator expressions, the following notation is + used: +

+
    +
  • +fwdRng is an expression + of a type R that models + ForwardRange +
  • +
  • +biRng is an expression + of a type R that models + BidirectionalRange +
  • +
  • +rndRng is an expression + of a type R that models + RandomAccessRange +
  • +
  • +pred is an expression + of a type that models UnaryPredicate +
  • +
  • +bi_pred is an expression + of a type that models BinaryPredicate +
  • +
  • +fun is an expression + of a type that models UnaryFunction +
  • +
  • +value, new_value and old_value + are objects convertible to boost::range_value<R>::type +
  • +
  • +n,m are integer expressions convertible + to range_difference<R>::type +
  • +
+

+ Also note that boost::range_value<R>::type must be implicitly convertible to + the type arguments to pred, + bi_pred and fun. +

+

+ Range Category in the following adaptor descriptions refers to the minimum + range concept required by the range passed to the adaptor. The resultant + range is a model of the same range concept as the input range unless specified + otherwise. +

+

+ Returned Range Category is the concept of the returned range. In some cases + the returned range is of a lesser category than the range passed to the + adaptor. For example, the filtered + adaptor returns only a ForwardRange + regardless of the input. +

+

+ Furthermore, the following rules apply to any expression of the form +

+
rng | boost::adaptors::adaptor_generator
+
+

+

+

+ 1. Applying operator|() + to a range R (always left + argument) and a range adapter RA + (always right argument) yields a new range type which may not conform to + the same range concept as R. +

+

+ 2. The return-type of operator|() is otherwise unspecified. +

+

+ 3. operator|() + is found by Argument Dependent Lookup (ADL) because a range adaptor is + implemented in namespace boost::adaptors. +

+

+ 4. operator|() + is used to add new behaviour lazily + and never modifies its left argument. +

+

+ 5. All iterators extracted from the left argument are extracted using qualified + calls to boost::begin() + and boost::end(). +

+

+ 6. In addition to the throw-clauses + below, operator|() + may throw exceptions as a result of copying iterators. If such copying + cannot throw an exception, then neither can the whole expression. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_introduction.html b/doc/html/range/reference/adaptors/adaptors_introduction.html new file mode 100644 index 0000000..efa54fd --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_introduction.html @@ -0,0 +1,274 @@ + + + +Introduction and motivation + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ A Range Adaptor is a class that wraps + an existing Range to provide a new Range with different behaviour. Since + the behaviour of Ranges is determined by their associated iterators, a + Range Adaptor simply wraps the underlying iterators with new special iterators. + In this example +

+

+ +

+
#include <boost/range/adaptors.hpp>
+#include <boost/range/algorithm.hpp>
+#include <iostream>
+#include <vector>
+
+std::vector<int> vec;
+boost::copy( vec | boost::adaptors::reversed,
+             std::ostream_iterator<int>(std::cout) );
+
+

+

+

+ the iterators from vec + are wrapped reverse_iterators. + The type of the underlying Range Adapter is not documented because you + do not need to know it. All that is relevant is that the expression +

+

+ +

+
vec | boost::adaptors::reversed
+
+

+

+

+ returns a Range Adaptor where the iterator type is now the iterator type + of the range vec wrapped + in reverse_iterator. The + expression boost::adaptors::reversed is called an Adaptor + Generator. +

+

+ There are two ways of constructing a range adaptor. The first is by using + operator|(). + This is my preferred technique, however while discussing range adaptors + with others it became clear that some users of the library strongly prefer + a more familiar function syntax, so equivalent functions of the present + tense form have been added as an alternative syntax. The equivalent to + rng | + reversed is adaptors::reverse(rng) for example. +

+

+ Why do I prefer the operator| syntax? The answer is readability: +

+

+ +

+
std::vector<int> vec;
+boost::copy( boost::adaptors::reverse(vec),
+             std::ostream_iterator<int>(std::cout) );
+
+

+

+

+ This might not look so bad, but when we apply several adaptors, it becomes + much worse. Just compare +

+

+ +

+
std::vector<int> vec;
+boost::copy( boost::adaptors::unique( boost::adaptors::reverse( vec ) ),
+             std::ostream_iterator<int>(std::cout) );
+
+

+

+

+ to +

+

+ +

+
std::vector<int> vec;
+boost::copy( vec | boost::adaptors::reversed
+                 | boost::adaptors::uniqued,
+             std::ostream_iterator<int>(std::cout) );
+
+

+

+

+ Furthermore, some of the adaptor generators take arguments themselves and + these arguments are expressed with function call notation too. In those + situations, you will really appreciate the succinctness of operator|(). +

+
+ + Composition + of Adaptors +
+

+ Range Adaptors are a powerful complement to Range algorithms. The reason + is that adaptors are orthogonal + to algorithms. For example, consider these Range algorithms: +

+
    +
  • boost::copy( rng, out )
  • +
  • boost::count( rng, pred )
  • +
+

+ What should we do if we only want to copy an element a + if it satisfies some predicate, say pred(a)? + And what if we only want to count the elements that satisfy the same predicate? + The naive answer would be to use these algorithms: +

+
    +
  • boost::copy_if( + rng, + pred, + out )
  • +
  • boost::count_if( + rng, + pred )
  • +
+

+ These algorithms are only defined to maintain a one to one relationship + with the standard library algorithms. This approach of adding algorithm + suffers a combinatorial explosion. Inevitably many algorithms are missing + _if variants and there + is redundant development overhead for each new algorithm. The Adaptor Generator + is the design solution to this problem. +

+
+ + Range + Adaptor alternative to copy_if algorithm +
+

+ +

+
boost::copy_if( rng, pred, out );
+
+

+ can be expressed as +

+
boost::copy( rng | boost::adaptors::filtered(pred), out );
+
+

+

+
+ + Range + Adaptor alternative to count_if algorithm +
+

+ +

+
boost::count_if( rng, pred );
+
+

+ can be expressed as +

+
boost::count( rng | boost::adaptors::filtered(pred), out );
+
+

+

+

+ What this means is that no + algorithm with the _if + suffix is needed. Furthermore, it turns out that algorithms with the _copy suffix are not needed either. Consider + the somewhat misdesigned replace_copy_if() which may be used as +

+

+ +

+
std::vector<int> vec;
+boost::replace_copy_if( rng, std::back_inserter(vec), pred );
+
+

+

+

+ With adaptors and algorithms we can express this as +

+

+ +

+
std::vector<int> vec;
+boost::push_back(vec, rng | boost::adaptors::replaced_if(pred, new_value));
+
+

+

+

+ The latter code has several benefits: +

+

+ 1. it is more efficient + because we avoid extra allocations as might happen with std::back_inserter +

+

+ 2. it is flexible + as we can subsequently apply even more adaptors, for example: +

+
boost::push_back(vec, rng | boost::adaptors::replaced_if(pred, new_value)
+                          | boost::adaptors::reversed);
+
+

+

+

+ 3. it is safer because + there is no use of an unbounded output iterator. +

+

+ In this manner, the composition + of Range Adaptors has the following consequences: +

+

+ 1. we no longer need _if, + _copy, _copy_if + and _n variants of algorithms. +

+

+ 2. we can generate a multitude of new algorithms on the fly, for example, + above we generated reverse_replace_copy_if() +

+

+ In other words: +

+

+ Range Adaptors are to algorithms what algorithms + are to containers +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_reference.html b/doc/html/range/reference/adaptors/adaptors_reference.html new file mode 100644 index 0000000..d284888 --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_reference.html @@ -0,0 +1,75 @@ + + + +Reference + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_reference/adjacent_filtered.html b/doc/html/range/reference/adaptors/adaptors_reference/adjacent_filtered.html new file mode 100644 index 0000000..fa763c8 --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_reference/adjacent_filtered.html @@ -0,0 +1,151 @@ + + + +adjacent_filtered + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
++++ + + + + + + + + + + + + + + +
+

+ Syntax +

+
+

+ Code +

+
+

+ Pipe +

+
+

+ rng | + boost::adaptors::adjacent_filtered(bi_pred) +

+
+

+ Function +

+
+

+ boost::adaptors::adjacent_filter(rng, + bi_pred) +

+
+
    +
  • +Precondition: The value_type + of the range is convertible to both argument types of bi_pred. +
  • +
  • +Postcondition: For all adjacent elements + [x,y] in the returned range, bi_pred(x,y) + is true. +
  • +
  • +Throws: Whatever the copy constructor + of bi_pred might throw. +
  • +
  • +Range Category:SinglePassRange +
  • +
+
+ +

+ +

+
#include <boost/range/adaptor/adjacent_filtered.hpp>
+#include <boost/range/algorithm/copy.hpp>
+#include <boost/assign.hpp>
+#include <algorithm>
+#include <functional>
+#include <iostream>
+#include <vector>
+
+int main(int argc, const char* argv[])
+{
+    using namespace boost::assign;
+    using namespace boost::adaptors;
+
+    std::vector<int> input;
+    input += 1,1,2,2,2,3,4,5,6;
+
+    boost::copy(
+        input | adjacent_filtered(std::not_equal_to<int>()),
+        std::ostream_iterator<int>(std::cout, ","));
+
+    return 0;
+}
+
+

+

+
+

+ This would produce the output: +

+
1,2,3,4,5,6
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_reference/copied.html b/doc/html/range/reference/adaptors/adaptors_reference/copied.html new file mode 100644 index 0000000..650e29a --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_reference/copied.html @@ -0,0 +1,152 @@ + + + +copied + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
++++ + + + + + + + + + + + + + + +
+

+ Syntax +

+
+

+ Code +

+
+

+ Pipe +

+
+

+ rng | + boost::adaptors::copied(n, + m) +

+
+

+ Function +

+
+

+ boost::adaptors::copy(rng, + n, + m) +

+
+
    +
  • +Precondition:0 + <= n + && n + <= m + && m + < distance(rng) +
  • +
  • +Returns: A new iterator_range + that holds the sliced range [n,m) + of the original range. +
  • +
  • +Range Category:RandomAccessRange +
  • +
+
+ +

+ +

+
#include <boost/range/adaptor/copied.hpp>
+#include <boost/range/algorithm/copy.hpp>
+#include <boost/assign.hpp>
+#include <algorithm>
+#include <iostream>
+#include <vector>
+
+int main(int argc, const char* argv[])
+{
+    using namespace boost::assign;
+    using namespace boost::adaptors;
+
+    std::vector<int> input;
+    input += 1,2,3,4,5,6,7,8,9,10;
+
+    boost::copy(
+        input | copied(1, 5),
+        std::ostream_iterator<int>(std::cout, ","));
+
+    return 0;
+}
+
+

+

+
+

+ This would produce the output: +

+
2,3,4,5
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_reference/filtered.html b/doc/html/range/reference/adaptors/adaptors_reference/filtered.html new file mode 100644 index 0000000..1551a9f --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_reference/filtered.html @@ -0,0 +1,156 @@ + + + +filtered + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
++++ + + + + + + + + + + + + + + +
+

+ Syntax +

+
+

+ Code +

+
+

+ Pipe +

+
+

+ rng | + boost::adaptors::filtered(pred) +

+
+

+ Function +

+
+

+ boost::adaptors::filter(rng, + pred) +

+
+
    +
  • +Precondition: The value_type + of the range is convertible to the argument type of pred. +
  • +
  • +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:ForwardRange +
  • +
  • +Returned Range Category:ForwardRange +
  • +
+
+ +

+ +

+
#include <boost/range/adaptor/filtered.hpp>
+#include <boost/range/algorithm/copy.hpp>
+#include <boost/assign.hpp>
+#include <algorithm>
+#include <iostream>
+#include <vector>
+
+struct is_even
+{
+    bool operator()( int x ) const { return x % 2 == 0; }
+};
+
+int main(int argc, const char* argv[])
+{
+    using namespace boost::assign;
+    using namespace boost::adaptors;
+
+    std::vector<int> input;
+    input += 1,2,3,4,5,6,7,8,9;
+
+    boost::copy(
+        input | filtered(is_even()),
+        std::ostream_iterator<int>(std::cout, ","));
+}
+
+

+

+
+

+ This would produce the output: +

+
2,4,6,8
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_reference/indexed.html b/doc/html/range/reference/adaptors/adaptors_reference/indexed.html new file mode 100644 index 0000000..d8c8674 --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_reference/indexed.html @@ -0,0 +1,186 @@ + + + +indexed + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
++++ + + + + + + + + + + + + + + +
+

+ Syntax +

+
+

+ Code +

+
+

+ Pipe +

+
+

+ rng | + boost::adaptors::indexed +

+
+

+ Function +

+
+

+ boost::adaptors::index(rng) +

+
+
    +
  • +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:SinglePassRange +
  • +
+
+ +

+ +

+
#include <boost/range/adaptor/indexed.hpp>
+#include <boost/range/algorithm/copy.hpp>
+#include <boost/assign.hpp>
+#include <algorithm>
+#include <iostream>
+#include <vector>
+
+template<class Iterator>
+void display_element_and_index(Iterator first, Iterator last)
+{
+    for (Iterator it = first; it != last; ++it)
+    {
+        std::cout << "Element = " << *it << " Index = " << it.index() << std::endl;
+    }
+}
+
+template<class SinglePassRange>
+void display_element_and_index(const SinglePassRange& rng)
+{
+    display_element_and_index(boost::begin(rng), boost::end(rng));
+}
+
+template<class Iterator1, class Iterator2>
+void check_element_and_index(
+        Iterator1 test_first,
+        Iterator1 test_last,
+        Iterator2 reference_first,
+        Iterator2 reference_last)
+{
+    BOOST_CHECK_EQUAL( std::distance(test_first, test_last),
+                       std::distance(reference_first, reference_last) );
+
+    int reference_index = 0;
+
+    Iterator1 test_it = test_first;
+    Iterator2 reference_it = reference_first;
+    for (; test_it != test_last; ++test_it, ++reference_it, ++reference_index)
+    {
+        BOOST_CHECK_EQUAL( *test_it, *reference_it );
+        BOOST_CHECK_EQUAL( test_it.index(), reference_index );
+    }
+}
+
+int main(int argc, const char* argv[])
+{
+    using namespace boost::assign;
+    using namespace boost::adaptors;
+
+    std::vector<int> input;
+    input += 10,20,30,40,50,60,70,80,90;
+
+    display_element_and_index( input | indexed(0) );
+
+    return 0;
+}
+
+

+

+
+

+ This would produce the output: +

+
Element = 10 Index = 0
+Element = 20 Index = 1
+Element = 30 Index = 2
+Element = 40 Index = 3
+Element = 50 Index = 4
+Element = 60 Index = 5
+Element = 70 Index = 6
+Element = 80 Index = 7
+Element = 90 Index = 8
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_reference/indirected.html b/doc/html/range/reference/adaptors/adaptors_reference/indirected.html new file mode 100644 index 0000000..adcd57a --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_reference/indirected.html @@ -0,0 +1,146 @@ + + + +indirected + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
++++ + + + + + + + + + + + + + + +
+

+ Syntax +

+
+

+ Code +

+
+

+ Pipe +

+
+

+ rng | + boost::adaptors::indirected +

+
+

+ Function +

+
+

+ boost::adaptors::indirect(rng) +

+
+
    +
  • +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:SinglePassRange +
  • +
+
+ +

+ +

+
#include <boost/range/adaptor/indirected.hpp>
+#include <boost/range/algorithm/copy.hpp>
+#include <boost/shared_ptr.hpp>
+#include <algorithm>
+#include <iostream>
+#include <vector>
+
+int main(int argc, const char* argv[])
+{
+    using namespace boost::adaptors;
+
+    std::vector<boost::shared_ptr<int> > input;
+
+    for (int i = 0; i < 10; ++i)
+        input.push_back(boost::shared_ptr<int>(new int(i)));
+
+    boost::copy(
+        input | indirected,
+        std::ostream_iterator<int>(std::cout, ","));
+
+    return 0;
+}
+
+

+

+
+

+ This would produce the output: +

+
0,1,2,3,4,5,6,7,8,9
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_reference/map_keys.html b/doc/html/range/reference/adaptors/adaptors_reference/map_keys.html new file mode 100644 index 0000000..95c1746 --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_reference/map_keys.html @@ -0,0 +1,146 @@ + + + +map_keys + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
++++ + + + + + + + + + + + + + + +
+

+ Syntax +

+
+

+ Code +

+
+

+ Pipe +

+
+

+ rng | + boost::adaptors::map_keys +

+
+

+ Function +

+
+

+ boost::adaptors::keys(rng) +

+
+
    +
  • +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:SinglePassRange +
  • +
+
+ +

+ +

+
#include <boost/range/adaptor/map.hpp>
+#include <boost/range/algorithm/copy.hpp>
+#include <boost/assign.hpp>
+#include <algorithm>
+#include <iostream>
+#include <map>
+#include <vector>
+
+int main(int argc, const char* argv[])
+{
+    using namespace boost::assign;
+    using namespace boost::adaptors;
+
+    std::map<int,int> input;
+    for (int i = 0; i < 10; ++i)
+        input.insert(std::make_pair(i, i * 10));
+
+    boost::copy(
+        input | map_keys,
+        std::ostream_iterator<int>(std::cout, ","));
+
+    return 0;
+}
+
+

+

+
+

+ This would produce the output: +

+
0,1,2,3,4,5,6,7,8,9
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_reference/map_values.html b/doc/html/range/reference/adaptors/adaptors_reference/map_values.html new file mode 100644 index 0000000..553a8f3 --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_reference/map_values.html @@ -0,0 +1,146 @@ + + + +map_values + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
++++ + + + + + + + + + + + + + + +
+

+ Syntax +

+
+

+ Code +

+
+

+ Pipe +

+
+

+ rng | + boost::adaptors::map_values +

+
+

+ Function +

+
+

+ boost::adaptors::values(rng) +

+
+
    +
  • +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:SinglePassRange +
  • +
+
+ +

+ +

+
#include <boost/range/adaptor/map.hpp>
+#include <boost/range/algorithm/copy.hpp>
+#include <boost/assign.hpp>
+#include <algorithm>
+#include <iostream>
+#include <map>
+#include <vector>
+
+int main(int argc, const char* argv[])
+{
+    using namespace boost::assign;
+    using namespace boost::adaptors;
+
+    std::map<int,int> input;
+    for (int i = 0; i < 10; ++i)
+        input.insert(std::make_pair(i, i * 10));
+
+    boost::copy(
+        input | map_values,
+        std::ostream_iterator<int>(std::cout, ","));
+
+    return 0;
+}
+
+

+

+
+

+ This would produce the output: +

+
0,10,20,30,40,50,60,70,80,90
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_reference/replaced.html b/doc/html/range/reference/adaptors/adaptors_reference/replaced.html new file mode 100644 index 0000000..0990ede --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_reference/replaced.html @@ -0,0 +1,161 @@ + + + +replaced + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
++++ + + + + + + + + + + + + + + +
+

+ Syntax +

+
+

+ Code +

+
+

+ Pipe +

+
+

+ rng | + boost::adaptors::replaced(new_value, + old_value) +

+
+

+ Function +

+
+

+ boost::adaptors::replace(rng, + new_value, + old_value) +

+
+
    +
  • +Precondition:
      +
    • +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:ForwardRange +
  • +
+
+ +

+ +

+
#include <boost/range/adaptor/replaced.hpp>
+#include <boost/range/algorithm/copy.hpp>
+#include <boost/assign.hpp>
+#include <algorithm>
+#include <iostream>
+#include <vector>
+
+int main(int argc, const char* argv[])
+{
+    using namespace boost::adaptors;
+    using namespace boost::assign;
+
+    std::vector<int> input;
+    input += 1,2,3,2,5,2,7,2,9;
+
+    boost::copy(
+        input | replaced(2, 10),
+        std::ostream_iterator<int>(std::cout, ","));
+
+    return 0;
+}
+
+

+

+
+

+ This would produce the output: +

+
1,10,3,10,5,10,7,10,9
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_reference/replaced_if.html b/doc/html/range/reference/adaptors/adaptors_reference/replaced_if.html new file mode 100644 index 0000000..abcf00f --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_reference/replaced_if.html @@ -0,0 +1,165 @@ + + + +replaced_if + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
++++ + + + + + + + + + + + + + + +
+

+ Syntax +

+
+

+ Code +

+
+

+ Pipe +

+
+

+ rng | + boost::adaptors::replaced_if(pred, + new_value) +

+
+

+ Function +

+
+

+ boost::adaptors::replace_if(rng, + pred, + new_value) +

+
+
    +
  • +Precondition:
      +
    • + 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:ForwardRange +
  • +
+
+ +

+ +

+
#include <boost/range/adaptor/replaced_if.hpp>
+#include <boost/range/algorithm/copy.hpp>
+#include <boost/assign.hpp>
+#include <algorithm>
+#include <iostream>
+#include <vector>
+
+struct is_even
+{
+    bool operator()(int x) const { return x % 2 == 0; }
+};
+
+int main(int argc, const char* argv[])
+{
+    using namespace boost::adaptors;
+    using namespace boost::assign;
+
+    std::vector<int> input;
+    input += 1,2,3,4,5,6,7,8,9;
+
+    boost::copy(
+        input | replaced_if(is_even(), 10),
+        std::ostream_iterator<int>(std::cout, ","));
+
+    return 0;
+}
+
+

+

+
+

+ This would produce the output: +

+
1,10,3,10,5,10,7,10,9
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_reference/reversed.html b/doc/html/range/reference/adaptors/adaptors_reference/reversed.html new file mode 100644 index 0000000..52f4cda --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_reference/reversed.html @@ -0,0 +1,140 @@ + + + +reversed + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
++++ + + + + + + + + + + + + + + +
+

+ Syntax +

+
+

+ Code +

+
+

+ Pipe +

+
+

+ rng | + boost::adaptors::reversed +

+
+

+ Function +

+
+

+ boost::adaptors::reverse(rng) +

+
+
    +
  • +Returns: A range whose iterators behave + as if they were the original iterators wrapped in reverse_iterator. +
  • +
  • +Range Category:BidirectionalRange +
  • +
+
+ +

+ +

+
#include <boost/range/adaptor/reversed.hpp>
+#include <boost/range/algorithm/copy.hpp>
+#include <boost/assign.hpp>
+#include <algorithm>
+#include <iostream>
+#include <vector>
+
+void reversed_example_test()
+{
+    using namespace boost::adaptors;
+    using namespace boost::assign;
+
+    std::vector<int> input;
+    input += 1,2,3,4,5,6,7,8,9;
+
+    boost::copy(
+        input | reversed,
+        std::ostream_iterator<int>(std::cout, ","));
+
+    return 0;
+}
+
+

+

+
+

+ This would produce the output: +

+
9,8,7,6,5,4,3,2,1
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_reference/sliced.html b/doc/html/range/reference/adaptors/adaptors_reference/sliced.html new file mode 100644 index 0000000..9793092 --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_reference/sliced.html @@ -0,0 +1,150 @@ + + + +sliced + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
++++ + + + + + + + + + + + + + + +
+

+ Syntax +

+
+

+ Code +

+
+

+ Pipe +

+
+

+ rng | + boost::adaptors::sliced(n, + m) +

+
+

+ Function +

+
+

+ boost::adaptors::slice(rng, + n, + m) +

+
+
    +
  • +Precondition:0 + <= n + && n + <= m + && m + < distance(rng) +
  • +
  • +Returns:make_range(rng, n, m) +
  • +
  • +Range Category:RandomAccessRange +
  • +
+
+ +

+ +

+
#include <boost/range/adaptor/sliced.hpp>
+#include <boost/range/algorithm/copy.hpp>
+#include <boost/assign.hpp>
+#include <algorithm>
+#include <iostream>
+#include <vector>
+
+int main(int argc, const char* argv[])
+{
+    using namespace boost::adaptors;
+    using namespace boost::assign;
+
+    std::vector<int> input;
+    input += 1,2,3,4,5,6,7,8,9;
+
+    boost::copy(
+        input | sliced(2, 5),
+        std::ostream_iterator<int>(std::cout, ","));
+
+    return 0;
+}
+
+

+

+
+

+ This would produce the output: +

+
3,4,5
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_reference/strided.html b/doc/html/range/reference/adaptors/adaptors_reference/strided.html new file mode 100644 index 0000000..6fcc281 --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_reference/strided.html @@ -0,0 +1,147 @@ + + + +strided + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
++++ + + + + + + + + + + + + + + +
+

+ Syntax +

+
+

+ Code +

+
+

+ Pipe +

+
+

+ rng | + boost::adaptors::strided(n) +

+
+

+ Function +

+
+

+ boost::adaptors::stride(rng, + n) +

+
+
    +
  • +Precondition:0 + <= n + && n + < distance(rng) +
  • +
  • +Returns: A new range based on rng where traversal is performed + in steps of n. +
  • +
  • +Range Category:RandomAccessRange +
  • +
+
+ +

+ +

+
#include <boost/range/adaptor/strided.hpp>
+#include <boost/range/algorithm/copy.hpp>
+#include <boost/assign.hpp>
+#include <algorithm>
+#include <iostream>
+#include <vector>
+
+int main(int argc, const char* argv[])
+{
+    using namespace boost::adaptors;
+    using namespace boost::assign;
+
+    std::vector<int> input;
+    input += 1,2,3,4,5,6,7,8,9,10;
+
+    boost::copy(
+        input | strided(2),
+        std::ostream_iterator<int>(std::cout, ","));
+
+    return 0;
+}
+
+

+

+
+

+ This would produce the output: +

+
1,3,5,7,9
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_reference/tokenized.html b/doc/html/range/reference/adaptors/adaptors_reference/tokenized.html new file mode 100644 index 0000000..fc4bc42 --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_reference/tokenized.html @@ -0,0 +1,143 @@ + + + +tokenized + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
++++ + + + + + + + + + + + + + + +
+

+ Syntax +

+
+

+ Code +

+
+

+ Pipe +

+
+

+ +

+
rng | boost::adaptors::tokenized(regex)
+rng | boost::adaptors::tokenized(regex, i)
+rng | boost::adaptors::tokenized(regex, rndRng)
+rng | boost::adaptors::tokenized(regex, i, flags)
+rng | boost::adaptors::tokenized(regex, rndRng, flags)
+
+

+

+
+

+ Function +

+
+

+ +

+
boost::adaptors::tokenize(rng, regex)
+boost::adaptors::tokenize(rng, regex, i)
+boost::adaptors::tokenize(rng, regex, rndRng)
+boost::adaptors::tokenize(rng, regex, i, flags)
+boost::adaptors::tokenize(rng, regex, rndRng, flags)
+
+

+

+
+
    +
  • +Precondition:
      +
    • + Let T denote typename range_value<decltype(rng)>::type, + then regex has + the type basic_regex<T> or is implicitly convertible + to one of these types. +
    • +
    • +i has the type + int. +
    • +
    • + the value_type + of rndRng is int. +
    • +
    • +flags has the type + regex_constants::syntax_option_type. +
    • +
    +
  • +
  • +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_iterators + might throw. +
  • +
  • +Range Category:RandomAccessRange +
  • +
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_reference/transformed.html b/doc/html/range/reference/adaptors/adaptors_reference/transformed.html new file mode 100644 index 0000000..56a6170 --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_reference/transformed.html @@ -0,0 +1,156 @@ + + + +transformed + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
++++ + + + + + + + + + + + + + + +
+

+ Syntax +

+
+

+ Code +

+
+

+ Pipe +

+
+

+ rng | + boost::adaptors::transformed(fun) +

+
+

+ Function +

+
+

+ boost::adaptors::transform(rng, + fun) +

+
+
    +
  • +Precondition: The value_type + of the range is convertible to the argument type of fun. +
  • +
  • +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:SinglePassRange +
  • +
+
+ +

+ +

+
#include <boost/range/adaptor/transformed.hpp>
+#include <boost/range/algorithm/copy.hpp>
+#include <boost/assign.hpp>
+#include <algorithm>
+#include <iostream>
+#include <vector>
+
+struct double_int
+{
+    typedef int result_type;
+    int operator()(int x) const { return x * 2; }
+};
+
+int main(int argc, const char* argv[])
+{
+    using namespace boost::adaptors;
+    using namespace boost::assign;
+
+    std::vector<int> input;
+    input += 1,2,3,4,5,6,7,8,9,10;
+
+    boost::copy(
+        input | transformed(double_int()),
+        std::ostream_iterator<int>(std::cout, ","));
+
+    return 0;
+}
+
+

+

+
+

+ This would produce the output: +

+
2,4,6,8,10,12,14,16,18,20
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_reference/uniqued.html b/doc/html/range/reference/adaptors/adaptors_reference/uniqued.html new file mode 100644 index 0000000..3b314ab --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_reference/uniqued.html @@ -0,0 +1,142 @@ + + + +uniqued + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
++++ + + + + + + + + + + + + + + +
+

+ Syntax +

+
+

+ Code +

+
+

+ Pipe +

+
+

+ rng | + boost::adaptors::uniqued +

+
+

+ Function +

+
+

+ boost::adaptors::unique(rng) +

+
+
    +
  • +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:ForwardRange +
  • +
+
+ +

+ +

+
#include <boost/range/adaptor/uniqued.hpp>
+#include <boost/range/algorithm/copy.hpp>
+#include <boost/assign.hpp>
+#include <algorithm>
+#include <iostream>
+#include <vector>
+
+void uniqued_example_test()
+{
+    using namespace boost::assign;
+    using namespace boost::adaptors;
+
+    std::vector<int> input;
+    input += 1,1,2,2,2,3,4,5,6;
+
+    boost::copy(
+        input | uniqued,
+        std::ostream_iterator<int>(std::cout, ","));
+}
+
+

+

+
+

+ This would produce the output: +

+
1,2,3,4,5,6
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/adaptors/adaptors_synopsis.html b/doc/html/range/reference/adaptors/adaptors_synopsis.html new file mode 100644 index 0000000..d0fea59 --- /dev/null +++ b/doc/html/range/reference/adaptors/adaptors_synopsis.html @@ -0,0 +1,67 @@ + + + +Synopsis + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ The library provides the following Adapter Generator expressions: +

+

+ +

+
rng | boost::adaptors::adjacent_filtered(bi_pred)
+rng | boost::adaptors::copied(n,m)
+rng | boost::adaptors::filtered(pred)
+rng | boost::adaptors::indexed
+rng | boost::adaptors::indirected
+rng | boost::adaptors::map_keys
+rng | boost::adaptors::map_values
+rng | boost::adaptors::replaced(new_value, old_value)
+rng | boost::adaptors::replaced_if(pred, new_value)
+rng | boost::adaptors::reversed
+rng | boost::adaptors::sliced(n, m)
+rng | boost::adaptors::strided(n)
+rng | boost::adaptors::tokenized( <see arguments below> )
+rng | boost::adaptors::transformed(fun)
+rng | boost::adaptors::uniqued
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms.html b/doc/html/range/reference/algorithms.html new file mode 100644 index 0000000..fc70d02 --- /dev/null +++ b/doc/html/range/reference/algorithms.html @@ -0,0 +1,59 @@ + + + +Range Algorithm + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/heap_algorithms.html b/doc/html/range/reference/algorithms/heap_algorithms.html new file mode 100644 index 0000000..25c45e4 --- /dev/null +++ b/doc/html/range/reference/algorithms/heap_algorithms.html @@ -0,0 +1,51 @@ + + + +Heap algorithms + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/heap_algorithms/make_heap.html b/doc/html/range/reference/algorithms/heap_algorithms/make_heap.html new file mode 100644 index 0000000..d8d4033 --- /dev/null +++ b/doc/html/range/reference/algorithms/heap_algorithms/make_heap.html @@ -0,0 +1,144 @@ + + + +make_heap + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class RandomAccessRange>
+void make_heap(RandomAccessRange& rng);
+
+template<class RandomAccessRange>
+void make_heap(const RandomAccessRange& rng);
+
+template<class RandomAccessRange, class Compare>
+void make_heap(RandomAccessRange& rng, Compare pred);
+
+template<class RandomAccessRange, class Compare>
+void make_heap(const RandomAccessRange& rng, Compare pred);
+
+

+

+
+ + Description +
+

+ make_heap turns rng into a heap. +

+

+ The ordering relationship is determined by using operator< in the non-predicate versions, and + by evaluating pred in + the predicate versions. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/heap_algorithm.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +RandomAccessRange is + a model of the Random + Access Range Concept. +
  • +
  • +RandomAccessRange is + mutable. +
  • +
  • +RandomAccessRange's + value type is a model of the LessThanComparableConcept. +
  • +
  • + The ordering of objects of type RandomAccessRange's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
+

+ For the predicate versions: +

+
    +
  • +RandomAccessRange is + a model of the Random + Access Range Concept. +
  • +
  • +RandomAccessRange is + mutable. +
  • +
  • +Compare is a model + of the StrictWeakOrderingConcept. +
  • +
  • +RandomAccessRange's + value type is convertible to both of Compare's + argument types. +
  • +
+
+ + Complexity +
+

+ Linear. At most 3 * + distance(rng) + comparisons. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/heap_algorithms/pop_heap.html b/doc/html/range/reference/algorithms/heap_algorithms/pop_heap.html new file mode 100644 index 0000000..f1588b7 --- /dev/null +++ b/doc/html/range/reference/algorithms/heap_algorithms/pop_heap.html @@ -0,0 +1,156 @@ + + + +pop_heap + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class RandomAccessRange>
+void pop_heap(RandomAccessRange& rng);
+
+template<class RandomAccessRange>
+void pop_heap(const RandomAccessRange& rng);
+
+template<class RandomAccessRange, class Compare>
+void pop_heap(RandomAccessRange& rng, Compare pred);
+
+template<class RandomAccessRange, class Compare>
+void pop_heap(const RandomAccessRange& rng, Compare pred);
+
+

+

+
+ + Description +
+

+ pop_heap removes the + largest element from the heap. It is assumed that begin(rng), prior(end(rng)) is already a heap and that the element + to be added is *prior(end(rng)). +

+

+ The ordering relationship is determined by using operator< in the non-predicate versions, and + by evaluating pred in + the predicate versions. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/heap_algorithm.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +RandomAccessRange is + a model of the Random + Access Range Concept. +
  • +
  • +RandomAccessRange is + mutable. +
  • +
  • +RandomAccessRange's + value type is a model of the LessThanComparableConcept. +
  • +
  • + The ordering of objects of type RandomAccessRange's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
+

+ For the predicate versions: +

+
    +
  • +RandomAccessRange is + a model of the Random + Access Range Concept. +
  • +
  • +RandomAccessRange is + mutable. +
  • +
  • +Compare is a model + of the StrictWeakOrderingConcept. +
  • +
  • +RandomAccessRange's + value type is convertible to both of Compare's + argument types. +
  • +
+
+ + Precondition: +
+
    +
  • !empty(rng)
  • +
  • +rng is a heap. +
  • +
+
+ + Complexity +
+

+ Logarithmic. At most 2 * + log(distance(rng)) + comparisons. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/heap_algorithms/push_heap.html b/doc/html/range/reference/algorithms/heap_algorithms/push_heap.html new file mode 100644 index 0000000..35b64ca --- /dev/null +++ b/doc/html/range/reference/algorithms/heap_algorithms/push_heap.html @@ -0,0 +1,154 @@ + + + +push_heap + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class RandomAccessRange>
+void push_heap(RandomAccessRange& rng);
+
+template<class RandomAccessRange>
+void push_heap(const RandomAccessRange& rng);
+
+template<class RandomAccessRange, class Compare>
+void push_heap(RandomAccessRange& rng, Compare pred);
+
+template<class RandomAccessRange, class Compare>
+void push_heap(const RandomAccessRange& rng, Compare pred);
+
+

+

+
+ + Description +
+

+ push_heap adds an element + to a heap. It is assumed that begin(rng), prior(end(rng)) is already a heap and that the element + to be added is *prior(end(rng)). +

+

+ The ordering relationship is determined by using operator< in the non-predicate versions, and + by evaluating pred in + the predicate versions. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/heap_algorithm.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +RandomAccessRange is + a model of the Random + Access Range Concept. +
  • +
  • +RandomAccessRange is + mutable. +
  • +
  • +RandomAccessRange's + value type is a model of the LessThanComparableConcept. +
  • +
  • + The ordering of objects of type RandomAccessRange's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
+

+ For the predicate versions: +

+
    +
  • +RandomAccessRange is + a model of the Random + Access Range Concept. +
  • +
  • +RandomAccessRange is + mutable. +
  • +
  • +Compare is a model + of the StrictWeakOrderingConcept. +
  • +
  • +RandomAccessRange's + value type is convertible to both of Compare's + argument types. +
  • +
+
+ + Precondition: +
+
    +
  • !empty(rng)
  • +
  • +[begin(rng), prior(end(rng))) is a heap. +
  • +
+
+ + Complexity +
+

+ Logarithmic. At most log(distance(rng)) comparisons. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/permutation_algorithms.html b/doc/html/range/reference/algorithms/permutation_algorithms.html new file mode 100644 index 0000000..12e33f9 --- /dev/null +++ b/doc/html/range/reference/algorithms/permutation_algorithms.html @@ -0,0 +1,50 @@ + + + +Permutation algorithms + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/permutation_algorithms/next_permutation.html b/doc/html/range/reference/algorithms/permutation_algorithms/next_permutation.html new file mode 100644 index 0000000..8521343 --- /dev/null +++ b/doc/html/range/reference/algorithms/permutation_algorithms/next_permutation.html @@ -0,0 +1,149 @@ + + + +next_permutation + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class BidirectionalRange>
+void next_permutation(BidirectionalRange& rng);
+
+template<class BidirectionalRange>
+void next_permutation(const BidirectionalRange& rng);
+
+template<class BidirectionalRange, class Compare>
+void next_permutation(BidirectionalRange& rng, Compare pred);
+
+template<class BidirectionalRange, class Compare>
+void next_permutation(const BidirectionalRange& rng, Compare pred);
+
+

+

+
+ + Description +
+

+ next_permutation transforms + the range of elements rng + into the lexicographically next greater permutation of the elements if + such a permutation exists. If one does not exist then the range is transformed + into the lexicographically smallest permutation and false + is returned. true is returned + when the next greater permutation is successfully generated. +

+

+ The ordering relationship is determined by using operator< in the non-predicate versions, and + by evaluating pred in + the predicate versions. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/permutation.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +BidirectionalRange + is a model of the Bidirectional + Range Concept. +
  • +
  • +BidirectionalRange + is mutable. +
  • +
  • +BidirectionalRange's + value type is a model of the LessThanComparableConcept. +
  • +
  • + The ordering of objects of type BidirectionalRange's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
+

+ For the predicate versions: +

+
    +
  • +BidirectionalRange + is a model of the Bidirectional + Range Concept. +
  • +
  • +BidirectionalRange + is mutable. +
  • +
  • +Compare is a model + of the StrictWeakOrderingConcept. +
  • +
  • +BidirectionalRange's + value type is convertible to both of Compare's + argument types. +
  • +
+
+ + Complexity +
+

+ Linear. At most distance(rng) / 2 + swaps. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/permutation_algorithms/prev_permutation.html b/doc/html/range/reference/algorithms/permutation_algorithms/prev_permutation.html new file mode 100644 index 0000000..a1e0d1d --- /dev/null +++ b/doc/html/range/reference/algorithms/permutation_algorithms/prev_permutation.html @@ -0,0 +1,149 @@ + + + +prev_permutation + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class BidirectionalRange>
+void prev_permutation(BidirectionalRange& rng);
+
+template<class BidirectionalRange>
+void prev_permutation(const BidirectionalRange& rng);
+
+template<class BidirectionalRange, class Compare>
+void prev_permutation(BidirectionalRange& rng, Compare pred);
+
+template<class BidirectionalRange, class Compare>
+void prev_permutation(const BidirectionalRange& rng, Compare pred);
+
+

+

+
+ + Description +
+

+ prev_permutation transforms + the range of elements rng + into the lexicographically next smaller permutation of the elements if + such a permutation exists. If one does not exist then the range is transformed + into the lexicographically largest permutation and false + is returned. true is returned + when the next smaller permutation is successfully generated. +

+

+ The ordering relationship is determined by using operator< in the non-predicate versions, and + by evaluating pred in + the predicate versions. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/permutation.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +BidirectionalRange + is a model of the Bidirectional + Range Concept. +
  • +
  • +BidirectionalRange + is mutable. +
  • +
  • +BidirectionalRange's + value type is a model of the LessThanComparableConcept. +
  • +
  • + The ordering of objects of type BidirectionalRange's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
+

+ For the predicate versions: +

+
    +
  • +BidirectionalRange + is a model of the Bidirectional + Range Concept. +
  • +
  • +BidirectionalRange + is mutable. +
  • +
  • +Compare is a model + of the StrictWeakOrderingConcept. +
  • +
  • +BidirectionalRange's + value type is convertible to both of Compare's + argument types. +
  • +
+
+ + Complexity +
+

+ Linear. At most distance(rng) / 2 + swaps. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_introduction.html b/doc/html/range/reference/algorithms/range_algorithm_introduction.html new file mode 100644 index 0000000..9f15ed5 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_introduction.html @@ -0,0 +1,257 @@ + + + +Introduction and motivation + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ In its most simple form a Range Algorithm + (or range-based algorithm) is simply an iterator-based algorithm where + the two iterator arguments have been replaced by + one range argument. For example, we may write +

+

+ +

+
#include <boost/range/algorithm.hpp>
+#include <vector>
+
+std::vector<int> vec = ...;
+boost::sort(vec);
+
+

+

+

+ instead of +

+

+ +

+
std::sort(vec.begin(), vec.end());
+
+

+

+

+ However, the return type of range algorithms is almost always different + from that of existing iterator-based algorithms. +

+

+ One group of algorithms, like boost::sort(), will simply return the same range so + that we can continue to pass the range around and/or further modify it. + Because of this we may write +

+
boost:unique(boost::sort(vec));
+
+

+ to first sort the range and then run unique() on the sorted range. +

+

+ Algorithms like boost::unique() + fall into another group of algorithms that return (potentially) narrowed + views of the original range. By default boost::unique(rng) returns the range [boost::begin(rng), found) + where found denotes the + iterator returned by std::unique(boost::begin(rng), boost::end(rng)) +

+

+ Therefore exactly the unique values can be copied by writing +

+
boost::copy(boost::unique(boost::sort(vec)),
+            std::ostream_iterator<int>(std::cout));
+
+

+

+

+ Algorithms like boost::unique usually return the same range: + [boost::begin(rng), found). However, this behaviour may be changed + by supplying the algorithms with a template argument: +

+
++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ Expression +

+
+

+ Return +

+
+

+ boost::unique<boost::return_found>(rng) +

+
+

+ returns a single iterator like std::unique +

+
+

+ boost::unique<boost::return_begin_found>(rng) +

+
+

+ returns the range [boost::begin(rng), + found) + (this is the default) +

+
+

+ boost::unique<boost::return_begin_next>(rng) +

+
+

+ returns the range [boost::begin(rng), + boost::next(found)) +

+
+

+ boost::unique<boost::return_found_end>(rng) +

+
+

+ returns the range [found, + boost::end(rng)) +

+
+

+ boost::unique<boost::return_next_end>(rng) +

+
+

+ returns the range [boost::next(found),boost::end(rng)) +

+
+

+ boost::unique<boost::return_begin_end>(rng) +

+
+

+ returns the entire original range. +

+
+

+ This functionality has the following advantages: +

+
    +
  1. + it allows for seamless functional-style + programming where you do not need to use named + local variables to store intermediate results +
  2. +
  3. + it is very safe + because the algorithm can verify out-of-bounds conditions and handle + tricky conditions that lead to empty ranges +
  4. +
+

+ For example, consider how easy we may erase the duplicates in a sorted + container: +

+

+ +

+
std::vector<int> vec = ...;
+boost::erase(vec, boost::unique<boost::return_found_end>(boost::sort(vec)));
+
+

+

+

+ Notice the use of boost::return_found_end. + What if we wanted to erase all the duplicates except one of them? In old-fashined + STL-programming we might write +

+

+ +

+
// assume 'vec' is already sorted
+std::vector<int>::iterator i = std::unique(vec.begin(), vec.end());
+
+// remember this check or you get into problems
+if (i != vec.end())
+    ++i;
+
+vec.erase(i, vec.end());
+
+

+

+

+ The same task may be accomplished simply with +

+
boost::erase(vec, boost::unique<boost::return_next_end>(vec));
+
+

+ and there is no need to worry about generating an invalid range. Furthermore, + if the container is complex, calling vec.begin() several times will be more expensive + than using a range algorithm. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms.html new file mode 100644 index 0000000..80710b0 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms.html @@ -0,0 +1,86 @@ + + + +Mutating algorithms + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/copy.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/copy.html new file mode 100644 index 0000000..0decd23 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/copy.html @@ -0,0 +1,116 @@ + + + +Range Algorithm - copy + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class SinglePassRange, class OutputIterator>
+OutputIterator copy(const SinglePassRange& source_rng, OutputIterator out_it);
+
+

+

+
+ + Description +
+

+ copy copies all elements + from source_rng to the + range [out_it, out_it + + distance(source_rng)). The return value is out_it + + distance(source_rng) +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/copy.hpp +

+
+ + Requirements +
+
    +
  • +SinglePassRange is + a model of the Single + Pass Range Concept. +
  • +
  • +OutputIterator is a + model of the OutputIteratorConcept. +
  • +
  • + The value_type of + Single Pass Range + Concept is convertible to a type in OutputIterator's + set of value types. +
  • +
+
+ + Precondition: +
+
    +
  • +out_it is not an iterator + within the source_rng. +
  • +
  • +[out_it, out_it + + distance(source_rng)) is a valid range. +
  • +
+
+ + Complexity +
+

+ Linear. Exactly distance(source_rng) assignments are performed. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/copy_backward.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/copy_backward.html new file mode 100644 index 0000000..541db9a --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/copy_backward.html @@ -0,0 +1,125 @@ + + + +Range Algorithm - copy_backward + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class BidirectionalRange, class BidirectionalOutputIterator>
+    BidirectionalOutputIterator
+        copy_backward(const BidirectionalRange& source_rng,
+                      BidirectionalOutputIterator out_it);
+
+

+

+
+ + Description +
+

+ copy_backward copies + all elements from source_rng + to the range [out_it + - distance(source_rng), out_it). +

+

+ The values are copied in reverse order. The return value is out_it - + distance(source_rng). +

+

+ Note well that unlike all other standard algorithms out_it + denotes the end of the output sequence. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/copy_backward.hpp +

+
+ + Requirements +
+
    +
  • +BidirectionalRange + is a model of Bidirectional + Range Concept. +
  • +
  • +OutputIterator is a + model of the OutputIteratorConcept. +
  • +
  • + The value_type of + Bidirectional Range + Concept is convertible to a type in OutputIterator's + set of value types. +
  • +
+
+ + Precondition: +
+
    +
  • +out_it is not an iterator + within the source_rng. +
  • +
  • +[out_it, out_it + + distance(source_rng)) is a valid range. +
  • +
+
+ + Complexity +
+

+ Linear. Exactly distance(source_rng) assignments are performed. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/fill.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/fill.html new file mode 100644 index 0000000..4bb5340 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/fill.html @@ -0,0 +1,105 @@ + + + +Range Algorithm - fill + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class ForwardRange, class Value>
+void fill( ForwardRange& rng, const Value& val );
+
+template<class ForwardRange, class Value>
+void fill( const ForwardRange& rng, const Value& val );
+
+

+

+
+ + Description +
+

+ fill assigns the value + val to every element + in the range rng. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/fill.hpp +

+
+ + Requirements +
+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +ForwardRange is mutable. +
  • +
  • +Value is a model of + the AssignableConcept. +
  • +
  • +Value is convertible + to ForwardRange's value + type. +
  • +
+
+ + Complexity +
+

+ Linear. Exactly distance(rng) assignments are performed. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/generate.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/generate.html new file mode 100644 index 0000000..1a5ba8a --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/generate.html @@ -0,0 +1,121 @@ + + + +Range Algorithm - generate + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class ForwardRange, class Generator>
+ForwardRange& generate( ForwardRange& rng, Generator gen );
+
+template<class ForwardRange, class Generator>
+const ForwardRange& generate( const ForwardRange& rng, Generator gen );
+
+

+

+
+ + Description +
+

+ generate assigns the + result of gen() + to each element in range rng. + Returns the resultant range. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/generate.hpp +

+
+ + Requirements +
+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +ForwardRange is mutable. +
  • +
  • +Generator is a model + of the GeneratorConcept. +
  • +
  • + The value_type of + SinglePassRange is + convertible to a type in OutputIterator's + set of value types. +
  • +
+
+ + Precondition: +
+
    +
  • +out_it is not an iterator + within rng. +
  • +
  • +[out_it, out_it + + distance(rng)) is a valid range. +
  • +
+
+ + Complexity +
+

+ Linear. Exactly distance(rng) assignments are performed. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/inplace_merge.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/inplace_merge.html new file mode 100644 index 0000000..fafc9d5 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/inplace_merge.html @@ -0,0 +1,187 @@ + + + +Range Algorithm - inplace_merge + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class BidirectionalRange>
+BidirectionalRange&
+inplace_merge( BidirectionalRange& rng,
+               typename range_iterator<BidirectionalRange>::type middle );
+               
+template<class BidirectionalRange>
+const BidirectionalRange&
+inplace_merge( const BidirectionalRange& rng,
+               typename range_iterator<const BidirectionalRange>::type middle );
+               
+template<class BidirectionalRange, class BinaryPredicate>
+BidirectionalRange&
+inplace_merge( BidirectionalRange& rng,
+               typename range_iterator<BidirectionalRange>::type middle,
+               BinaryPredicate pred );
+               
+template<class BidirectionalRange, class BinaryPredicate>
+const BidirectionalRange&
+inplace_merge( const BidirectionalRange& rng,
+               typename range_iterator<const BidirectionalRange>::type middle,
+               BinaryPredicate pred );
+
+

+

+
+ + Description +
+

+ inplace_merge combines + two consecutive sorted ranges [begin(rng), middle) + and [middle, end(rng)) into a single sorted range [begin(rng), end(rng)). That is, it starts with a range [begin(rng), end(rng)) that consists of two pieces each of + which is in ascending order, and rearranges it so that the entire range + is in ascending order. inplace_merge + is stable, meaning both that the relative order of elements within each + input range is preserved. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/inplace_merge.hpp +

+
+ + Requirements +
+

+ For the non-predicate version: +

+
    +
  • +BidirectionalRange + is a model of the Bidirectional + Range Concept. +
  • +
  • +BidirectionalRange + is mutable. +
  • +
  • +range_value<BidirectionalRange>::type is a model of LessThanComparableConcept +
  • +
  • + The ordering on objects of range_type<BidirectionalRange>::type + is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
+

+ For the predicate version: * BidirectionalRange is a model of the + Bidirectional Range + Concept. * BidirectionalRange + is mutable. * BinaryPredicate + is a model of the StrictWeakOrderingConcept. + * BidirectionalRange's + value type is convertible to both BinaryPredicate's + argument types. +

+
+ + Precondition: +
+
+ + For + the non-predicate version: +
+
    +
  • +middle is in the range + rng. +
  • +
  • +[begin(rng), middle) is in ascending order. That is for + each pair of adjacent elements [x,y], + y < + x is false. +
  • +
  • +[middle, end(rng)) is in ascending order. That is for + each pair of adjacent elements [x,y], + y < + x is false. +
  • +
+
+ + For + the predicate version: +
+
    +
  • +middle is in the range + rng. +
  • +
  • +[begin(rng), middle) is in ascending order. That is for + each pair of adjacent elements [x,y], + pred(y,x) == false. +
  • +
  • +[middle, end(rng)) is in ascending order. That is for + each pair of adjacent elements [x,y], + pred(y,x) == false. +
  • +
+
+ + Complexity +
+

+ Worst case: O(N log(N)) +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/merge.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/merge.html new file mode 100644 index 0000000..9bd570e --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/merge.html @@ -0,0 +1,247 @@ + + + +Range Algorithm - merge + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class OutputIterator
+    >
+OutputIterator merge(const SinglePassRange1& rng1,
+                     const SinglePassRange2& rng2,
+                     OutputIterator          out);
+
+template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class OutputIterator,
+    class BinaryPredicate
+    >
+OutputIterator merge(const SinglePassRange1& rng1,
+                     const SinglePassRange2& rng2,
+                     OutputIterator          out,
+                     BinaryPredicate         pred);
+
+

+

+
+ + Description +
+

+ merge combines two sorted + ranges rng1 and rng2 into a single sorted range by + copying elements. merge + is stable. The return value is out + + distance(rng1) + distance(rng2). +

+

+ The two versions of merge + differ by how they compare the elements. +

+

+ The non-predicate version uses the operator<() for the range value type. The predicate + version uses the predicate instead of operator<(). +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/merge.hpp +

+
+ + Requirements +
+

+ For the non-predicate version: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +range_value<SinglePassRange1>::type is the same as range_value<SinglePassRange2>::type. +
  • +
  • +range_value<SinglePassRange1>::type is a model of the LessThanComparableConcept. +
  • +
  • + The ordering on objects of range_value<SinglePassRange1>::type + is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
  • +range_value<SinglePassRange1>::type is convertible to a type in + OutputIterator's set + of value types. +
  • +
+

+ For the predicate version: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +range_value<SinglePassRange1>::type is the same as range_value<SinglePassRange2>::type. +
  • +
  • +BinaryPredicate is + a model of the StrictWeakOrderingConcept. +
  • +
  • +SinglePassRange1's + value type is convertible to both BinaryPredicate's + argument types. +
  • +
  • +range_value<SinglePassRange1>::type is convertible to a type in + OutputIterator's set + of value types. +
  • +
+
+ + Precondition: +
+
+ + For + the non-predicate version: +
+
    +
  • + The elements of rng1 + are in ascending order. That is, for each adjacent element pair [x,y] of rng1, + y < + x == + false. +
  • +
  • + The elements of rng2 + are in ascending order. That is, for each adjacent element pair [x,y] of rng2, + y < + x == + false. +
  • +
  • + The ranges rng1 and + [out, out + distance(rng1) + distance(rng2)) + do not overlap. +
  • +
  • + The ranges rng2 and + [out, out + distance(rng1) + distance(rng2)) + do not overlap. +
  • +
  • +[out, out + distance(rng1) + distance(rng2)) + is a valid range. +
  • +
+
+ + For + the predicate version: +
+
    +
  • + The elements of rng1 + are in ascending order. That is, for each adjacent element pair [x,y], of rng1, + pred(y, x) == false. +
  • +
  • + The elements of rng2 + are in ascending order. That is, for each adjacent element pair [x,y], of rng2, + pred(y, x) == false. +
  • +
  • + The ranges rng1 and + [out, out + distance(rng1) + distance(rng2)) + do not overlap. +
  • +
  • + The ranges rng2 and + [out, out + distance(rng1) + distance(rng2)) + do not overlap. +
  • +
  • +[out, out + distance(rng1) + distance(rng2)) + is a valid range. +
  • +
+
+ + Complexity +
+

+ Linear. There are no comparisons if both rng1 + and rng2 are empty, otherwise + at most distance(rng1) + distance(rng2) - 1 + comparisons. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/nth_element.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/nth_element.html new file mode 100644 index 0000000..b8d27f0 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/nth_element.html @@ -0,0 +1,147 @@ + + + +Range Algorithm - nth_element + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class RandomAccessRange>
+void nth_element(RandomAccessRange& rng,
+                 typename range_iterator<RandomAccessRange>::type nth);
+                 
+template<class RandomAccessRange>
+void nth_element(const RandomAccessRange& rng,
+                 typename range_iterator<const RandomAccessRange>::type nth);
+                 
+template<class RandomAccessRange>
+void nth_element(RandomAccessRange& rng,
+                 typename range_iterator<RandomAccessRange>::type nth,
+                 BinaryPredicate sort_pred);
+                 
+template<class RandomAccessRange>
+void nth_element(const RandomAccessRange& rng,
+                 typename range_iterator<const RandomAccessRange>::type nth,
+                 BinaryPredicate sort_pred);
+
+

+

+
+ + Description +
+

+ nth_element partially + orders a range of elements. nth_element + arranges the range rng + such that the element corresponding with the iterator nth + is the same as the element that would be in that position if rng has been sorted. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/nth_element.hpp +

+
+ + Requirements +
+

+ For the non-predicate version: +

+
    +
  • +RandomAccessRange is + a model of the Random + Access Range Concept. +
  • +
  • +RandomAccessRange is + mutable. +
  • +
  • +RandomAccessRange's + value type is a model of the LessThanComparableConcept. +
  • +
  • + The ordering relation on RandomAccessRange's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
+

+ For the predicate version: +

+
    +
  • +RandomAccessRange is + a model of the Random + Access Range Concept. +
  • +
  • +RandomAccessRange is + mutable. +
  • +
  • +BinaryPredicate is + a model of the StrictWeakOrderingConcept. +
  • +
  • +RandomAccessRange's + value type is convertible to both of BinaryPredicate's + argument types. +
  • +
+
+ + Complexity +
+

+ On average, linear in distance(rng). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/partial_sort.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/partial_sort.html new file mode 100644 index 0000000..d218c43 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/partial_sort.html @@ -0,0 +1,152 @@ + + + +Range Algorithm - partial_sort + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class RandomAccessRange>
+void partial_sort(RandomAccessRange& rng,
+                  typename range_iterator<RandomAccessRange>::type middle);
+                 
+template<class RandomAccessRange>
+void partial_sort(const RandomAccessRange& rng,
+                  typename range_iterator<const RandomAccessRange>::type middle);
+                 
+template<class RandomAccessRange>
+void partial_sort(RandomAccessRange& rng,
+                  typename range_iterator<RandomAccessRange>::type middle,
+                  BinaryPredicate sort_pred);
+                 
+template<class RandomAccessRange>
+void partial_sort(const RandomAccessRange& rng,
+                  typename range_iterator<const RandomAccessRange>::type middle,
+                  BinaryPredicate sort_pred);
+
+

+

+
+ + Description +
+

+ partial_sort rearranges + the elements in rng. + It places the smallest distance(begin(rng), middle) elements, sorted in ascending order, + into the range [begin(rng), middle). The remaining elements are placed in + an unspecified order into [middle, last). +

+

+ The non-predicative versions of this function specify that one element + is less than another by using operator<(). The predicate versions use the + predicate instead. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/partial_sort.hpp +

+
+ + Requirements +
+

+ For the non-predicate version: +

+
    +
  • +RandomAccessRange is + a model of the Random + Access Range Concept. +
  • +
  • +RandomAccessRange is + mutable. +
  • +
  • +RandomAccessRange's + value type is a model of the LessThanComparableConcept. +
  • +
  • + The ordering relation on RandomAccessRange's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
+

+ For the predicate version: +

+
    +
  • +RandomAccessRange is + a model of the Random + Access Range Concept. +
  • +
  • +RandomAccessRange is + mutable. +
  • +
  • +BinaryPredicate is + a model of the StrictWeakOrderingConcept. +
  • +
  • +RandomAccessRange's + value type is convertible to both of BinaryPredicate's + argument types. +
  • +
+
+ + Complexity +
+

+ Approximately distance(rng) * log(distance(begin(rng), middle)) comparisons. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/partition.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/partition.html new file mode 100644 index 0000000..4136a2a --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/partition.html @@ -0,0 +1,133 @@ + + + +Range Algorithm - partition + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class ForwardRange,
+    class UnaryPredicate
+    >
+typename range_iterator<ForwardRange>::type
+partition(ForwardRange& rng, UnaryPredicate pred);
+
+template<
+    class ForwardRange,
+    class UnaryPredicate
+    >
+typename range_iterator<const ForwardRange>::type
+partition(const ForwardRange& rng, UnaryPredicate pred);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class UnaryPredicate
+    >
+typename range_return<ForwardRange, re>::type
+partition(ForwardRange& rng, UnaryPredicate pred);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class UnaryPredicate
+    >
+typename range_return<const ForwardRange, re>::type
+partition(const ForwardRange& rng, UnaryPredicate pred);
+
+

+

+
+ + Description +
+

+ partition orders the + elements in rng based + on pred, such that the + elements that satisfy pred + precede the elements that do not. In the versions that return a single + iterator, the return value is the middle iterator. In the versions that + have a configurable range_return, found + corresponds to the middle iterator. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/partition.hpp +

+
+ + Requirements +
+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +UnaryPredicate is a + model of the PredicateConcept. +
  • +
  • +ForwardRange's value + type is convertible to UnaryPredicate's + argument type. +
  • +
+
+ + Complexity +
+

+ Linear. Exactly distance(rng) applications of pred, + and at most distance(rng) / 2 + swaps. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/random_shuffle.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/random_shuffle.html new file mode 100644 index 0000000..190f66f --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/random_shuffle.html @@ -0,0 +1,132 @@ + + + +Range Algorithm - random_shuffle + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class RandomAccessRange>
+RandomAccessRange& random_shuffle(RandomAccessRange& rng);
+
+template<class RandomAccessRange>
+const RandomAccessRange& random_shuffle(const RandomAccessRange& rng);
+
+template<class RandomAccessRange, class Generator>
+RandomAccessRange& random_shuffle(RandomAccessRange& rng, Generator& gen);
+
+template<class RandomAccessRange, class Generator>
+const RandomAccessRange& random_shuffle(const RandomAccessRange& rng, Generator& gen);
+
+

+

+
+ + Description +
+

+ random_shuffle randomly + rearranges the elements in rng. + The versions of random_shuffle + that do not specify a Generator + use an internal random number generator. The versions of random_shuffle that do specify a Generator use this instead. Returns + the shuffles range. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/random_shuffle.hpp +

+
+ + Requirements +
+

+ For the version without a Generator: +

+
+

+ For the version with a Generator: +

+
    +
  • +RandomAccessRange is + a model of the Random + Access Range Concept. +
  • +
  • +Generator is a model + of the RandomNumberGeneratorConcept. +
  • +
  • +RandomAccessRange's + distance type is convertible to Generator's + argument type. +
  • +
+
+ + Precondition: +
+
  • +distance(rng) + is less than gen's + maximum value. +
+
+ + Complexity +
+

+ Linear. If !empty(rng), exactly distance(rng) - 1 + swaps are performed. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/remove.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/remove.html new file mode 100644 index 0000000..4cb906c --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/remove.html @@ -0,0 +1,139 @@ + + + +Range Algorithm - remove + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class ForwardRange,
+    class Value
+    >
+typename range_iterator<ForwardRange>::type
+remove(ForwardRange& rng, const Value& val);
+
+template<
+    class ForwardRange,
+    class Value
+    >
+typename range_iterator<const ForwardRange>::type
+remove(const ForwardRange& rng, const Value& val);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class Value
+    >
+typename range_return<ForwardRange,re>::type
+remove(ForwardRange& rng, const Value& val);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class Value
+    >
+typename range_return<const ForwardRange,re>::type
+remove(const ForwardRange& rng, const Value& val);
+
+

+

+
+ + Description +
+

+ remove removes from + rng all of the elements + x for which x == val is true. + The versions of remove + that return an iterator, return an iterator new_last + such that the range [begin(rng), new_last) contains no elements equal to val. The range_return + versions of remove defines + found as the new last + element. The iterators in the range [new_last, + end(rng)) + are dereferenceable, but the elements are unspecified. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/remove.hpp +

+
+ + Requirements +
+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +ForwardRange is mutable. +
  • +
  • +Value is a model of + the EqualityComparableConcept. +
  • +
  • + Objects of type Value + can be compared for equality with objects of ForwardRange's + value type. +
  • +
+
+ + Complexity +
+

+ Linear. remove performs + exactly distance(rng) + comparisons for equality. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/remove_if.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/remove_if.html new file mode 100644 index 0000000..9896adc --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/remove_if.html @@ -0,0 +1,138 @@ + + + +Range Algorithm - remove_if + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class ForwardRange,
+    class UnaryPredicate
+    >
+typename range_iterator<ForwardRange>::type
+remove(ForwardRange& rng, UnaryPredicate pred);
+
+template<
+    class ForwardRange,
+    class UnaryPredicate
+    >
+typename range_iterator<const ForwardRange>::type
+remove(const ForwardRange& rng, UnaryPredicate pred);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class UnaryPredicate
+    >
+typename range_return<ForwardRange,re>::type
+remove(ForwardRange& rng, UnaryPredicate pred);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class UnaryPredicate
+    >
+typename range_return<const ForwardRange,re>::type
+remove(const ForwardRange& rng, UnaryPredicate pred);
+
+

+

+
+ + Description +
+

+ remove_if removes from + rng all of the elements + x for which pred(x) + is true. The versions of + remove_if that return + an iterator, return an iterator new_last + such that the range [begin(rng), new_last) contains no elements where pred(x) + is true. The iterators in + the range [new_last, end(rng)) are dereferenceable, but the elements + are unspecified. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/remove_if.hpp +

+
+ + Requirements +
+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +ForwardRange is mutable. +
  • +
  • +UnaryPredicate is a + model of the PredicateConcept. +
  • +
  • +ForwardRange's value + type is convertible to UnaryPredicate's + argument type. +
  • +
+
+ + Complexity +
+

+ Linear. remove_if performs + exactly distance(rng) + applications of pred. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/replace.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/replace.html new file mode 100644 index 0000000..ab4232d --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/replace.html @@ -0,0 +1,119 @@ + + + +Range Algorithm - replace + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class ForwardRange,
+    class Value
+    >
+ForwardRange& replace(ForwardRange& rng, const Value& what, const Value& with_what);
+
+template<
+    class ForwardRange,
+    class UnaryPredicate
+    >
+const ForwardRange& replace(const ForwardRange& rng, const Value& what, const Value& with_what);
+
+

+

+
+ + Description +
+

+ replace every element + in rng equal to what with with_what. + Return a reference to rng. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/replace.hpp +

+
+ + Requirements +
+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +ForwardRange is mutable. +
  • +
  • +Value is convertible + to ForwardRange's value + type. +
  • +
  • +Value is a model of + the AssignableConcept. +
  • +
  • +Value is a model of + the EqualityComparableConcept, + and may be compared for equality with objects of ForwardRange's + value type. +
  • +
+
+ + Complexity +
+

+ Linear. replace performs + exactly distance(rng) + comparisons for equality and at most distance(rng) assignments. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/replace_if.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/replace_if.html new file mode 100644 index 0000000..7677651 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/replace_if.html @@ -0,0 +1,117 @@ + + + +Range Algorithm - replace_if + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class ForwardRange, class UnaryPredicate, class Value>
+ForwardRange& replace_if(ForwardRange& rng, UnaryPredicate pred, const Value& with_what);
+
+template<class ForwardRange, class UnaryPredicate, class Value>
+const ForwardRange& replace_if(const ForwardRange& rng, UnaryPredicate pred, const Value& with_what);
+
+

+

+
+ + Description +
+

+ replace_if replaces every + element x in rng for which pred(x) == true with with_what. + Returns a reference to rng. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/replace_if.hpp +

+
+ + Requirements +
+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +ForwardRange is mutable. +
  • +
  • +UnaryPredicate is a + model of the PredicateConcept +
  • +
  • +ForwardRange's value + type is convertible to UnaryPredicate's + argument type. +
  • +
  • +Value is convertible + to ForwardRange's value + type. +
  • +
  • +Value is a model of + the AssignableConcept. +
  • +
+
+ + Complexity +
+

+ Linear. replace_if performs + exactly distance(rng) + applications of pred, + and at most distance(rng) assignments. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/rotate.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/rotate.html new file mode 100644 index 0000000..55faad4 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/rotate.html @@ -0,0 +1,110 @@ + + + +Range Algorithm - rotate + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class ForwardRange>
+ForwardRange& rotate(ForwardRange& rng,
+                     typename range_iterator<ForwardRange>::type middle);
+                     
+template<class ForwardRange>
+const ForwardRange& rotate(const ForwardRange& rng,
+                           typename range_iterator<const ForwardRange>::type middle);
+
+

+

+
+ + Description +
+

+ rotate rotates the elements + in a range. It exchanges the two ranges [begin(rng), middle) + and [middle, end(rng)). Returns a reference to rng. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/rotate.hpp +

+
+ + Requirements +
+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +ForwardRange is mutable. +
  • +
+
+ + Precondition: +
+
    +
  • +[begin(rng), middle) is a valid range. +
  • +
  • +[middle, end(rng)) is a valid range. +
  • +
+
+ + Complexity +
+

+ Linear. At most distance(rng) swaps are performed. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/sort.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/sort.html new file mode 100644 index 0000000..290f8e7 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/sort.html @@ -0,0 +1,154 @@ + + + +Range Algorithm - sort + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class RandomAccessRange>
+RandomAccessRange& sort(RandomAccessRange& rng);
+
+template<class RandomAccessRange>
+const RandomAccessRange& sort(const RandomAccessRange& rng);
+
+template<class RandomAccessRange, class BinaryPredicate>
+RandomAccessRange& sort(RandomAccessRange& rng, BinaryPredicate pred);
+
+template<class RandomAccessRange, class BinaryPredicate>
+const RandomAccessRange& sort(const RandomAccessRange& rng, BinaryPredicate pred);
+
+

+

+
+ + Description +
+

+ sort sorts the elements + in rng into ascending + order. sort is not guaranteed + to be stable. Returns the sorted range. +

+

+ For versions of the sort + function without a predicate, ascending order is defined by operator<() + such that for all adjacent elements [x,y], + y < + x == + false. +

+

+ For versions of the sort + function with a predicate, ascending order is defined by pred such that for all adjacent elements + [x,y], pred(y, x) == false. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/sort.hpp +

+
+ + Requirements +
+

+ For versions of sort without a predicate: +

+
    +
  • +RandomAccessRange is + a model of the Random + Access Range Concept. +
  • +
  • +RandomAccessRange is + mutable. +
  • +
  • +RandomAccessRange's + value type is a model of the LessThanComparableConcept. +
  • +
  • + The ordering relation on RandomAccessRange's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
+

+ For versions of sort with a predicate +

+
    +
  • +RandomAccessRange is + a model of the Random + Access Range Concept. +
  • +
  • +RandomAccessRange is + mutable. +
  • +
  • +BinaryPredicate is + a model of the StrictWeakOrderingConcept. +
  • +
  • +RandomAccessRange's + value type is convertible to both of BinaryPredicate's + argument types. +
  • +
+
+ + Complexity +
+

+ O(N log(N)) comparisons (both average and worst-case), + where N is distance(rng). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/stable_partition.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/stable_partition.html new file mode 100644 index 0000000..eb0032a --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/stable_partition.html @@ -0,0 +1,135 @@ + + + +Range Algorithm - stable_partition + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class ForwardRange, class UnaryPredicate>
+typename range_iterator<ForwardRange>::type
+stable_partition(ForwardRange& rng, UnaryPredicate pred);
+
+template<class ForwardRange, class UnaryPredicate>
+typename range_iterator<const ForwardRange>::type
+stable_partition(const ForwardRange& rng, UnaryPredicate pred);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class UnaryPredicate
+>
+typename range_return<ForwardRange, re>::type
+stable_partition(ForwardRange& rng, UnaryPredicate pred);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class UnaryPredicate
+>
+typename range_return<const ForwardRange, re>::type
+stable_partition(const ForwardRange& rng, UnaryPredicate pred);
+
+

+

+
+ + Description +
+

+ stable_partition reorders + the elements in the range rng + base on the function object pred. + Once this function has completed all of the elements that satisfy pred appear before all of the elements + that fail to satisfy it. stable_partition + differs from partition + because it preserves relative order. It is stable. +

+

+ For the versions that return an iterator, the return value is the iterator + to the first element that fails to satisfy pred. +

+

+ For versions that return a range_return, + the found iterator is + the iterator to the first element that fails to satisfy pred. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/stable_partition.hpp +

+
+ + Requirements +
+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +ForwardRange is mutable. +
  • +
  • +UnaryPredicate is a + model of the PredicateConcept. +
  • +
+
+ + Complexity +
+

+ Best case: O(N) + where N is distance(rng). + Worst case: N * + log(N) + swaps, where N is distance(rng). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/stable_sort.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/stable_sort.html new file mode 100644 index 0000000..984024d --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/stable_sort.html @@ -0,0 +1,157 @@ + + + +Range Algorithm - stable_sort + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class RandomAccessRange>
+RandomAccessRange& stable_sort(RandomAccessRange& rng);
+
+template<class RandomAccessRange>
+const RandomAccessRange& stable_sort(const RandomAccessRange& rng);
+
+template<class RandomAccessRange, class BinaryPredicate>
+RandomAccessRange& stable_sort(RandomAccessRange& rng, BinaryPredicate pred);
+
+template<class RandomAccessRange, class BinaryPredicate>
+const RandomAccessRange& stable_sort(const RandomAccessRange& rng, BinaryPredicate pred);
+
+

+

+
+ + Description +
+

+ stable_sort sorts the + elements in rng into + ascending order. stable_sort + is guaranteed to be stable. The order is preserved for equivalent elements. +

+

+ For versions of the stable_sort + function without a predicate ascending order is defined by operator<() + such that for all adjacent elements [x,y], + y < + x == + false. +

+

+ For versions of the stable_sort + function with a predicate, ascending order is designed by pred such that for all adjacent elements + [x,y], pred(y,x) == false. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/stable_sort.hpp +

+
+ + Requirements +
+

+ For versions of stable_sort without a predicate +

+
    +
  • +RandomAccessRange is + a model of the Random + Access Range Concept. +
  • +
  • +RandomAccessRange is + mutable. +
  • +
  • +RandomAccessRange's + value type is a model of the LessThanComparableConcept. +
  • +
  • + The ordering relation on RandomAccessRange's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
+

+ For versions of stable_sort with a predicate: +

+
    +
  • +RandomAccessRange is + a model of the Random + Access Range Concept. +
  • +
  • +RandomAccessRange is + mutable. +
  • +
  • +BinaryPredicate is + a model of the StrictWeakOrderingConcept. +
  • +
  • +RandomAccessRange's + value type is convertible to both of BinaryPredicate's + argument types. +
  • +
+
+ + Complexity +
+

+ Best case: O(N) + where N is distance(rng). + Worst case: O(N log(N)^2) + comparisons, where N + is distance(rng). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/transform.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/transform.html new file mode 100644 index 0000000..58da4ca --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/transform.html @@ -0,0 +1,226 @@ + + + +Range Algorithm - transform + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class SinglePassRange1,
+    class OutputIterator,
+    class UnaryOperation
+>
+OutputIterator transform(const SinglePassRange1& rng,
+                         OutputIterator out,
+                         UnaryOperation fun);
+                         
+template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class OutputIterator,
+    class BinaryOperation
+>
+OutputIterator transform(const SinglePassRange1& rng1,
+                         const SinglePassRange2& rng2,
+                         OutputIterator out,
+                         BinaryOperation fun);
+
+

+

+
+ + Description +
+

+ UnaryOperation version: +

+

+ transform assigns the + value y to each element + [out, out + distance(rng)), y = fun(x) where x + is the corresponding value to y + in rng1. The return value + is out + + distance(rng). +

+

+ BinaryOperation version: +

+

+ transform assigns the + value z to each element + [out, out + min(distance(rng1), distance(rng2))), z = fun(x,y) where x + is the corresponding value in rng1 + and y is the corresponding + value in rng2. This version + of transform stops upon + reaching either the end of rng1, + or the end of rng2. Hence + there isn't a requirement for distance(rng1) == distance(rng2) + since there is a safe guaranteed behaviour, unlike with the iterator + counterpart in the standard library. +

+

+ The return value is out + min(distance(rng1), distance(rng2)). +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/transform.hpp +

+
+ + Requirements +
+

+ For the unary versions of transform: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +OutputIterator is a + model of the OutputIteratorConcept. +
  • +
  • +UnaryOperation is a + model of the UnaryFunctionConcept. +
  • +
  • +SinglePassRange1's + value type must be convertible to UnaryFunction's + argument type. +
  • +
  • +UnaryFunction's result + type must be convertible to a type in OutputIterator's + set of value types. +
  • +
+

+ For the binary versions of transform: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +OutputIterator is a + model of the OutputIteratorConcept. +
  • +
  • +BinaryOperation is + a model of the BinaryFunctionConcept. +
  • +
  • +SinglePassRange1's + value type must be convertible to BinaryFunction's + first argument type. +
  • +
  • +SinglePassRange2's + value type must be convertible to BinaryFunction's + second argument type. +
  • +
  • +BinaryOperation's result + type must be convertible to a type in OutputIterator's + set of value types. +
  • +
+
+ + Precondition: +
+

+ For the unary version of transform: +

+
    +
  • +out is not an iterator + within the range [begin(rng1) + 1, end(rng1)). +
  • +
  • +[out, out + distance(rng1)) is a valid range. +
  • +
+

+ For the binary version of transform: +

+
    +
  • +out is not an iterator + within the range [begin(rng1) + 1, end(rng1)). +
  • +
  • +out is not an iterator + within the range [begin(rng2) + 1, end(rng2)). +
  • +
  • +[out, out + min(distance(rng1), distance(rng2))) is a valid range. +
  • +
+
+ + Complexity +
+

+ Linear. The operation is applied exactly distance(rng1) for the unary version and min(distance(rng1), distance(rng2)) + for the binary version. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/unique.html b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/unique.html new file mode 100644 index 0000000..aaa5525 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_mutating_algorithms/unique.html @@ -0,0 +1,164 @@ + + + +Range Algorithm - unique + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class ForwardRange>
+typename range_return<ForwardRange, return_begin_found>::type
+unique(ForwardRange& rng);
+
+template<class ForwardRange>
+typename range_return<const ForwardRange, return_begin_found>::type
+unique(const ForwardRange& rng);
+
+template<class ForwardRange, class BinaryPredicate>
+typename range_return<ForwardRange, return_begin_found>::type
+unique(ForwardRange& rng, BinaryPredicate pred);
+
+template<class ForwardRange, class BinaryPredicate>
+typename range_return<const ForwardRange, return_begin_found>::type
+unique(const ForwardRange& rng, BinaryPredicate pred);
+
+template<range_return_value re, class ForwardRange>
+typename range_return<ForwardRange, re>::type
+unique(ForwardRange& rng);
+
+template<range_return_value re, class ForwardRange>
+typename range_return<const ForwardRange, re>::type
+unique(const ForwardRange& rng);
+
+template<range_return_value re, class ForwardRange, class BinaryPredicate>
+typename range_return<ForwardRange, re>::type
+unique(ForwardRange& rng, BinaryPredicate pred);
+
+template<range_return_value re, class ForwardRange, class BinaryPredicate>
+typename range_return<const ForwardRange, re>::type
+unique(const ForwardRange& rng, BinaryPredicate pred);
+
+

+

+
+ + Description +
+

+ unique removes all but + the first element of each sequence of duplicate encountered in rng. +

+

+ Elements in the range [new_last, + end(rng)) + are dereferenceable but undefined. +

+

+ Equality is determined by the predicate if one is supplied, or by operator==() + for ForwardRange's value + type. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/unique.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions of unique: +

+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +ForwardRange is mutable. +
  • +
  • +ForwardRange's value + type is a model of the EqualityComparableConcept. +
  • +
+

+ For the predicate versions of unique: +

+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +ForwardRange is mutable. +
  • +
  • +BinaryPredicate is + a model of the BinaryPredicateConcept. +
  • +
  • +ForwardRange's value + type is convertible to BinaryPredicate's + first argument type and to BinaryPredicate's + second argument type. +
  • +
+
+ + Complexity +
+

+ Linear. O(N) + where N is distance(rng). + Exactly distance(rng) + comparisons are performed. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_new_algorithms.html b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms.html new file mode 100644 index 0000000..7b34570 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms.html @@ -0,0 +1,62 @@ + + + +New algorithms + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/erase.html b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/erase.html new file mode 100644 index 0000000..3520dba --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/erase.html @@ -0,0 +1,91 @@ + + + +erase + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class Container,
+    class SinglePassRange
+    >
+void erase(Container& target,
+           iterator_range<typename Container::iterator> to_erase);
+
+

+

+
+ + Description +
+

+ erase the iterator range + to_erase from the container + target. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm_ext/erase.hpp +

+
+ + Requirements +
+
  1. +Container supports + erase of an iterator range. +
+
+ + Complexity +
+

+ Linear. Proprotional to distance(to_erase). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/for_each.html b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/for_each.html new file mode 100644 index 0000000..4a1cb75 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/for_each.html @@ -0,0 +1,150 @@ + + + +for_each + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class BinaryFunction
+    >
+BinaryFunction for_each(const SinglePassRange1& rng1,
+                        const SinglePassRange2& rng2,
+                        BinaryFunction fn);
+
+template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class BinaryFunction
+    >
+BinaryFunction for_each(const SinglePassRange1& rng1,
+                        SinglePassRange2& rng2,
+                        BinaryFunction fn);
+
+template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class BinaryFunction
+    >
+BinaryFunction for_each(SinglePassRange1& rng1,
+                        const SinglePassRange2& rng2,
+                        BinaryFunction fn);
+
+template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class BinaryFunction
+    >
+BinaryFunction for_each(SinglePassRange1& rng1,
+                        SinglePassRange2& rng2,
+                        BinaryFunction fn);
+
+

+

+
+ + Description +
+

+ for_each traverses forward + through rng1 and rng2 simultaneously. For each iteration, + the element x is used + from rng1 and the corresponding + element y is used from + rng2 to invoke fn(x,y). +

+

+ Iteration is stopped upon reaching the end of the shorter of rng1, or rng2. + It is safe to call this function with unequal length ranges. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm_ext/for_each.hpp +

+
+ + Requirements +
+
    +
  1. +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  2. +
  3. +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  4. +
  5. +BinaryFunction is a + model of the BinaryFunctionConcept. +
  6. +
  7. +SinglePassRange1's + value type is convertible to BinaryFunction's + first argument type. +
  8. +
  9. +SinglepassRange2's + value type is convertible to BinaryFunction's + second argument type. +
  10. +
+
+ + Complexity +
+

+ Linear. Exactly min(distance(rng1), distance(rng2)) + applications of BinaryFunction. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/insert.html b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/insert.html new file mode 100644 index 0000000..fc06253 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/insert.html @@ -0,0 +1,106 @@ + + + +insert + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class Container,
+    class SinglePassRange
+    >
+void insert(Container& target,
+            typename Container::iterator before,
+            const SinglePassRange& from);
+
+

+

+
+ + Description +
+

+ insert all of the elements + in the range from before + the before iterator into + target. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm_ext/insert.hpp +

+
+ + Requirements +
+
    +
  1. +SinglePassRange is + a model of the Single + Pass Range Concept. +
  2. +
  3. +Container supports + insert at a specified position. +
  4. +
  5. +SinglePassRange's value + type is convertible to Container's + value type. +
  6. +
+
+ + Complexity +
+

+ Linear. distance(from) + assignments are performed. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/overwrite.html b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/overwrite.html new file mode 100644 index 0000000..b856c39 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/overwrite.html @@ -0,0 +1,111 @@ + + + +overwrite + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class SinglePassRange1,
+    class SinglePassRange2
+    >
+void overwrite(const SinglePassRange1& from,
+               SinglePassRange2& to);
+
+

+

+
+ + Description +
+

+ overwrite assigns the + values from the range from + into the range to. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm_ext/overwrite.hpp +

+
+ + Requirements +
+
    +
  1. +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  2. +
  3. +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  4. +
  5. +SinglePassRange2 is + mutable. +
  6. +
  7. distance(SinglePassRange1) + <= distance(SinglePassRange2)
  8. +
  9. +SinglePassRange1's + value type is convertible to SinglePassRange2's + value type. +
  10. +
+
+ + Complexity +
+

+ Linear. distance(rng1) + assignments are performed. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/push_back.html b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/push_back.html new file mode 100644 index 0000000..26741e2 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/push_back.html @@ -0,0 +1,104 @@ + + + +push_back + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class Container,
+    class SinglePassRange
+    >
+void push_back(Container& target,
+               const SinglePassRange& from);
+
+

+

+
+ + Description +
+

+ push_back all of the + elements in the range from + to the back of the container target. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm_ext/push_back.hpp +

+
+ + Requirements +
+
    +
  1. +SinglePassRange is + a model of the Single + Pass Range Concept. +
  2. +
  3. +Container supports + insert at end(). +
  4. +
  5. +SinglePassRange's value + type is convertible to Container's + value type. +
  6. +
+
+ + Complexity +
+

+ Linear. distance(from) + assignments are performed. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/push_front.html b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/push_front.html new file mode 100644 index 0000000..4afd63c --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/push_front.html @@ -0,0 +1,104 @@ + + + +push_front + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class Container,
+    class SinglePassRange
+    >
+void push_front(Container& target,
+                const SinglePassRange& from);
+
+

+

+
+ + Description +
+

+ push_front all of the + elements in the range from + to the front of the container target. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm_ext/push_front.hpp +

+
+ + Requirements +
+
    +
  1. +SinglePassRange is + a model of the Single + Pass Range Concept. +
  2. +
  3. +Container supports + insert at begin(). +
  4. +
  5. +SinglePassRange's value + type is convertible to Container's + value type. +
  6. +
+
+ + Complexity +
+

+ Linear. distance(from) + assignments are performed. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/remove_erase.html b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/remove_erase.html new file mode 100644 index 0000000..f80666a --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/remove_erase.html @@ -0,0 +1,92 @@ + + + +remove_erase + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class Container,
+    class T
+    >
+void remove_erase(Container& target,
+                  const T& val);
+
+

+

+
+ + Description +
+

+ remove_erase actually + eliminates the elements equal to val + from the container. This is in contrast to the remove + algorithm which merely rearranges elements. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm_ext/erase.hpp +

+
+ + Requirements +
+
  1. +Container supports + erase of an iterator range. +
+
+ + Complexity +
+

+ Linear. Proportional to distance(target)s. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/remove_erase_if.html b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/remove_erase_if.html new file mode 100644 index 0000000..0f4c190 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_new_algorithms/remove_erase_if.html @@ -0,0 +1,99 @@ + + + +remove_erase_if + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class Container,
+    class Pred
+    >
+void remove_erase(Container& target,
+                  Pred pred);
+
+

+

+
+ + Description +
+

+ remove_erase_if removes + the elements x that satisfy + pred(x) + from the container. This is in contrast to the erase + algorithm which merely rearranges elements. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm_ext/erase.hpp +

+
+ + Requirements +
+
    +
  1. +Container supports + erase of an iterator range. +
  2. +
  3. +Pred is a model of + the Predicate Concept. +
  4. +
+
+ + Complexity +
+

+ Linear. Proportional to distance(target)s. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms.html new file mode 100644 index 0000000..87820b8 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms.html @@ -0,0 +1,80 @@ + + + +Non-mutating algorithms + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/adjacent_find.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/adjacent_find.html new file mode 100644 index 0000000..e45a101 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/adjacent_find.html @@ -0,0 +1,168 @@ + + + +Range Algorithm - adjacent_find + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class ForwardRange>
+typename range_iterator<ForwardRange>::type
+adjacent_find(ForwardRange& rng);
+
+template<class ForwardRange>
+typename range_iterator<const ForwardRange>::type
+adjacent_find(const ForwardRange& rng);
+
+template<class ForwardRange, class BinaryPredicate>
+typename range_iterator<ForwardRange>::type
+adjacent_find(ForwardRange& rng, BinaryPred pred);
+
+template<class ForwardRange, class BinaryPredicate>
+typename range_iterator<const ForwardRange>::type
+adjacent_find(const ForwardRange& rng, BinaryPred pred);
+
+template<range_return_value_re, class ForwardRange>
+typename range_return<ForwardRange, re>::type
+adjacent_find(ForwardRange& rng);
+
+template<range_return_value_re, class ForwardRange>
+typename range_return<const ForwardRange, re>::type
+adjacent_find(const ForwardRange& rng);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class BinaryPredicate
+    >
+typename range_return<ForwardRange, re>::type
+adjacent_find(ForwardRange& rng, BinaryPredicate pred);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class BinaryPredicate
+    >
+typename range_return<const ForwardRange, re>::type
+adjacent_find(const ForwardRange& rng, BinaryPredicate pred);
+
+

+

+
+ + Description +
+

+ Non-predicate versions: +

+

+ adjacent_find finds the + first adjacent elements [x,y] + in rng where x == y +

+

+ Predicate versions: +

+

+ adjacent_find finds the + first adjacent elements [x,y] + in rng where pred(x,y) + is true. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/adjacent_find.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions of adjacent_find: +

+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +ForwardRange's value + type is a model of the EqualityComparableConcept. +
  • +
+

+ For the predicate versions of adjacent_find: +

+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +BinaryPredicate is + a model of the BinaryPredicateConcept. +
  • +
  • +ForwardRange's value + type is convertible to BinaryPredicate's + first argument type and to BinaryPredicate's + second argument type. +
  • +
+
+ + Complexity +
+

+ Linear. If empty(rng) + then no comparisons are performed; otherwise, at most distance(rng) - 1 + comparisons. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/binary_search.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/binary_search.html new file mode 100644 index 0000000..247d8bc --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/binary_search.html @@ -0,0 +1,157 @@ + + + +binary_search + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class ForwardRange, class Value>
+bool binary_search(const ForwardRange& rng, const Value& val);
+
+template<class ForwardRange, class Value, class BinaryPredicate>
+bool binary_search(const ForwardRange& rng, const Value& val, BinaryPredicate pred);
+
+

+

+
+ + Description +
+

+ binary_search returns + true if and only if the + value val exists in the + range rng. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/binary_search.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions of binary_search: +

+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +Value is a model of + the LessThanComparableConcept. +
  • +
  • + The ordering of objects of type Value + is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
  • +ForwardRange's value + type is the same type as Value. +
  • +
+

+ For the predicate versions of binary_search: +

+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +BinaryPredicate is + a model of the StrictWeakOrderingConcept. +
  • +
  • +ForwardRange's value + type is the same type as Value. +
  • +
  • +ForwardRange's value + type is convertible to BinaryPredicate's + argument type. +
  • +
+
+ + Precondition: +
+

+ For the non-predicate version: +

+

+ rng is ordered in ascending + order according to operator<. +

+

+ For the predicate version: +

+

+ rng is ordered in ascending + order according to the function object pred. +

+
+ + Complexity +
+

+ For non-random-access ranges, the complexity is O(N) where N + is distance(rng). +

+

+ For random-access ranges, the complexity is O(log N) + where N is distance(rng). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/count.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/count.html new file mode 100644 index 0000000..bdfc489 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/count.html @@ -0,0 +1,108 @@ + + + +count + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class SinglePassRange, class Value>
+typename range_difference<SinglePassRange>::type
+count(SinglePassRange& rng, const Value& val);
+
+template<class SinglePassRange, class Value>
+typename range_difference<const SinglePassRange>::type
+count(const SinglePassRange& rng, const Value& val);
+
+

+

+
+ + Description +
+

+ count returns the number + of elements x in rng where x + == val + is true. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/count.hpp +

+
+ + Requirements +
+
    +
  • +SinglePassRange is + a model of the Single + Pass Range Concept. +
  • +
  • +Value is a model of + the EqualityComparableConcept. +
  • +
  • +SinglePassRange's value + type is a model of the EqualityComparableConcept. +
  • +
  • + An object of SinglePassRange's + value type can be compared for equality with an object of type Value. +
  • +
+
+ + Complexity +
+

+ Linear. Exactly distance(rng) comparisons. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/equal.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/equal.html new file mode 100644 index 0000000..d6d54a1 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/equal.html @@ -0,0 +1,163 @@ + + + +equal + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class SinglePassRange1,
+    class SinglePassRange2
+>
+bool equal(const SinglePassRange1& rng1,
+           const SinglePassRange2& rng2);
+
+template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class BinaryPredicate
+>
+bool equal(const SinglePassRange1& rng1,
+           const SinglePassRange2& rng2,
+           BinaryPredicate         pred);
+
+

+

+
+ + Description +
+

+ equal returns true if distance(rng1) is equal to the distance(rng2) and for each element x + in rng1, the corresponding + element y in rng2 is equal. Otherwise false is returned. +

+

+ In this range version of equal + it is perfectly acceptable to pass in two ranges of unequal lengths. +

+

+ Elements are considered equal in the non-predicate version if operator== + returns true. Elements are + considered equal in the predicate version if pred(x,y) is true. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/equal.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange1's + value type is a model of the EqualityComparableConcept. +
  • +
  • +SinglePassRange2's + value type is a model of the EqualityComparableConcept. +
  • +
  • +SinglePassRange1's + value type can be compared for equality with SinglePassRange2's + value type. +
  • +
+

+ For the predicate versions: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +BinaryPredicate is + a model of the BinaryPredicateConcept. +
  • +
  • +SinglePassRange1's + value type is convertible to BinaryPredicate's + first argument type. +
  • +
  • +SinglePassRange2's + value type is convertible to BinaryPredicate's + second argument type. +
  • +
+
+ + Complexity +
+

+ Linear. At most min(distance(rng1), distance(rng2)) + comparisons. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/equal_range.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/equal_range.html new file mode 100644 index 0000000..94bd133 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/equal_range.html @@ -0,0 +1,179 @@ + + + +equal_range + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class ForwardRange,
+    class Value
+    >
+std::pair<typename range_iterator<ForwardRange>::type,
+          typename range_iterator<ForwardRange>::type>
+equal_range(ForwardRange& rng, const Value& val);
+
+template<
+    class ForwardRange,
+    class Value
+    >
+std::pair<typename range_iterator<const ForwardRange>::type,
+          typename range_iterator<const ForwardRange>::type>
+equal_range(const ForwardRange& rng, const Value& val);
+
+template<
+    class ForwardRange,
+    class Value,
+    class SortPredicate
+    >
+std::pair<typename range_iterator<ForwardRange>::type,
+          typename range_iterator<ForwardRange>::type>
+equal_range(ForwardRange& rng, const Value& val, SortPredicate pred);
+
+template<
+    class ForwardRange,
+    class Value,
+    class SortPredicate
+    >
+std::pair<typename range_iterator<const ForwardRange>::type,
+          typename range_iterator<const ForwardRange>::type>
+equal_range(const ForwardRange& rng, const Value& val, SortPredicate pred);                      
+ 
+

+

+
+ + Description +
+

+ equal_range returns a + range in the form of a pair of iterators where all of the elements are + equal to val. If no values + are found that are equal to val, + then an empty range is returned, hence result.first == result.second. + For the non-predicate versions of equal_range + the equality of elements is determined by operator<. For the predicate versions of equal_range the equality of elements + is determined by pred. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/equal_range.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +Value is a model of + the LessThanComparableConcept. +
  • +
  • + The ordering of objects of type Value + is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
  • +ForwardRange's value + type is the same type as Value. +
  • +
+

+ For the predicate versions: +

+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +SortPredicate is a + model of the StrictWeakOrderingConcept. +
  • +
  • +ForwardRange's value + type is the same as Value. +
  • +
  • +ForwardRange's value + type is convertible to both of SortPredicate's + argument types. +
  • +
+
+ + Precondition: +
+

+ For the non-predicate versions: rng + is ordered in ascending order according to operator<. +

+

+ For the predicate versions: rng + is ordered in ascending order according to pred. +

+
+ + Complexity +
+

+ For random-access ranges, the complexity is O(log N), + otherwise the complexity is O(N). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/find.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/find.html new file mode 100644 index 0000000..3e45381 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/find.html @@ -0,0 +1,123 @@ + + + +find + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class SinglePassRange, class Value>
+typename range_iterator<SinglePassRange>::type
+find(SinglePassRange& rng, Value val);
+
+template<class SinglePassRange, class Value>
+typename range_iterator<const SinglePassRange>::type
+find(const SinglePassRange& rng, Value val);
+
+template<
+    range_return_value re,
+    class SinglePassRange,
+    class Value
+    >
+typename range_return<SinglePassRange, re>::type
+find(SinglePassRange& rng, Value val);
+
+template<
+    range_return_value re,
+    class SinglePassRange,
+    class Value
+    >
+typename range_return<const SinglePassRange, re>::type
+find(const SinglePassRange& rng, Value val);
+
+

+

+
+ + Description +
+

+ The versions of find + that return an iterator, returns the first iterator in the range rng such that *i == value. end(rng) is returned if no such iterator exists. + The versions of find that return a range_return, + defines found in the + same manner as the returned iterator described above. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/find.hpp +

+
+ + Requirements +
+
    +
  • +SinglePassRange is + a model of the Single + Pass Range Concept. +
  • +
  • +Value is a model of + the EqualityComparableConcept. +
  • +
  • + The operator== + is defined for type Value + to be compared with the SinglePassRange's + value type. +
  • +
+
+ + Complexity +
+

+ Linear. At most distance(rng) comparisons for equality. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/find_end.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/find_end.html new file mode 100644 index 0000000..9412d18 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/find_end.html @@ -0,0 +1,204 @@ + + + +find_end + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class ForwardRange1, class ForwardRange2>
+typename range_iterator<ForwardRange1>::type
+find_end(ForwardRange1& rng1, const ForwardRange2& rng2);
+
+template<class ForwardRange1, class ForwardRange2>
+typename range_iterator<const ForwardRange1>::type
+find_end(const ForwardRange1& rng1, const ForwardRange2& rng2);
+
+template<
+    class ForwardRange1,
+    class ForwardRange2,
+    class BinaryPredicate
+    >
+typename range_iterator<ForwardRange1>::type
+find_end(ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred);
+
+template<
+    class ForwardRange1,
+    class ForwardRange2,
+    class BinaryPredicate
+    >
+typename range_iterator<const ForwardRange1>::type
+find_end(const ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred);
+
+
+template<
+    range_return_value re,
+    class ForwardRange1,
+    class ForwardRange2
+    >
+typename range_return<ForwardRange1, re>::type
+find_end(ForwardRange1& rng1, const ForwardRange2& rng2);
+
+template<
+    range_return_value re,
+    class ForwardRange1,
+    class ForwardRange2
+    >
+typename range_return<const ForwardRange1, re>::type
+find_end(const ForwardRange1& rng1, const ForwardRange2& rng2);
+
+template<
+    range_return_value re,
+    class ForwardRange1,
+    class ForwardRange2,
+    class BinaryPredicate
+    >
+typename range_return<ForwardRange1, re>::type
+find_end(ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred);
+
+template<
+    range_return_value re,
+    class ForwardRange1,
+    class ForwardRange2,
+    class BinaryPredicate
+    >
+typename range_return<const ForwardRange1, re>::type
+find_end(const ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred);
+
+

+

+
+ + Description +
+

+ The versions of find_end + that return an iterator, return an iterator to the beginning of the last + sub-sequence equal to rng2 + within rng1. Equality + is determined by operator== for non-predicate versions of find_end, and by satisfying pred in the predicate versions. The + versions of find_end + that return a range_return, + defines found in the + same manner as the returned iterator described above. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/find_end.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +ForwardRange1 is a + model of the Forward Range + Concept. +
  • +
  • +ForwardRange2 is a + model of the Forward Range + Concept. +
  • +
  • +ForwardRange1's value + type is a model of the EqualityComparableConcept. +
  • +
  • +ForwardRange2's value + type is a model of the EqualityComparableConcept. +
  • +
  • + Objects of ForwardRange1's + value type can be compared for equality with objects of ForwardRange2's value type. +
  • +
+

+ For the predicate versions: +

+
    +
  • +ForwardRange1 is a + model of the Forward Range + Concept. +
  • +
  • +ForwardRange2 is a + model of the Forward Range + Concept. +
  • +
  • +BinaryPredicate is + a model of the BinaryPredicateConcept. +
  • +
  • +ForwardRange1's value + type is convertible to BinaryPredicate's + first argument type. +
  • +
  • +ForwardRange2's value + type is convertible to BinaryPredicate's + second argument type. +
  • +
+
+ + Complexity +
+

+ The number of comparisons is proportional to distance(rng1) * distance(rng2). If both ForwardRange1 + and ForwardRange2 are + models of BidirectionalRangeConcept + then the average complexity is linear and the worst case is distance(rng1) * distance(rng2). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/find_first_of.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/find_first_of.html new file mode 100644 index 0000000..5f15b42 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/find_first_of.html @@ -0,0 +1,200 @@ + + + +find_first_of + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class SinglePassRange1, class ForwardRange2>
+typename range_iterator<SinglePassRange1>::type
+find_first_of(SinglePassRange1& rng1, const ForwardRange2& rng2);
+
+template<class SinglePassRange1, class ForwardRange2>
+typename range_iterator<const SinglePassRange1>::type
+find_first_of(const SinglePassRange1& rng1, const ForwardRange2& rng2);
+
+template<
+    class SinglePassRange1,
+    class ForwardRange2,
+    class BinaryPredicate
+    >
+typename range_iterator<SinglePassRange1>::type
+find_first_of(SinglePassRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred);
+
+template<
+    class SinglePassRange1,
+    class ForwardRange2,
+    class BinaryPredicate
+    >
+typename range_iterator<const SinglePassRange1>::type
+find_first_of(const SinglePassRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred);
+
+
+template<
+    range_return_value re,
+    class SinglePassRange1,
+    class ForwardRange2
+    >
+typename range_return<SinglePassRange1, re>::type
+find_first_of(SinglePassRange1& rng1, const ForwardRange2& rng2);
+
+template<
+    range_return_value re,
+    class SinglePassRange1,
+    class ForwardRange2
+    >
+typename range_return<const SinglePassRange1, re>::type
+find_first_of(const SinglePassRange1& rng1, const ForwardRange2& rng2);
+
+template<
+    range_return_value re,
+    class SinglePassRange1,
+    class ForwardRange2,
+    class BinaryPredicate
+    >
+typename range_return<SinglePassRange1, re>::type
+find_first_of(SinglePassRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred);
+
+template<
+    range_return_value re,
+    class SinglePassRange1,
+    class ForwardRange2,
+    class BinaryPredicate
+    >
+typename range_return<const SinglePassRange1, re>::type
+find_first_of(const SinglePassRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred);
+
+

+

+
+ + Description +
+

+ The versions of find_first_of + that return an iterator, return an iterator to the first occurrence in + rng1 of any of the elements + in rng2. Equality is + determined by operator== + for non-predicate versions of find_first_of, + and by satisfying pred + in the predicate versions. +

+

+ The versions of find_first_of + that return a range_return, + defines found in the + same manner as the returned iterator described above. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/find_first_of.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +ForwardRange2 is a + model of the Forward Range + Concept. +
  • +
  • +SinglePassRange1's + value type is a model of the EqualityComparableConcept, + and can be compared for equality with ForwardRange2's + value type. +
  • +
+

+ For the predicate versions: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +ForwardRange2 is a + model of the Forward Range + Concept. +
  • +
  • +BinaryPredicate is + a model of the BinaryPredicateConcept. +
  • +
  • +SinglePassRange1's + value type is convertible to BinaryPredicate's + first argument type. +
  • +
  • +ForwardRange2's value + type is convertible to BinaryPredicate's + second argument type. +
  • +
+
+ + Complexity +
+

+ At most distance(rng1) * distance(rng2) comparisons. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/find_if.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/find_if.html new file mode 100644 index 0000000..424b833 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/find_if.html @@ -0,0 +1,133 @@ + + + +find_if + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class SinglePassRange, class UnaryPredicate>
+typename range_iterator<SinglePassRange>::type
+find_if(SinglePassRange& rng, UnaryPredicate pred);
+
+template<class SinglePassRange, class UnaryPredicate>
+typename range_iterator<const SinglePassRange>::type
+find_if(const SinglePassRange& rng, UnaryPredicate pred);
+
+template<
+    range_return_value re,
+    class SinglePassRange,
+    class UnaryPredicate
+    >
+typename range_return<SinglePassRange, re>::type
+find_if(SinglePassRange& rng, UnaryPredicate pred);
+
+template<
+    range_return_value re,
+    class SinglePassRange,
+    class UnaryPredicate
+    >
+typename range_return<const SinglePassRange, re>::type
+find_if(const SinglePassRange& rng, UnaryPredicate pred);
+
+

+

+
+ + Description +
+

+ The versions of find_if + that return an iterator, returns the first iterator in the range rng such that pred(*i) is true. + end(rng) + is returned if no such iterator exists. +

+

+ The versions of find_if + that return a range_return, + defines found in the same manner as the returned iterator described above. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/find_if.hpp +

+
+ + Requirements +
+
    +
  • +SinglePassRange is + a model of the Single + Pass Range Concept. +
  • +
  • +UnaryPredicate is a + model of the PredicateConcept. +
  • +
  • + The value type of SinglePassRange + is convertible to the argument type of UnaryPredicate. +
  • +
+
+ + Precondition: +
+

+ For each iterator i in + rng, *i is in the domain of UnaryPredicate. +

+
+ + Complexity +
+

+ Linear. At most distance(rng) invocations of pred. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/for_each.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/for_each.html new file mode 100644 index 0000000..3c85cc0 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/for_each.html @@ -0,0 +1,113 @@ + + + +for_each + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class SinglePassRange,
+    class UnaryFunction
+    >
+UnaryFunction for_each(SinglePassRange& rng, UnaryFunction fun);
+
+template<
+    class SinglePassRange,
+    class UnaryFunction
+    >
+UnaryFunction for_each(const SinglePassRange& rng, UnaryFunction fun);    
+
+

+

+
+ + Description +
+

+ for_each traverses forward + through rng and for each + element x it invokes + fun(x). +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/for_each.hpp +

+
+ + Requirements +
+
    +
  • +SinglePassRange is + a model of the Single + Pass Range Concept. +
  • +
  • +UnaryFunction is a + model of the UnaryFunctionConcept. +
  • +
  • +UnaryFunction does + not apply any non-constant operation through its argument. +
  • +
  • +SinglePassRange's value + type is convertible to UnaryFunction's + argument type. +
  • +
+
+ + Complexity +
+

+ Linear. Exactly distance(rng) applications of UnaryFunction. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/lexicographical_compare.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/lexicographical_compare.html new file mode 100644 index 0000000..0cf9505 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/lexicographical_compare.html @@ -0,0 +1,170 @@ + + + +lexicographical_compare + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class SinglePassRange1,
+    class SinglePassRange2
+    >
+bool lexicographical_compare(const SinglePassRange1& rng1,
+                             const SinglePassRange2& rng2);
+
+template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class BinaryPredicate
+    >
+bool lexicographical_compare(const SinglePassRange1& rng1,
+                             const SinglePassRange2& rng2,
+                             BinaryPredicate pred);    
+
+

+

+
+ + Description +
+

+ lexicographical_compare + compares element by element rng1 + against rng2. If the + element from rng1 is + less than the element from rng2 + then true is returned. If + the end of rng1 without + reaching the end of rng2 + this also causes the return value to be true. + The return value is false + in all other circumstances. The elements are compared using operator< + in the non-predicate versions of lexicographical_compare + and using pred in the + predicate versions. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/lexicographical_compare.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions of lexicographical_compare: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange1's + value type is a model of the LessThanComparableConcept. +
  • +
  • +SinglePassRange2's + value type is a model of the LessThanComparableConcept. +
  • +
  • + Let x be an object + of SinglePassRange1's + value type. Let y be + an obect of SinglePassRange2's + value type. x < + y must be valid. y < + x must be valid. +
  • +
+

+ For the predicate versions of lexicographical_compare: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +BinaryPredicate is + a model of the BinaryPredicateConcept. +
  • +
  • +SinglePassRange1's + value type is convertible to BinaryPredicate's + first argument type. +
  • +
  • +SinglePassRange2's + value type is convertible to BinaryPredicate's + second argument type. +
  • +
+
+ + Complexity +
+

+ Linear. At most 2 * + min(distance(rng1), distance(rng2)) + comparisons. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/lower_bound.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/lower_bound.html new file mode 100644 index 0000000..4e1f526 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/lower_bound.html @@ -0,0 +1,188 @@ + + + +lower_bound + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class ForwardRange, class Value>
+typename range_iterator<ForwardRange>::type
+lower_bound(ForwardRange& rng, Value val);
+
+template<class ForwardRange, class Value>
+typename range_iterator<const ForwardRange>::type
+lower_bound(const ForwardRange& rng, Value val);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class Value
+    >
+typename range_return<ForwardRange, re>::type
+lower_bound(ForwardRange& rng, Value val);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class Value
+    >
+typename range_return<const ForwardRange, re>::type
+lower_bound(const ForwardRange& rng, Value val);
+
+

+

+
+ + Description +
+

+ The versions of lower_bound + that return an iterator, returns the first iterator in the range rng such that: without predicate - + *i + < value + is false, with predicate + - pred(*i, value) + is false. +

+

+ end(rng) + is returned if no such iterator exists. +

+

+ The versions of lower_bound + that return a range_return, + defines found in the + same manner as the returned iterator described above. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/lower_bound.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +Value is a model of + the LessThanComparableConcept. +
  • +
  • + The ordering of objects of type Value + is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
  • +ForwardRange's value + type is the same type as Value. +
  • +
+

+ For the predicate versions: +

+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +BinaryPredicate is + a model of the StrictWeakOrderingConcept. +
  • +
  • +ForwardRange's value + type is the same type as Value. +
  • +
  • +ForwardRange's value + type is convertible to both of BinaryPredicate's + argument types. +
  • +
+
+ + Precondition: +
+

+ For the non-predicate versions: +

+

+ rng is sorted in ascending + order according to operator<. +

+

+ For the predicate versions: +

+

+ rng is sorted in ascending + order according to pred. +

+
+ + Complexity +
+

+ For ranges that model the Random + Access Range concept the complexity is O(log N), + where N is distance(rng). +

+

+ For all other range types the complexity is O(N). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/max_element.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/max_element.html new file mode 100644 index 0000000..8ca03f7 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/max_element.html @@ -0,0 +1,166 @@ + + + +max_element + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class ForwardRange>
+typename range_iterator<ForwardRange>::type
+max_element(ForwardRange& rng);
+
+template<class ForwardRange>
+typename range_iterator<const ForwardRange>::type
+max_element(const ForwardRange& rng);
+
+template<class ForwardRange, class BinaryPredicate>
+typename range_iterator<ForwardRange>::type
+max_element(ForwardRange& rng, BinaryPredicate pred);
+
+template<class ForwardRange, class BinaryPredicate>
+typename range_iterator<const ForwardRange>::type
+max_element(const ForwardRange& rng, BinaryPredicate pred);
+
+
+template<
+    range_return_value re,
+    class ForwardRange
+    >
+typename range_return<ForwardRange, re>::type
+max_element(ForwardRange& rng);
+
+template<
+    range_return_value_re,
+    class ForwardRange
+    >
+typename range_return<const ForwardRange, re>::type
+max_element(const ForwardRange& rng);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class BinaryPredicate
+    >
+typename range_return<ForwardRange, re>::type
+max_element(ForwardRange& rng, BinaryPredicate pred);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class BinaryPredicate
+    >
+typename range_return<const ForwardRange, re>::type
+max_element(const ForwardRange& rng, BinaryPredicate pred);
+
+

+

+
+ + Description +
+

+ The versions of max_element + that return an iterator, return the iterator to the maximum value as + determined by using operator< if a predicate is not supplied. Otherwise + the predicate pred is + used to determine the maximum value. The versions of max_element + that return a range_return, + defines found in the + same manner as the returned iterator described above. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/max_element.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +ForwardRange's value + type is a model of the LessThanComparableConcept. +
  • +
+

+ For the predicate versions: +

+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +BinaryPredicate is + a model of the BinaryPredicateConcept. +
  • +
  • +ForwardRange's value + type is convertible to both of BinaryPredicate's + argument types. +
  • +
+
+ + Complexity +
+

+ Linear. Zero comparisons if empty(rng), otherwise distance(rng) - 1 + comparisons. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/min_element.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/min_element.html new file mode 100644 index 0000000..08903d1 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/min_element.html @@ -0,0 +1,166 @@ + + + +min_element + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class ForwardRange>
+typename range_iterator<ForwardRange>::type
+min_element(ForwardRange& rng);
+
+template<class ForwardRange>
+typename range_iterator<const ForwardRange>::type
+min_element(const ForwardRange& rng);
+
+template<class ForwardRange, class BinaryPredicate>
+typename range_iterator<ForwardRange>::type
+min_element(ForwardRange& rng, BinaryPredicate pred);
+
+template<class ForwardRange, class BinaryPredicate>
+typename range_iterator<const ForwardRange>::type
+min_element(const ForwardRange& rng, BinaryPredicate pred);
+
+
+template<
+    range_return_value re,
+    class ForwardRange
+    >
+typename range_return<ForwardRange, re>::type
+min_element(ForwardRange& rng);
+
+template<
+    range_return_value_re,
+    class ForwardRange
+    >
+typename range_return<const ForwardRange, re>::type
+min_element(const ForwardRange& rng);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class BinaryPredicate
+    >
+typename range_return<ForwardRange, re>::type
+min_element(ForwardRange& rng, BinaryPredicate pred);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class BinaryPredicate
+    >
+typename range_return<const ForwardRange, re>::type
+min_element(const ForwardRange& rng, BinaryPredicate pred);
+
+

+

+
+ + Description +
+

+ The versions of min_element + that return an iterator, return the iterator to the minimum value as + determined by using operator< if a predicate is not supplied. Otherwise + the predicate pred is + used to determine the minimum value. The versions of min_element + that return a range_return, + defines found in the + same manner as the returned iterator described above. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/min_element.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +ForwardRange's value + type is a model of the LessThanComparableConcept. +
  • +
+

+ For the predicate versions: +

+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +BinaryPredicate is + a model of the BinaryPredicateConcept. +
  • +
  • +ForwardRange's value + type is convertible to both of BinaryPredicate's + argument types. +
  • +
+
+ + Complexity +
+

+ Linear. Zero comparisons if empty(rng), otherwise distance(rng) - 1 + comparisons. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/mismatch.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/mismatch.html new file mode 100644 index 0000000..5a168da --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/mismatch.html @@ -0,0 +1,222 @@ + + + +mismatch + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class SinglePassRange1, class SinglePassRange2>
+std::pair<
+    typename range_iterator<SinglePassRange1>::type,
+    typename range_iterator<const SinglePassRange2>::type >
+mismatch(SinglePassRange1& rng1, const SinglePassRange2& rng2);
+
+template<class SinglePassRange1, class SinglePassRange2>
+std::pair<
+    typename range_iterator<const SinglePassRange1>::type,
+    typename range_iterator<const SinglePassRange2>::type >
+mismatch(const SinglePassRange1& rng1, const SinglePassRange2& rng2);
+
+template<class SinglePassRange1, class SinglePassRange2>
+std::pair<
+    typename range_iterator<SinglePassRange1>::type,
+    typename range_iterator<SinglePassRange2>::type >
+mismatch(SinglePassRange1& rng1, SinglePassRange2& rng2);
+
+template<class SinglePassRange1, class SinglePassRange2>
+std::pair<
+    typename range_iterator<const SinglePassRange1>::type,
+    typename range_iterator<SinglePassRange2>::type >
+mismatch(const SinglePassRange1& rng1, SinglePassRange2& rng2);
+
+
+template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class BinaryPredicate
+    >
+std::pair<
+    typename range_iterator<SinglePassRange1>::type,
+    typename range_iterator<const SinglePassRange2>::type >
+mismatch(SinglePassRange1& rng1, const SinglePassRange2& rng2,
+         BinaryPredicate pred);
+
+template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class BinaryPredicate
+    >
+std::pair<
+    typename range_iterator<const SinglePassRange1>::type,
+    typename range_iterator<const SinglePassRange2>::type >
+mismatch(const SinglePassRange1& rng1, const SinglePassRange2& rng2,
+         BinaryPredicate pred);
+
+template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class BinaryPredicate
+    >
+std::pair<
+    typename range_iterator<SinglePassRange1>::type,
+    typename range_iterator<SinglePassRange2>::type >
+mismatch(SinglePassRange1& rng1, SinglePassRange2& rng2,
+         BinaryPredicate pred);
+
+template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class BinaryPredicate
+    >
+std::pair<
+    typename range_iterator<const SinglePassRange1>::type,
+    typename range_iterator<SinglePassRange2>::type >
+mismatch(const SinglePassRange1& rng1, SinglePassRange2& rng2,
+         BinaryPredicate pred);
+
+

+

+
+ + Description +
+

+ The versions of mismatch + that return an iterator, return an iterator to the first position where + rng1 and rng2 differ. +

+

+ Equality is determined by operator== for non-predicate versions of mismatch, and by satisfying pred in the predicate versions. +

+

+ The versions of mismatch + that return a range_return, + defines found in the + same manner as the returned iterator described above. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/mismatch.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange1's + value type is a model of the EqualityComparableConcept. +
  • +
  • +SinglePassRange2's + value type is a model of the EqualityComparableConcept. +
  • +
  • +SinglePassRange1s value + type can be compared for equality with SinglePassRange2's + value type. +
  • +
+

+ For the predicate versions: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +BinaryPredicate is + a model of the BinaryPredicateConcept. +
  • +
  • +SinglePassRange1's + value type is convertible to BinaryPredicate's + first argument type. +
  • +
  • +SinglePassRange2's + value type is convertible to BinaryPredicate's + second argument type. +
  • +
+
+ + Precondition: +
+

+ distance(rng2) >= distance(rng1) +

+
+ + Complexity +
+

+ Linear. At most distance(rng1) comparisons. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/search.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/search.html new file mode 100644 index 0000000..1dcf8c0 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/search.html @@ -0,0 +1,206 @@ + + + +search + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class ForwardRange1, class ForwardRange2>
+typename range_iterator<ForwardRange1>::type
+search(ForwardRange1& rng1, const ForwardRange2& rng2);
+
+template<class ForwardRange1, class ForwardRange2>
+typename range_iterator<const ForwardRange1>::type
+search(const ForwardRange1& rng1, const ForwardRange2& rng2);
+
+template<
+    class ForwardRange1,
+    class ForwardRange2,
+    class BinaryPredicate
+    >
+typename range_iterator<ForwardRange1>::type,
+search(ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred);
+
+template<
+    class ForwardRange1,
+    class ForwardRange2,
+    class BinaryPredicate
+    >
+typename range_iterator<const ForwardRange1>::type
+search(const ForwardRange1& rng1, ForwardRange2& rng2, BinaryPredicate pred);
+
+
+template<
+    range_return_value re,
+    class ForwardRange1,
+    class ForwardRange2
+    >
+typename range_return<ForwardRange1, re>::type
+search(ForwardRange1& rng1, const ForwardRange2& rng2);
+
+template<
+    range_return_value re,
+    class ForwardRange1,
+    class ForwardRange2
+    >
+typename range_return<const ForwardRange1, re>::type
+search(const ForwardRange1& rng1, const ForwardRange2& rng2);
+
+template<
+    range_return_value re,
+    class ForwardRange1,
+    class ForwardRange2,
+    class BinaryPredicate
+    >
+typename range_return<ForwardRange1, re>::type,
+search(ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred);
+
+template<
+    range_return_value re,
+    class ForwardRange1,
+    class ForwardRange2,
+    class BinaryPredicate
+    >
+typename range_return<const ForwardRange1, re>::type
+search(const ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred);
+
+

+

+
+ + Description +
+

+ The versions of search + that return an iterator, return an iterator to the start of the first + subsequence in rng1 that + is equal to the subsequence rng2. + The end(rng1) + is returned if no such subsequence exists in rng1. + Equality is determined by operator== for non-predicate versions of search, and by satisfying pred in the predicate versions. +

+

+ The versions of search + that return a range_return, + defines found in the + same manner as the returned iterator described above. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/search.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +ForwardRange1 is a + model of the Forward Range + Concept. +
  • +
  • +ForwardRange2 is a + model of the Forward Range + Concept. +
  • +
  • +ForwardRange1's value + type is a model of the EqualityComparableConcept. +
  • +
  • +ForwardRange2's value + type is a model of the EqualityComparableConcept. +
  • +
  • +ForwardRange1s value + type can be compared for equality with ForwardRange2's + value type. +
  • +
+

+ For the predicate versions: +

+
    +
  • +ForwardRange1 is a + model of the Forward Range + Concept. +
  • +
  • +ForwardRange2 is a + model of the Forward Range + Concept. +
  • +
  • +BinaryPredicate is + a model of the BinaryPredicateConcept. +
  • +
  • +ForwardRange1's value + type is convertible to BinaryPredicate's + first argument type. +
  • +
  • +ForwardRange2's value + type is convertible to BinaryPredicate's + second argument type. +
  • +
+
+ + Complexity +
+

+ Average complexity is Linear. Worst-case complexity is quadratic. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/upper_bound.html b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/upper_bound.html new file mode 100644 index 0000000..8db1558 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_algorithm_non_mutating_algorithms/upper_bound.html @@ -0,0 +1,185 @@ + + + +upper_bound + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class ForwardRange, class Value>
+typename range_iterator<ForwardRange>::type
+upper_bound(ForwardRange& rng, Value val);
+
+template<class ForwardRange, class Value>
+typename range_iterator<const ForwardRange>::type
+upper_bound(const ForwardRange& rng, Value val);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class Value
+    >
+typename range_return<ForwardRange, re>::type
+upper_bound(ForwardRange& rng, Value val);
+
+template<
+    range_return_value re,
+    class ForwardRange,
+    class Value
+    >
+typename range_return<const ForwardRange, re>::type
+upper_bound(const ForwardRange& rng, Value val);
+
+

+

+
+ + Description +
+

+ The versions of upper_bound + that return an iterator, returns the first iterator in the range rng such that: without predicate - + val < + *i + is true, with predicate + - pred(val, *i) is true. +

+

+ end(rng) + is returned if no such iterator exists. +

+

+ The versions of upper_bound + that return a range_return, + defines found in the + same manner as the returned iterator described above. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/upper_bound.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +Value is a model of + the LessThanComparableConcept. +
  • +
  • + The ordering of objects of type Value + is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
  • +ForwardRange's value + type is the same type as Value. +
  • +
+

+ For the predicate versions: +

+
    +
  • +ForwardRange is a model + of the Forward Range + Concept. +
  • +
  • +BinaryPredicate is + a model of the StrictWeakOrderingConcept. +
  • +
  • +ForwardRange's value + type is the same type as Value. +
  • +
  • +ForwardRange's value + type is convertible to both of BinaryPredicate's + argument types. +
  • +
+
+ + Precondition: +
+

+ For the non-predicate versions: +

+

+ rng is sorted in ascending + order according to operator<. +

+

+ For the predicate versions: +

+

+ rng is sorted in ascending + order according to pred. +

+
+ + Complexity +
+

+ For ranges that model the Random + Access Range Concept the complexity is O(log N), + where N is distance(rng). + For all other range types the complexity is O(N). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_numeric.html b/doc/html/range/reference/algorithms/range_numeric.html new file mode 100644 index 0000000..c6c6767 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_numeric.html @@ -0,0 +1,54 @@ + + + +Numeric algorithms + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_numeric/accumulate.html b/doc/html/range/reference/algorithms/range_numeric/accumulate.html new file mode 100644 index 0000000..448b1fa --- /dev/null +++ b/doc/html/range/reference/algorithms/range_numeric/accumulate.html @@ -0,0 +1,157 @@ + + + +accumulate + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class SinglePassRange,
+    class Value
+    >
+Value accumulate(const SinglePassRange& source_rng,
+                 Value init);
+
+template<
+    class SinglePassRange,
+    class Value,
+    class BinaryOperation
+    >
+Value accumulate(const SinglePassRange& source_rng,
+                 Value init,
+                 BinaryOperation op);
+
+

+

+
+ + Description +
+

+ accumulate is a generalisation + of summation. It computes a binary operation (operator+ in the non-predicate version) of init and all of the elements in rng. +

+

+ The return value is the resultant value of the above algorithm. +

+
+ + Definition +
+

+ Defined in the header file boost/range/numeric.hpp +

+
+ + Requirements +
+
+ + For + the first version +
+
    +
  1. +SinglePassRange is + a model of the Single + Pass Range Concept. +
  2. +
  3. +Value is a model of + the AssignableConcept. +
  4. +
  5. + An operator+ + is defined for a left-hand operand of type Value + and a right-hand operance of the SinglePassRange + value type. +
  6. +
  7. + The return type of the above operator is convertible to Value. +
  8. +
+
+ + For + the second version +
+
    +
  1. +SinglePassRange is + a model of the Single + Pass Range Concept. +
  2. +
  3. +Value is a model of + the AssignableConcept. +
  4. +
  5. +BinaryOperation is + a model of the BinaryFunctionConcept. +
  6. +
  7. +Value is convertible + to BinaryOperation's + first argument type. +
  8. +
  9. +SinglePassRange's value + type is convertible to BinaryOperation's + second argument type. +
  10. +
  11. + The return type of BinaryOperation + is convertible to Value. +
  12. +
+
+ + Complexity +
+

+ Linear. Exactly distance(source_rng). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_numeric/adjacent_difference.html b/doc/html/range/reference/algorithms/range_numeric/adjacent_difference.html new file mode 100644 index 0000000..8c76593 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_numeric/adjacent_difference.html @@ -0,0 +1,179 @@ + + + +adjacent_difference + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class SinglePassRange,
+    class OutputIterator
+    >
+OutputIterator adjacent_difference(
+    const SinglePassRange& source_rng,
+    OutputIterator out_it);
+
+template<
+    class SinglePassRange,
+    class OutputIterator,
+    class BinaryOperation
+    >
+OutputIterator adjacent_difference(
+    const SinglePassRange& source_rng,
+    OutputIterator out_it,
+    BinaryOperation op);
+
+

+

+
+ + Description +
+

+ adjacent_difference calculates + the differences of adjacent_elements in rng. +

+

+ The first version of adjacent_difference + uses operator-() + to calculate the differences. The second version uses BinaryOperation + instead of operator-(). +

+
+ + Definition +
+

+ Defined in the header file boost/range/numeric.hpp +

+
+ + Requirements +
+
+ + For + the first version +
+
    +
  1. +SinglePassRange is + a model of the Single + Pass Range Concept. +
  2. +
  3. +OutputIterator is a + model of the OutputIteratorConcept. +
  4. +
  5. + If x and y are objects of SinglePassRange's + value type, then x - y + is defined. +
  6. +
  7. + The value type of SinglePassRange + is convertible to a type in OutputIterator's + set of value types. +
  8. +
  9. + The return type of x - y + is convertible to a type in OutputIterator's + set of value types. +
  10. +
+
+ + For + the second version +
+
    +
  1. +SinglePassRange is + a model of the Single + Pass Range Concept. +
  2. +
  3. +OutputIterator is a + model of the OutputIteratorConcept. +
  4. +
  5. +BinaryOperation is + a model of the BinaryFunctionConcept. +
  6. +
  7. + The value type of SinglePassRange + is convertible to BinaryOperation's + first and second argument types. +
  8. +
  9. + The value type of SinglePassRange + is convertible to a type in OutputIterator's + set of value types. +
  10. +
  11. + The result type of BinaryOperation + is convertible to a type in OutputIterator's + set of value types. +
  12. +
+
+ + Precondition: +
+

+ [result, result + + distance(rng)) is a valid range. +

+
+ + Complexity +
+

+ Linear. If empty(rng) + then zero applications, otherwise distance(rng) - 1 + applications are performed. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_numeric/inner_product.html b/doc/html/range/reference/algorithms/range_numeric/inner_product.html new file mode 100644 index 0000000..6d48b14 --- /dev/null +++ b/doc/html/range/reference/algorithms/range_numeric/inner_product.html @@ -0,0 +1,192 @@ + + + +inner_product + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class SinglePassRange1,
+         class SinglePassRange2,
+         class Value>
+    Value inner_product( const SinglePassRange1& rng1,
+                         const SinglePassRange2& rng2,
+                         Value                   init );
+
+template<class SinglePassRange1,
+         class SinglePassRange2,
+         class Value,
+         class BinaryOperation1,
+         class BinaryOperation2>
+    Value inner_product( const SinglePassRange1& rng1,
+                         const SinglePassRange2& rng2,
+                         Value                   init,
+                         BinaryOperation1        op1 );
+
+

+

+
+ + Description +
+

+ inner_product calculates + a generalised inner product of the range rng1 + and rng2. +

+

+ For further information on the inner_product + algorithm please see inner_product. +

+
+ + Definition +
+

+ Defined in the header file boost/range/numeric.hpp +

+
+ + Requirements +
+
+ + For + the first version +
+
    +
  1. +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  2. +
  3. +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  4. +
  5. +Value is a model of + the AssignableConcept. +
  6. +
  7. + If x is an object of + type Value, y is an object of SinglePassRange1's + value type, and z is + an object of SinglePassRange2's + value type, then x + y * z + is defined. +
  8. +
  9. + The result type of the expression x + + y + * z + is convertible to Value. +
  10. +
+
+ + For + the second version +
+
    +
  1. +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  2. +
  3. +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  4. +
  5. +Value is a model of + the AssignableConcept. +
  6. +
  7. +BinaryOperation1 is + a model of the BinaryFunctionConcept. +
  8. +
  9. +BinaryOperation2 is + a model of the BinaryFunctionConcept. +
  10. +
  11. + The value type of SinglePassRange1 + is convertible to the first argument type of BinaryOperation2. +
  12. +
  13. + The value type of SinglePassRange2 + is convertible to the second argument type of BinaryOperation2. +
  14. +
  15. +Value is convertible + to the value type of BinaryOperation1. +
  16. +
  17. + The return type of BinaryOperation2 + is convertible to the second argument type of BinaryOperation1. +
  18. +
  19. + The return type of BinaryOperation1 + is convertible to Value. +
  20. +
+
+ + Precondition: +
+

+ distance(rng2) >= distance(rng1) is a valid range. +

+
+ + Complexity +
+

+ Linear. Exactly distance(rng). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_numeric/irange.html b/doc/html/range/reference/algorithms/range_numeric/irange.html new file mode 100644 index 0000000..a23253d --- /dev/null +++ b/doc/html/range/reference/algorithms/range_numeric/irange.html @@ -0,0 +1,105 @@ + + + +irange + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class Integer>
+integer_range< range_detail::integer_iterator<Integer> >
+irange(Integer first, Integer  last);
+
+template<class Integer, class StepSize>
+integer_range< range_detail::integer_iterator_with_step<Integer, StepSize> >
+irange(Integer first, Integer last, StepSize step_size);
+
+

+

+
+ + Description +
+

+ irange is a function + to generate an Integer Range. +

+

+ irange allows treating + integers as a model of the Random + Access Range Concept. It should be noted that the first and last + parameters denoted a half-open range. +

+
+ + Definition +
+

+ Defined in the header file boost/range/irange.hpp +

+
+ + Requirements +
+
    +
  1. +Integer is a model + of the Integer Concept. +
  2. +
  3. +StepSize is a model + of the SignedInteger + Concept. +
  4. +
+
+ + Complexity +
+

+ Constant. Since this function generates a new range the most significant + performance cost is incurred through the iteration of the generated range. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/range_numeric/partial_sum.html b/doc/html/range/reference/algorithms/range_numeric/partial_sum.html new file mode 100644 index 0000000..b89e58e --- /dev/null +++ b/doc/html/range/reference/algorithms/range_numeric/partial_sum.html @@ -0,0 +1,161 @@ + + + +partial_sum + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class SinglePassRange,
+         class OutputIterator>
+OutputIterator partial_sum(const SinglePassRange& rng,
+                           OutputIterator out_it);
+
+template<class SinglePassRange,
+         class OutputIterator,
+         class BinaryOperation>
+OutputIterator partial_sum(const SinglePassRange& rng,
+                           OutputIterator out_it,
+                           BinaryOperation op);
+
+

+

+
+ + Description +
+

+ partial_sum calculates + a generalised partial sum of rng + in the same manner as std::partial_sum(boost::begin(rng), boost::end(rng), out_it). See partial_sum. +

+
+ + Definition +
+

+ Defined in the header file boost/range/numeric.hpp +

+
+ + Requirements +
+
+ + For + the first version +
+
    +
  1. +SinglePassRange is + a model of the Single + Pass Range Concept. +
  2. +
  3. +OutputIterator is a + model of the OutputIteratorConcept. +
  4. +
  5. + If x and y are objects of SinglePassRange's + value type, then x + y + is defined. +
  6. +
  7. + The return type of x + y + is convertible to the value type of SinglePassRange. +
  8. +
  9. + The value type of SinglePassRange + is convertible to a type in OutputIterator's + set of value types. +
  10. +
+
+ + For + the second version +
+
    +
  1. +SinglePassRange is + a model of the Single + Pass Range Concept. +
  2. +
  3. +OutputIterator is a + model of the OutputIteratorConcept. +
  4. +
  5. +BinaryOperation is + a model of the BinaryFunctionConcept. +
  6. +
  7. + The result type of BinaryOperation + is convertible to the value type of SinglePassRange. +
  8. +
  9. + The value type of SinglePassRange + is convertible to a type in OutputIterator's + set of value types. +
  10. +
+
+ + Precondition: +
+

+ [result, result + + distance(rng)) is a valid range. +

+
+ + Complexity +
+

+ Linear. If empty(rng) + then zero applications, otherwise distance(rng) - 1 + applications are performed. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/set_algorithms.html b/doc/html/range/reference/algorithms/set_algorithms.html new file mode 100644 index 0000000..b9888f5 --- /dev/null +++ b/doc/html/range/reference/algorithms/set_algorithms.html @@ -0,0 +1,55 @@ + + + +Set algorithms + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/set_algorithms/includes.html b/doc/html/range/reference/algorithms/set_algorithms/includes.html new file mode 100644 index 0000000..015474a --- /dev/null +++ b/doc/html/range/reference/algorithms/set_algorithms/includes.html @@ -0,0 +1,187 @@ + + + +includes + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class SinglePassRange1, class SinglePassRange2>
+bool includes(const SinglePassRange1& rng1, const SinglePassRange2& rng2);
+
+template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class BinaryPredicate
+    >
+bool includes(const SinglePassRange1& rng1, const SinglePassRange2& rng2,
+              BinaryPredicate pred);    
+
+

+

+
+ + Description +
+

+ includes returns true if and only if, for every element + in rng2, an equivalent + element is also present in rng1. + The ordering relationship is determined by using operator< in the non-predicate versions, and + by evaluating pred in + the predicate versions. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/set_algorithm.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange1 and + SinglePassRange2 have + the same value type. +
  • +
  • +SinglePassRange1's + value type is a model of the LessThanComparableConcept. +
  • +
  • +SinglePassRange2's + value type is a model of the LessThanComparableConcept. +
  • +
  • + The ordering of objects of type SinglePassRange1's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
  • + The ordering of objects of type SinglePassRange2's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
+

+ For the predicate versions: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange1 and + SinglePassRange2 have + the same value type. +
  • +
  • +BinaryPredicate is + a model of the StrictWeakOrderingConcept. +
  • +
  • +SinglePassRange1's + value type is convertible to BinaryPredicate's + first argument type. +
  • +
  • +SinglePassRange2's + value type is convertible to BinaryPredicate's + second argument types. +
  • +
+
+ + Precondition: +
+

+ For the non-predicate versions: +

+

+ rng1 and rng2 are sorted in ascending order + according to operator<. +

+

+ For the predicate versions: +

+

+ rng1 and rng2 are sorted in ascending order + according to pred. +

+
+ + Complexity +
+

+ Linear. O(N), + where N is distance(rng1) + distance(rng2). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/set_algorithms/set_difference.html b/doc/html/range/reference/algorithms/set_algorithms/set_difference.html new file mode 100644 index 0000000..58d8a54 --- /dev/null +++ b/doc/html/range/reference/algorithms/set_algorithms/set_difference.html @@ -0,0 +1,206 @@ + + + +set_difference + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class OutputIterator
+    >
+OutputIterator set_difference(const SinglePassRange1& rng1,
+                              const SinglePassRange2& rng2,
+                              OutputIterator          out);
+
+template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class OutputIterator,
+    class BinaryPredicate
+    >
+OutputIterator set_difference(const SinglePassRange1& rng1,
+                              const SinglePassRange2& rng2,
+                              OutputIterator          out,
+                              BinaryPredicate         pred);
+
+

+

+
+ + Description +
+

+ set_difference constructs + a sorted range that is the set difference of the sorted ranges rng1 and rng2. + The return value is the end of the output range. +

+

+ The ordering relationship is determined by using operator< in the non-predicate versions, and + by evaluating pred in + the predicate versions. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/set_algorithm.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +OutputIterator is a + model of the OutputIteratorConcept. +
  • +
  • +SinglePassRange1 and + SinglePassRange2 have + the same value type. +
  • +
  • +SinglePassRange1's + value type is a model of the LessThanComparableConcept. +
  • +
  • +SinglePassRange2's + value type is a model of the LessThanComparableConcept. +
  • +
  • + The ordering of objects of type SinglePassRange1's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
  • + The ordering of objects of type SinglePassRange2's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
+

+ For the predicate versions: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +OutputIterator is a + model of the OutputIteratorConcept. +
  • +
  • +SinglePassRange1 and + SinglePassRange2 have + the same value type. +
  • +
  • +BinaryPredicate is + a model of the StrictWeakOrderingConcept. +
  • +
  • +SinglePassRange1's + value type is convertible to BinaryPredicate's + first argument type. +
  • +
  • +SinglePassRange2's + value type is convertible to BinaryPredicate's + second argument types. +
  • +
+
+ + Precondition: +
+

+ For the non-predicate versions: +

+

+ rng1 and rng2 are sorted in ascending order + according to operator<. +

+

+ For the predicate versions: +

+

+ rng1 and rng2 are sorted in ascending order + according to pred. +

+
+ + Complexity +
+

+ Linear. O(N), + where N is distance(rng1) + distance(rng2). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/set_algorithms/set_intersection.html b/doc/html/range/reference/algorithms/set_algorithms/set_intersection.html new file mode 100644 index 0000000..65840cd --- /dev/null +++ b/doc/html/range/reference/algorithms/set_algorithms/set_intersection.html @@ -0,0 +1,206 @@ + + + +set_intersection + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class OutputIterator
+    >
+OutputIterator set_intersection(const SinglePassRange1& rng1,
+                                const SinglePassRange2& rng2,
+                                OutputIterator          out);
+
+template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class OutputIterator,
+    class BinaryPredicate
+    >
+OutputIterator set_intersection(const SinglePassRange1& rng1,
+                                const SinglePassRange2& rng2,
+                                OutputIterator          out,
+                                BinaryPredicate         pred);    
+
+

+

+
+ + Description +
+

+ set_intersection constructs + a sorted range that is the intersection of the sorted ranges rng1 and rng2. + The return value is the end of the output range. +

+

+ The ordering relationship is determined by using operator< in the non-predicate versions, and + by evaluating pred in + the predicate versions. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/set_algorithm.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +OutputIterator is a + model of the OutputIteratorConcept. +
  • +
  • +SinglePassRange1 and + SinglePassRange2 have + the same value type. +
  • +
  • +SinglePassRange1's + value type is a model of the LessThanComparableConcept. +
  • +
  • +SinglePassRange2's + value type is a model of the LessThanComparableConcept. +
  • +
  • + The ordering of objects of type SinglePassRange1's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
  • + The ordering of objects of type SinglePassRange2's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
+

+ For the predicate versions: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +OutputIterator is a + model of the OutputIteratorConcept. +
  • +
  • +SinglePassRange1 and + SinglePassRange2 have + the same value type. +
  • +
  • +BinaryPredicate is + a model of the StrictWeakOrderingConcept. +
  • +
  • +SinglePassRange1's + value type is convertible to BinaryPredicate's + first argument type. +
  • +
  • +SinglePassRange2's + value type is convertible to BinaryPredicate's + second argument types. +
  • +
+
+ + Precondition: +
+

+ For the non-predicate versions: +

+

+ rng1 and rng2 are sorted in ascending order + according to operator<. +

+

+ For the predicate versions: +

+

+ rng1 and rng2 are sorted in ascending order + according to pred. +

+
+ + Complexity +
+

+ Linear. O(N), + where N is distance(rng1) + distance(rng2). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/set_algorithms/set_symmetric_difference.html b/doc/html/range/reference/algorithms/set_algorithms/set_symmetric_difference.html new file mode 100644 index 0000000..a25e8e4 --- /dev/null +++ b/doc/html/range/reference/algorithms/set_algorithms/set_symmetric_difference.html @@ -0,0 +1,210 @@ + + + +set_symmetric_difference + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class OutputIterator
+    >
+OutputIterator
+set_symmetric_difference(const SinglePassRange1& rng1,
+                         const SinglePassRange2& rng2,
+                         OutputIterator          out);
+
+template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class OutputIterator,
+    class BinaryPredicate
+    >
+OutputIterator
+set_symmetric_difference(const SinglePassRange1& rng1,
+                         const SinglePassRange2& rng2,
+                         OutputIterator          out,
+                         BinaryPredicate         pred);    
+
+

+

+
+ + Description +
+

+ set_symmetric_difference + constructs a sorted range that is the set symmetric difference of the + sorted ranges rng1 and + rng2. The return value + is the end of the output range. +

+

+ The ordering relationship is determined by using operator< in the non-predicate versions, and + by evaluating pred in + the predicate versions. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/set_algorithm.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +OutputIterator is a + model of the OutputIteratorConcept. +
  • +
  • +SinglePassRange1 and + SinglePassRange2 have + the same value type. +
  • +
  • +SinglePassRange1's + value type is a model of the LessThanComparableConcept. +
  • +
  • +SinglePassRange2's + value type is a model of the LessThanComparableConcept. +
  • +
  • + The ordering of objects of type SinglePassRange1's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
  • + The ordering of objects of type SinglePassRange2's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
+

+ For the predicate versions: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +OutputIterator is a + model of the OutputIteratorConcept. +
  • +
  • +SinglePassRange1 and + SinglePassRange2 have + the same value type. +
  • +
  • +BinaryPredicate is + a model of the StrictWeakOrderingConcept. +
  • +
  • +SinglePassRange1's + value type is convertible to BinaryPredicate's + first argument type. +
  • +
  • +SinglePassRange2's + value type is convertible to BinaryPredicate's + second argument types. +
  • +
+
+ + Precondition: +
+

+ For the non-predicate versions: +

+

+ rng1 and rng2 are sorted in ascending order + according to operator<. +

+

+ For the predicate versions: +

+

+ rng1 and rng2 are sorted in ascending order + according to pred. +

+
+ + Complexity +
+

+ Linear. O(N), + where N is distance(rng1) + distance(rng2). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/algorithms/set_algorithms/set_union.html b/doc/html/range/reference/algorithms/set_algorithms/set_union.html new file mode 100644 index 0000000..90c343c --- /dev/null +++ b/doc/html/range/reference/algorithms/set_algorithms/set_union.html @@ -0,0 +1,205 @@ + + + +set_union + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class OutputIterator
+    >
+OutputIterator set_union(const SinglePassRange1& rng1,
+                         const SinglePassRange2& rng2,
+                         OutputIterator          out);
+
+template<
+    class SinglePassRange1,
+    class SinglePassRange2,
+    class OutputIterator,
+    class BinaryPredicate
+    >
+OutputIterator set_union(const SinglePassRange1& rng1,
+                         const SinglePassRange2& rng2,
+                         OutputIterator          out,
+                         BinaryPredicate         pred);    
+ 
+

+

+
+ + Description +
+

+ set_union constructs + a sorted range that is the union of the sorted ranges rng1 + and rng2. The return + value is the end of the output range. The ordering relationship is determined + by using operator< + in the non-predicate versions, and by evaluating pred + in the predicate versions. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/set_algorithm.hpp +

+
+ + Requirements +
+

+ For the non-predicate versions: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +OutputIterator is a + model of the OutputIteratorConcept. +
  • +
  • +SinglePassRange1 and + SinglePassRange2 have + the same value type. +
  • +
  • +SinglePassRange1's + value type is a model of the LessThanComparableConcept. +
  • +
  • +SinglePassRange2's + value type is a model of the LessThanComparableConcept. +
  • +
  • + The ordering of objects of type SinglePassRange1's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
  • + The ordering of objects of type SinglePassRange2's + value type is a strict weak ordering, + as defined in the LessThanComparableConcept + requirements. +
  • +
+

+ For the predicate versions: +

+
    +
  • +SinglePassRange1 is + a model of the Single + Pass Range Concept. +
  • +
  • +SinglePassRange2 is + a model of the Single + Pass Range Concept. +
  • +
  • +OutputIterator is a + model of the OutputIteratorConcept. +
  • +
  • +SinglePassRange1 and + SinglePassRange2 have + the same value type. +
  • +
  • +BinaryPredicate is + a model of the StrictWeakOrderingConcept. +
  • +
  • +SinglePassRange1's + value type is convertible to BinaryPredicate's + first argument type. +
  • +
  • +SinglePassRange2's + value type is convertible to BinaryPredicate's + second argument types. +
  • +
+
+ + Precondition: +
+

+ For the non-predicate versions: +

+

+ rng1 and rng2 are sorted in ascending order + according to operator<. +

+

+ For the predicate versions: +

+

+ rng1 and rng2 are sorted in ascending order + according to pred. +

+
+ + Complexity +
+

+ Linear. O(N), + where N is distance(rng1) + distance(rng2). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/extending.html b/doc/html/range/reference/extending.html new file mode 100644 index 0000000..fc32e83 --- /dev/null +++ b/doc/html/range/reference/extending.html @@ -0,0 +1,51 @@ + + + +Extending the library + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/extending/method_1.html b/doc/html/range/reference/extending/method_1.html new file mode 100644 index 0000000..3283d10 --- /dev/null +++ b/doc/html/range/reference/extending/method_1.html @@ -0,0 +1,161 @@ + + + +Method 1: provide member functions and nested types + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ This procedure assumes that you have control over the types that should + be made conformant to a Range concept. If not, see method + 2. +

+

+ The primary templates in this library are implemented such that standard + containers will work automatically and so will boost::array. + Below is given an overview of which member functions and member types a + class must specify to be useable as a certain Range concept. +

+
++++ + + + + + + + + + + + + + + +
+

+ Member function +

+
+

+ Related concept +

+
+

+ begin() +

+
+

+ Single Pass + Range +

+
+

+ end() +

+
+

+ Single Pass + Range +

+
+

+ Notice that rbegin() + and rend() + member functions are not needed even though the container can support bidirectional + iteration. +

+

+ The required member types are: +

+
++++ + + + + + + + + + + + + + + +
+

+ Member type +

+
+

+ Related concept +

+
+

+ iterator +

+
+

+ Single Pass + Range +

+
+

+ const_iterator +

+
+

+ Single Pass + Range +

+
+

+ Again one should notice that member types reverse_iterator + and const_reverse_iterator + are not needed. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/extending/method_2.html b/doc/html/range/reference/extending/method_2.html new file mode 100644 index 0000000..f4f3524 --- /dev/null +++ b/doc/html/range/reference/extending/method_2.html @@ -0,0 +1,267 @@ + + + +Method 2: provide free-standing functions and specialize metafunctions + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ This procedure assumes that you cannot (or do not wish to) change the types + that should be made conformant to a Range concept. If this is not true, + see method 1. +

+

+ The primary templates in this library are implemented such that certain + functions are found via argument-dependent-lookup (ADL). Below is given + an overview of which free-standing functions a class must specify to be + useable as a certain Range concept. Let x + be a variable (const or mutable) of the class in question. +

+
++++ + + + + + + + + + + + + + + +
+

+ Function +

+
+

+ Related concept +

+
+

+ range_begin(x) +

+
+

+ Single Pass + Range +

+
+

+ range_end(x) +

+
+

+ Single Pass + Range +

+
+

+ range_begin() + and range_end() + must be overloaded for both const + and mutable reference arguments. +

+

+ You must also specialize two metafunctions for your type X: +

+
++++ + + + + + + + + + + + + + + +
+

+ Metafunction +

+
+

+ Related concept +

+
+

+ boost::range_mutable_iterator +

+
+

+ Single Pass + Range +

+
+

+ boost::range_const_iterator +

+
+

+ Single Pass + Range +

+
+

+ A complete example is given here: +

+

+ +

+
#include <boost/range.hpp>
+#include <iterator>         // for std::iterator_traits, std::distance()
+
+namespace Foo
+{
+    //
+    // Our sample UDT. A 'Pair'
+    // will work as a range when the stored
+    // elements are iterators.
+    //
+    template< class T >
+    struct Pair
+    {
+        T first, last;
+    };
+
+} // namespace 'Foo'
+
+namespace boost
+{
+    //
+    // Specialize metafunctions. We must include the range.hpp header.
+    // We must open the 'boost' namespace.
+    //
+
+	template< class T >
+	struct range_mutable_iterator< Foo::Pair<T> >
+	{
+		typedef T type;
+	};
+
+	template< class T >
+	struct range_const_iterator< Foo::Pair<T> >
+	{
+		//
+		// Remark: this is defined similar to 'range_iterator'
+		//         because the 'Pair' type does not distinguish
+		//         between an iterator and a const_iterator.
+		//
+		typedef T type;
+	};
+
+} // namespace 'boost'
+
+namespace Foo
+{
+	//
+	// The required functions. These should be defined in
+	// the same namespace as 'Pair', in this case
+	// in namespace 'Foo'.
+	//
+
+	template< class T >
+	inline T range_begin( Pair<T>& x )
+	{
+		return x.first;
+	}
+
+	template< class T >
+	inline T range_begin( const Pair<T>& x )
+	{
+		return x.first;
+	}
+
+	template< class T >
+	inline T range_end( Pair<T>& x )
+	{
+		return x.last;
+	}
+
+	template< class T >
+	inline T range_end( const Pair<T>& x )
+	{
+		return x.last;
+	}
+
+} // namespace 'Foo'
+
+#include <vector>
+
+int main(int argc, const char* argv[])
+{
+	typedef std::vector<int>::iterator  iter;
+	std::vector<int>                    vec;
+	Foo::Pair<iter>                     pair = { vec.begin(), vec.end() };
+	const Foo::Pair<iter>&              cpair = pair;
+	//
+	// Notice that we call 'begin' etc with qualification.
+	//
+	iter i = boost::begin( pair );
+	iter e = boost::end( pair );
+	i      = boost::begin( cpair );
+	e      = boost::end( cpair );
+	boost::range_difference< Foo::Pair<iter> >::type s = boost::size( pair );
+	s      = boost::size( cpair );
+	boost::range_reverse_iterator< const Foo::Pair<iter> >::type
+	ri     = boost::rbegin( cpair ),
+	re     = boost::rend( cpair );
+
+	return 0;
+}
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/extending/method_3.html b/doc/html/range/reference/extending/method_3.html new file mode 100644 index 0000000..f841237 --- /dev/null +++ b/doc/html/range/reference/extending/method_3.html @@ -0,0 +1,50 @@ + + + +Method 3: provide range adaptor implementations + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/extending/method_3/method_3_1.html b/doc/html/range/reference/extending/method_3/method_3_1.html new file mode 100644 index 0000000..e995bee --- /dev/null +++ b/doc/html/range/reference/extending/method_3/method_3_1.html @@ -0,0 +1,100 @@ + + + +Method 3.1: Implement a Range Adaptor without arguments + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ To implement a Range Adaptor without arguments (e.g. reversed) you need + to: +

+
    +
  1. + Provide a range for your return type, for example: +
    #include <boost/range/iterator_range.hpp>
    +#include <boost/iterator/reverse_iterator.hpp>
    +
    +template< typename R >
    +struct reverse_range :
    +    boost::iterator_range<
    +        boost::reverse_iterator<
    +            typename boost::range_iterator<R>::type> >
    +{
    +private:
    +    typedef boost::iterator_range<
    +        boost::reverse_iterator<
    +            typename boost::range_iterator<R>::type> > base;
    +
    +public:
    +    typedef boost::reverse_iterator<
    +        typename boost::range_iterator<R>::type > iterator;
    +
    +    reverse_range(R& r)
    +        : base(iterator(boost::end(r)), iterator(boost::begin(r)))
    +    { }
    +};
    +
    +
  2. +
  3. + Provide a tag to uniquely identify your adaptor in the operator| + function overload set +
    namespace detail {
    +    struct reverse_forwarder {};
    +}
    +
    +
  4. +
  5. + Implement operator|
    template< class BidirectionalRng >
    +inline reverse_range<BidirectionalRng>
    +operator|( BidirectionalRng& r, detail::reverse_forwarder )
    +{
    +	return reverse_range<BidirectionalRng>( r );
    +}
    +
    +template< class BidirectionalRng >
    +inline reverse_range<const BidirectionalRng>
    +operator|( const BidirectionalRng& r, detail::reverse_forwarder )
    +{
    +	return reverse_range<const BidirectionalRng>( r );
    +}
    +
    +
  6. +
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/extending/method_3/method_3_2.html b/doc/html/range/reference/extending/method_3/method_3_2.html new file mode 100644 index 0000000..f0bae90 --- /dev/null +++ b/doc/html/range/reference/extending/method_3/method_3_2.html @@ -0,0 +1,155 @@ + + + +Method 3.2: Implement a Range Adaptor with arguments + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
    +
  1. + Provide a range for your return type, for example: +
    #include <boost/range/adaptor/argument_fwd.hpp>
    +#include <boost/range/iterator_range.hpp>
    +#include <boost/iterator/transform_iterator.hpp>
    +
    +template<typename Value>
    +class replace_value
    +{
    +public:
    +    typedef const Value& result_type;
    +    typedef const Value& argument_type;
    +
    +    replace_value(const Value& from, const Value& to)
    +        : m_from(from), m_to(to)
    +    {
    +    }
    +
    +    const Value& operator()(const Value& x) const
    +    {
    +        return (x == m_from) ? m_to : x;
    +    }
    +private:
    +    Value m_from;
    +    Value m_to;
    +};
    +
    +template<typename Range>
    +class replace_range
    +: public boost::iterator_range<
    +    boost::transform_iterator<
    +        replace_value<typename boost::range_value<Range>::type>,
    +        typename boost::range_iterator<Range>::type> >
    +{
    +private:
    +    typedef typename boost::range_value<Range>::type value_type;
    +    typedef typename boost::range_iterator<Range>::type iterator_base;
    +    typedef replace_value<value_type> Fn;
    +    typedef boost::transform_iterator<Fn, iterator_base> replaced_iterator;
    +    typedef boost::iterator_range<replaced_iterator> base_t;
    +
    +public:
    +    replace_range(Range& rng, value_type from, value_type to)
    +        : base_t(replaced_iterator(boost::begin(rng), Fn(from,to)),
    +                 replaced_iterator(boost::end(rng), Fn(from,to)))
    +     {
    +     }
    + };
    +
    +
  2. +
  3. + Implement a holder class to hold the arguments required to construct + the RangeAdaptor. +
  4. +
+

+ The holder combines multiple parameters into one that can be passed as + the right operand of operator|(). +

+

+ +

+
template<typename T>
+class replace_holder : public boost::range_detail::holder2<T>
+{
+public:
+    replace_holder(const T& from, const T& to)
+        : boost::range_detail::holder2<T>(from, to)
+    { }
+private:
+    void operator=(const replace_holder&);
+};
+
+

+

+
  1. + Define an instance of the holder with the name of the adaptor +
+

+ +

+
static boost::range_detail::forwarder2<replace_holder>
+replaced = boost::range_detail::forwarder2<replace_holder>();
+
+

+

+
  1. + Define operator| +
+

+ +

+
template<typename SinglePassRange>
+inline replace_range<SinglePassRange>
+operator|(SinglePassRange& rng,
+          const replace_holder<typename boost::range_value<SinglePassRange>::type>& f)
+{
+    return replace_range<SinglePassRange>(rng, f.val1, f.val2);
+}
+
+template<typename SinglePassRange>
+inline replace_range<const SinglePassRange>
+operator|(const SinglePassRange& rng,
+          const replace_holder<typename boost::range_value<SinglePassRange>::type>& f)
+{
+    return replace_range<const SinglePassRange>(rng, f.val1, f.val2);
+}
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/overview.html b/doc/html/range/reference/overview.html new file mode 100644 index 0000000..ae0bbf0 --- /dev/null +++ b/doc/html/range/reference/overview.html @@ -0,0 +1,68 @@ + + + +Overview + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ Three types of objects are currently supported by the library: +

+
    +
  • + standard-like containers +
  • +
  • std::pair<iterator,iterator>
  • +
  • + built-in arrays +
  • +
+

+ Even though the behavior of the primary templates are exactly such that standard + containers will be supported by default, the requirements are much lower + than the standard container requirements. For example, the utility class + iterator_range + implements the minimal interface + required to make the class a Forward + Range. +

+

+ Please also see Range concepts for + more details. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/range_algorithm.html b/doc/html/range/reference/range_algorithm.html new file mode 100644 index 0000000..1e197c9 --- /dev/null +++ b/doc/html/range/reference/range_algorithm.html @@ -0,0 +1,52 @@ + + + +Range Algorithm + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/range_algorithm/range_algorithm_introduction.html b/doc/html/range/reference/range_algorithm/range_algorithm_introduction.html new file mode 100644 index 0000000..e24351f --- /dev/null +++ b/doc/html/range/reference/range_algorithm/range_algorithm_introduction.html @@ -0,0 +1,257 @@ + + + +Introduction and motivation + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ In its most simple form a Range Algorithm + (or range-based algorithm) is simply an iterator-based algorithm where + the two iterator arguments have been replaced by + one range argument. For example, we may write +

+

+ +

+
#include <boost/range/algorithm.hpp>
+#include <vector>
+
+std::vector<int> vec = ...;
+boost::sort(vec);
+
+

+

+

+ instead of +

+

+ +

+
std::sort(vec.begin(), vec.end());
+
+

+

+

+ However, the return type of range algorithms is almost always different + from that of existing iterator-based algorithms. +

+

+ One group of algorithms, like boost::sort(), will simply return the same range so + that we can continue to pass the range around and/or further modify it. + Because of this we may write +

+
boost:unique(boost::sort(vec));
+
+

+ to first sort the range and then run unique() on the sorted range. +

+

+ Algorithms like boost::unique() + fall into another group of algorithms that return (potentially) narrowed + views of the original range. By default boost::unique(rng) returns the range [boost::begin(rng), found) + where found denotes the + iterator returned by std::unique(boost::begin(rng), boost::end(rng)) +

+

+ Therefore exactly the unique values can be copied by writing +

+
boost::copy(boost::unique(boost::sort(vec)),
+            std::ostream_iterator<int>(std::cout));
+
+

+

+

+ Algorithms like boost::unique usually return the same range: + [boost::begin(rng), found). However, this behaviour may be changed + by supplying the algorithms with a template argument: +

+
++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ Expression +

+
+

+ Return +

+
+

+ boost::unique<boost::return_found>(rng) +

+
+

+ returns a single iterator like std::unique +

+
+

+ boost::unique<boost::return_begin_found>(rng) +

+
+

+ returns the range [boost::begin(rng), + found) + (this is the default) +

+
+

+ boost::unique<boost::return_begin_next>(rng) +

+
+

+ returns the range [boost::begin(rng), + boost::next(found)) +

+
+

+ boost::unique<boost::return_found_end>(rng) +

+
+

+ returns the range [found, + boost::end(rng)) +

+
+

+ boost::unique<boost::return_next_end>(rng) +

+
+

+ returns the range [boost::next(found),boost::end(rng)) +

+
+

+ boost::unique<boost::return_begin_end>(rng) +

+
+

+ returns the entire original range. +

+
+

+ This functionality has the following advantages: +

+
    +
  1. + it allows for seamless functional-style + programming where you do not need to use named + local variables to store intermediate results +
  2. +
  3. + it is very safe + because the algorithm can verify out-of-bounds conditions and handle + tricky conditions that lead to empty ranges +
  4. +
+

+ For example, consider how easy we may erase the duplicates in a sorted + container: +

+

+ +

+
std::vector<int> vec = ...;
+boost::erase(vec, boost::unique<boost::return_found_end>(boost::sort(vec)));
+
+

+

+

+ Notice the use of boost::return_found_end. + What if we wanted to erase all the duplicates except one of them? In old-fashined + STL-programming we might write +

+

+ +

+
// assume 'vec' is already sorted
+std::vector<int>::iterator i = std::unique(vec.begin(), vec.end());
+
+// remember this check or you get into problems
+if (i != vec.end())
+    ++i;
+    
+vec.erase(i, vec.end());
+
+

+

+

+ The same task may be accomplished simply with +

+
boost::erase(vec, boost::unique<boost::return_next_end>(vec));
+
+

+ and there is no need to worry about generating an invalid range. Furthermore, + if the container is complex, calling vec.begin() several times will be more expensive + than using a range algorithm. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/range_algorithm/range_algorithm_mutating_algorithms.html b/doc/html/range/reference/range_algorithm/range_algorithm_mutating_algorithms.html new file mode 100644 index 0000000..5c11829 --- /dev/null +++ b/doc/html/range/reference/range_algorithm/range_algorithm_mutating_algorithms.html @@ -0,0 +1,50 @@ + + + +Mutating algorithms + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/range_algorithm/range_algorithm_mutating_algorithms/copy.html b/doc/html/range/reference/range_algorithm/range_algorithm_mutating_algorithms/copy.html new file mode 100644 index 0000000..4bf5ab0 --- /dev/null +++ b/doc/html/range/reference/range_algorithm/range_algorithm_mutating_algorithms/copy.html @@ -0,0 +1,115 @@ + + + +Range Algorithm - copy + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class SinglePassRange, class OutputIterator>
+OutputIterator copy(const SinglePassRange& source_rng, OutputIterator out_it);
+
+

+

+
+ + Description +
+

+ copy copies all elements + from source_rng to the + range [out_it, out_it + + distance(source_rng)). The return value is out_it + + distance(source_rng) +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/copy.hpp +

+
+ + Requirements +
+
    +
  • +SinglePassRange is + a model of the SinglePassRangeConcept. +
  • +
  • +OutputIterator is a + model of the OutputIteratorConcept. +
  • +
  • + The value_type of + SinglePassRange is + convertible to a type in OutputIterator's + set of value types. +
  • +
+
+ + Precondition: +
+
    +
  • +out_it is not an iterator + within the source_rng. +
  • +
  • +[out_it, out_it + + distance(source_rng)) is a valid range. +
  • +
+
+ + Complexity +
+

+ Linear. Exactly distance(source_rng) assignments are performed. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/range_algorithm/range_algorithm_mutating_algorithms/copy_backward.html b/doc/html/range/reference/range_algorithm/range_algorithm_mutating_algorithms/copy_backward.html new file mode 100644 index 0000000..de14a89 --- /dev/null +++ b/doc/html/range/reference/range_algorithm/range_algorithm_mutating_algorithms/copy_backward.html @@ -0,0 +1,124 @@ + + + +Range Algorithm - copy_backward + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class BidirectionalRange, class BidirectionalOutputIterator>
+    BidirectionalOutputIterator
+        copy_backward(const BidirectionalRange& source_rng,
+                      BidirectionalOutputIterator out_it);
+
+

+

+
+ + Description +
+

+ copy_backward copies + all elements from source_rng + to the range [out_it + - distance(source_rng), out_it). +

+

+ The values are copied in reverse order. The return value is out_it - + distance(source_rng). +

+

+ Note well that unlike all other standard algorithms out_it + denotes the end of the output sequence. +

+
+ + Definition +
+

+ Defined in the header file boost/range/algorithm/copy_backward.hpp +

+
+ + Requirements +
+
    +
  • +BidirectionalRange + is a model of the SinglePassRangeConcept. +
  • +
  • +OutputIterator is a + model of the OutputIteratorConcept. +
  • +
  • + The value_type of + SinglePassRange is + convertible to a type in OutputIterator's + set of value types. +
  • +
+
+ + Precondition: +
+
    +
  • +out_it is not an iterator + within the source_rng. +
  • +
  • +[out_it, out_it + + distance(source_rng)) is a valid range. +
  • +
+
+ + Complexity +
+

+ Linear. Exactly distance(source_rng) assignments are performed. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/range_algorithm/range_algorithm_new_algorithms.html b/doc/html/range/reference/range_algorithm/range_algorithm_new_algorithms.html new file mode 100644 index 0000000..a7f08e5 --- /dev/null +++ b/doc/html/range/reference/range_algorithm/range_algorithm_new_algorithms.html @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+

+??? +

+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/range_algorithm/range_algorithm_non_mutating_algorithms.html b/doc/html/range/reference/range_algorithm/range_algorithm_non_mutating_algorithms.html new file mode 100644 index 0000000..9974a92 --- /dev/null +++ b/doc/html/range/reference/range_algorithm/range_algorithm_non_mutating_algorithms.html @@ -0,0 +1,42 @@ + + + +Non-mutating algorithms + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/ranges.html b/doc/html/range/reference/ranges.html new file mode 100644 index 0000000..2e16372 --- /dev/null +++ b/doc/html/range/reference/ranges.html @@ -0,0 +1,48 @@ + + + +Provided Ranges + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/ranges/counting_range.html b/doc/html/range/reference/ranges/counting_range.html new file mode 100644 index 0000000..b556488 --- /dev/null +++ b/doc/html/range/reference/ranges/counting_range.html @@ -0,0 +1,90 @@ + + + +counting_range + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template< class Incrementable > inline
+iterator_range< counting_iterator<Incrementable> >
+counting_range(Incrementable first, Incrementable last);
+
+template< class SinglePassRange > inline
+iterator_range< counting_iterator<typename range_iterator<SinglePassRange>::type >
+counting_range(const SinglePassRange& rng);
+
+template< class SinglePassRange > inline
+iterator_range< counting_iterator<typename range_iterator<SinglePassRange>::type >
+counting_range(SinglePassRange& rng);
+
+

+

+
+ + Description +
+

+ counting_range is a function + to generator that generates an iterator_range + wrapping a counting_iterator + (from Boost.Iterator). +

+
+ + Definition +
+

+ Defined in header file boost/range/counting_range.hpp +

+
+ + Requirements +
+
  1. +Incrementable is a model + of the Incrementable + Concept. +
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/ranges/introduction.html b/doc/html/range/reference/ranges/introduction.html new file mode 100644 index 0000000..f0080c6 --- /dev/null +++ b/doc/html/range/reference/ranges/introduction.html @@ -0,0 +1,46 @@ + + + +Introduction + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ The Boost.Range library provides some of the more commonly required ranges. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/ranges/irange.html b/doc/html/range/reference/ranges/irange.html new file mode 100644 index 0000000..f4565c0 --- /dev/null +++ b/doc/html/range/reference/ranges/irange.html @@ -0,0 +1,103 @@ + + + +irange + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class Integer>
+integer_range< range_detail::integer_iterator<Integer> >
+irange(Integer first, Integer  last);
+
+template<class Integer, class StepSize>
+integer_range< range_detail::integer_iterator_with_step<Integer, StepSize> >
+irange(Integer first, Integer last, StepSize step_size);
+
+

+

+
+ + Description +
+

+ irange is a function to + generate an Integer Range. +

+

+ irange allows treating + integers as a model of the Random + Access Range Concept. It should be noted that the first and last + parameters denoted a half-open range. +

+
+ + Definition +
+

+ Defined in the header file boost/range/irange.hpp +

+
+ + Requirements +
+
    +
  1. +Integer is a model of + the Integer Concept. +
  2. +
  3. +StepSize is a model of + the SignedInteger Concept. +
  4. +
+
+ + Complexity +
+

+ Constant. Since this function generates a new range the most significant + performance cost is incurred through the iteration of the generated range. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/ranges/istream_range.html b/doc/html/range/reference/ranges/istream_range.html new file mode 100644 index 0000000..e7d81d8 --- /dev/null +++ b/doc/html/range/reference/ranges/istream_range.html @@ -0,0 +1,72 @@ + + + +istream_range + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template< class Type, class Elem, class Traits > inline
+iterator_range< std::istream_iterator<Type, Elem, Traits> >
+istream_range(std::basic_istream<Elem, Traits>& in);
+
+

+

+
+ + Description +
+

+ istream_range is a function + to generator that generates an iterator_range + wrapping a std::istream_iterator. +

+
+ + Definition +
+

+ Defined in header file boost/range/istream_range.hpp +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/ranges/reference.html b/doc/html/range/reference/ranges/reference.html new file mode 100644 index 0000000..edaf8fa --- /dev/null +++ b/doc/html/range/reference/ranges/reference.html @@ -0,0 +1,50 @@ + + + +Reference + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/ranges/reference/counting_range.html b/doc/html/range/reference/ranges/reference/counting_range.html new file mode 100644 index 0000000..68fa72c --- /dev/null +++ b/doc/html/range/reference/ranges/reference/counting_range.html @@ -0,0 +1,91 @@ + + + +counting_range + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template< class Incrementable > inline
+iterator_range< counting_iterator<Incrementable> >
+counting_range(Incrementable first, Incrementable last);
+
+template< class SinglePassRange > inline
+iterator_range< counting_iterator<typename range_iterator<SinglePassRange>::type >
+counting_range(const SinglePassRange& rng);
+
+template< class SinglePassRange > inline
+iterator_range< counting_iterator<typename range_iterator<SinglePassRange>::type >
+counting_range(SinglePassRange& rng);
+
+

+

+
+ + Description +
+

+ counting_range is a function + to generator that generates an iterator_range + wrapping a counting_iterator + (from Boost.Iterator). +

+
+ + Definition +
+

+ Defined in header file boost/range/counting_range.hpp +

+
+ + Requirements +
+
  1. +Incrementable is a + model of the Incrementable + Concept. +
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/ranges/reference/irange.html b/doc/html/range/reference/ranges/reference/irange.html new file mode 100644 index 0000000..d827097 --- /dev/null +++ b/doc/html/range/reference/ranges/reference/irange.html @@ -0,0 +1,104 @@ + + + +irange + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template<class Integer>
+integer_range< range_detail::integer_iterator<Integer> >
+irange(Integer first, Integer  last);
+
+template<class Integer, class StepSize>
+integer_range< range_detail::integer_iterator_with_step<Integer, StepSize> >
+irange(Integer first, Integer last, StepSize step_size);
+
+

+

+
+ + Description +
+

+ irange is a function + to generate an Integer Range. +

+

+ irange allows treating + integers as a model of the Random + Access Range Concept. It should be noted that the first and last + parameters denoted a half-open range. +

+
+ + Definition +
+

+ Defined in the header file boost/range/irange.hpp +

+
+ + Requirements +
+
    +
  1. +Integer is a model + of the Integer Concept. +
  2. +
  3. +StepSize is a model + of the SignedInteger + Concept. +
  4. +
+
+ + Complexity +
+

+ Constant. Since this function generates a new range the most significant + performance cost is incurred through the iteration of the generated range. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/ranges/reference/istream_range.html b/doc/html/range/reference/ranges/reference/istream_range.html new file mode 100644 index 0000000..7552ec7 --- /dev/null +++ b/doc/html/range/reference/ranges/reference/istream_range.html @@ -0,0 +1,73 @@ + + + +istream_range + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+ + Prototype +
+

+ +

+
template< class Type, class Elem, class Traits > inline
+iterator_range< std::istream_iterator<Type, Elem, Traits> >
+istream_range(std::basic_istream<Elem, Traits>& in);
+
+

+

+
+ + Description +
+

+ istream_range is a function + to generator that generates an iterator_range + wrapping a std::istream_iterator. +

+
+ + Definition +
+

+ Defined in header file boost/range/istream_range.hpp +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/semantics.html b/doc/html/range/reference/semantics.html new file mode 100644 index 0000000..fbb1aa8 --- /dev/null +++ b/doc/html/range/reference/semantics.html @@ -0,0 +1,163 @@ + + + +Semantics + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +
+ + notation +
+
+++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ Type +

+
+

+ Object +

+
+

+ Describes +

+
+

+ X +

+
+

+ x +

+
+

+ any type +

+
+

+ T +

+
+

+ t +

+
+

+ denotes behavior of the primary templates +

+
+

+ P +

+
+

+ p +

+
+

+ denotes std::pair<iterator,iterator> +

+
+

+ A[sz] +

+
+

+ a +

+
+

+ denotes an array of type A + of size sz +

+
+

+ Char* +

+
+

+ s +

+
+

+ denotes either char* or wchar_t* +

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/semantics/functions.html b/doc/html/range/reference/semantics/functions.html new file mode 100644 index 0000000..232b680 --- /dev/null +++ b/doc/html/range/reference/semantics/functions.html @@ -0,0 +1,408 @@ + + + +Functions + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ Expression +

+
+

+ Return type +

+
+

+ Returns +

+
+

+ Complexity +

+
+

+ begin(x) +

+
+

+ range_iterator<X>::type +

+
+

+ p.first if p + is of type std::pair<T> a + if a is an array + range_begin(x) + if that expression would invoke a function found by ADL t.begin() + otherwise +

+
+

+ constant time +

+
+

+ end(x) +

+
+

+ range_iterator<X>::type +

+
+

+ p.second if p + is of type std::pair<T> a + + sz + if a is an array + of size sz range_end(x) + if that expression would invoke a function found by ADL t.end() + otherwise +

+
+

+ constant time +

+
+

+ empty(x) +

+
+

+ bool +

+
+

+ boost::begin(x) + == boost::end(x) +

+
+

+ constant time +

+
+

+ distance(x) +

+
+

+ range_difference<X>::type +

+
+

+ std::distance(boost::begin(x),boost::end(x)) +

+
+

+ - +

+
+

+ size(x) +

+
+

+ range_difference<X>::type +

+
+

+ boost::end(x) + - boost::begin(x) +

+
+

+ constant time +

+
+

+ rbegin(x) +

+
+

+ range_reverse_iterator<X>::type +

+
+

+ range_reverse_iterator<X>::type(boost::end(x)) +

+
+

+ constant time +

+
+

+ rend(x) +

+
+

+ range_reverse_iterator<X>::type +

+
+

+ range_reverse_iterator<X>::type(boost::begin(x)) +

+
+

+ constant time +

+
+

+ const_begin(x) +

+
+

+ range_iterator<const + X>::type +

+
+

+ range_iterator<const + X>::type(boost::begin(x)) +

+
+

+ constant time +

+
+

+ const_end(x) +

+
+

+ range_iterator<const + X>::type +

+
+

+ range_iterator<const + X>::type(boost::end(x)) +

+
+

+ constant time +

+
+

+ const_rbegin(x) +

+
+

+ range_reverse_iterator<const + X>::type +

+
+

+ range_reverse_iterator<const + X>::type(boost::rbegin(x)) +

+
+

+ constant time +

+
+

+ const_rend(x) +

+
+

+ range_reverse_iterator<const + X>::type +

+
+

+ range_reverse_iterator<const + X>::type(boost::rend(x)) +

+
+

+ constant time +

+
+

+ as_literal(x) +

+
+

+ iterator_range<U> where U + is Char* + if x is a pointer + to a string and U + is range_iterator<X>::type + otherwise +

+
+

+ [s,s + + std::char_traits<X>::length(s)) if s + is a Char* + or an array of Char + [boost::begin(x),boost::end(x)) otherwise +

+
+

+ linear time for pointers to a string or arrays of Char, constant time otherwise +

+
+

+ as_array(x) +

+
+

+ iterator_range<X> +

+
+

+ [boost::begin(x),boost::end(x)) +

+
 
+

+ The special const_-named + functions are useful when you want to document clearly that your code is + read-only. +

+

+ as_literal() + can be used internally + in string algorithm libraries such that arrays of characters are handled + correctly. +

+

+ as_array() + can be used with string algorithm libraries to make it clear that arrays + of characters are handled like an array and not like a string. +

+

+ Notice that the above functions should always be called with qualification + (boost::) + to prevent unintended + Argument Dependent Lookup (ADL). +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/semantics/metafunctions.html b/doc/html/range/reference/semantics/metafunctions.html new file mode 100644 index 0000000..6df4902 --- /dev/null +++ b/doc/html/range/reference/semantics/metafunctions.html @@ -0,0 +1,236 @@ + + + +Metafunctions + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +
+++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

+ Expression +

+
+

+ Return type +

+
+

+ Complexity +

+
+

+ range_iterator<X>::type +

+
+

+ +

+
T::iterator
+P::first_type
+A*
+
+

+

+
+

+ compile time +

+
+

+ range_iterator<const + X>::type +

+
+

+ +

+
T::const_iterator
+P::first_type
+const A*
+
+

+

+
+

+ compile time +

+
+

+ range_value<X>::type +

+
+

+ boost::iterator_value<range_iterator<X>::type>::type +

+
+

+ compile time +

+
+

+ range_reference<X>::type +

+
+

+ boost::iterator_reference<range_iterator<X>::type>::type +

+
+

+ compile time +

+
+

+ range_pointer<X>::type +

+
+

+ boost::iterator_pointer<range_iterator<X>::type>::type +

+
+

+ compile time +

+
+

+ range_category<X>::type +

+
+

+ boost::iterator_category<range_iterator<X>::type>::type +

+
+

+ compile time +

+
+

+ range_difference<X>::type +

+
+

+ boost::iterator_category<range_iterator<X>::type>::type +

+
+

+ compile time +

+
+

+ range_reverse_iterator<X>::type +

+
+

+ boost::reverse_iterator<range_iterator<X>::type> +

+
+

+ compile time +

+
+

+ range_reverse_iterator<const + X>::type +

+
+

+ boost::reverse_iterator<range_iterator<const X>::type +

+
+

+ compile time +

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/reference/synopsis.html b/doc/html/range/reference/synopsis.html new file mode 100644 index 0000000..248e8c1 --- /dev/null +++ b/doc/html/range/reference/synopsis.html @@ -0,0 +1,185 @@ + + + +Synopsis + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ +

+
namespace boost
+{
+    //
+    // Single Pass Range metafunctions
+    //
+
+    template< class T >
+    struct range_iterator;
+
+    template< class T >
+    struct range_value;
+
+    template< class T >
+    struct range_reference;
+    
+    template< class T >
+    struct range_pointer;
+    
+    template< class T >
+    struct range_category;
+
+    //
+    // Forward Range metafunctions
+    //
+
+    template< class T >
+    struct range_difference;
+
+    //
+    // Bidirectional Range metafunctions
+    //
+
+    template< class T >
+    struct range_reverse_iterator;
+
+    //
+    // Single Pass Range functions
+    //
+
+    template< class T >
+    typename range_iterator<T>::type
+    begin( T& r );
+
+    template< class T >
+    typename range_iterator<const T>::type
+    begin( const T& r );
+
+    template< class T >
+    typename range_iterator<T>::type
+    end( T& r );
+
+    template< class T >
+    typename range_iterator<const T>::type
+    end( const T& r );
+
+    template< class T >
+    bool
+    empty( const T& r );
+
+    //
+    // Forward Range functions
+    //
+
+    template< class T >
+    typename range_difference<T>::type
+    distance( const T& r );
+
+    //
+    // Bidirectional Range functions
+    //
+
+    template< class T >
+    typename range_reverse_iterator<T>::type
+    rbegin( T& r );
+
+    template< class T >
+    typename range_reverse_iterator<const T>::type
+    rbegin( const T& r );
+
+    template< class T >
+    typename range_reverse_iterator<T>::type
+    rend( T& r );
+
+    template< class T >
+    typename range_reverse_iterator<const T>::type
+    rend( const T& r );
+    
+    //
+    // Random Access Range functions
+    //
+    
+    template< class T >
+    typename range_difference<T>::type
+    size( const T& r );
+
+    //
+    // Special const Range functions
+    //
+
+    template< class T >
+    typename range_iterator<const T>::type 
+    const_begin( const T& r );
+
+    template< class T >
+    typename range_iterator<const T>::type 
+    const_end( const T& r );
+
+    template< class T >
+    typename range_reverse_iterator<const T>::type 
+    const_rbegin( const T& r );
+
+    template< class T >
+    typename range_reverse_iterator<const T>::type 
+    const_rend( const T& r );
+    
+    //
+    // String utilities
+    //
+    
+    template< class T >
+    iterator_range< ... see below ... >
+    as_literal( T& r );
+    
+    template< class T >
+    iterator_range< ... see below ... >
+    as_literal( const T& r );
+    
+    template< class T >
+    iterator_range< typename range_iterator<T>::type >
+    as_array( T& r );
+    
+    template< class T >
+    iterator_range< typename range_iterator<const T>::type >
+    as_array( const T& r );
+
+} // namespace 'boost' 
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/style_guide.html b/doc/html/range/style_guide.html new file mode 100644 index 0000000..f064884 --- /dev/null +++ b/doc/html/range/style_guide.html @@ -0,0 +1,141 @@ + + + +Terminology and style guidelines + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ The use of a consistent terminology is as important for Ranges + and range-based algorithms as it is for iterators and iterator-based algorithms. + If a conventional set of names are adopted, we can avoid misunderstandings + and write generic function prototypes that are self-documenting. +

+

+ Since ranges are characterized by a specific underlying iterator type, we get + a type of range for each type of iterator. Hence we can speak of the following + types of ranges: +

+
+

+ Notice how we have used the categories from the new + style iterators. +

+

+ Notice that an iterator (and therefore an range) has one traversal + property and one or more properties from the value + access category. So in reality we will mostly talk about + mixtures such as +

+
    +
  • + Random Access Readable Writeable Range +
  • +
  • + Forward Lvalue Range +
  • +
+

+ By convention, we should always specify the traversal + property first as done above. This seems reasonable since there will only be + one traversal property, + but perhaps many value access + properties. +

+

+ It might, however, be reasonable to specify only one category if the other + category does not matter. For example, the iterator_range can be constructed + from a Forward Range. This means that we do not care about what value + access properties the Range has. Similarly, a Readable + Range will be one that has the lowest possible traversal + property (Single Pass). +

+

+ As another example, consider how we specify the interface of std::sort(). Algorithms are usually more cumbersome to + specify the interface of since both traversal + and value access properties + must be exactly defined. The iterator-based version looks like this: +

+

+ +

+
template< class RandomAccessTraversalReadableWritableIterator >
+void sort( RandomAccessTraversalReadableWritableIterator first,
+           RandomAccessTraversalReadableWritableIterator last );
+
+

+

+

+ For ranges the interface becomes +

+

+ +

+
template< class RandomAccessReadableWritableRange >
+void sort( RandomAccessReadableWritableRange& r );
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/upgrade.html b/doc/html/range/upgrade.html new file mode 100644 index 0000000..ad53c37 --- /dev/null +++ b/doc/html/range/upgrade.html @@ -0,0 +1,49 @@ + + + +Upgrade version of Boost.Range + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+ + + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/upgrade/upgrade_1_34_to_1_35.html b/doc/html/range/upgrade/upgrade_1_34_to_1_35.html new file mode 100644 index 0000000..252ec93 --- /dev/null +++ b/doc/html/range/upgrade/upgrade_1_34_to_1_35.html @@ -0,0 +1,77 @@ + + + +Upgrade from version 1.34 + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ Boost version 1.35 introduced some larger refactorings of the library: +

+
    +
  1. + Direct support for character arrays was abandoned in favor of uniform treatment + of all arrays. Instead string algorithms can use the new function as_literal(). +
  2. +
  3. +size + now requires a Random + Access Range. The old behavior is provided as distance(). +
  4. +
  5. +range_size<T>::type has been completely removed in favor + of range_difference<T>::type +
  6. +
  7. +boost_range_begin() + and boost_range_end() + have been renamed range_begin() and range_end() respectively. +
  8. +
  9. +range_result_iterator<T>::type and range_reverse_result_iterator<T>::type + have been renamed range_iterator<T>::type + and range_reverse_iterator<T>::type. +
  10. +
  11. + The procedure that makes a custom type work with the library has been greatly + simplified. See Extending the + library for UDTs for details. +
  12. +
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/upgrade/upgrade_from_1_34.html b/doc/html/range/upgrade/upgrade_from_1_34.html new file mode 100644 index 0000000..dfc4c52 --- /dev/null +++ b/doc/html/range/upgrade/upgrade_from_1_34.html @@ -0,0 +1,77 @@ + + + +Upgrade from version 1.34 + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ Boost version 1.35 introduced some larger refactorings of the library: +

+
    +
  1. + Direct support for character arrays was abandoned in favor of uniform treatment + of all arrays. Instead string algorithms can use the new function as_literal(). +
  2. +
  3. +size + now requires a Random + Access Range. The old behavior is provided as distance(). +
  4. +
  5. +range_size<T>::type has been completely removed in favor + of range_difference<T>::type +
  6. +
  7. +boost_range_begin() + and boost_range_end() + have been renamed range_begin() and range_end() respectively. +
  8. +
  9. +range_result_iterator<T>::type and range_reverse_result_iterator<T>::type + have been renamed range_iterator<T>::type + and range_reverse_iterator<T>::type. +
  10. +
  11. + The procedure that makes a custom type work with the library has been greatly + simplified. See Extending the + library for UDTs for details. +
  12. +
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/upgrade/upgrade_from_1_42.html b/doc/html/range/upgrade/upgrade_from_1_42.html new file mode 100644 index 0000000..3fbc2d2 --- /dev/null +++ b/doc/html/range/upgrade/upgrade_from_1_42.html @@ -0,0 +1,64 @@ + + + +Upgrade from version 1.42 + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ New features: +

+ +

+ Removed: +

+
  1. +iterator_range no longer + has a is_singular member + function. The singularity restrictions have been removed from the iterator_range class since this added + restrictions to ranges of iterators whose default constructors were not + singular. Previously the is_singular + member function always returned false + in release build configurations, hence it is not anticipated that this + interface change will produce difficulty in upgrading. +
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/utilities.html b/doc/html/range/utilities.html new file mode 100644 index 0000000..d9caa5f --- /dev/null +++ b/doc/html/range/utilities.html @@ -0,0 +1,82 @@ + + + +Utilities + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ + +

+ Having an abstraction that encapsulates a pair of iterators is very useful. + The standard library uses std::pair in + some circumstances, but that class is cumbersome to use because we need to + specify two template arguments, and for all range algorithm purposes we must + enforce the two template arguments to be the same. Moreover, std::pair<iterator,iterator> is hardly self-documenting whereas more + domain specific class names are. Therefore these two classes are provided: +

+
    +
  • + Class iterator_range +
  • +
  • + Class sub_range +
  • +
  • + Function join +
  • +
+

+ The iterator_range class is + templated on an Forward + Traversal Iterator and should be used whenever fairly general code + is needed. The sub_range class + is templated on an Forward Range + and it is less general, but a bit easier to use since its template argument + is easier to specify. The biggest difference is, however, that a sub_range can propagate constness because + it knows what a corresponding const_iterator + is. +

+

+ Both classes can be used as ranges since they implement the minimal + interface required for this to work automatically. +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/utilities/iterator_range.html b/doc/html/range/utilities/iterator_range.html new file mode 100644 index 0000000..07efc15 --- /dev/null +++ b/doc/html/range/utilities/iterator_range.html @@ -0,0 +1,322 @@ + + + +Class iterator_range + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ The intention of the iterator_range + class is to encapsulate two iterators so they fulfill the Forward + Range concept. A few other functions are also provided for convenience. +

+

+ If the template argument is not a model of Forward + Traversal Iterator, one can still use a subset of the interface. + In particular, size() + requires Random Access Traversal Iterators whereas empty() only requires Single Pass Iterators. +

+

+ Recall that many default constructed iterators are singular + and hence can only be assigned, but not compared or incremented or anything. + However, if one creates a default constructed iterator_range, + then one can still call all its member functions. This design decision avoids + the iterator_range imposing + limitations upon ranges of iterators that are not singular. Any singularity + limitation is simply propogated from the underlying iterator type. +

+
+ + Synopsis +
+

+ +

+
namespace boost
+{
+    template< class ForwardTraversalIterator >
+    class iterator_range
+    {
+    public: // Forward Range types
+        typedef ForwardTraversalIterator   iterator;
+        typedef ForwardTraversalIterator   const_iterator;
+        typedef iterator_difference<iterator>::type difference_type;
+
+    public: // construction, assignment
+        template< class ForwardTraversalIterator2 >
+        iterator_range( ForwardTraversalIterator2 Begin, ForwardTraversalIterator2 End );
+                    
+        template< class ForwardRange >
+        iterator_range( ForwardRange& r );
+  
+        template< class ForwardRange >
+        iterator_range( const ForwardRange& r );
+        
+        template< class ForwardRange >
+        iterator_range& operator=( ForwardRange& r );
+
+        template< class ForwardRange >
+        iterator_range& operator=( const ForwardRange& r );
+    
+    public: // Forward Range functions
+        iterator  begin() const;
+        iterator  end() const;
+        
+    public: // convenience
+        operator    unspecified_bool_type() const;
+        bool        equal( const iterator_range& ) const;
+        value_type& front() const;
+        value_type& back() const;
+        iterator_range& advance_begin(difference_type n);
+        iterator_range& advance_end(difference_type n);
+        bool      empty() const;
+        // for Random Access Range only: 
+        reference operator[]( difference_type at ) const;
+        value_type operator()( difference_type at ) const;
+        size_type size() const;
+    };
+    
+    // stream output
+    template< class ForwardTraversalIterator, class T, class Traits >
+    std::basic_ostream<T,Traits>& 
+    operator<<( std::basic_ostream<T,Traits>& Os,
+                const iterator_range<ForwardTraversalIterator>& r );
+
+    // comparison
+    template< class ForwardTraversalIterator, class ForwardTraversalIterator2 >
+    bool operator==( const iterator_range<ForwardTraversalIterator>& l, 
+                     const iterator_range<ForwardTraversalIterator2>& r );
+
+    template< class ForwardTraversalIterator, class ForwardRange >
+    bool operator==( const iterator_range<ForwardTraversalIterator>& l, 
+                     const ForwardRange& r );
+
+    template< class ForwardTraversalIterator, class ForwardRange >
+    bool operator==( const ForwardRange& l,
+                     const iterator_range<ForwardTraversalIterator>& r );
+
+    template< class ForwardTraversalIterator, class ForwardTraversalIterator2 >
+    bool operator!=( const iterator_range<ForwardTraversalIterator>& l, 
+                     const iterator_range<ForwardTraversalIterator2>& r );
+
+    template< class ForwardTraversalIterator, class ForwardRange >
+    bool operator!=( const iterator_range<ForwardTraversalIterator>& l, 
+                     const ForwardRange& r );
+
+    template< class ForwardTraversalIterator, class ForwardRange >
+    bool operator!=( const ForwardRange& l,
+                     const iterator_range<ForwardTraversalIterator>& r );
+
+    template< class ForwardTraversalIterator, class ForwardTraversalIterator2 >
+    bool operator<( const iterator_range<ForwardTraversalIterator>& l, 
+                    const iterator_range<ForwardTraversalIterator2>& r );
+
+    template< class ForwardTraversalIterator, class ForwardRange >
+    bool operator<( const iterator_range<ForwardTraversalIterator>& l, 
+                    const ForwardRange& r );
+
+    template< class ForwardTraversalIterator, class ForwardRange >
+    bool operator<( const ForwardRange& l,
+                    const iterator_range<ForwardTraversalIterator>& r );
+ 
+    // external construction
+    template< class ForwardTraversalIterator >
+    iterator_range< ForwardTraversalIterator >
+    make_iterator_range( ForwardTraversalIterator Begin, 
+                         ForwardTraversalIterator End );
+       
+    template< class ForwardRange >
+    iterator_range< typename range_iterator<ForwardRange>::type >
+    make_iterator_range( ForwardRange& r );
+
+    template< class ForwardRange >
+    iterator_range< typename range_iterator<const ForwardRange>::type >
+    make_iterator_range( const ForwardRange& r );
+    
+    template< class Range >
+    iterator_range< typename range_iterator<Range>::type >
+    make_iterator_range( Range& r,
+                         typename range_difference<Range>::type advance_begin,
+                         typename range_difference<Range>::type advance_end );
+    
+    template< class Range >
+    iterator_range< typename range_iterator<const Range>::type >
+    make_iterator_range( const Range& r, 
+                         typename range_difference<const Range>::type advance_begin,
+                         typename range_difference<const Range>::type advance_end );
+    
+    // convenience
+    template< class Sequence, class ForwardRange >
+    Sequence copy_range( const ForwardRange& r );
+    
+} // namespace 'boost'
+
+

+

+

+ If an instance of iterator_range + is constructed by a client with two iterators, the client must ensure that + the two iterators delimit a valid closed-open range [begin,end). +

+

+ It is worth noticing that the templated constructors and assignment operators + allow conversion from iterator_range<iterator> to iterator_range<const_iterator>. Similarly, since the comparison operators + have two template arguments, we can compare ranges whenever the iterators + are comparable; for example when we are dealing with const and non-const + iterators from the same container. +

+
+ + Details + member functions +
+

+ operator unspecified_bool_type() const; +

+
+

+

+

+ Returns !empty(); +

+

+

+
+

+ bool equal( iterator_range& r ) const; +

+
+

+

+

+ Returns begin() == r.begin() && + end() + == r.end(); +

+

+

+
+
+ + Details + functions +
+

+ bool operator==( const ForwardRange1& + l, const ForwardRange2& r ); +

+
+

+

+

+ Returns size(l) != size(r) ? false + : std::equal( begin(l), end(l), begin(r) ); +

+

+

+
+

+ bool operator!=( const ForwardRange1& + l, const ForwardRange2& r ); +

+
+

+

+

+ Returns !( l == r ); +

+

+

+
+

+ bool operator<( const ForwardRange1& + l, const ForwardRange2& r ); +

+
+

+

+

+ Returns std::lexicographical_compare( + begin(l), end(l), begin(r), end(r) ); +

+

+

+
+

+ +

+
iterator_range make_iterator_range( Range& r,
+                                    typename range_difference<Range>::type advance_begin, 
+                                    typename range_difference<Range>::type advance_end );
+
+

+

+
+

+

+

+ Effects: +

+

+

+
+

+ +

+
iterator new_begin = begin( r ),
+iterator new_end   = end( r );
+std::advance( new_begin, advance_begin );
+std::advance( new_end, advance_end );
+return make_iterator_range( new_begin, new_end );
+
+

+

+

+ Sequence copy_range( const ForwardRange& r ); +

+
+

+

+

+ Returns Sequence( + begin(r), end(r) ); +

+

+

+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/utilities/join.html b/doc/html/range/utilities/join.html new file mode 100644 index 0000000..c2c9e15 --- /dev/null +++ b/doc/html/range/utilities/join.html @@ -0,0 +1,89 @@ + + + +Function join + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ The intention of the join + function is to join two ranges into one longer range. +

+

+ The resultant range will have the lowest common traversal of the two ranges + supplied as parameters. +

+

+ Note that the joined range incurs a performance cost due to the need to check + if the end of a range has been reached internally during traversal. +

+
+ + Synposis +
+

+ +

+
template<typename SinglePassRange1, typename SinglePassRange2>
+iterator_range<range_detail::join_iterator<
+    typename range_iterator<const SinglePassRange1>::type,
+    typename range_iterator<const SinglePassRange2>::type,
+    typename add_const<
+        typename range_value<const SinglePassRange1>::type>::type>
+>
+join(const SinglePassRange1& rng1, const SinglePassRange2& rng2)
+
+template<typename SinglePassRange1, typename SinglePassRange2>
+iterator_range<range_detail::join_iterator<
+    typename range_iterator<SinglePassRange1>::type,
+    typename range_iterator<SinglePassRange2>::type,
+    typename range_value<SinglePassRange1>::type>
+>
+join(SinglePassRange1& rng1, SinglePassRange2& rng2);
+
+

+

+
+ + Example +
+

+ The expression join(irange(0,5), irange(5,10)) would + evaluate to a range representing an integer range [0,10) +

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/range/utilities/sub_range.html b/doc/html/range/utilities/sub_range.html new file mode 100644 index 0000000..0b474d7 --- /dev/null +++ b/doc/html/range/utilities/sub_range.html @@ -0,0 +1,122 @@ + + + +Class sub_range + + + + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+PrevUpHomeNext +
+
+ +

+ The sub_range class inherits + all its functionality from the iterator_range class. The sub_range class is often easier to use + because one must specify the Forward + Range template argument instead of an iterator. Moreover, the sub_range class can propagate constness + since it knows what a corresponding const_iterator + is. +

+
+ + Synopsis +
+

+ +

+
namespace boost
+{
+    template< class ForwardRange >
+    class sub_range : public iterator_range< typename range_iterator<ForwardRange>::type >
+    {
+    public: 
+        typedef typename range_iterator<ForwardRange>::type iterator;
+        typedef typename range_iterator<const ForwardRange>::type  const_iterator;
+        typedef typename iterator_difference<iterator>::type difference_type;
+    
+    public: // construction, assignment
+        template< class ForwardTraversalIterator >
+        sub_range( ForwardTraversalIterator Begin, ForwardTraversalIterator End );
+
+        template< class ForwardRange2 >
+        sub_range( ForwardRange2& r );
+         
+        template< class ForwardRange2 >
+        sub_range( const Range2& r );
+         
+        template< class ForwardRange2 >
+        sub_range& operator=( ForwardRange2& r );
+
+        template< class ForwardRange2 >
+        sub_range& operator=( const ForwardRange2& r );    
+    
+    public:  // Forward Range functions 
+        iterator        begin();
+        const_iterator  begin() const;
+        iterator        end();
+        const_iterator  end() const;    
+        
+    public: // convenience 
+        value_type&       front();
+        const value_type& front() const;
+        value_type&       back();
+        const value_type& back() const;
+        // for Random Access Range only: 
+        value_type&       operator[]( size_type at );
+        const value_type& operator[]( size_type at ) const;
+    
+    public:
+        // rest of interface inherited from iterator_range
+    };
+    
+} // namespace 'boost'
+
+

+

+

+ The class should be trivial to use as seen below. Imagine that we have an + algorithm that searches for a sub-string in a string. The result is an iterator_range, + that delimits the match. We need to store the result from this algorithm. + Here is an example of how we can do it with and without sub_range +

+

+ +

+
std::string str("hello");
+iterator_range<std::string::iterator> ir = find_first( str, "ll" );
+sub_range<std::string>               sub = find_first( str, "ll" );
+
+

+

+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/standalone_HTML.manifest b/doc/html/standalone_HTML.manifest new file mode 100644 index 0000000..e9d38e8 --- /dev/null +++ b/doc/html/standalone_HTML.manifest @@ -0,0 +1,19 @@ +index.html +range/concepts.html +range/concepts/single_pass_range.html +range/concepts/forward_range.html +range/concepts/bidirectional_range.html +range/concepts/random_access_range.html +range/concepts/concept_checking.html +range/reference.html +range/reference/synopsis.html +range/reference/semantics.html +range/reference/extending.html +range/utilities.html +range/utilities/sub_range.html +range/style_guide.html +range/library_headers.html +range/examples.html +range/portability.html +range/faq.html +range/history_ack.html diff --git a/doc/introduction.qbk b/doc/introduction.qbk new file mode 100644 index 0000000..c25eeae --- /dev/null +++ b/doc/introduction.qbk @@ -0,0 +1,73 @@ +[section Introduction] + +Generic algorithms have so far been specified in terms of two or more iterators. Two iterators would together form a range of values that the algorithm could work on. This leads to a very general interface, but also to a somewhat clumsy use of the algorithms with redundant specification of container names. Therefore we would like to raise the abstraction level for algorithms so they specify their interface in terms of __ranges__ as much as possible. + +The most common form of ranges used throughout the C++ community are standard library containers. When writing algorithms however, one often finds it desirable for the algorithm to accept other types that offer enough functionality to satisfy the needs of the generic code [*/if a suitable layer of indirection is applied/] . For example, raw arrays are often suitable for use with generic code that works with containers, provided a suitable adapter is used. Likewise, null terminated strings can be treated as containers of characters, if suitably adapted. + +This library therefore provides the means to adapt standard-like containers, null terminated strings, `std::pairs` of iterators, and raw arrays (and more), such that the same generic code can work with them all. The basic idea is to add another layer of indirection using __metafunctions__ and free-standing functions so syntactic and/or semantic differences can be removed. + +The main advantages are + +* simpler implementation and specification of generic range algorithms +* more flexible, compact and maintainable client code +* safe use of built-in arrays (for legacy code; why else would you use built-in arrays?) + +Below are given a small example (the complete example can be found [@http://www.boost.org/libs/range/test/algorithm_example.cpp here] ): + +`` + // + // example: extracting bounds in a generic algorithm + // + template< class ForwardReadableRange, class T > + inline typename boost::range_iterator< ForwardReadableRange >::type + find( ForwardReadableRange& c, const T& value ) + { + return std::find( boost::begin( c ), boost::end( c ), value ); + } + + template< class ForwardReadableRange, class T > + inline typename boost::range_iterator< const ForwardReadableRange >::type + find( const ForwardReadableRange& c, const T& value ) + { + return std::find( boost::begin( c ), boost::end( c ), value ); + } + + // + // replace first value and return its index + // + template< class ForwardReadableWriteableRange, class T > + inline typename boost::range_size< ForwardReadableWriteableRange >::type + my_generic_replace( ForwardReadableWriteableRange& c, const T& value, const T& replacement ) + { + typename boost::range_iterator< ForwardReadableWriteableRange >::type found = find( c, value ); + + if( found != boost::end( c ) ) + *found = replacement; + return std::distance( boost::begin( c ), found ); + } + + // + // usage + // + const int N = 5; + std::vector my_vector; + int values[] = { 1,2,3,4,5,6,7,8,9 }; + + my_vector.assign( values, boost::end( values ) ); + typedef std::vector::iterator iterator; + std::pair my_view( boost::begin( my_vector ), + boost::begin( my_vector ) + N ); + char str_val[] = "a string"; + char* str = str_val; + + std::cout << my_generic_replace( my_vector, 4, 2 ); + std::cout << my_generic_replace( my_view, 4, 2 ); + std::cout << my_generic_replace( str, 'a', 'b' ); + + // prints '3', '5' and '0' +`` + +By using the free-standing functions and __metafunctions__, the code automatically works for all the types supported by this library; now and in the future. Notice that we have to provide two versions of `find()` since we cannot forward a non-const rvalue with reference arguments (see this article about __the_forwarding_problem__ ). + +[endsect] + diff --git a/doc/istream_range.html b/doc/istream_range.html new file mode 100755 index 0000000..8f41fc4 --- /dev/null +++ b/doc/istream_range.html @@ -0,0 +1,64 @@ + + + + + + Boost.Range Utilities + + + + + + + + + +

Boost.Range

+

Function istream_range

+

+ The intention of the istream_range function is to construct + a new range with a pair of std::istream_iterators that wrap a + specified std::basic_istream instance. +

+ +

Synopsis

+ +
+namespace boost
+{
+    template< class 
+        Type, class 
+            Elem, class Traits > inline
+    range< std::istream_iterator<Type, Elem, Traits> >
+    istream_range(std::basic_istream<Elem, Traits>& in);
+}    
+ +

+ © Copyright Neil Groves 2009. +

+ +

+ Distributed under the Boost Software License, Version 1.0. (See + accompanying file LICENSE_1_0.txt or copy + at www.boost.org/LICENSE_1_0.txt) +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + + + diff --git a/doc/mfc_atl.qbk b/doc/mfc_atl.qbk new file mode 100644 index 0000000..2a7bb9c --- /dev/null +++ b/doc/mfc_atl.qbk @@ -0,0 +1,139 @@ +[def __mfc_collections__ [@http://msdn.microsoft.com/en-us/library/942860sh.aspx MFC Collection Classes]] +[def __atl_collections__ [@http://msdn.microsoft.com/en-us/library/15e672bd.aspx ATL Collection Classes]] + +[section:mfc_atl MFC/ATL (courtesy of Shunsuke Sogame)] + +[h4 Introduction] +This implementation was kindly donated by Shunsuke Sogame. This header adapts MFC and ATL containers to the appropriate Range concepts. + +[table + [] + [[[*Author:]] [Shunsuke Sogame]] + [[[*Contact:]] [mb2act@yahoo.co.jp]] + [[[*Date:]] [26th of May 2006]] + [[[*Copyright:]] [Shunsuke Sogame 2005-2006. Use, modification and distribution is subject to the Boost Software License, Version 1.0]] +] + +[h4 Overview] + +Boost.Range MFC/ATL Extension provides Boost.Range support for MFC/ATL collection and string types. + +`` +CTypedPtrArray *> myArray; +... +BOOST_FOREACH (CList *theList, myArray) +{ + BOOST_FOREACH (CString& str, *theList) + { + boost::to_upper(str); + std::sort(boost::begin(str), boost::end(str)); + ... + } +} +`` + +[section:requirements Requirements] + +* Boost C++ Libraries Version 1.34.0 or later (no compilation required) +* Visual C++ 7.1 or later (for MFC and ATL) + +[endsect] + +[section:mfc_ranges MFC Ranges] +If the `` is included before or after Boost.Range headers, the MFC collections and strings become models of Range. The table below lists the Traversal Category and `range_reference` of MFC ranges. + +[table + [[Range] [Traversal Category] [`range_reference::type`]] + [[`CArray`] [__random_access_range__] [`T&`]] + [[`CList`] [__bidirectional_range__] [`T&`]] + [[`CMap`] [__forward_range__] [`Range::CPair&`]] + [[`CTypedPtrArray`] [__random_access_range__] [`T* const`]] + [[`CTypedPtrList`] [__bidirectional_range__] [`T* const`]] + [[`CTypedPtrMap`] [__forward_range__] [`std::pair const`]] + [[`CByteArray`] [__random_access_range__] [`BYTE&`]] + [[`CDWordArray`] [__random_access_range__] [`DWORD&`]] + [[`CObArray`] [__random_access_range__] [`CObject*&`]] + [[`CPtrArray`] [__random_access_range__] [`void*&`]] + [[`CStringArray`] [__random_access_range__] [`CString&`]] + [[`CUIntArray`] [__random_access_range__] [`UINT&`]] + [[`CWordArray`] [__random_access_range__] [`WORD&`]] + [[`CObList`] [__bidirectional_range__] [`CObject*&`]] + [[`CPtrList`] [__bidirectional_range__] [`void*&`]] + [[`CStringList`] [__bidirectional_range__] [`CString&`]] + [[`CMapPtrToWord`] [__forward_range__] [`std::pair const`]] + [[`CMapPtrToPtr`] [__forward_range__] [`std::pair const`]] + [[`CMapStringToOb`] [__forward_range__] [`std::pair const`]] + [[`CMapStringToString`] [__forward_range__] [`Range::CPair&`]] + [[`CMapWordToOb`] [__forward_range__] [`std::pair const`]] + [[`CMapWordToPtr`] [__forward_range__] [`std::pair const`]] +] + +Other Boost.Range metafunctions are defined by the following. Let `Range` be any type listed above and `Ref` be the same as `range_reference::type`. `range_value::type` is the same as `remove_reference::type>::type`, `range_difference::type` is the same as `std::ptrdiff_t`, and `range_pointer::type` is the same as `add_pointer::type>::type`. As for `const Range`, see below. +[endsect] + +[section:atl_ranges ATL Ranges] + +If the `` is included before or after Boost.Range headers, the ATL collections and strings become models of Range. The table below lists the Traversal Category and `range_reference` of ATL ranges. + +[table + [[Range] [Traversal Category] [`range_reference::type`]] + [[`CAtlArray`] [__random_access_range__] [`E&`]] + [[`CAutoPtrArray`] [__random_access_range__] [`E&`]] + [[`CInterfaceArray`] [__random_access_range__] [`CComQIPtr&`]] + [[`CAtlList`] [__bidirectional_range__] [`E&`]] + [[`CAutoPtrList`] [__bidirectional_range__] [`E&`]] + [[`CHeapPtrList`] [__bidirectional_range__] [`E&`]] + [[`CInterfaceList`] [__bidirectional_range__] [`CComQIPtr&`]] + [[`CAtlMap`] [__forward_range__] [`Range::CPair&`]] + [[`CRBTree`] [__bidirectional_range__] [`Range::CPair&`]] + [[`CRBMap`] [__bidirectional_range__] [`Range::CPair&`]] + [[`CRBMultiMap`] [__bidirectional_range__] [`Range::CPair&`]] + [[`CSimpleStringT`] [__random_access_range__] [`B&`]] + [[`CStringT`] [__random_access_range__] [`B&`]] + [[`CFixedStringT`] [__random_access_range__] [`range_reference::type`]] + [[`CComBSTR`] [__random_access_range__] [`OLECHAR&`]] + [[`CSimpleArray`] [__random_access_range__] [`T&`]] +] + +Other __boost_range_home__ metafunctions are defined by the following. Let `Range` be any type listed above and `Ref` be the same as `range_reference::type`. `range_value::type` is the same as `remove_reference::type`, `range_difference::type` is the same as `std::ptrdiff_t`, and `range_pointer::type` is the same as `add_pointer::type>::type`. As for `const Range`, see below. + +[endsect] + +[section:const_ranges const Ranges] + +`range_reference::type` is defined by the following algorithm. Let `Range` be any type listed above and `Ref` be the same as `range_reference::type`. + +`` +if (Range is CObArray || Range is CObList) + return CObject const * & +else if (Range is CPtrArray || Range is CPtrList) + return void const * & +else if (there is a type X such that X& is the same as Ref) + return X const & +else if (there is a type X such that X* const is the same as Ref) + return X const * const +else + return Ref +`` + + +Other Boost.Range metafunctions are defined by the following. + +[table + [[Range metafunction] [Result]] + [[`range_value::type`] [`range_value::type`]] + [[`range_difference::type`] [`std::ptrdiff_t`]] + [[`range_pointer::type`] [`add_pointer::type>::type>::type`]] +] + +[endsect] + +[section:references References] + +# __boost_range_home__ +# __mfc_collections__ +# __atl_collections__ + +[endsect] + +[endsect] diff --git a/doc/portability.qbk b/doc/portability.qbk new file mode 100644 index 0000000..b4aadbb --- /dev/null +++ b/doc/portability.qbk @@ -0,0 +1,22 @@ +[section Portability] + +A huge effort has been made to port the library to as many compilers as possible. + +Full support for built-in arrays require that the compiler supports class template partial specialization. For non-conforming compilers there might be a chance that it works anyway thanks to workarounds in the type traits library. +Visual C++ 6/7.0 has a limited support for arrays: as long as the arrays are of built-in type it should work. + +Notice also that some compilers cannot do function template ordering properly. In that case one must rely of __range_iterator__ and a single function definition instead of overloaded versions for const and non-const arguments. So if one cares about old compilers, one should not pass rvalues to the functions. + +For maximum portability you should follow these guidelines: + +# do not use built-in arrays, +# do not pass rvalues to __begin__`()`, __end__`()` and __iterator_range__ Range constructors and assignment operators, +# use __const_begin__`()` and __const_end__`()` whenever your code by intention is read-only; this will also solve most rvalue problems, +# do not rely on ADL: + * if you overload functions, include that header before the headers in this library, + * put all overloads in namespace boost. + + + +[endsect] + diff --git a/doc/reference.qbk b/doc/reference.qbk new file mode 100644 index 0000000..037495e --- /dev/null +++ b/doc/reference.qbk @@ -0,0 +1,11 @@ +[section Reference] + +[include reference/overview.qbk] +[include reference/synopsis.qbk] +[include reference/semantics.qbk] +[include reference/adaptors.qbk] +[include reference/algorithms.qbk] +[include reference/ranges.qbk] +[include reference/extending.qbk] + +[endsect] diff --git a/doc/reference/adaptors.qbk b/doc/reference/adaptors.qbk new file mode 100644 index 0000000..9de7fc5 --- /dev/null +++ b/doc/reference/adaptors.qbk @@ -0,0 +1,205 @@ +[section:adaptors Range Adaptors] + +[section:adaptors_introduction Introduction and motivation] + +A [*Range Adaptor] is a class that wraps an existing Range to provide a new Range with different behaviour. Since the behaviour of Ranges is determined by their associated iterators, a Range Adaptor simply wraps the underlying iterators with new special iterators. In this example + +`` +#include +#include +#include +#include + +std::vector vec; +boost::copy( vec | boost::adaptors::reversed, + std::ostream_iterator(std::cout) ); +`` + +the iterators from `vec` are wrapped `reverse_iterator`s. The type of the underlying Range Adapter is not documented because you do not need to know it. All that is relevant is that the expression + +`` +vec | boost::adaptors::reversed +`` + +returns a Range Adaptor where the iterator type is now the iterator type of the range `vec` wrapped in `reverse_iterator`. The expression `boost::adaptors::reversed` is called an *Adaptor Generator*. + +There are two ways of constructing a range adaptor. The first is by using `operator|()`. This is my preferred technique, however while discussing range adaptors with others it became clear that some users of the library strongly prefer a more familiar function syntax, so equivalent functions of the present tense form have been added as an alternative syntax. The equivalent to `rng | reversed` is `adaptors::reverse(rng)` for example. + +Why do I prefer the `operator|` syntax? The answer is readability: + +`` +std::vector vec; +boost::copy( boost::adaptors::reverse(vec), + std::ostream_iterator(std::cout) ); +`` + +This might not look so bad, but when we apply several adaptors, it becomes much worse. Just compare + +`` +std::vector vec; +boost::copy( boost::adaptors::unique( boost::adaptors::reverse( vec ) ), + std::ostream_iterator(std::cout) ); +`` + +to + +`` +std::vector vec; +boost::copy( vec | boost::adaptors::reversed + | boost::adaptors::uniqued, + std::ostream_iterator(std::cout) ); +`` + +Furthermore, some of the adaptor generators take arguments themselves and these arguments are expressed with function call notation too. In those situations, you will really appreciate the succinctness of `operator|()`. + +[heading Composition of Adaptors] + +Range Adaptors are a powerful complement to Range algorithms. The reason is that adaptors are ['*orthogonal*] to algorithms. For example, consider these Range algorithms: + +* `boost::copy( rng, out )` +* `boost::count( rng, pred )` + +What should we do if we only want to copy an element `a` if it satisfies some predicate, say `pred(a)`? And what if we only want to count the elements that satisfy the same predicate? The naive answer would be to use these algorithms: + +* `boost::copy_if( rng, pred, out )` +* `boost::count_if( rng, pred )` + +These algorithms are only defined to maintain a one to one relationship with the standard library algorithms. This approach of adding algorithm suffers a combinatorial explosion. Inevitably many algorithms are missing `_if` variants and there is redundant development overhead for each new algorithm. The Adaptor Generator is the design solution to this problem. + +[heading Range Adaptor alternative to copy_if algorithm] +`` +boost::copy_if( rng, pred, out ); +`` +can be expressed as +`` +boost::copy( rng | boost::adaptors::filtered(pred), out ); +`` + +[heading Range Adaptor alternative to count_if algorithm] +`` +boost::count_if( rng, pred ); +`` +can be expressed as +`` +boost::count( rng | boost::adaptors::filtered(pred), out ); +`` + +What this means is that ['*no*] algorithm with the `_if` suffix is needed. Furthermore, it turns out that algorithms with the `_copy` suffix are not needed either. Consider the somewhat misdesigned `replace_copy_if()` which may be used as + +`` +std::vector vec; +boost::replace_copy_if( rng, std::back_inserter(vec), pred ); +`` + +With adaptors and algorithms we can express this as + +`` +std::vector vec; +boost::push_back(vec, rng | boost::adaptors::replaced_if(pred, new_value)); +`` + +The latter code has several benefits: + +1. it is more ['*efficient*] because we avoid extra allocations as might happen with `std::back_inserter` + +2. it is ['*flexible*] as we can subsequently apply even more adaptors, for example: `` +boost::push_back(vec, rng | boost::adaptors::replaced_if(pred, new_value) + | boost::adaptors::reversed); +`` + +3. it is ['*safer*] because there is no use of an unbounded output iterator. + +In this manner, the ['*composition*] of Range Adaptors has the following consequences: + +1. we no longer need `_if`, `_copy`, `_copy_if` and `_n` variants of algorithms. + +2. we can generate a multitude of new algorithms on the fly, for example, above we generated `reverse_replace_copy_if()` + +In other words: + +[*Range Adaptors are to algorithms what algorithms are to containers] + +[endsect] + +[section:adaptors_synopsis Synopsis] + +The library provides the following Adapter Generator expressions: + +`` +rng | boost::adaptors::adjacent_filtered(bi_pred) +rng | boost::adaptors::copied(n,m) +rng | boost::adaptors::filtered(pred) +rng | boost::adaptors::indexed +rng | boost::adaptors::indirected +rng | boost::adaptors::map_keys +rng | boost::adaptors::map_values +rng | boost::adaptors::replaced(new_value, old_value) +rng | boost::adaptors::replaced_if(pred, new_value) +rng | boost::adaptors::reversed +rng | boost::adaptors::sliced(n, m) +rng | boost::adaptors::strided(n) +rng | boost::adaptors::tokenized( ) +rng | boost::adaptors::transformed(fun) +rng | boost::adaptors::uniqued +`` + +[endsect] + +[section:adaptors_general_requirements General Requirements] + +In the description of generator expressions, the following notation is used: + +* `fwdRng` is an expression of a type `R` that models `ForwardRange` +* `biRng` is an expression of a type `R` that models `BidirectionalRange` +* `rndRng` is an expression of a type `R` that models `RandomAccessRange` +* `pred` is an expression of a type that models `UnaryPredicate` +* `bi_pred` is an expression of a type that models `BinaryPredicate` +* `fun` is an expression of a type that models `UnaryFunction` +* `value`, `new_value` and `old_value` are objects convertible to `boost::range_value::type` +* `n,m` are integer expressions convertible to `range_difference::type` + +Also note that `boost::range_value::type` must be implicitly convertible to the type arguments to `pred`, `bi_pred` and `fun`. + +Range Category in the following adaptor descriptions refers to the minimum range concept required by the range passed to the adaptor. The resultant range is a model of the same range concept as the input range unless specified otherwise. + +Returned Range Category is the concept of the returned range. In some cases the returned range is of a lesser category than the range passed to the adaptor. For example, the `filtered` adaptor returns only a `ForwardRange` regardless of the input. + +Furthermore, the following rules apply to any expression of the form +`` +rng | boost::adaptors::adaptor_generator +`` + +1. Applying `operator|()` to a range `R` (always left argument) and a range adapter `RA` (always right argument) yields a new range type which may not conform to the same range concept as `R`. + +2. The return-type of `operator|()` is otherwise unspecified. + +3. `operator|()` is found by Argument Dependent Lookup (ADL) because a range adaptor is implemented in namespace `boost::adaptors`. + +4. `operator|()` is used to add new behaviour ['*lazily*] and never modifies its left argument. + +5. All iterators extracted from the left argument are extracted using qualified calls to `boost::begin()` and `boost::end()`. + +6. In addition to the `throw`-clauses below, `operator|()` may throw exceptions as a result of copying iterators. If such copying cannot throw an exception, then neither can the whole expression. + +[endsect] + +[section:adaptors_reference Reference] +[include adaptors/adjacent_filtered.qbk] +[include adaptors/copied.qbk] +[include adaptors/filtered.qbk] +[include adaptors/indexed.qbk] +[include adaptors/indirected.qbk] +[include adaptors/map_keys.qbk] +[include adaptors/map_values.qbk] +[include adaptors/replaced.qbk] +[include adaptors/replaced_if.qbk] +[include adaptors/reversed.qbk] +[include adaptors/sliced.qbk] +[include adaptors/strided.qbk] +[include adaptors/tokenized.qbk] +[include adaptors/transformed.qbk] +[include adaptors/uniqued.qbk] +[endsect] + +[endsect] + diff --git a/doc/reference/adaptors/adjacent_filtered.html b/doc/reference/adaptors/adjacent_filtered.html new file mode 100755 index 0000000..a5da75a --- /dev/null +++ b/doc/reference/adaptors/adjacent_filtered.html @@ -0,0 +1,101 @@ + + + + + + Boost.Range Range Adaptors + + + + + + + + + + +

Boost.Range

+ +

Range Adaptors

+ +
+ +

adjacent_filtered

+
+
            rng | boost::adaptors::adjacent_filtered( bi_pred )
+        
+
            boost::make_adjacent_filtered_range( rng, bi_pred )
+        
+
+
    +
  • + Precondition: + The value-type of the range is convertible to both argument types + of bi_pred. +
  • +
  • + Postcondition: + For all adjacent elements [x,y] in the returned range, + bi_pred(x,y) is true. +
  • +
  • + Throws: + Whatever the copy-constructor of bi_pred might throw. +
  • +
  • + Range Category: + SinglePassRange +
  • +
+ +
+

Example

+
+        #include <boost/range/adaptor/adjacent_filtered.hpp>
+        #include <boost/range/algorithm/copy.hpp>
+        #include <boost/assign.hpp>
+        #include <algorithm>
+        #include <functional>
+        #include <iostream>
+        #include <vector>
+        
+        int main(int argc, const char* argv[])
+        {
+            using namespace boost::assign;
+            using namespace boost::adaptors;
+            
+            std::vector<int> input;
+            input += 1,1,2,2,2,3,4,5,6;
+            
+            boost::copy(
+                input | adjacent_filtered(std::not_equal_to<int>()),
+                std::ostream_iterator<int>(std::cout, ","));
+                
+            return 0;
+        }
+    
+

+ This would produce the output:
+ 1,2,3,4,5,6
+

+
+

+ (C) Copyright Neil Groves 2009 + (C) Copyright Thorsten Ottosen 2003-2004 +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + diff --git a/doc/reference/adaptors/adjacent_filtered.qbk b/doc/reference/adaptors/adjacent_filtered.qbk new file mode 100644 index 0000000..933536d --- /dev/null +++ b/doc/reference/adaptors/adjacent_filtered.qbk @@ -0,0 +1,47 @@ +[section:adjacent_filtered adjacent_filtered] + +[table + [[Syntax] [Code]] + [[Pipe] [`rng | boost::adaptors::adjacent_filtered(bi_pred)`]] + [[Function] [`boost::adaptors::adjacent_filter(rng, bi_pred)`]] +] + +* [*Precondition:] The `value_type` of the range is convertible to both argument types of `bi_pred`. +* [*Postcondition:] For all adjacent elements `[x,y]` in the returned range, `bi_pred(x,y)` is `true`. +* [*Throws:] Whatever the copy constructor of `bi_pred` might throw. +* [*Range Category:] `SinglePassRange` + +[section:adjacent_filtered_example adjacent_filtered example] +`` +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::assign; + using namespace boost::adaptors; + + std::vector input; + input += 1,1,2,2,2,3,4,5,6; + + boost::copy( + input | adjacent_filtered(std::not_equal_to()), + std::ostream_iterator(std::cout, ",")); + + return 0; +} +`` +[endsect] + +This would produce the output: +`` +1,2,3,4,5,6 +`` +[endsect] + + diff --git a/doc/reference/adaptors/copied.html b/doc/reference/adaptors/copied.html new file mode 100755 index 0000000..12b3351 --- /dev/null +++ b/doc/reference/adaptors/copied.html @@ -0,0 +1,93 @@ + + + + + + Boost.Range Range Adaptors + + + + + + + + + + +

Boost.Range

+ +

Range Adaptors

+ +
+ +

copied

+
+
rng | boost::adaptors::copied( n, m )
+
boost::make_copied_range( rng, n, m )
+
+
    +
  • + Precondition: + 0 <= n && n <= m && m < distance(rng) +
  • +
  • + Returns: + A new iterator_range that holds the sliced range + [n,m) of the original range. +
  • +
  • + Range Category: + RandomAccessRange +
  • +
+ +
+

Example

+
+    #include <boost/range/adaptor/copied.hpp>
+    #include <boost/range/algorithm/copy.hpp>
+    #include <boost/assign.hpp>
+    #include <algorithm>
+    #include <iostream>
+    #include <vector>
+
+    int main(int argc, const char* argv[])
+    {
+        using namespace boost::assign;
+        using namespace boost::adaptors;
+
+        std::vector<int> input;
+        input += 1,2,3,4,5,6,7,8,9,10;
+
+        boost::copy(
+            input | copied(1, 5),
+            std::ostream_iterator<int>(std::cout, ","));
+
+        return 0;
+    }
+    
+

+ This would produce the output: + 2,3,4,5 +

+
+

+ (C) Copyright Neil Groves 2009 + (C) Copyright Thorsten Ottosen 2003-2004 +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + diff --git a/doc/reference/adaptors/copied.qbk b/doc/reference/adaptors/copied.qbk new file mode 100644 index 0000000..263286c --- /dev/null +++ b/doc/reference/adaptors/copied.qbk @@ -0,0 +1,45 @@ +[section:copied copied] + +[table + [[Syntax] [Code]] + [[Pipe] [`rng | boost::adaptors::copied(n, m)`]] + [[Function] [`boost::adaptors::copy(rng, n, m)`]] +] + +* [*Precondition:] `0 <= n && n <= m && m < distance(rng)` +* [*Returns:] A new `iterator_range` that holds the sliced range `[n,m)` of the original range. +* [*Range Category:] `RandomAccessRange` + +[section:copied_example copied example] +`` +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::assign; + using namespace boost::adaptors; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9,10; + + boost::copy( + input | copied(1, 5), + std::ostream_iterator(std::cout, ",")); + + return 0; +} +`` +[endsect] + +This would produce the output: +`` +2,3,4,5 +`` +[endsect] + + diff --git a/doc/reference/adaptors/examples/adjacent_filtered.cpp b/doc/reference/adaptors/examples/adjacent_filtered.cpp new file mode 100644 index 0000000..70923f8 --- /dev/null +++ b/doc/reference/adaptors/examples/adjacent_filtered.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::assign; + using namespace boost::adaptors; + + std::vector input; + input += 1,1,2,2,2,3,4,5,6; + + boost::copy( + input | adjacent_filtered(std::not_equal_to()), + std::ostream_iterator(std::cout, ",")); + + return 0; +} + diff --git a/doc/reference/adaptors/examples/copied.cpp b/doc/reference/adaptors/examples/copied.cpp new file mode 100644 index 0000000..0ab0ca2 --- /dev/null +++ b/doc/reference/adaptors/examples/copied.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::assign; + using namespace boost::adaptors; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9,10; + + boost::copy( + input | copied(1, 5), + std::ostream_iterator(std::cout, ",")); + + return 0; +} + diff --git a/doc/reference/adaptors/examples/filtered.cpp b/doc/reference/adaptors/examples/filtered.cpp new file mode 100644 index 0000000..65242f3 --- /dev/null +++ b/doc/reference/adaptors/examples/filtered.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +#include +#include +#include + +struct is_even +{ + bool operator()(int x) const { return x % 2 == 0; } +}; + +int main(int argc, const char* argv[]) +{ + using namespace boost::assign; + using namespace boost::adaptors; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9; + + boost::copy( + input | filtered(is_even()), + std::ostream_iterator(std::cout, ",")); + + return 0; +} + diff --git a/doc/reference/adaptors/examples/indexed.cpp b/doc/reference/adaptors/examples/indexed.cpp new file mode 100644 index 0000000..3dc31d1 --- /dev/null +++ b/doc/reference/adaptors/examples/indexed.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include +#include + +template +void display_element_and_index(Iterator first, Iterator last) +{ + for (Iterator it = first; it != last; ++it) + { + std::cout << "Element = " << *it + << " Index = " << it.index() << std::endl; + } +} + +template +void display_element_and_index(const SinglePassRange& rng) +{ + display_element_and_index(boost::begin(rng), boost::end(rng)); +} + +int main(int argc, const char* argv[]) +{ + using namespace boost::assign; + using namespace boost::adaptors; + + std::vector input; + input += 10,20,30,40,50,60,70,80,90; + + display_element_and_index( input | indexed(0) ); + + return 0; +] + diff --git a/doc/reference/adaptors/examples/indirected.cpp b/doc/reference/adaptors/examples/indirected.cpp new file mode 100644 index 0000000..47cf493 --- /dev/null +++ b/doc/reference/adaptors/examples/indirected.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::adaptors; + + std::vector > input; + + for (int i = 0; i < 10; ++i) + input.push_back(boost::shared_ptr(new int(i))); + + boost::copy( + input | indirected, + std::ostream_iterator(std::cout, ",")); + + return 0; +} + diff --git a/doc/reference/adaptors/examples/map_keys.cpp b/doc/reference/adaptors/examples/map_keys.cpp new file mode 100644 index 0000000..6c5fc44 --- /dev/null +++ b/doc/reference/adaptors/examples/map_keys.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::assign; + using namespace boost::adaptors; + + std::map input; + for (int i = 0; i < 10; ++i) + input.insert(std::make_pair(i, i * 10)); + + boost::copy( + input | map_keys, + std::ostream_iterator(std::cout, ",")); + + return 0; +} + diff --git a/doc/reference/adaptors/examples/map_values.cpp b/doc/reference/adaptors/examples/map_values.cpp new file mode 100644 index 0000000..9442612 --- /dev/null +++ b/doc/reference/adaptors/examples/map_values.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::assign; + using namespace boost::adaptors; + + std::map input; + for (int i = 0; i < 10; ++i) + input.insert(std::make_pair(i, i * 10)); + + boost::copy( + input | map_values, + std::ostream_iterator(std::cout, ",")); + + return 0; +} + diff --git a/doc/reference/adaptors/examples/replaced.cpp b/doc/reference/adaptors/examples/replaced.cpp new file mode 100644 index 0000000..7c8926b --- /dev/null +++ b/doc/reference/adaptors/examples/replaced.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,2,5,2,7,2,9; + + boost::copy( + input | replaced(2, 10), + std::ostream_iterator(std::cout, ",")); + + return 0; +} + diff --git a/doc/reference/adaptors/examples/replaced_if.cpp b/doc/reference/adaptors/examples/replaced_if.cpp new file mode 100644 index 0000000..fedd364 --- /dev/null +++ b/doc/reference/adaptors/examples/replaced_if.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include +#include +#include + +struct is_even +{ + bool operator()(int x) const { return x % 2 == 0; } +}; + +int main(int argc, const char* argv[]) +{ + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9; + + boost::copy( + input | replaced_if(is_even(), 10), + std::ostream_iterator(std::cout, ",")); + + return 0; +} diff --git a/doc/reference/adaptors/examples/reversed.cpp b/doc/reference/adaptors/examples/reversed.cpp new file mode 100644 index 0000000..e2aa80c --- /dev/null +++ b/doc/reference/adaptors/examples/reversed.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9; + + boost::copy( + input | reversed, + std::ostream_iterator(std::cout, ",")); + + return 0; +} + diff --git a/doc/reference/adaptors/examples/sliced.cpp b/doc/reference/adaptors/examples/sliced.cpp new file mode 100644 index 0000000..6ce4b12 --- /dev/null +++ b/doc/reference/adaptors/examples/sliced.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9; + + boost::copy( + input | sliced(2, 5), + std::ostream_iterator(std::cout, ",")); + + return 0; +} + diff --git a/doc/reference/adaptors/examples/strided.cpp b/doc/reference/adaptors/examples/strided.cpp new file mode 100644 index 0000000..4509758 --- /dev/null +++ b/doc/reference/adaptors/examples/strided.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9,10; + + boost::copy( + input | strided(2), + std::ostream_iterator(std::cout, ",")); + + return 0; +} + diff --git a/doc/reference/adaptors/examples/tokenized.cpp b/doc/reference/adaptors/examples/tokenized.cpp new file mode 100644 index 0000000..b4e6371 --- /dev/null +++ b/doc/reference/adaptors/examples/tokenized.cpp @@ -0,0 +1,19 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::adaptors; + + std::string input = " a b c d e f g hijklmnopqrstuvwxyz"; + std::vector< boost::sub_match< std::string::iterator > > result; + boost::push_back(result, input | tokenized(boost::regex("\\b"))); + + BOOST_ASSERT( boost::size(result) == 16u ); + + return 0; +} diff --git a/doc/reference/adaptors/examples/transformed.cpp b/doc/reference/adaptors/examples/transformed.cpp new file mode 100644 index 0000000..1508969 --- /dev/null +++ b/doc/reference/adaptors/examples/transformed.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include +#include + +struct double_int +{ + typedef int result_type; + int operator()(int x) const { return x * 2; } +}; + +int main(int argc, const char* argv[]) +{ + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9,10; + + boost::copy( + input | transformed(double_int()), + std::ostream_iterator(std::cout, ",")); + + return 0; +} + diff --git a/doc/reference/adaptors/examples/uniqued.cpp b/doc/reference/adaptors/examples/uniqued.cpp new file mode 100644 index 0000000..0511ade --- /dev/null +++ b/doc/reference/adaptors/examples/uniqued.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::assign; + using namespace boost::adaptors; + + std::vector input; + input += 1,1,2,2,2,3,4,5,6; + + boost::copy( + input | uniqued, + std::ostream_iterator(std::cout, ",")); + + return 0; +} + diff --git a/doc/reference/adaptors/filtered.html b/doc/reference/adaptors/filtered.html new file mode 100755 index 0000000..055c826 --- /dev/null +++ b/doc/reference/adaptors/filtered.html @@ -0,0 +1,108 @@ + + + + + + Boost.Range Range Adaptors + + + + + + + + + + +

Boost.Range

+ +

Range Adaptors

+ +
+ +

filtered

+
+
rng | boost::adaptors::filtered( pred )
+
boost::make_filtered_range( rng, pred )
+
+
    +
  • + Precondition: + The value-type of the range is convertible to the argument type of + pred. +
  • +
  • + Postcondition: + For all elements x in the returned range, + pred(x) is true +
  • +
  • + Throws: + Whatever the copy-constructor of pred might throw. +
  • +
  • + Range Category: + ForwardRange +
  • +
  • + Returned Range Category: + ForwardRange +
  • +
+ +
+

Example

+
+        #include <boost/range/adaptor/filtered.hpp>
+        #include <boost/range/algorithm/copy.hpp>
+        #include <boost/assign.hpp>
+        #include <algorithm>
+        #include <iostream>
+        #include <vector>
+
+        struct is_even
+        {
+            bool operator()(int x) const { return x % 2 == 0; }
+        };
+        
+        int main(int argc, const char* argv[])
+        {
+            using namespace boost::assign;
+            using namespace boost::adaptors;
+            
+            std::vector<int> input;
+            input += 1,2,3,4,5,6,7,8,9;
+
+            boost::copy(
+                input | filtered(is_even()),
+                std::ostream_iterator<int>(std::cout, ","));
+
+            return 0;
+        }
+    
+

+ This would produce the output:
+ 2,4,6,8 +

+ +
+

+ (C) Copyright Neil Groves 2009 + (C) Copyright Thorsten Ottosen 2003-2004 +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + diff --git a/doc/reference/adaptors/filtered.qbk b/doc/reference/adaptors/filtered.qbk new file mode 100644 index 0000000..2a6dc33 --- /dev/null +++ b/doc/reference/adaptors/filtered.qbk @@ -0,0 +1,50 @@ +[section:filtered filtered] + +[table + [[Syntax] [Code]] + [[Pipe] [`rng | boost::adaptors::filtered(pred)`]] + [[Function] [`boost::adaptors::filter(rng, pred)`]] +] + +* [*Precondition:] The `value_type` of the range is convertible to the argument type of `pred`. +* [*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:] `ForwardRange` +* [*Returned Range Category:] `ForwardRange` + +[section:filtered_example filtered example] +`` +#include +#include +#include +#include +#include +#include + +struct is_even +{ + bool operator()( int x ) const { return x % 2 == 0; } +}; + +int main(int argc, const char* argv[]) +{ + using namespace boost::assign; + using namespace boost::adaptors; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9; + + boost::copy( + input | filtered(is_even()), + std::ostream_iterator(std::cout, ",")); +} +`` +[endsect] + +This would produce the output: +`` +2,4,6,8 +`` +[endsect] + + diff --git a/doc/reference/adaptors/indexed.html b/doc/reference/adaptors/indexed.html new file mode 100755 index 0000000..74e0d04 --- /dev/null +++ b/doc/reference/adaptors/indexed.html @@ -0,0 +1,117 @@ + + + + + + Boost.Range Range Adaptors + + + + + + + + + + +

Boost.Range

+ +

Range Adaptors

+ +
+ +

indexed

+
+
rng | boost::adaptors::indexed
+
boost::make_indexed_range( rng )
+
+
    +
  • + 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: + SinglePassRange +
  • +
+
+

Example

+
+        #include <boost/range/adaptor/indexed.hpp>
+        #include <boost/range/algorithm/copy.hpp>
+        #include <boost/assign.hpp>
+        #include <algorithm>
+        #include <iostream>
+        #include <vector>
+        
+        template<class Iterator>
+        void display_element_and_index(Iterator first, Iterator last)
+        {
+            for (Iterator it = first; it != last; ++it)
+            {
+                std::cout << "Element = " << *it
+                          << " Index = " << it.index() << std::endl;
+            }
+        }
+        
+        template<class SinglePassRange>
+        void display_element_and_index(const SinglePassRange& rng)
+        {
+            display_element_and_index(boost::begin(rng), boost::end(rng));
+        }
+        
+        int main(int argc, const char* argv[])
+        {
+            using namespace boost::assign;
+            using namespace boost::adaptors;
+            
+            std::vector<int> input;
+            input += 10,20,30,40,50,60,70,80,90;
+            
+            display_element_and_index( input | indexed(0) );
+            
+            return 0;
+        }
+    
+

+ This produces the output:
+ + Element = 10 Index = 0
+ Element = 20 Index = 1
+ Element = 30 Index = 2
+ Element = 40 Index = 3
+ Element = 50 Index = 4
+ Element = 60 Index = 5
+ Element = 70 Index = 6
+ Element = 80 Index = 7
+ Element = 90 Index = 8
+
+

+
+

+ (C) Copyright Neil Groves 2009 + (C) Copyright Thorsten Ottosen 2003-2004 +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + diff --git a/doc/reference/adaptors/indexed.qbk b/doc/reference/adaptors/indexed.qbk new file mode 100644 index 0000000..36dfd88 --- /dev/null +++ b/doc/reference/adaptors/indexed.qbk @@ -0,0 +1,86 @@ +[section:indexed indexed] + +[table + [[Syntax] [Code]] + [[Pipe] [`rng | boost::adaptors::indexed`]] + [[Function] [`boost::adaptors::index(rng)`]] +] + +* [*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:] `SinglePassRange` + +[section:indexed_example indexed example] +`` +#include +#include +#include +#include +#include +#include + +template +void display_element_and_index(Iterator first, Iterator last) +{ + for (Iterator it = first; it != last; ++it) + { + std::cout << "Element = " << *it << " Index = " << it.index() << std::endl; + } +} + +template +void display_element_and_index(const SinglePassRange& rng) +{ + display_element_and_index(boost::begin(rng), boost::end(rng)); +} + +template +void check_element_and_index( + Iterator1 test_first, + Iterator1 test_last, + Iterator2 reference_first, + Iterator2 reference_last) +{ + BOOST_CHECK_EQUAL( std::distance(test_first, test_last), + std::distance(reference_first, reference_last) ); + + int reference_index = 0; + + Iterator1 test_it = test_first; + Iterator2 reference_it = reference_first; + for (; test_it != test_last; ++test_it, ++reference_it, ++reference_index) + { + BOOST_CHECK_EQUAL( *test_it, *reference_it ); + BOOST_CHECK_EQUAL( test_it.index(), reference_index ); + } +} + +int main(int argc, const char* argv[]) +{ + using namespace boost::assign; + using namespace boost::adaptors; + + std::vector input; + input += 10,20,30,40,50,60,70,80,90; + + display_element_and_index( input | indexed(0) ); + + return 0; +} +`` +[endsect] + +This would produce the output: +`` +Element = 10 Index = 0 +Element = 20 Index = 1 +Element = 30 Index = 2 +Element = 40 Index = 3 +Element = 50 Index = 4 +Element = 60 Index = 5 +Element = 70 Index = 6 +Element = 80 Index = 7 +Element = 90 Index = 8 +`` +[endsect] + + diff --git a/doc/reference/adaptors/indirected.html b/doc/reference/adaptors/indirected.html new file mode 100755 index 0000000..0a56e32 --- /dev/null +++ b/doc/reference/adaptors/indirected.html @@ -0,0 +1,95 @@ + + + + + + Boost.Range Range Adaptors + + + + + + + + + + +

Boost.Range

+ +

Range Adaptors

+ +
+ +

indirected

+
+
rng | boost::adaptors::indirected
+
boost::make_indirected_range( rng )
+
+
    +
  • + 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: + SinglePassRange +
  • +
+ +
+

Example

+
+        #include <boost/range/adaptor/indirected.hpp>
+        #include <boost/range/algorithm/copy.hpp>
+        #include <boost/shared_ptr.hpp>
+        #include <algorithm>
+        #include <iostream>
+        #include <vector>
+        
+        int main(int argc, const char* argv[])
+        {
+            using namespace boost::adaptors;
+            
+            std::vector<boost::shared_ptr<int> > input;
+            
+            for (int i = 0; i < 10; ++i)
+                input.push_back(boost::shared_ptr<int>(new int(i)));
+                
+            boost::copy(
+                input | indirected,
+                std::ostream_iterator<int>(std::cout, ","));
+                
+            return 0;
+        }
+    
+

+ This produces the output:
+ 0,1,2,3,4,5,6,7,8,9 +

+
+

+ (C) Copyright Neil Groves 2009 + (C) Copyright Thorsten Ottosen 2003-2004 +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + diff --git a/doc/reference/adaptors/indirected.qbk b/doc/reference/adaptors/indirected.qbk new file mode 100644 index 0000000..f0cbd7a --- /dev/null +++ b/doc/reference/adaptors/indirected.qbk @@ -0,0 +1,46 @@ +[section:indirected indirected] + +[table + [[Syntax] [Code]] + [[Pipe] [`rng | boost::adaptors::indirected`]] + [[Function] [`boost::adaptors::indirect(rng)`]] +] + +* [*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:] `SinglePassRange` + +[section:indirected_example indirected example] +`` +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::adaptors; + + std::vector > input; + + for (int i = 0; i < 10; ++i) + input.push_back(boost::shared_ptr(new int(i))); + + boost::copy( + input | indirected, + std::ostream_iterator(std::cout, ",")); + + return 0; +} +`` +[endsect] + +This would produce the output: +`` +0,1,2,3,4,5,6,7,8,9 +`` +[endsect] + + diff --git a/doc/reference/adaptors/map_keys.html b/doc/reference/adaptors/map_keys.html new file mode 100755 index 0000000..a1eec17 --- /dev/null +++ b/doc/reference/adaptors/map_keys.html @@ -0,0 +1,99 @@ + + + + + + Boost.Range Range Adaptors + + + + + + + + + + +

Boost.Range

+ +

Range Adaptors

+ +
+ +

map_keys

+
+
rng | boost::adaptors::map_keys
+
boost::make_map_key_range( rng )
+
+
    +
  • + 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: + SinglePassRange +
  • +
+ +
+

Example

+
+        #include <boost/range/adaptor/map.hpp>
+        #include <boost/range/algorithm/copy.hpp>
+        #include <boost/assign.hpp>
+        #include <algorithm>
+        #include <iostream>
+        #include <map>
+        #include <vector>
+        
+        int main(int argc, const char* argv[])
+        {
+            using namespace boost::assign;
+            using namespace boost::adaptors;
+            
+            std::map<int,int> input;
+            for (int i = 0; i < 10; ++i)
+                input.insert(std::make_pair(i, i * 10));
+                
+            boost::copy(
+                input | map_keys,
+                std::ostream_iterator<int>(std::cout, ","));
+                
+            return 0;
+        }
+    
+

+ This produces the output:
+ + 0,1,2,3,4,5,6,7,8,9 + +

+ +
+

+ (C) Copyright Neil Groves 2009 + (C) Copyright Thorsten Ottosen 2003-2004 +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + diff --git a/doc/reference/adaptors/map_keys.qbk b/doc/reference/adaptors/map_keys.qbk new file mode 100644 index 0000000..7b29013 --- /dev/null +++ b/doc/reference/adaptors/map_keys.qbk @@ -0,0 +1,47 @@ +[section:map_keys map_keys] + +[table + [[Syntax] [Code]] + [[Pipe] [`rng | boost::adaptors::map_keys`]] + [[Function] [`boost::adaptors::keys(rng)`]] +] + +* [*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:] `SinglePassRange` + +[section:map_keys_example map_keys example] +`` +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::assign; + using namespace boost::adaptors; + + std::map input; + for (int i = 0; i < 10; ++i) + input.insert(std::make_pair(i, i * 10)); + + boost::copy( + input | map_keys, + std::ostream_iterator(std::cout, ",")); + + return 0; +} +`` +[endsect] + +This would produce the output: +`` +0,1,2,3,4,5,6,7,8,9 +`` +[endsect] + + diff --git a/doc/reference/adaptors/map_values.html b/doc/reference/adaptors/map_values.html new file mode 100755 index 0000000..bc3c165 --- /dev/null +++ b/doc/reference/adaptors/map_values.html @@ -0,0 +1,98 @@ + + + + + + Boost.Range Range Adaptors + + + + + + + + + + +

Boost.Range

+ +

Range Adaptors

+ +
+ +

map_values

+
+
rng | boost::adaptors::map_values
+
boost::make_map_value_range( rng )
+
+
    +
  • + 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: + SinglePassRange +
  • +
+
+

Example

+
+        #include <boost/range/adaptor/map.hpp>
+        #include <boost/range/algorithm/copy.hpp>
+        #include <boost/assign.hpp>
+        #include <algorithm>
+        #include <iostream>
+        #include <map>
+        #include <vector>
+        
+        int main(int argc, const char* argv[])
+        {
+            using namespace boost::assign;
+            using namespace boost::adaptors;
+            
+            std::map<int,int> input;
+            for (int i = 0; i < 10; ++i)
+                input.insert(std::make_pair(i, i * 10));
+                
+            boost::copy(
+                input | map_values,
+                std::ostream_iterator<int>(std::cout, ","));
+                
+            return 0;
+        }
+    
+

+ This produces the output:
+ + 0,10,20,30,40,50,60,70,80,90 + +

+ +
+

+ (C) Copyright Neil Groves 2009 + (C) Copyright Thorsten Ottosen 2003-2004 +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + diff --git a/doc/reference/adaptors/map_values.qbk b/doc/reference/adaptors/map_values.qbk new file mode 100644 index 0000000..28f75c8 --- /dev/null +++ b/doc/reference/adaptors/map_values.qbk @@ -0,0 +1,47 @@ +[section:map_values map_values] + +[table + [[Syntax] [Code]] + [[Pipe] [`rng | boost::adaptors::map_values`]] + [[Function] [`boost::adaptors::values(rng)`]] +] + +* [*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:] `SinglePassRange` + +[section:map_values_example map_values example] +`` +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::assign; + using namespace boost::adaptors; + + std::map input; + for (int i = 0; i < 10; ++i) + input.insert(std::make_pair(i, i * 10)); + + boost::copy( + input | map_values, + std::ostream_iterator(std::cout, ",")); + + return 0; +} +`` +[endsect] + +This would produce the output: +`` +0,10,20,30,40,50,60,70,80,90 +`` +[endsect] + + diff --git a/doc/reference/adaptors/replaced.html b/doc/reference/adaptors/replaced.html new file mode 100755 index 0000000..861277f --- /dev/null +++ b/doc/reference/adaptors/replaced.html @@ -0,0 +1,107 @@ + + + + + + Boost.Range Range Adaptors + + + + + + + + + + +

Boost.Range

+ +

Range Adaptors

+ +
+ +

replaced

+
+
rng | boost::adaptors::replaced( new_value, old_value )
+
boost::make_replaced_range( rng, new_value, old_value )
+
+
    +
  • + Precondition: +
      +
    • + 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: + ForwardRange +
  • +
+
+

Example

+
+        #include <boost/range/adaptor/replaced.hpp>
+        #include <boost/range/algorithm/copy.hpp>
+        #include <boost/assign.hpp>
+        #include <algorithm>
+        #include <iostream>
+        #include <vector>
+        
+        int main(int argc, const char* argv[])
+        {
+            using namespace boost::adaptors;
+            using namespace boost::assign;
+            
+            std::vector<int> input;
+            input += 1,2,3,2,5,2,7,2,9;
+            
+            boost::copy(
+                input | replaced(2, 10),
+                std::ostream_iterator<int>(std::cout, ","));
+                
+            return 0;
+        }
+    
+

+ This produces the output:
+ + 1,10,3,10,5,10,7,10,9 + +

+ +
+

+ (C) Copyright Neil Groves 2009 + (C) Copyright Thorsten Ottosen 2003-2004 +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + diff --git a/doc/reference/adaptors/replaced.qbk b/doc/reference/adaptors/replaced.qbk new file mode 100644 index 0000000..92a673b --- /dev/null +++ b/doc/reference/adaptors/replaced.qbk @@ -0,0 +1,47 @@ +[section:replaced replaced] + +[table + [[Syntax] [Code]] + [[Pipe] [`rng | boost::adaptors::replaced(new_value, old_value)`]] + [[Function] [`boost::adaptors::replace(rng, new_value, old_value)`]] +] + +* [*Precondition:] + * `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:] `ForwardRange` + +[section:replaced_example replaced example] +`` +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,2,5,2,7,2,9; + + boost::copy( + input | replaced(2, 10), + std::ostream_iterator(std::cout, ",")); + + return 0; +} +`` +[endsect] + +This would produce the output: +`` +1,10,3,10,5,10,7,10,9 +`` +[endsect] + + diff --git a/doc/reference/adaptors/replaced_if.html b/doc/reference/adaptors/replaced_if.html new file mode 100755 index 0000000..cde3678 --- /dev/null +++ b/doc/reference/adaptors/replaced_if.html @@ -0,0 +1,114 @@ + + + + + + Boost.Range Range Adaptors + + + + + + + + + + +

Boost.Range

+ +

Range Adaptors

+ +
+ +

replaced_if

+
+
rng | boost::adaptors::replaced_if( pred, new_value )
+
boost::make_replaced_if_range( rng, pred, new_value )
+
+
    +
  • + Precondition: +
      +
    • + 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: + ForwardRange +
  • +
+ +
+

Example

+
+        #include <boost/range/adaptor/replaced_if.hpp>
+        #include <boost/range/algorithm/copy.hpp>
+        #include <boost/assign.hpp>
+        #include <algorithm>
+        #include <iostream>
+        #include <vector>
+        
+        struct is_even
+        {
+            bool operator()(int x) const { return x % 2 == 0; }
+        };
+        
+        int main(int argc, const char* argv[])
+        {
+            using namespace boost::adaptors;
+            using namespace boost::assign;
+            
+            std::vector<int> input;
+            input += 1,2,3,4,5,6,7,8,9;
+            
+            boost::copy(
+                input | replaced_if(is_even(), 10),
+                std::ostream_iterator<int>(std::cout, ","));
+                
+            return 0;
+        }
+        
+    
+

+ This produces the output:
+ + 1,10,3,10,5,10,7,10,9 + +

+ +
+

+ (C) Copyright Neil Groves 2009 + (C) Copyright Thorsten Ottosen 2003-2004 +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + diff --git a/doc/reference/adaptors/replaced_if.qbk b/doc/reference/adaptors/replaced_if.qbk new file mode 100644 index 0000000..b7b7e57 --- /dev/null +++ b/doc/reference/adaptors/replaced_if.qbk @@ -0,0 +1,52 @@ +[section:replaced_if replaced_if] + +[table + [[Syntax] [Code]] + [[Pipe] [`rng | boost::adaptors::replaced_if(pred, new_value)`]] + [[Function] [`boost::adaptors::replace_if(rng, pred, new_value)`]] +] + +* [*Precondition:] + * 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:] `ForwardRange` + +[section:replaced_if_example replaced_if example] +`` +#include +#include +#include +#include +#include +#include + +struct is_even +{ + bool operator()(int x) const { return x % 2 == 0; } +}; + +int main(int argc, const char* argv[]) +{ + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9; + + boost::copy( + input | replaced_if(is_even(), 10), + std::ostream_iterator(std::cout, ",")); + + return 0; +} +`` +[endsect] + +This would produce the output: +`` +1,10,3,10,5,10,7,10,9 +`` +[endsect] + + diff --git a/doc/reference/adaptors/reversed.html b/doc/reference/adaptors/reversed.html new file mode 100755 index 0000000..0aea1ee --- /dev/null +++ b/doc/reference/adaptors/reversed.html @@ -0,0 +1,91 @@ + + + + + + Boost.Range Range Adaptors + + + + + + + + + + +

Boost.Range

+ +

Range Adaptors

+ +
+ +

reversed

+
+
rng | boost::adaptors::reversed
+
boost::make_reversed_range( rng )
+
+
    +
  • + Returns: + A range whose iterators behave as if they were the original + iterators wrapped in reverse_iterator. +
  • +
  • + Range Category: + BidirectionalRange +
  • +
+
+

Example

+
+        #include <boost/range/adaptor/reversed.hpp>
+        #include <boost/range/algorithm/copy.hpp>
+        #include <boost/assign.hpp>
+        #include <algorithm>
+        #include <iostream>
+        #include <vector>
+        
+        int main(int argc, const char* argv[])
+        {
+            using namespace boost::adaptors;
+            using namespace boost::assign;
+            
+            std::vector<int> input;
+            input += 1,2,3,4,5,6,7,8,9;
+            
+            boost::copy(
+                input | reversed,
+                std::ostream_iterator<int>(std::cout, ","));
+                
+            return 0;
+        }
+    
+

+ This produces the output:
+ + 9,8,7,6,5,4,3,2,1 + +

+ +
+

+ (C) Copyright Neil Groves 2009 + (C) Copyright Thorsten Ottosen 2003-2004 +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + diff --git a/doc/reference/adaptors/reversed.qbk b/doc/reference/adaptors/reversed.qbk new file mode 100644 index 0000000..4ad623b --- /dev/null +++ b/doc/reference/adaptors/reversed.qbk @@ -0,0 +1,44 @@ +[section:reversed reversed] + +[table + [[Syntax] [Code]] + [[Pipe] [`rng | boost::adaptors::reversed`]] + [[Function] [`boost::adaptors::reverse(rng)`]] +] + +* [*Returns:] A range whose iterators behave as if they were the original iterators wrapped in `reverse_iterator`. +* [*Range Category:] `BidirectionalRange` + +[section:reversed_example reversed example] +`` +#include +#include +#include +#include +#include +#include + +void reversed_example_test() +{ + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9; + + boost::copy( + input | reversed, + std::ostream_iterator(std::cout, ",")); + + return 0; +} +`` +[endsect] + +This would produce the output: +`` +9,8,7,6,5,4,3,2,1 +`` +[endsect] + + diff --git a/doc/reference/adaptors/sliced.html b/doc/reference/adaptors/sliced.html new file mode 100755 index 0000000..d979392 --- /dev/null +++ b/doc/reference/adaptors/sliced.html @@ -0,0 +1,94 @@ + + + + + + Boost.Range Range Adaptors + + + + + + + + + + +

Boost.Range

+ +

Range Adaptors

+ +
+ +

sliced

+
+
rng | boost::adaptors::sliced( n, m )
+
boost::make_sliced_range( rng, n, m )
+
+
    +
  • + Precondition: + 0 <= n && n <= m && m < distance(rng) +
  • +
  • + Returns: + make_range(rng, n, m) +
  • +
  • + Range Category: + RandomAccessRange +
  • +
+
+

Example

+
+        #include <boost/range/adaptor/sliced.hpp>
+        #include <boost/range/algorithm/copy.hpp>
+        #include <boost/assign.hpp>
+        #include <algorithm>
+        #include <iostream>
+        #include <vector>
+        
+        int main(int argc, const char* argv[])
+        {
+            using namespace boost::adaptors;
+            using namespace boost::assign;
+            
+            std::vector<int> input;
+            input += 1,2,3,4,5,6,7,8,9;
+            
+            boost::copy(
+                input | sliced(2, 5),
+                std::ostream_iterator<int>(std::cout, ","));
+                
+            return 0;
+        }
+    
+

+ This produces the output:
+ + 3,4,5 + +

+ +
+

+ (C) Copyright Neil Groves 2009 + (C) Copyright Thorsten Ottosen 2003-2004 +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + diff --git a/doc/reference/adaptors/sliced.qbk b/doc/reference/adaptors/sliced.qbk new file mode 100644 index 0000000..e424ddc --- /dev/null +++ b/doc/reference/adaptors/sliced.qbk @@ -0,0 +1,45 @@ +[section:sliced sliced] + +[table + [[Syntax] [Code]] + [[Pipe] [`rng | boost::adaptors::sliced(n, m)`]] + [[Function] [`boost::adaptors::slice(rng, n, m)`]] +] + +* [*Precondition:] `0 <= n && n <= m && m < distance(rng)` +* [*Returns:] `make_range(rng, n, m)` +* [*Range Category:] `RandomAccessRange` + +[section:sliced_example sliced example] +`` +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9; + + boost::copy( + input | sliced(2, 5), + std::ostream_iterator(std::cout, ",")); + + return 0; +} +`` +[endsect] + +This would produce the output: +`` +3,4,5 +`` +[endsect] + + diff --git a/doc/reference/adaptors/strided.html b/doc/reference/adaptors/strided.html new file mode 100755 index 0000000..3e23af5 --- /dev/null +++ b/doc/reference/adaptors/strided.html @@ -0,0 +1,94 @@ + + + + + + Boost.Range Range Adaptors + + + + + + + + + + +

Boost.Range

+ +

Range Adaptors

+ +
+ +

strided

+
+
rng | boost::adaptors::strided( n )
+
boost::make_strided_range( rng, n )
+
+
    +
  • + Precondition: + 0 <= n && n <= distance(rng) +
  • +
  • + Returns: + A new range based on rng where traversal is performed in steps of n. +
  • +
  • + Range Category: + RandomAccessRange +
  • +
+
+

Example

+
+        #include <boost/range/adaptor/strided.hpp>
+        #include <boost/range/algorithm/copy.hpp>
+        #include <boost/assign.hpp>
+        #include <algorithm>
+        #include <iostream>
+        #include <vector>
+        
+        int main(int argc, const char* argv[])
+        {
+            using namespace boost::adaptors;
+            using namespace boost::assign;
+            
+            std::vector<int> input;
+            input += 1,2,3,4,5,6,7,8,9,10;
+            
+            boost::copy(
+                input | strided(2),
+                std::ostream_iterator<int>(std::cout, ","));
+                
+            return 0;
+        }
+    
+

+ This produces the output: + + 1,3,5,7,9 + +

+ +
+

+ (C) Copyright Neil Groves 2009 + (C) Copyright Thorsten Ottosen 2003-2004 +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + diff --git a/doc/reference/adaptors/strided.qbk b/doc/reference/adaptors/strided.qbk new file mode 100644 index 0000000..cf2f09f --- /dev/null +++ b/doc/reference/adaptors/strided.qbk @@ -0,0 +1,45 @@ +[section:strided strided] + +[table + [[Syntax] [Code]] + [[Pipe] [`rng | boost::adaptors::strided(n)`]] + [[Function] [`boost::adaptors::stride(rng, n)`]] +] + +* [*Precondition:] `0 <= n && n < distance(rng)` +* [*Returns:] A new range based on `rng` where traversal is performed in steps of `n`. +* [*Range Category:] `RandomAccessRange` + +[section:strided_example strided example] +`` +#include +#include +#include +#include +#include +#include + +int main(int argc, const char* argv[]) +{ + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9,10; + + boost::copy( + input | strided(2), + std::ostream_iterator(std::cout, ",")); + + return 0; +} +`` +[endsect] + +This would produce the output: +`` +1,3,5,7,9 +`` +[endsect] + + diff --git a/doc/reference/adaptors/tokenized.html b/doc/reference/adaptors/tokenized.html new file mode 100755 index 0000000..304e91d --- /dev/null +++ b/doc/reference/adaptors/tokenized.html @@ -0,0 +1,118 @@ + + + + + + Boost.Range Range Adaptors + + + + + + + + + + +

Boost.Range

+ +

Range Adaptors

+ +
+ +

tokenized

+
+
rng | boost::adaptors::tokenized( regex )
+
rng | boost::adaptors::tokenized( regex, i )
+
rng | boost::adaptors::tokenized( regex, rndRng )
+
rng | boost::adaptors::tokenized( regex, i, flags )
+
rng | boost::adaptors::tokenized( regex, rndRng, flags )
+
boost::make_tokenized_range( rng, regex, i, flags )
+
boost::make_tokenized_range( rng, regex, rngRng, flags )
+
+
    +
  • + Precondition: +
      +
    • + Let T denote + typename range_value< decltype(rng) >::type, + then regex has the type + basic_regex<T> or is + implicitly convertible to one of these types. +
    • +
    • + i has the type int. +
    • +
    • + the value-type of rndRng is int. +
    • +
    • + flags has the type + regex_constants::syntax_option_type. +
    • +
    +
  • +
  • + 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_iterators might throw. +
  • +
  • + Range Category: + RandomAccessRange +
  • +
+
+

Example

+
+        #include <boost/range/adaptor/tokenized.hpp>
+        #include <boost/range/algorithm_ext/push_back.hpp>
+        #include <boost/assert.hpp>
+        #include <algorithm>
+        #include <string>
+        #include <vector>
+        
+        int main(int argc, const char* argv)
+        {
+            using namespace boost::adaptors;
+            
+            std::string input = "a b c d e f g hijklmnopqrstuvwxyz";
+            std::vector< boost::sub_match< std::string::iterator > > result;
+            boost::push_back(result, input | tokenized(boost::regex("\\b")));
+            
+            BOOST_ASSERT( boost::size(result) == 16u );
+            
+            return 0;
+        }
+    
+ +
+

+ (C) Copyright Neil Groves 2009 + (C) Copyright Thorsten Ottosen 2003-2004 +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + diff --git a/doc/reference/adaptors/tokenized.qbk b/doc/reference/adaptors/tokenized.qbk new file mode 100644 index 0000000..7b7504c --- /dev/null +++ b/doc/reference/adaptors/tokenized.qbk @@ -0,0 +1,42 @@ +[section:tokenized tokenized] + +[table + [[Syntax] [Code]] + [ + [Pipe] + [ + `` + rng | boost::adaptors::tokenized(regex) + rng | boost::adaptors::tokenized(regex, i) + rng | boost::adaptors::tokenized(regex, rndRng) + rng | boost::adaptors::tokenized(regex, i, flags) + rng | boost::adaptors::tokenized(regex, rndRng, flags) + `` + ] + ] + [ + [Function] + [ + `` + boost::adaptors::tokenize(rng, regex) + boost::adaptors::tokenize(rng, regex, i) + boost::adaptors::tokenize(rng, regex, rndRng) + boost::adaptors::tokenize(rng, regex, i, flags) + boost::adaptors::tokenize(rng, regex, rndRng, flags) + `` + ] + ] +] + +* [*Precondition:] + * Let `T` denote `typename range_value::type`, then `regex` has the type `basic_regex` or is implicitly convertible to one of these types. + * `i` has the type `int`. + * the `value_type` of `rndRng` is `int`. + * `flags` has the type `regex_constants::syntax_option_type`. +* [*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:] `RandomAccessRange` + +[endsect] + + diff --git a/doc/reference/adaptors/transformed.html b/doc/reference/adaptors/transformed.html new file mode 100755 index 0000000..4069f9a --- /dev/null +++ b/doc/reference/adaptors/transformed.html @@ -0,0 +1,107 @@ + + + + + + Boost.Range Range Adaptors + + + + + + + + + + +

Boost.Range

+ +

Range Adaptors

+ +
+ +

transformed

+
+
rng | boost::adaptors::transformed( fun )
+
boost::make_transformed_range( rng, fun )
+
+
    +
  • + Precondition: + The value-type of the range is convertible to the argument type + of fun. +
  • +
  • + 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: + SinglePassRange +
  • +
+
+

Example

+
+        #include <boost/range/adaptor/transformed.hpp>
+        #include <boost/range/algorithm/copy.hpp>
+        #include <boost/range/assign.hpp>
+        #include <algorithm>
+        #include <iostream>
+        #include <vector>
+        
+        struct double_int
+        {
+            typedef int result_type;
+            int operator()(int x) const { return x * 2; }
+        };
+        
+        int main(int argc, const char* argv[])
+        {
+            using namespace boost::adaptors;
+            using namespace boost::assign;
+            
+            std::vector<int> input;
+            input += 1,2,3,4,5,6,7,8,9,10;
+            
+            boost::copy(
+                input | transformed(double_int()),
+                std::ostream_iterator<int>(std::cout, ","));
+                
+            return 0;
+        }
+    
+

+ This produces the output:
+ + 2,4,6,8,10,12,14,16,18,20 + +

+ +
+

+ (C) Copyright Neil Groves 2009 + (C) Copyright Thorsten Ottosen 2003-2004 +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + diff --git a/doc/reference/adaptors/transformed.qbk b/doc/reference/adaptors/transformed.qbk new file mode 100644 index 0000000..3b64768 --- /dev/null +++ b/doc/reference/adaptors/transformed.qbk @@ -0,0 +1,52 @@ +[section:transformed transformed] + +[table + [[Syntax] [Code]] + [[Pipe] [`rng | boost::adaptors::transformed(fun)`]] + [[Function] [`boost::adaptors::transform(rng, fun)`]] +] + +* [*Precondition:] The `value_type` of the range is convertible to the argument type of `fun`. +* [*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:] `SinglePassRange` + +[section:transformed_example transformed example] +`` +#include +#include +#include +#include +#include +#include + +struct double_int +{ + typedef int result_type; + int operator()(int x) const { return x * 2; } +}; + +int main(int argc, const char* argv[]) +{ + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9,10; + + boost::copy( + input | transformed(double_int()), + std::ostream_iterator(std::cout, ",")); + + return 0; +} +`` +[endsect] + +This would produce the output: +`` +2,4,6,8,10,12,14,16,18,20 +`` +[endsect] + + diff --git a/doc/reference/adaptors/uniqued.html b/doc/reference/adaptors/uniqued.html new file mode 100755 index 0000000..43ca130 --- /dev/null +++ b/doc/reference/adaptors/uniqued.html @@ -0,0 +1,95 @@ + + + + + + Boost.Range Range Adaptors + + + + + + + + + + +

Boost.Range

+ +

Range Adaptors

+ +
+ +

uniqued

+
+
rng | boost::adaptors::uniqued
+
boost::make_uniqued_range( rng )
+
+
    +
  • + 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: + ForwardRange +
  • +
+ +
+

Example

+ +
+    #include <boost/range/adaptor/uniqued.hpp>
+    #include <boost/range/algorithm/copy.hpp>
+    #include <boost/assign.hpp>
+    #include <algorithm>
+    #include <iostream>
+    #include <vector>
+    
+    int main(int argc, const char* argv)
+    {
+        using namespace boost::assign;
+        using namespace boost::adaptors;
+        
+        std::vector<int> input;
+	input += 1,1,2,2,2,3,4,5,6;
+        
+	boost::copy(
+	    input | uniqued,
+            std::ostream_iterator<int>(std::cout, ",") );
+         
+        return 0;
+    }
+   
+

+ This would produce the output:
+ 1,2,3,4,5,6
+

+
+

+ (C) Copyright Neil Groves 2009 + (C) Copyright Thorsten Ottosen 2003-2004 +

+ +
+
+
+
+
+
+
+
+
+
+
+
+ + + diff --git a/doc/reference/adaptors/uniqued.qbk b/doc/reference/adaptors/uniqued.qbk new file mode 100644 index 0000000..a90cdde --- /dev/null +++ b/doc/reference/adaptors/uniqued.qbk @@ -0,0 +1,43 @@ +[section:uniqued uniqued] + +[table + [[Syntax] [Code]] + [[Pipe] [`rng | boost::adaptors::uniqued`]] + [[Function] [`boost::adaptors::unique(rng)`]] +] + +* [*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:] `ForwardRange` + +[section:uniqued_example uniqued example] +`` +#include +#include +#include +#include +#include +#include + +void uniqued_example_test() +{ + using namespace boost::assign; + using namespace boost::adaptors; + + std::vector input; + input += 1,1,2,2,2,3,4,5,6; + + boost::copy( + input | uniqued, + std::ostream_iterator(std::cout, ",")); +} +`` +[endsect] + +This would produce the output: +`` +1,2,3,4,5,6 +`` +[endsect] + + diff --git a/doc/reference/algorithm/adjacent_find.qbk b/doc/reference/algorithm/adjacent_find.qbk new file mode 100644 index 0000000..32c881e --- /dev/null +++ b/doc/reference/algorithm/adjacent_find.qbk @@ -0,0 +1,80 @@ +[section:adjacent_find Range Algorithm - adjacent_find] + +[heading Prototype] + +`` +template +typename range_iterator::type +adjacent_find(ForwardRange& rng); + +template +typename range_iterator::type +adjacent_find(const ForwardRange& rng); + +template +typename range_iterator::type +adjacent_find(ForwardRange& rng, BinaryPred pred); + +template +typename range_iterator::type +adjacent_find(const ForwardRange& rng, BinaryPred pred); + +template +typename range_return::type +adjacent_find(ForwardRange& rng); + +template +typename range_return::type +adjacent_find(const ForwardRange& rng); + +template< + range_return_value re, + class ForwardRange, + class BinaryPredicate + > +typename range_return::type +adjacent_find(ForwardRange& rng, BinaryPredicate pred); + +template< + range_return_value re, + class ForwardRange, + class BinaryPredicate + > +typename range_return::type +adjacent_find(const ForwardRange& rng, BinaryPredicate pred); +`` + +[heading Description] + +[*Non-predicate versions:] + +`adjacent_find` finds the first adjacent elements `[x,y]` in `rng` where `x == y` + +[*Predicate versions:] + +`adjacent_find` finds the first adjacent elements `[x,y]` in `rng` where `pred(x,y)` is `true`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/adjacent_find.hpp` + +[heading Requirements] + +[*For the non-predicate versions of adjacent_find:] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `ForwardRange`'s value type is a model of the `EqualityComparableConcept`. + +[*For the predicate versions of adjacent_find:] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `BinaryPredicate` is a model of the `BinaryPredicateConcept`. +* `ForwardRange`'s value type is convertible to `BinaryPredicate`'s first argument type and to `BinaryPredicate`'s second argument type. + +[heading Complexity] + +Linear. If `empty(rng)` then no comparisons are performed; otherwise, at most `distance(rng) - 1` comparisons. + +[endsect] + + diff --git a/doc/reference/algorithm/binary_search.qbk b/doc/reference/algorithm/binary_search.qbk new file mode 100644 index 0000000..542906f --- /dev/null +++ b/doc/reference/algorithm/binary_search.qbk @@ -0,0 +1,55 @@ +[section:binary_search binary_search] + +[heading Prototype] + +`` +template +bool binary_search(const ForwardRange& rng, const Value& val); + +template +bool binary_search(const ForwardRange& rng, const Value& val, BinaryPredicate pred); +`` + +[heading Description] + +`binary_search` returns `true` if and only if the value `val` exists in the range `rng`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/binary_search.hpp` + +[heading Requirements] + +[*For the non-predicate versions of binary_search:] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `Value` is a model of the `LessThanComparableConcept`. +* The ordering of objects of type `Value` is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. +* `ForwardRange`'s value type is the same type as `Value`. + +[*For the predicate versions of binary_search:] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`. +* `ForwardRange`'s value type is the same type as `Value`. +* `ForwardRange`'s value type is convertible to `BinaryPredicate`'s argument type. + +[heading Precondition:] + +[*For the non-predicate version:] + +`rng` is ordered in ascending order according to `operator<`. + +[*For the predicate version:] + +`rng` is ordered in ascending order according to the function object `pred`. + +[heading Complexity] + +For non-random-access ranges, the complexity is `O(N)` where `N` is `distance(rng)`. + +For random-access ranges, the complexity is `O(log N)` where `N` is `distance(rng)`. + +[endsect] + + diff --git a/doc/reference/algorithm/copy.qbk b/doc/reference/algorithm/copy.qbk new file mode 100644 index 0000000..70dd3a3 --- /dev/null +++ b/doc/reference/algorithm/copy.qbk @@ -0,0 +1,36 @@ +[section:copy Range Algorithm - copy] + +[heading Prototype] + +`` +template +OutputIterator copy(const SinglePassRange& source_rng, OutputIterator out_it); +`` + +[heading Description] + +`copy` copies all elements from `source_rng` to the range `[out_it, out_it + distance(source_rng))`. +The return value is `out_it + distance(source_rng)` + +[heading Definition] + +Defined in the header file `boost/range/algorithm/copy.hpp` + +[heading Requirements] + +* `SinglePassRange` is a model of the __single_pass_range__ Concept. +* `OutputIterator` is a model of the `OutputIteratorConcept`. +* The `value_type` of __single_pass_range__ Concept is convertible to a type in `OutputIterator`'s set of value types. + +[heading Precondition:] + +* `out_it` is not an iterator within the `source_rng`. +* `[out_it, out_it + distance(source_rng))` is a valid range. + +[heading Complexity] + +Linear. Exactly `distance(source_rng)` assignments are performed. + +[endsect] + + diff --git a/doc/reference/algorithm/copy_backward.qbk b/doc/reference/algorithm/copy_backward.qbk new file mode 100644 index 0000000..f6aa444 --- /dev/null +++ b/doc/reference/algorithm/copy_backward.qbk @@ -0,0 +1,41 @@ +[section:copy_backward Range Algorithm - copy_backward] + +[heading Prototype] + +`` +template + BidirectionalOutputIterator + copy_backward(const BidirectionalRange& source_rng, + BidirectionalOutputIterator out_it); +`` + +[heading Description] + +`copy_backward` copies all elements from `source_rng` to the range `[out_it - distance(source_rng), out_it)`. + +The values are copied in reverse order. The return value is `out_it - distance(source_rng)`. + +Note well that unlike all other standard algorithms `out_it` denotes the *end* of the output sequence. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/copy_backward.hpp` + +[heading Requirements] + +* `BidirectionalRange` is a model of __bidirectional_range__ Concept. +* `OutputIterator` is a model of the `OutputIteratorConcept`. +* The `value_type` of __bidirectional_range__ Concept is convertible to a type in `OutputIterator`'s set of value types. + +[heading Precondition:] + +* `out_it` is not an iterator within the `source_rng`. +* `[out_it, out_it + distance(source_rng))` is a valid range. + +[heading Complexity] + +Linear. Exactly `distance(source_rng)` assignments are performed. + +[endsect] + + diff --git a/doc/reference/algorithm/count.qbk b/doc/reference/algorithm/count.qbk new file mode 100644 index 0000000..3a41ec8 --- /dev/null +++ b/doc/reference/algorithm/count.qbk @@ -0,0 +1,36 @@ +[section:count count] + +[heading Prototype] + +`` +template +typename range_difference::type +count(SinglePassRange& rng, const Value& val); + +template +typename range_difference::type +count(const SinglePassRange& rng, const Value& val); +`` + +[heading Description] + +`count` returns the number of elements `x` in `rng` where `x == val` is `true`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/count.hpp` + +[heading Requirements] + +* `SinglePassRange` is a model of the __single_pass_range__ Concept. +* `Value` is a model of the `EqualityComparableConcept`. +* `SinglePassRange`'s value type is a model of the `EqualityComparableConcept`. +* An object of `SinglePassRange`'s value type can be compared for equality with an object of type `Value`. + +[heading Complexity] + +Linear. Exactly `distance(rng)` comparisons. + +[endsect] + + diff --git a/doc/reference/algorithm/equal.qbk b/doc/reference/algorithm/equal.qbk new file mode 100644 index 0000000..278fe45 --- /dev/null +++ b/doc/reference/algorithm/equal.qbk @@ -0,0 +1,59 @@ +[section:equal equal] + +[heading Prototype] + +`` +template< + class SinglePassRange1, + class SinglePassRange2 +> +bool equal(const SinglePassRange1& rng1, + const SinglePassRange2& rng2); + +template< + class SinglePassRange1, + class SinglePassRange2, + class BinaryPredicate +> +bool equal(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + BinaryPredicate pred); +`` + +[heading Description] + +`equal` returns `true` if `distance(rng1)` is equal to the `distance(rng2)` and for each element `x` in `rng1`, the corresponding element `y` in `rng2` is equal. Otherwise `false` is returned. + +In this range version of `equal` it is perfectly acceptable to pass in two ranges of unequal lengths. + +Elements are considered equal in the non-predicate version if `operator==` returns `true`. Elements are considered equal in the predicate version if `pred(x,y)` is `true`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/equal.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `SinglePassRange1`'s value type is a model of the `EqualityComparableConcept`. +* `SinglePassRange2`'s value type is a model of the `EqualityComparableConcept`. +* `SinglePassRange1`'s value type can be compared for equality with `SinglePassRange2`'s value type. + +[*For the predicate versions:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `BinaryPredicate` is a model of the `BinaryPredicateConcept`. +* `SinglePassRange1`'s value type is convertible to `BinaryPredicate`'s first argument type. +* `SinglePassRange2`'s value type is convertible to `BinaryPredicate`'s second argument type. + +[heading Complexity] + +Linear. At most `min(distance(rng1), distance(rng2))` comparisons. + +[endsect] + + diff --git a/doc/reference/algorithm/equal_range.qbk b/doc/reference/algorithm/equal_range.qbk new file mode 100644 index 0000000..6d9650a --- /dev/null +++ b/doc/reference/algorithm/equal_range.qbk @@ -0,0 +1,78 @@ +[section:equal_range equal_range] + +[heading Prototype] + +`` +template< + class ForwardRange, + class Value + > +std::pair::type, + typename range_iterator::type> +equal_range(ForwardRange& rng, const Value& val); + +template< + class ForwardRange, + class Value + > +std::pair::type, + typename range_iterator::type> +equal_range(const ForwardRange& rng, const Value& val); + +template< + class ForwardRange, + class Value, + class SortPredicate + > +std::pair::type, + typename range_iterator::type> +equal_range(ForwardRange& rng, const Value& val, SortPredicate pred); + +template< + class ForwardRange, + class Value, + class SortPredicate + > +std::pair::type, + typename range_iterator::type> +equal_range(const ForwardRange& rng, const Value& val, SortPredicate pred); + `` + +[heading Description] + +`equal_range` returns a range in the form of a pair of iterators where all of the elements are equal to `val`. If no values are found that are equal to `val`, then an empty range is returned, hence `result.first == result.second`. For the non-predicate versions of `equal_range` the equality of elements is determined by `operator<`. +For the predicate versions of `equal_range` the equality of elements is determined by `pred`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/equal_range.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `Value` is a model of the `LessThanComparableConcept`. +* The ordering of objects of type `Value` is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. +* `ForwardRange`'s value type is the same type as `Value`. + +[*For the predicate versions:] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `SortPredicate` is a model of the `StrictWeakOrderingConcept`. +* `ForwardRange`'s value type is the same as `Value`. +* `ForwardRange`'s value type is convertible to both of `SortPredicate`'s argument types. + +[heading Precondition:] + +For the non-predicate versions: `rng` is ordered in ascending order according to `operator<`. + +For the predicate versions: `rng` is ordered in ascending order according to `pred`. + +[heading Complexity] + +For random-access ranges, the complexity is `O(log N)`, otherwise the complexity is `O(N)`. + +[endsect] + + diff --git a/doc/reference/algorithm/fill.qbk b/doc/reference/algorithm/fill.qbk new file mode 100644 index 0000000..e8419ab --- /dev/null +++ b/doc/reference/algorithm/fill.qbk @@ -0,0 +1,34 @@ +[section:fill Range Algorithm - fill] + +[heading Prototype] + +`` +template +void fill( ForwardRange& rng, const Value& val ); + +template +void fill( const ForwardRange& rng, const Value& val ); +`` + +[heading Description] + +`fill` assigns the value `val` to every element in the range `rng`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/fill.hpp` + +[heading Requirements] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `ForwardRange` is mutable. +* `Value` is a model of the `AssignableConcept`. +* `Value` is convertible to `ForwardRange`'s value type. + +[heading Complexity] + +Linear. Exactly `distance(rng)` assignments are performed. + +[endsect] + + diff --git a/doc/reference/algorithm/find.qbk b/doc/reference/algorithm/find.qbk new file mode 100644 index 0000000..38d5507 --- /dev/null +++ b/doc/reference/algorithm/find.qbk @@ -0,0 +1,40 @@ +[section:find find] + +[heading Prototype] + +`` +template +typename range_iterator::type +find(SinglePassRange& rng, Value val); + +template< + range_return_value re, + class SinglePassRange, + class Value + > +typename range_return::type +find(SinglePassRange& rng, Value val); +`` + +[heading Description] + +The versions of `find` that return an iterator, returns the first iterator in the range `rng` such that `*i == value`. `end(rng)` is returned if no such iterator exists. +The versions of find that return a `range_return`, defines `found` in the same manner as the returned iterator described above. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/find.hpp` + +[heading Requirements] + +* `SinglePassRange` is a model of the __single_pass_range__ Concept. +* `Value` is a model of the `EqualityComparableConcept`. +* The `operator==` is defined for type `Value` to be compared with the `SinglePassRange`'s value type. + +[heading Complexity] + +Linear. At most `distance(rng)` comparisons for equality. + +[endsect] + + diff --git a/doc/reference/algorithm/find_end.qbk b/doc/reference/algorithm/find_end.qbk new file mode 100644 index 0000000..a5999ce --- /dev/null +++ b/doc/reference/algorithm/find_end.qbk @@ -0,0 +1,69 @@ +[section:find_end find_end] + +[heading Prototype] + +`` +template +typename range_iterator::type +find_end(ForwardRange1& rng1, const ForwardRange2& rng2); + +template< + class ForwardRange1, + class ForwardRange2, + class BinaryPredicate + > +typename range_iterator::type +find_end(ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred); + +template< + range_return_value re, + class ForwardRange1, + class ForwardRange2 + > +typename range_return::type +find_end(ForwardRange1& rng1, const ForwardRange2& rng2); + +template< + range_return_value re, + class ForwardRange1, + class ForwardRange2, + class BinaryPredicate + > +typename range_return::type +find_end(ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred); +`` + +[heading Description] + +The versions of `find_end` that return an iterator, return an iterator to the beginning of the last sub-sequence equal to `rng2` within `rng1`. +Equality is determined by `operator==` for non-predicate versions of `find_end`, and by satisfying `pred` in the predicate versions. The versions of `find_end` that return a `range_return`, defines `found` in the same manner as the returned iterator described above. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/find_end.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `ForwardRange1` is a model of the __forward_range__ Concept. +* `ForwardRange2` is a model of the __forward_range__ Concept. +* `ForwardRange1`'s value type is a model of the `EqualityComparableConcept`. +* `ForwardRange2`'s value type is a model of the `EqualityComparableConcept`. +* Objects of `ForwardRange1`'s value type can be compared for equality with objects of `ForwardRange2`'s value type. + +[*For the predicate versions:] + +* `ForwardRange1` is a model of the __forward_range__ Concept. +* `ForwardRange2` is a model of the __forward_range__ Concept. +* `BinaryPredicate` is a model of the `BinaryPredicateConcept`. +* `ForwardRange1`'s value type is convertible to `BinaryPredicate`'s first argument type. +* `ForwardRange2`'s value type is convertible to `BinaryPredicate`'s second argument type. + +[heading Complexity] + +The number of comparisons is proportional to `distance(rng1) * distance(rng2)`. If both `ForwardRange1` and `ForwardRange2` are models of `BidirectionalRangeConcept` then the average complexity is linear and the worst case is `distance(rng1) * distance(rng2)`. + +[endsect] + + diff --git a/doc/reference/algorithm/find_first_of.qbk b/doc/reference/algorithm/find_first_of.qbk new file mode 100644 index 0000000..a6af825 --- /dev/null +++ b/doc/reference/algorithm/find_first_of.qbk @@ -0,0 +1,69 @@ +[section:find_first_of find_first_of] + +[heading Prototype] + +`` +template +typename range_iterator::type +find_first_of(SinglePassRange1& rng1, const ForwardRange2& rng2); + +template< + class SinglePassRange1, + class ForwardRange2, + class BinaryPredicate + > +typename range_iterator::type +find_first_of(SinglePassRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred); + +template< + range_return_value re, + class SinglePassRange1, + class ForwardRange2 + > +typename range_return::type +find_first_of(SinglePassRange1& rng1, const ForwardRange2& rng2); + +template< + range_return_value re, + class SinglePassRange1, + class ForwardRange2, + class BinaryPredicate + > +typename range_return::type +find_first_of(SinglePassRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred); +`` + +[heading Description] + +The versions of `find_first_of` that return an iterator, return an iterator to the first occurrence in `rng1` of any of the elements in `rng2`. +Equality is determined by `operator==` for non-predicate versions of `find_first_of`, and by satisfying `pred` in the predicate versions. + +The versions of `find_first_of` that return a `range_return`, defines `found` in the same manner as the returned iterator described above. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/find_first_of.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `ForwardRange2` is a model of the __forward_range__ Concept. +* `SinglePassRange1`'s value type is a model of the `EqualityComparableConcept`, and can be compared for equality with `ForwardRange2`'s value type. + +[*For the predicate versions:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `ForwardRange2` is a model of the __forward_range__ Concept. +* `BinaryPredicate` is a model of the `BinaryPredicateConcept`. +* `SinglePassRange1`'s value type is convertible to `BinaryPredicate`'s first argument type. +* `ForwardRange2`'s value type is convertible to `BinaryPredicate`'s second argument type. + +[heading Complexity] + +At most `distance(rng1) * distance(rng2)` comparisons. + +[endsect] + + diff --git a/doc/reference/algorithm/find_if.qbk b/doc/reference/algorithm/find_if.qbk new file mode 100644 index 0000000..862d8a1 --- /dev/null +++ b/doc/reference/algorithm/find_if.qbk @@ -0,0 +1,45 @@ +[section:find_if find_if] + +[heading Prototype] + +`` +template +typename range_iterator::type +find_if(SinglePassRange& rng, UnaryPredicate pred); + +template< + range_return_value re, + class SinglePassRange, + class UnaryPredicate + > +typename range_return::type +find_if(SinglePassRange& rng, UnaryPredicate pred); +`` + +[heading Description] + +The versions of `find_if` that return an iterator, returns the first iterator in the range `rng` such that `pred(*i)` is `true`. `end(rng)` is returned if no such iterator exists. + +The versions of `find_if` that return a `range_return`, defines found in the same manner as the returned iterator described above. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/find_if.hpp` + +[heading Requirements] + +* `SinglePassRange` is a model of the __single_pass_range__ Concept. +* `UnaryPredicate` is a model of the `PredicateConcept`. +* The value type of `SinglePassRange` is convertible to the argument type of `UnaryPredicate`. + +[heading Precondition:] + +For each iterator `i` in `rng`, `*i` is in the domain of `UnaryPredicate`. + +[heading Complexity] + +Linear. At most `distance(rng)` invocations of `pred`. + +[endsect] + + diff --git a/doc/reference/algorithm/for_each.qbk b/doc/reference/algorithm/for_each.qbk new file mode 100644 index 0000000..a11530c --- /dev/null +++ b/doc/reference/algorithm/for_each.qbk @@ -0,0 +1,40 @@ +[section:for_each for_each] + +[heading Prototype] + +`` +template< + class SinglePassRange, + class UnaryFunction + > +UnaryFunction for_each(SinglePassRange& rng, UnaryFunction fun); + +template< + class SinglePassRange, + class UnaryFunction + > +UnaryFunction for_each(const SinglePassRange& rng, UnaryFunction fun); +`` + +[heading Description] + +`for_each` traverses forward through `rng` and for each element `x` it invokes `fun(x)`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/for_each.hpp` + +[heading Requirements] + +* `SinglePassRange` is a model of the __single_pass_range__ Concept. +* `UnaryFunction` is a model of the `UnaryFunctionConcept`. +* `UnaryFunction` does not apply any non-constant operation through its argument. +* `SinglePassRange`'s value type is convertible to `UnaryFunction`'s argument type. + +[heading Complexity] + +Linear. Exactly `distance(rng)` applications of `UnaryFunction`. + +[endsect] + + diff --git a/doc/reference/algorithm/generate.qbk b/doc/reference/algorithm/generate.qbk new file mode 100644 index 0000000..adc85af --- /dev/null +++ b/doc/reference/algorithm/generate.qbk @@ -0,0 +1,39 @@ +[section:generate Range Algorithm - generate] + +[heading Prototype] + +`` +template +ForwardRange& generate( ForwardRange& rng, Generator gen ); + +template +const ForwardRange& generate( const ForwardRange& rng, Generator gen ); +`` + +[heading Description] + +`generate` assigns the result of `gen()` to each element in range `rng`. Returns the resultant range. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/generate.hpp` + +[heading Requirements] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `ForwardRange` is mutable. +* `Generator` is a model of the `GeneratorConcept`. +* The `value_type` of `SinglePassRange` is convertible to a type in `OutputIterator`'s set of value types. + +[heading Precondition:] + +* `out_it` is not an iterator within `rng`. +* `[out_it, out_it + distance(rng))` is a valid range. + +[heading Complexity] + +Linear. Exactly `distance(rng)` assignments are performed. + +[endsect] + + diff --git a/doc/reference/algorithm/includes.qbk b/doc/reference/algorithm/includes.qbk new file mode 100644 index 0000000..5b7eb84 --- /dev/null +++ b/doc/reference/algorithm/includes.qbk @@ -0,0 +1,64 @@ +[section:includes includes] + +[heading Prototype] + +`` +template +bool includes(const SinglePassRange1& rng1, const SinglePassRange2& rng2); + +template< + class SinglePassRange1, + class SinglePassRange2, + class BinaryPredicate + > +bool includes(const SinglePassRange1& rng1, const SinglePassRange2& rng2, + BinaryPredicate pred); +`` + +[heading Description] + +`includes` returns `true` if and only if, for every element in `rng2`, an equivalent element is also present in `rng1`. +The ordering relationship is determined by using `operator<` in the non-predicate versions, and by evaluating `pred` in the predicate versions. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/set_algorithm.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `SinglePassRange1` and `SinglePassRange2` have the same value type. +* `SinglePassRange1`'s value type is a model of the `LessThanComparableConcept`. +* `SinglePassRange2`'s value type is a model of the `LessThanComparableConcept`. +* The ordering of objects of type `SinglePassRange1`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. +* The ordering of objects of type `SinglePassRange2`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. + +[*For the predicate versions:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `SinglePassRange1` and `SinglePassRange2` have the same value type. +* `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`. +* `SinglePassRange1`'s value type is convertible to `BinaryPredicate`'s first argument type. +* `SinglePassRange2`'s value type is convertible to `BinaryPredicate`'s second argument types. + +[heading Precondition:] + +[*For the non-predicate versions:] + +`rng1` and `rng2` are sorted in ascending order according to `operator<`. + +[*For the predicate versions:] + +`rng1` and `rng2` are sorted in ascending order according to `pred`. + +[heading Complexity] + +Linear. `O(N)`, where `N` is `distance(rng1) + distance(rng2)`. + +[endsect] + + diff --git a/doc/reference/algorithm/inplace_merge.qbk b/doc/reference/algorithm/inplace_merge.qbk new file mode 100644 index 0000000..a393423 --- /dev/null +++ b/doc/reference/algorithm/inplace_merge.qbk @@ -0,0 +1,72 @@ +[section:inplace_merge Range Algorithm - inplace_merge] + +[heading Prototype] + +`` +template +BidirectionalRange& +inplace_merge( BidirectionalRange& rng, + typename range_iterator::type middle ); + +template +const BidirectionalRange& +inplace_merge( const BidirectionalRange& rng, + typename range_iterator::type middle ); + +template +BidirectionalRange& +inplace_merge( BidirectionalRange& rng, + typename range_iterator::type middle, + BinaryPredicate pred ); + +template +const BidirectionalRange& +inplace_merge( const BidirectionalRange& rng, + typename range_iterator::type middle, + BinaryPredicate pred ); +`` + +[heading Description] + +`inplace_merge` combines two consecutive sorted ranges `[begin(rng), middle)` and `[middle, end(rng))` into a single sorted range `[begin(rng), end(rng))`. That is, it starts with a range `[begin(rng), end(rng))` that consists of two pieces each of which is in ascending order, and rearranges it so that the entire range is in ascending order. `inplace_merge` is stable, meaning both that the relative order of elements within each input range is preserved. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/inplace_merge.hpp` + +[heading Requirements] + +[*For the non-predicate version:] + +* `BidirectionalRange` is a model of the __bidirectional_range__ Concept. +* `BidirectionalRange` is mutable. +* `range_value::type` is a model of `LessThanComparableConcept` +* The ordering on objects of `range_type::type` is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. + +[*For the predicate version:] +* `BidirectionalRange` is a model of the __bidirectional_range__ Concept. +* `BidirectionalRange` is mutable. +* `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`. +* `BidirectionalRange`'s value type is convertible to both `BinaryPredicate`'s argument types. + +[heading Precondition:] + +[heading For the non-predicate version:] + +* `middle` is in the range `rng`. +* `[begin(rng), middle)` is in ascending order. That is for each pair of adjacent elements `[x,y]`, `y < x` is `false`. +* `[middle, end(rng))` is in ascending order. That is for each pair of adjacent elements `[x,y]`, `y < x` is `false`. + +[heading For the predicate version:] + +* `middle` is in the range `rng`. +* `[begin(rng), middle)` is in ascending order. That is for each pair of adjacent elements `[x,y]`, `pred(y,x) == false`. +* `[middle, end(rng))` is in ascending order. That is for each pair of adjacent elements `[x,y]`, `pred(y,x) == false`. + +[heading Complexity] + +Worst case: `O(N log(N))` + +[endsect] + + diff --git a/doc/reference/algorithm/lexicographical_compare.qbk b/doc/reference/algorithm/lexicographical_compare.qbk new file mode 100644 index 0000000..16d155d --- /dev/null +++ b/doc/reference/algorithm/lexicographical_compare.qbk @@ -0,0 +1,55 @@ +[section:lexicographical_compare lexicographical_compare] + +[heading Prototype] + +`` +template< + class SinglePassRange1, + class SinglePassRange2 + > +bool lexicographical_compare(const SinglePassRange1& rng1, + const SinglePassRange2& rng2); + +template< + class SinglePassRange1, + class SinglePassRange2, + class BinaryPredicate + > +bool lexicographical_compare(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + BinaryPredicate pred); +`` + +[heading Description] + +`lexicographical_compare` compares element by element `rng1` against `rng2`. If the element from `rng1` is less than the element from `rng2` then `true` is returned. If the end of `rng1` without reaching the end of `rng2` this also causes the return value to be `true`. The return value is `false` in all other circumstances. The elements are compared using `operator<` in the non-predicate versions of `lexicographical_compare` and using `pred` in the predicate versions. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/lexicographical_compare.hpp` + +[heading Requirements] + +[*For the non-predicate versions of lexicographical_compare:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `SinglePassRange1`'s value type is a model of the `LessThanComparableConcept`. +* `SinglePassRange2`'s value type is a model of the `LessThanComparableConcept`. +* Let `x` be an object of `SinglePassRange1`'s value type. Let `y` be an obect of `SinglePassRange2`'s value type. `x < y` must be valid. `y < x` must be valid. + +[*For the predicate versions of lexicographical_compare:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `BinaryPredicate` is a model of the `BinaryPredicateConcept`. +* `SinglePassRange1`'s value type is convertible to `BinaryPredicate`'s first argument type. +* `SinglePassRange2`'s value type is convertible to `BinaryPredicate`'s second argument type. + +[heading Complexity] + +Linear. At most `2 * min(distance(rng1), distance(rng2))` comparisons. + +[endsect] + + diff --git a/doc/reference/algorithm/lower_bound.qbk b/doc/reference/algorithm/lower_bound.qbk new file mode 100644 index 0000000..6228928 --- /dev/null +++ b/doc/reference/algorithm/lower_bound.qbk @@ -0,0 +1,68 @@ +[section:lower_bound lower_bound] + +[heading Prototype] + +`` +template +typename range_iterator::type +lower_bound(ForwardRange& rng, Value val); + +template< + range_return_value re, + class ForwardRange, + class Value + > +typename range_return::type +lower_bound(ForwardRange& rng, Value val); +`` + +[heading Description] + +The versions of `lower_bound` that return an iterator, returns the first iterator in the range `rng` such that: +without predicate - `*i < value` is `false`, +with predicate - `pred(*i, value)` is `false`. + +`end(rng)` is returned if no such iterator exists. + +The versions of `lower_bound` that return a `range_return`, defines `found` in the same manner as the returned iterator described above. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/lower_bound.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `Value` is a model of the `LessThanComparableConcept`. +* The ordering of objects of type `Value` is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. +* `ForwardRange`'s value type is the same type as `Value`. + +[*For the predicate versions:] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`. +* `ForwardRange`'s value type is the same type as `Value`. +* `ForwardRange`'s value type is convertible to both of `BinaryPredicate`'s argument types. + +[heading Precondition:] + +[*For the non-predicate versions:] + +`rng` is sorted in ascending order according to `operator<`. + +[*For the predicate versions:] + +`rng` is sorted in ascending order according to `pred`. + +[heading Complexity] + +For ranges that model the __random_access_range__ concept the complexity is `O(log N)`, where `N` is `distance(rng)`. + +For all other range types the complexity is `O(N)`. + + +[endsect] + + diff --git a/doc/reference/algorithm/make_heap.qbk b/doc/reference/algorithm/make_heap.qbk new file mode 100644 index 0000000..6f54a15 --- /dev/null +++ b/doc/reference/algorithm/make_heap.qbk @@ -0,0 +1,51 @@ +[section:make_heap make_heap] + +[heading Prototype] + +`` +template +void make_heap(RandomAccessRange& rng); + +template +void make_heap(const RandomAccessRange& rng); + +template +void make_heap(RandomAccessRange& rng, Compare pred); + +template +void make_heap(const RandomAccessRange& rng, Compare pred); +`` + +[heading Description] + +`make_heap` turns `rng` into a heap. + +The ordering relationship is determined by using `operator<` in the non-predicate versions, and by evaluating `pred` in the predicate versions. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/heap_algorithm.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `RandomAccessRange` is mutable. +* `RandomAccessRange`'s value type is a model of the `LessThanComparableConcept`. +* The ordering of objects of type `RandomAccessRange`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. + +[*For the predicate versions:] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `RandomAccessRange` is mutable. +* `Compare` is a model of the `StrictWeakOrderingConcept`. +* `RandomAccessRange`'s value type is convertible to both of `Compare`'s argument types. + +[heading Complexity] + +Linear. At most `3 * distance(rng)` comparisons. + +[endsect] + + diff --git a/doc/reference/algorithm/max_element.qbk b/doc/reference/algorithm/max_element.qbk new file mode 100644 index 0000000..35cc0ed --- /dev/null +++ b/doc/reference/algorithm/max_element.qbk @@ -0,0 +1,81 @@ +[section:max_element max_element] + +[heading Prototype] + +`` +template +typename range_iterator::type +max_element(ForwardRange& rng); + +template +typename range_iterator::type +max_element(const ForwardRange& rng); + +template +typename range_iterator::type +max_element(ForwardRange& rng, BinaryPredicate pred); + +template +typename range_iterator::type +max_element(const ForwardRange& rng, BinaryPredicate pred); + + +template< + range_return_value re, + class ForwardRange + > +typename range_return::type +max_element(ForwardRange& rng); + +template< + range_return_value_re, + class ForwardRange + > +typename range_return::type +max_element(const ForwardRange& rng); + +template< + range_return_value re, + class ForwardRange, + class BinaryPredicate + > +typename range_return::type +max_element(ForwardRange& rng, BinaryPredicate pred); + +template< + range_return_value re, + class ForwardRange, + class BinaryPredicate + > +typename range_return::type +max_element(const ForwardRange& rng, BinaryPredicate pred); +`` + +[heading Description] + +The versions of `max_element` that return an iterator, return the iterator to the maximum value as determined by using `operator<` if a predicate is not supplied. Otherwise the predicate `pred` is used to determine the maximum value. The versions of `max_element` that return a `range_return`, defines `found` in the same manner as the returned iterator described above. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/max_element.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `ForwardRange`'s value type is a model of the `LessThanComparableConcept`. + +[*For the predicate versions:] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `BinaryPredicate` is a model of the `BinaryPredicateConcept`. +* `ForwardRange`'s value type is convertible to both of `BinaryPredicate`'s argument types. + +[heading Complexity] + +Linear. Zero comparisons if `empty(rng)`, otherwise `distance(rng) - 1` comparisons. + +[endsect] + + diff --git a/doc/reference/algorithm/merge.qbk b/doc/reference/algorithm/merge.qbk new file mode 100644 index 0000000..edfed92 --- /dev/null +++ b/doc/reference/algorithm/merge.qbk @@ -0,0 +1,83 @@ +[section:merge Range Algorithm - merge] + +[heading Prototype] + +`` +template< + class SinglePassRange1, + class SinglePassRange2, + class OutputIterator + > +OutputIterator merge(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out); + +template< + class SinglePassRange1, + class SinglePassRange2, + class OutputIterator, + class BinaryPredicate + > +OutputIterator merge(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out, + BinaryPredicate pred); +`` + +[heading Description] + +`merge` combines two sorted ranges `rng1` and `rng2` into a single sorted range by copying elements. `merge` is stable. The return value is `out + distance(rng1) + distance(rng2)`. + +The two versions of `merge` differ by how they compare the elements. + +The non-predicate version uses the `operator<()` for the range value type. The predicate version uses the predicate instead of `operator<()`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/merge.hpp` + +[heading Requirements] + +[*For the non-predicate version:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `range_value::type` is the same as `range_value::type`. +* `range_value::type` is a model of the `LessThanComparableConcept`. +* The ordering on objects of `range_value::type` is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. +* `range_value::type` is convertible to a type in `OutputIterator`'s set of value types. + +[*For the predicate version:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `range_value::type` is the same as `range_value::type`. +* `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`. +* `SinglePassRange1`'s value type is convertible to both `BinaryPredicate`'s argument types. +* `range_value::type` is convertible to a type in `OutputIterator`'s set of value types. + +[heading Precondition:] + +[heading For the non-predicate version:] + +* The elements of `rng1` are in ascending order. That is, for each adjacent element pair `[x,y]` of `rng1`, `y < x == false`. +* The elements of `rng2` are in ascending order. That is, for each adjacent element pair `[x,y]` of `rng2`, `y < x == false`. +* The ranges `rng1` and `[out, out + distance(rng1) + distance(rng2))` do not overlap. +* The ranges `rng2` and `[out, out + distance(rng1) + distance(rng2))` do not overlap. +* `[out, out + distance(rng1) + distance(rng2))` is a valid range. + +[heading For the predicate version:] + +* The elements of `rng1` are in ascending order. That is, for each adjacent element pair `[x,y]`, of `rng1`, `pred(y, x) == false`. +* The elements of `rng2` are in ascending order. That is, for each adjacent element pair `[x,y]`, of `rng2`, `pred(y, x) == false`. +* The ranges `rng1` and `[out, out + distance(rng1) + distance(rng2))` do not overlap. +* The ranges `rng2` and `[out, out + distance(rng1) + distance(rng2))` do not overlap. +* `[out, out + distance(rng1) + distance(rng2))` is a valid range. + +[heading Complexity] + +Linear. There are no comparisons if both `rng1` and `rng2` are empty, otherwise at most `distance(rng1) + distance(rng2) - 1` comparisons. + +[endsect] + + diff --git a/doc/reference/algorithm/min_element.qbk b/doc/reference/algorithm/min_element.qbk new file mode 100644 index 0000000..3977f09 --- /dev/null +++ b/doc/reference/algorithm/min_element.qbk @@ -0,0 +1,81 @@ +[section:min_element min_element] + +[heading Prototype] + +`` +template +typename range_iterator::type +min_element(ForwardRange& rng); + +template +typename range_iterator::type +min_element(const ForwardRange& rng); + +template +typename range_iterator::type +min_element(ForwardRange& rng, BinaryPredicate pred); + +template +typename range_iterator::type +min_element(const ForwardRange& rng, BinaryPredicate pred); + + +template< + range_return_value re, + class ForwardRange + > +typename range_return::type +min_element(ForwardRange& rng); + +template< + range_return_value_re, + class ForwardRange + > +typename range_return::type +min_element(const ForwardRange& rng); + +template< + range_return_value re, + class ForwardRange, + class BinaryPredicate + > +typename range_return::type +min_element(ForwardRange& rng, BinaryPredicate pred); + +template< + range_return_value re, + class ForwardRange, + class BinaryPredicate + > +typename range_return::type +min_element(const ForwardRange& rng, BinaryPredicate pred); +`` + +[heading Description] + +The versions of `min_element` that return an iterator, return the iterator to the minimum value as determined by using `operator<` if a predicate is not supplied. Otherwise the predicate `pred` is used to determine the minimum value. The versions of `min_element` that return a `range_return`, defines `found` in the same manner as the returned iterator described above. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/min_element.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `ForwardRange`'s value type is a model of the `LessThanComparableConcept`. + +[*For the predicate versions:] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `BinaryPredicate` is a model of the `BinaryPredicateConcept`. +* `ForwardRange`'s value type is convertible to both of `BinaryPredicate`'s argument types. + +[heading Complexity] + +Linear. Zero comparisons if `empty(rng)`, otherwise `distance(rng) - 1` comparisons. + +[endsect] + + diff --git a/doc/reference/algorithm/mismatch.qbk b/doc/reference/algorithm/mismatch.qbk new file mode 100644 index 0000000..f470092 --- /dev/null +++ b/doc/reference/algorithm/mismatch.qbk @@ -0,0 +1,116 @@ +[section:mismatch mismatch] + +[heading Prototype] + +`` +template +std::pair< + typename range_iterator::type, + typename range_iterator::type > +mismatch(SinglePassRange1& rng1, const SinglePassRange2& rng2); + +template +std::pair< + typename range_iterator::type, + typename range_iterator::type > +mismatch(const SinglePassRange1& rng1, const SinglePassRange2& rng2); + +template +std::pair< + typename range_iterator::type, + typename range_iterator::type > +mismatch(SinglePassRange1& rng1, SinglePassRange2& rng2); + +template +std::pair< + typename range_iterator::type, + typename range_iterator::type > +mismatch(const SinglePassRange1& rng1, SinglePassRange2& rng2); + + +template< + class SinglePassRange1, + class SinglePassRange2, + class BinaryPredicate + > +std::pair< + typename range_iterator::type, + typename range_iterator::type > +mismatch(SinglePassRange1& rng1, const SinglePassRange2& rng2, + BinaryPredicate pred); + +template< + class SinglePassRange1, + class SinglePassRange2, + class BinaryPredicate + > +std::pair< + typename range_iterator::type, + typename range_iterator::type > +mismatch(const SinglePassRange1& rng1, const SinglePassRange2& rng2, + BinaryPredicate pred); + +template< + class SinglePassRange1, + class SinglePassRange2, + class BinaryPredicate + > +std::pair< + typename range_iterator::type, + typename range_iterator::type > +mismatch(SinglePassRange1& rng1, SinglePassRange2& rng2, + BinaryPredicate pred); + +template< + class SinglePassRange1, + class SinglePassRange2, + class BinaryPredicate + > +std::pair< + typename range_iterator::type, + typename range_iterator::type > +mismatch(const SinglePassRange1& rng1, SinglePassRange2& rng2, + BinaryPredicate pred); +`` + +[heading Description] + +The versions of `mismatch` that return an iterator, return an iterator to the first position where `rng1` and `rng2` differ. + +Equality is determined by `operator==` for non-predicate versions of `mismatch`, and by satisfying `pred` in the predicate versions. + +The versions of `mismatch` that return a `range_return`, defines `found` in the same manner as the returned iterator described above. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/mismatch.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `SinglePassRange1`'s value type is a model of the `EqualityComparableConcept`. +* `SinglePassRange2`'s value type is a model of the `EqualityComparableConcept`. +* `SinglePassRange1`s value type can be compared for equality with `SinglePassRange2`'s value type. + +[*For the predicate versions:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `BinaryPredicate` is a model of the `BinaryPredicateConcept`. +* `SinglePassRange1`'s value type is convertible to `BinaryPredicate`'s first argument type. +* `SinglePassRange2`'s value type is convertible to `BinaryPredicate`'s second argument type. + +[heading Precondition:] + +`distance(rng2) >= distance(rng1)` + +[heading Complexity] + +Linear. At most `distance(rng1)` comparisons. + +[endsect] + + diff --git a/doc/reference/algorithm/next_permutation.qbk b/doc/reference/algorithm/next_permutation.qbk new file mode 100644 index 0000000..37b901a --- /dev/null +++ b/doc/reference/algorithm/next_permutation.qbk @@ -0,0 +1,51 @@ +[section:next_permutation next_permutation] + +[heading Prototype] + +`` +template +void next_permutation(BidirectionalRange& rng); + +template +void next_permutation(const BidirectionalRange& rng); + +template +void next_permutation(BidirectionalRange& rng, Compare pred); + +template +void next_permutation(const BidirectionalRange& rng, Compare pred); +`` + +[heading Description] + +`next_permutation` transforms the range of elements `rng` into the lexicographically next greater permutation of the elements if such a permutation exists. If one does not exist then the range is transformed into the lexicographically smallest permutation and `false` is returned. `true` is returned when the next greater permutation is successfully generated. + +The ordering relationship is determined by using `operator<` in the non-predicate versions, and by evaluating `pred` in the predicate versions. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/permutation.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `BidirectionalRange` is a model of the __bidirectional_range__ Concept. +* `BidirectionalRange` is mutable. +* `BidirectionalRange`'s value type is a model of the `LessThanComparableConcept`. +* The ordering of objects of type `BidirectionalRange`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. + +[*For the predicate versions:] + +* `BidirectionalRange` is a model of the __bidirectional_range__ Concept. +* `BidirectionalRange` is mutable. +* `Compare` is a model of the `StrictWeakOrderingConcept`. +* `BidirectionalRange`'s value type is convertible to both of `Compare`'s argument types. + +[heading Complexity] + +Linear. At most `distance(rng) / 2` swaps. + +[endsect] + + diff --git a/doc/reference/algorithm/nth_element.qbk b/doc/reference/algorithm/nth_element.qbk new file mode 100644 index 0000000..69c87a8 --- /dev/null +++ b/doc/reference/algorithm/nth_element.qbk @@ -0,0 +1,58 @@ +[section:nth_element Range Algorithm - nth_element] + +[heading Prototype] + +`` +template +void nth_element(RandomAccessRange& rng, + typename range_iterator::type nth); + +template +void nth_element(const RandomAccessRange& rng, + typename range_iterator::type nth); + +template +void nth_element(RandomAccessRange& rng, + typename range_iterator::type nth, + BinaryPredicate sort_pred); + +template +void nth_element(const RandomAccessRange& rng, + typename range_iterator::type nth, + BinaryPredicate sort_pred); +`` + +[heading Description] + +`nth_element` partially orders a range of elements. `nth_element` arranges the range `rng` such that the element corresponding with the iterator `nth` is the same as the element that would be in that position if `rng` has been sorted. + + +[heading Definition] + +Defined in the header file `boost/range/algorithm/nth_element.hpp` + +[heading Requirements] + +[*For the non-predicate version:] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `RandomAccessRange` is mutable. +* `RandomAccessRange`'s value type is a model of the `LessThanComparableConcept`. +* The ordering relation on `RandomAccessRange`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. + + +[*For the predicate version:] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `RandomAccessRange` is mutable. +* `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`. +* `RandomAccessRange`'s value type is convertible to both of `BinaryPredicate`'s argument types. + + +[heading Complexity] + +On average, linear in `distance(rng)`. + +[endsect] + + diff --git a/doc/reference/algorithm/partial_sort.qbk b/doc/reference/algorithm/partial_sort.qbk new file mode 100644 index 0000000..298c16f --- /dev/null +++ b/doc/reference/algorithm/partial_sort.qbk @@ -0,0 +1,60 @@ +[section:partial_sort Range Algorithm - partial_sort] + +[heading Prototype] + +`` +template +void partial_sort(RandomAccessRange& rng, + typename range_iterator::type middle); + +template +void partial_sort(const RandomAccessRange& rng, + typename range_iterator::type middle); + +template +void partial_sort(RandomAccessRange& rng, + typename range_iterator::type middle, + BinaryPredicate sort_pred); + +template +void partial_sort(const RandomAccessRange& rng, + typename range_iterator::type middle, + BinaryPredicate sort_pred); +`` + +[heading Description] + +`partial_sort` rearranges the elements in `rng`. It places the smallest `distance(begin(rng), middle)` elements, sorted in ascending order, into the range `[begin(rng), middle)`. The remaining elements are placed in an unspecified order into `[middle, last)`. + +The non-predicative versions of this function specify that one element is less than another by using `operator<()`. The predicate versions use the predicate instead. + + +[heading Definition] + +Defined in the header file `boost/range/algorithm/partial_sort.hpp` + +[heading Requirements] + +[*For the non-predicate version:] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `RandomAccessRange` is mutable. +* `RandomAccessRange`'s value type is a model of the `LessThanComparableConcept`. +* The ordering relation on `RandomAccessRange`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. + + +[*For the predicate version:] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `RandomAccessRange` is mutable. +* `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`. +* `RandomAccessRange`'s value type is convertible to both of `BinaryPredicate`'s argument types. + + +[heading Complexity] + +Approximately `distance(rng) * log(distance(begin(rng), middle))` comparisons. + +[endsect] + + diff --git a/doc/reference/algorithm/partition.qbk b/doc/reference/algorithm/partition.qbk new file mode 100644 index 0000000..cd17db7 --- /dev/null +++ b/doc/reference/algorithm/partition.qbk @@ -0,0 +1,58 @@ +[section:partition Range Algorithm - partition] + +[heading Prototype] + +`` +template< + class ForwardRange, + class UnaryPredicate + > +typename range_iterator::type +partition(ForwardRange& rng, UnaryPredicate pred); + +template< + class ForwardRange, + class UnaryPredicate + > +typename range_iterator::type +partition(const ForwardRange& rng, UnaryPredicate pred); + +template< + range_return_value re, + class ForwardRange, + class UnaryPredicate + > +typename range_return::type +partition(ForwardRange& rng, UnaryPredicate pred); + +template< + range_return_value re, + class ForwardRange, + class UnaryPredicate + > +typename range_return::type +partition(const ForwardRange& rng, UnaryPredicate pred); +`` + +[heading Description] + +`partition` orders the elements in `rng` based on `pred`, such that the elements that satisfy `pred` precede the elements that do not. In the versions that return a single iterator, the return value is the middle iterator. In the versions that have a configurable range_return, `found` corresponds to the middle iterator. + + +[heading Definition] + +Defined in the header file `boost/range/algorithm/partition.hpp` + +[heading Requirements] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `UnaryPredicate` is a model of the `PredicateConcept`. +* `ForwardRange`'s value type is convertible to `UnaryPredicate`'s argument type. + +[heading Complexity] + +Linear. Exactly `distance(rng)` applications of `pred`, and at most `distance(rng) / 2` swaps. + +[endsect] + + diff --git a/doc/reference/algorithm/pop_heap.qbk b/doc/reference/algorithm/pop_heap.qbk new file mode 100644 index 0000000..4479d46 --- /dev/null +++ b/doc/reference/algorithm/pop_heap.qbk @@ -0,0 +1,56 @@ +[section:pop_heap pop_heap] + +[heading Prototype] + +`` +template +void pop_heap(RandomAccessRange& rng); + +template +void pop_heap(const RandomAccessRange& rng); + +template +void pop_heap(RandomAccessRange& rng, Compare pred); + +template +void pop_heap(const RandomAccessRange& rng, Compare pred); +`` + +[heading Description] + +`pop_heap` removes the largest element from the heap. It is assumed that `begin(rng), prior(end(rng))` is already a heap and that the element to be added is `*prior(end(rng))`. + +The ordering relationship is determined by using `operator<` in the non-predicate versions, and by evaluating `pred` in the predicate versions. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/heap_algorithm.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `RandomAccessRange` is mutable. +* `RandomAccessRange`'s value type is a model of the `LessThanComparableConcept`. +* The ordering of objects of type `RandomAccessRange`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. + +[*For the predicate versions:] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `RandomAccessRange` is mutable. +* `Compare` is a model of the `StrictWeakOrderingConcept`. +* `RandomAccessRange`'s value type is convertible to both of `Compare`'s argument types. + +[heading Precondition:] + +* `!empty(rng)` +* `rng` is a heap. + +[heading Complexity] + +Logarithmic. At most `2 * log(distance(rng))` comparisons. + +[endsect] + + diff --git a/doc/reference/algorithm/prev_permutation.qbk b/doc/reference/algorithm/prev_permutation.qbk new file mode 100644 index 0000000..11642a4 --- /dev/null +++ b/doc/reference/algorithm/prev_permutation.qbk @@ -0,0 +1,51 @@ +[section:prev_permutation prev_permutation] + +[heading Prototype] + +`` +template +void prev_permutation(BidirectionalRange& rng); + +template +void prev_permutation(const BidirectionalRange& rng); + +template +void prev_permutation(BidirectionalRange& rng, Compare pred); + +template +void prev_permutation(const BidirectionalRange& rng, Compare pred); +`` + +[heading Description] + +`prev_permutation` transforms the range of elements `rng` into the lexicographically next smaller permutation of the elements if such a permutation exists. If one does not exist then the range is transformed into the lexicographically largest permutation and `false` is returned. `true` is returned when the next smaller permutation is successfully generated. + +The ordering relationship is determined by using `operator<` in the non-predicate versions, and by evaluating `pred` in the predicate versions. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/permutation.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `BidirectionalRange` is a model of the __bidirectional_range__ Concept. +* `BidirectionalRange` is mutable. +* `BidirectionalRange`'s value type is a model of the `LessThanComparableConcept`. +* The ordering of objects of type `BidirectionalRange`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. + +[*For the predicate versions:] + +* `BidirectionalRange` is a model of the __bidirectional_range__ Concept. +* `BidirectionalRange` is mutable. +* `Compare` is a model of the `StrictWeakOrderingConcept`. +* `BidirectionalRange`'s value type is convertible to both of `Compare`'s argument types. + +[heading Complexity] + +Linear. At most `distance(rng) / 2` swaps. + +[endsect] + + diff --git a/doc/reference/algorithm/push_heap.qbk b/doc/reference/algorithm/push_heap.qbk new file mode 100644 index 0000000..eae2466 --- /dev/null +++ b/doc/reference/algorithm/push_heap.qbk @@ -0,0 +1,56 @@ +[section:push_heap push_heap] + +[heading Prototype] + +`` +template +void push_heap(RandomAccessRange& rng); + +template +void push_heap(const RandomAccessRange& rng); + +template +void push_heap(RandomAccessRange& rng, Compare pred); + +template +void push_heap(const RandomAccessRange& rng, Compare pred); +`` + +[heading Description] + +`push_heap` adds an element to a heap. It is assumed that `begin(rng)`, `prior(end(rng))` is already a heap and that the element to be added is `*prior(end(rng))`. + +The ordering relationship is determined by using `operator<` in the non-predicate versions, and by evaluating `pred` in the predicate versions. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/heap_algorithm.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `RandomAccessRange` is mutable. +* `RandomAccessRange`'s value type is a model of the `LessThanComparableConcept`. +* The ordering of objects of type `RandomAccessRange`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. + +[*For the predicate versions:] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `RandomAccessRange` is mutable. +* `Compare` is a model of the `StrictWeakOrderingConcept`. +* `RandomAccessRange`'s value type is convertible to both of `Compare`'s argument types. + +[heading Precondition:] + +* `!empty(rng)` +* `[begin(rng), prior(end(rng)))` is a heap. + +[heading Complexity] + +Logarithmic. At most `log(distance(rng))` comparisons. + +[endsect] + + diff --git a/doc/reference/algorithm/random_shuffle.qbk b/doc/reference/algorithm/random_shuffle.qbk new file mode 100644 index 0000000..e2d10b7 --- /dev/null +++ b/doc/reference/algorithm/random_shuffle.qbk @@ -0,0 +1,50 @@ +[section:random_shuffle Range Algorithm - random_shuffle] + +[heading Prototype] + +`` +template +RandomAccessRange& random_shuffle(RandomAccessRange& rng); + +template +const RandomAccessRange& random_shuffle(const RandomAccessRange& rng); + +template +RandomAccessRange& random_shuffle(RandomAccessRange& rng, Generator& gen); + +template +const RandomAccessRange& random_shuffle(const RandomAccessRange& rng, Generator& gen); +`` + +[heading Description] + +`random_shuffle` randomly rearranges the elements in `rng`. The versions of `random_shuffle` that do not specify a `Generator` use an internal random number generator. The versions of `random_shuffle` that do specify a `Generator` use this instead. Returns the shuffles range. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/random_shuffle.hpp` + +[heading Requirements] + +[*For the version without a Generator:] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. + +[*For the version with a Generator:] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `Generator` is a model of the `RandomNumberGeneratorConcept`. +* `RandomAccessRange`'s distance type is convertible to `Generator`'s argument type. + +[heading Precondition:] + +* `distance(rng)` is less than `gen`'s maximum value. + + +[heading Complexity] + +Linear. If `!empty(rng)`, exactly `distance(rng) - 1` swaps are performed. + +[endsect] + + diff --git a/doc/reference/algorithm/remove.qbk b/doc/reference/algorithm/remove.qbk new file mode 100644 index 0000000..5c609aa --- /dev/null +++ b/doc/reference/algorithm/remove.qbk @@ -0,0 +1,58 @@ +[section:remove Range Algorithm - remove] + +[heading Prototype] + +`` +template< + class ForwardRange, + class Value + > +typename range_iterator::type +remove(ForwardRange& rng, const Value& val); + +template< + class ForwardRange, + class Value + > +typename range_iterator::type +remove(const ForwardRange& rng, const Value& val); + +template< + range_return_value re, + class ForwardRange, + class Value + > +typename range_return::type +remove(ForwardRange& rng, const Value& val); + +template< + range_return_value re, + class ForwardRange, + class Value + > +typename range_return::type +remove(const ForwardRange& rng, const Value& val); +`` + +[heading Description] + +`remove` removes from `rng` all of the elements `x` for which `x == val` is `true`. The versions of `remove` that return an iterator, return an iterator `new_last` such that the range `[begin(rng), new_last)` contains no elements equal to `val`. The `range_return` versions of `remove` defines `found` as the new last element. The iterators in the range `[new_last, end(rng))` are dereferenceable, but the elements are unspecified. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/remove.hpp` + +[heading Requirements] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `ForwardRange` is mutable. +* `Value` is a model of the `EqualityComparableConcept`. +* Objects of type `Value` can be compared for equality with objects of `ForwardRange`'s value type. + +[heading Complexity] + +Linear. `remove` performs exactly `distance(rng)` comparisons for equality. + +[endsect] + + diff --git a/doc/reference/algorithm/remove_if.qbk b/doc/reference/algorithm/remove_if.qbk new file mode 100644 index 0000000..475e965 --- /dev/null +++ b/doc/reference/algorithm/remove_if.qbk @@ -0,0 +1,58 @@ +[section:remove_if Range Algorithm - remove_if] + +[heading Prototype] + +`` +template< + class ForwardRange, + class UnaryPredicate + > +typename range_iterator::type +remove(ForwardRange& rng, UnaryPredicate pred); + +template< + class ForwardRange, + class UnaryPredicate + > +typename range_iterator::type +remove(const ForwardRange& rng, UnaryPredicate pred); + +template< + range_return_value re, + class ForwardRange, + class UnaryPredicate + > +typename range_return::type +remove(ForwardRange& rng, UnaryPredicate pred); + +template< + range_return_value re, + class ForwardRange, + class UnaryPredicate + > +typename range_return::type +remove(const ForwardRange& rng, UnaryPredicate pred); +`` + +[heading Description] + +`remove_if` removes from `rng` all of the elements `x` for which `pred(x)` is `true`. The versions of `remove_if` that return an iterator, return an iterator `new_last` such that the range `[begin(rng), new_last)` contains no elements where `pred(x)` is `true`. The iterators in the range `[new_last, end(rng))` are dereferenceable, but the elements are unspecified. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/remove_if.hpp` + +[heading Requirements] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `ForwardRange` is mutable. +* `UnaryPredicate` is a model of the `PredicateConcept`. +* `ForwardRange`'s value type is convertible to `UnaryPredicate`'s argument type. + +[heading Complexity] + +Linear. `remove_if` performs exactly `distance(rng)` applications of `pred`. + +[endsect] + + diff --git a/doc/reference/algorithm/replace.qbk b/doc/reference/algorithm/replace.qbk new file mode 100644 index 0000000..a173a56 --- /dev/null +++ b/doc/reference/algorithm/replace.qbk @@ -0,0 +1,41 @@ +[section:replace Range Algorithm - replace] + +[heading Prototype] + +`` +template< + class ForwardRange, + class Value + > +ForwardRange& replace(ForwardRange& rng, const Value& what, const Value& with_what); + +template< + class ForwardRange, + class UnaryPredicate + > +const ForwardRange& replace(const ForwardRange& rng, const Value& what, const Value& with_what); +`` + +[heading Description] + +`replace` every element in `rng` equal to `what` with `with_what`. Return a reference to `rng`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/replace.hpp` + +[heading Requirements] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `ForwardRange` is mutable. +* `Value` is convertible to `ForwardRange`'s value type. +* `Value` is a model of the `AssignableConcept`. +* `Value` is a model of the `EqualityComparableConcept`, and may be compared for equality with objects of `ForwardRange`'s value type. + +[heading Complexity] + +Linear. `replace` performs exactly `distance(rng)` comparisons for equality and at most `distance(rng)` assignments. + +[endsect] + + diff --git a/doc/reference/algorithm/replace_if.qbk b/doc/reference/algorithm/replace_if.qbk new file mode 100644 index 0000000..2546395 --- /dev/null +++ b/doc/reference/algorithm/replace_if.qbk @@ -0,0 +1,36 @@ +[section:replace_if Range Algorithm - replace_if] + +[heading Prototype] + +`` +template +ForwardRange& replace_if(ForwardRange& rng, UnaryPredicate pred, const Value& with_what); + +template +const ForwardRange& replace_if(const ForwardRange& rng, UnaryPredicate pred, const Value& with_what); +`` + +[heading Description] + +`replace_if` replaces every element `x` in `rng` for which `pred(x) == true` with `with_what`. Returns a reference to `rng`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/replace_if.hpp` + +[heading Requirements] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `ForwardRange` is mutable. +* `UnaryPredicate` is a model of the `PredicateConcept` +* `ForwardRange`'s value type is convertible to `UnaryPredicate`'s argument type. +* `Value` is convertible to `ForwardRange`'s value type. +* `Value` is a model of the `AssignableConcept`. + +[heading Complexity] + +Linear. `replace_if` performs exactly `distance(rng)` applications of `pred`, and at most `distance(rng)` assignments. + +[endsect] + + diff --git a/doc/reference/algorithm/reverse.qbk b/doc/reference/algorithm/reverse.qbk new file mode 100644 index 0000000..7d678ef --- /dev/null +++ b/doc/reference/algorithm/reverse.qbk @@ -0,0 +1,32 @@ +[section:reverse Range Algorithm - reverse] + +[heading Prototype] + +`` +template +BidirectionalRange& reverse(BidirectionalRange& rng); + +template +const BidirectionalRange& reverse(const BidirectionalRange& rng); +`` + +[heading Description] + +`reverse` reverses a range. Returns a reference to the reversed range. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/reverse.hpp` + +[heading Requirements] + +* `BidirectionalRange` is a model of the __bidirectional_range__ Concept. +* `BidirectionalRange` is mutable. + +[heading Complexity] + +Linear. `reverse` makes `distance(rng)/2` calls to `iter_swap`. + +[endsect] + + diff --git a/doc/reference/algorithm/rotate.qbk b/doc/reference/algorithm/rotate.qbk new file mode 100644 index 0000000..9fa1b90 --- /dev/null +++ b/doc/reference/algorithm/rotate.qbk @@ -0,0 +1,39 @@ +[section:rotate Range Algorithm - rotate] + +[heading Prototype] + +`` +template +ForwardRange& rotate(ForwardRange& rng, + typename range_iterator::type middle); + +template +const ForwardRange& rotate(const ForwardRange& rng, + typename range_iterator::type middle); +`` + +[heading Description] + +`rotate` rotates the elements in a range. It exchanges the two ranges `[begin(rng), middle)` and `[middle, end(rng))`. Returns a reference to `rng`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/rotate.hpp` + +[heading Requirements] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `ForwardRange` is mutable. + +[heading Precondition:] + +* `[begin(rng), middle)` is a valid range. +* `[middle, end(rng))` is a valid range. + +[heading Complexity] + +Linear. At most `distance(rng)` swaps are performed. + +[endsect] + + diff --git a/doc/reference/algorithm/search.qbk b/doc/reference/algorithm/search.qbk new file mode 100644 index 0000000..e6c0a85 --- /dev/null +++ b/doc/reference/algorithm/search.qbk @@ -0,0 +1,101 @@ +[section:search search] + +[heading Prototype] + +`` +template +typename range_iterator::type +search(ForwardRange1& rng1, const ForwardRange2& rng2); + +template +typename range_iterator::type +search(const ForwardRange1& rng1, const ForwardRange2& rng2); + +template< + class ForwardRange1, + class ForwardRange2, + class BinaryPredicate + > +typename range_iterator::type, +search(ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred); + +template< + class ForwardRange1, + class ForwardRange2, + class BinaryPredicate + > +typename range_iterator::type +search(const ForwardRange1& rng1, ForwardRange2& rng2, BinaryPredicate pred); + + +template< + range_return_value re, + class ForwardRange1, + class ForwardRange2 + > +typename range_return::type +search(ForwardRange1& rng1, const ForwardRange2& rng2); + +template< + range_return_value re, + class ForwardRange1, + class ForwardRange2 + > +typename range_return::type +search(const ForwardRange1& rng1, const ForwardRange2& rng2); + +template< + range_return_value re, + class ForwardRange1, + class ForwardRange2, + class BinaryPredicate + > +typename range_return::type, +search(ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred); + +template< + range_return_value re, + class ForwardRange1, + class ForwardRange2, + class BinaryPredicate + > +typename range_return::type +search(const ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred); +`` + +[heading Description] + +The versions of `search` that return an iterator, return an iterator to the start of the first subsequence in `rng1` that is equal to the subsequence `rng2`. The `end(rng1)` is returned if no such subsequence exists in `rng1`. +Equality is determined by `operator==` for non-predicate versions of `search`, and by satisfying `pred` in the predicate versions. + +The versions of `search` that return a `range_return`, defines `found` in the same manner as the returned iterator described above. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/search.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `ForwardRange1` is a model of the __forward_range__ Concept. +* `ForwardRange2` is a model of the __forward_range__ Concept. +* `ForwardRange1`'s value type is a model of the `EqualityComparableConcept`. +* `ForwardRange2`'s value type is a model of the `EqualityComparableConcept`. +* `ForwardRange1`s value type can be compared for equality with `ForwardRange2`'s value type. + +[*For the predicate versions:] + +* `ForwardRange1` is a model of the __forward_range__ Concept. +* `ForwardRange2` is a model of the __forward_range__ Concept. +* `BinaryPredicate` is a model of the `BinaryPredicateConcept`. +* `ForwardRange1`'s value type is convertible to `BinaryPredicate`'s first argument type. +* `ForwardRange2`'s value type is convertible to `BinaryPredicate`'s second argument type. + +[heading Complexity] + +Average complexity is Linear. Worst-case complexity is quadratic. + +[endsect] + + diff --git a/doc/reference/algorithm/set_difference.qbk b/doc/reference/algorithm/set_difference.qbk new file mode 100644 index 0000000..cd9724d --- /dev/null +++ b/doc/reference/algorithm/set_difference.qbk @@ -0,0 +1,76 @@ +[section:set_difference set_difference] + +[heading Prototype] + +`` +template< + class SinglePassRange1, + class SinglePassRange2, + class OutputIterator + > +OutputIterator set_difference(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out); + +template< + class SinglePassRange1, + class SinglePassRange2, + class OutputIterator, + class BinaryPredicate + > +OutputIterator set_difference(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out, + BinaryPredicate pred); +`` + +[heading Description] + +`set_difference` constructs a sorted range that is the set difference of the sorted ranges `rng1` and `rng2`. The return value is the end of the output range. + +The ordering relationship is determined by using `operator<` in the non-predicate versions, and by evaluating `pred` in the predicate versions. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/set_algorithm.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `OutputIterator` is a model of the `OutputIteratorConcept`. +* `SinglePassRange1` and `SinglePassRange2` have the same value type. +* `SinglePassRange1`'s value type is a model of the `LessThanComparableConcept`. +* `SinglePassRange2`'s value type is a model of the `LessThanComparableConcept`. +* The ordering of objects of type `SinglePassRange1`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. +* The ordering of objects of type `SinglePassRange2`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. + +[*For the predicate versions:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `OutputIterator` is a model of the `OutputIteratorConcept`. +* `SinglePassRange1` and `SinglePassRange2` have the same value type. +* `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`. +* `SinglePassRange1`'s value type is convertible to `BinaryPredicate`'s first argument type. +* `SinglePassRange2`'s value type is convertible to `BinaryPredicate`'s second argument types. + +[heading Precondition:] + +[*For the non-predicate versions:] + +`rng1` and `rng2` are sorted in ascending order according to `operator<`. + +[*For the predicate versions:] + +`rng1` and `rng2` are sorted in ascending order according to `pred`. + +[heading Complexity] + +Linear. `O(N)`, where `N` is `distance(rng1) + distance(rng2)`. + +[endsect] + + diff --git a/doc/reference/algorithm/set_intersection.qbk b/doc/reference/algorithm/set_intersection.qbk new file mode 100644 index 0000000..3c4e984 --- /dev/null +++ b/doc/reference/algorithm/set_intersection.qbk @@ -0,0 +1,76 @@ +[section:set_intersection set_intersection] + +[heading Prototype] + +`` +template< + class SinglePassRange1, + class SinglePassRange2, + class OutputIterator + > +OutputIterator set_intersection(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out); + +template< + class SinglePassRange1, + class SinglePassRange2, + class OutputIterator, + class BinaryPredicate + > +OutputIterator set_intersection(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out, + BinaryPredicate pred); +`` + +[heading Description] + +`set_intersection` constructs a sorted range that is the intersection of the sorted ranges `rng1` and `rng2`. The return value is the end of the output range. + +The ordering relationship is determined by using `operator<` in the non-predicate versions, and by evaluating `pred` in the predicate versions. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/set_algorithm.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `OutputIterator` is a model of the `OutputIteratorConcept`. +* `SinglePassRange1` and `SinglePassRange2` have the same value type. +* `SinglePassRange1`'s value type is a model of the `LessThanComparableConcept`. +* `SinglePassRange2`'s value type is a model of the `LessThanComparableConcept`. +* The ordering of objects of type `SinglePassRange1`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. +* The ordering of objects of type `SinglePassRange2`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. + +[*For the predicate versions:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `OutputIterator` is a model of the `OutputIteratorConcept`. +* `SinglePassRange1` and `SinglePassRange2` have the same value type. +* `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`. +* `SinglePassRange1`'s value type is convertible to `BinaryPredicate`'s first argument type. +* `SinglePassRange2`'s value type is convertible to `BinaryPredicate`'s second argument types. + +[heading Precondition:] + +[*For the non-predicate versions:] + +`rng1` and `rng2` are sorted in ascending order according to `operator<`. + +[*For the predicate versions:] + +`rng1` and `rng2` are sorted in ascending order according to `pred`. + +[heading Complexity] + +Linear. `O(N)`, where `N` is `distance(rng1) + distance(rng2)`. + +[endsect] + + diff --git a/doc/reference/algorithm/set_symmetric_difference.qbk b/doc/reference/algorithm/set_symmetric_difference.qbk new file mode 100644 index 0000000..4c6ed3e --- /dev/null +++ b/doc/reference/algorithm/set_symmetric_difference.qbk @@ -0,0 +1,78 @@ +[section:set_symmetric_difference set_symmetric_difference] + +[heading Prototype] + +`` +template< + class SinglePassRange1, + class SinglePassRange2, + class OutputIterator + > +OutputIterator +set_symmetric_difference(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out); + +template< + class SinglePassRange1, + class SinglePassRange2, + class OutputIterator, + class BinaryPredicate + > +OutputIterator +set_symmetric_difference(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out, + BinaryPredicate pred); +`` + +[heading Description] + +`set_symmetric_difference` constructs a sorted range that is the set symmetric difference of the sorted ranges `rng1` and `rng2`. The return value is the end of the output range. + +The ordering relationship is determined by using `operator<` in the non-predicate versions, and by evaluating `pred` in the predicate versions. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/set_algorithm.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `OutputIterator` is a model of the `OutputIteratorConcept`. +* `SinglePassRange1` and `SinglePassRange2` have the same value type. +* `SinglePassRange1`'s value type is a model of the `LessThanComparableConcept`. +* `SinglePassRange2`'s value type is a model of the `LessThanComparableConcept`. +* The ordering of objects of type `SinglePassRange1`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. +* The ordering of objects of type `SinglePassRange2`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. + +[*For the predicate versions:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `OutputIterator` is a model of the `OutputIteratorConcept`. +* `SinglePassRange1` and `SinglePassRange2` have the same value type. +* `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`. +* `SinglePassRange1`'s value type is convertible to `BinaryPredicate`'s first argument type. +* `SinglePassRange2`'s value type is convertible to `BinaryPredicate`'s second argument types. + +[heading Precondition:] + +[*For the non-predicate versions:] + +`rng1` and `rng2` are sorted in ascending order according to `operator<`. + +[*For the predicate versions:] + +`rng1` and `rng2` are sorted in ascending order according to `pred`. + +[heading Complexity] + +Linear. `O(N)`, where `N` is `distance(rng1) + distance(rng2)`. + +[endsect] + + diff --git a/doc/reference/algorithm/set_union.qbk b/doc/reference/algorithm/set_union.qbk new file mode 100644 index 0000000..3788781 --- /dev/null +++ b/doc/reference/algorithm/set_union.qbk @@ -0,0 +1,75 @@ +[section:set_union set_union] + +[heading Prototype] + +`` +template< + class SinglePassRange1, + class SinglePassRange2, + class OutputIterator + > +OutputIterator set_union(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out); + +template< + class SinglePassRange1, + class SinglePassRange2, + class OutputIterator, + class BinaryPredicate + > +OutputIterator set_union(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out, + BinaryPredicate pred); + `` + +[heading Description] + +`set_union` constructs a sorted range that is the union of the sorted ranges `rng1` and `rng2`. The return value is the end of the output range. +The ordering relationship is determined by using `operator<` in the non-predicate versions, and by evaluating `pred` in the predicate versions. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/set_algorithm.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `OutputIterator` is a model of the `OutputIteratorConcept`. +* `SinglePassRange1` and `SinglePassRange2` have the same value type. +* `SinglePassRange1`'s value type is a model of the `LessThanComparableConcept`. +* `SinglePassRange2`'s value type is a model of the `LessThanComparableConcept`. +* The ordering of objects of type `SinglePassRange1`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. +* The ordering of objects of type `SinglePassRange2`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. + +[*For the predicate versions:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `OutputIterator` is a model of the `OutputIteratorConcept`. +* `SinglePassRange1` and `SinglePassRange2` have the same value type. +* `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`. +* `SinglePassRange1`'s value type is convertible to `BinaryPredicate`'s first argument type. +* `SinglePassRange2`'s value type is convertible to `BinaryPredicate`'s second argument types. + +[heading Precondition:] + +[*For the non-predicate versions:] + +`rng1` and `rng2` are sorted in ascending order according to `operator<`. + +[*For the predicate versions:] + +`rng1` and `rng2` are sorted in ascending order according to `pred`. + +[heading Complexity] + +Linear. `O(N)`, where `N` is `distance(rng1) + distance(rng2)`. + +[endsect] + + diff --git a/doc/reference/algorithm/sort.qbk b/doc/reference/algorithm/sort.qbk new file mode 100644 index 0000000..63fb8f8 --- /dev/null +++ b/doc/reference/algorithm/sort.qbk @@ -0,0 +1,53 @@ +[section:sort Range Algorithm - sort] + +[heading Prototype] + +`` +template +RandomAccessRange& sort(RandomAccessRange& rng); + +template +const RandomAccessRange& sort(const RandomAccessRange& rng); + +template +RandomAccessRange& sort(RandomAccessRange& rng, BinaryPredicate pred); + +template +const RandomAccessRange& sort(const RandomAccessRange& rng, BinaryPredicate pred); +`` + +[heading Description] + +`sort` sorts the elements in `rng` into ascending order. `sort` is not guaranteed to be stable. Returns the sorted range. + +For versions of the `sort` function without a predicate, ascending order is defined by `operator<()` such that for all adjacent elements `[x,y]`, `y < x == false`. + +For versions of the `sort` function with a predicate, ascending order is defined by `pred` such that for all adjacent elements `[x,y]`, `pred(y, x) == false`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/sort.hpp` + +[heading Requirements] + +[*For versions of sort without a predicate:] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `RandomAccessRange` is mutable. +* `RandomAccessRange`'s value type is a model of the `LessThanComparableConcept`. +* The ordering relation on `RandomAccessRange`'s value type is a [*strict weak ordering], as defined in the `LessThanComparableConcept` requirements. + +[*For versions of sort with a predicate] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `RandomAccessRange` is mutable. +* `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`. +* `RandomAccessRange`'s value type is convertible to both of `BinaryPredicate`'s argument types. + +[heading Complexity] + +`O(N log(N))` comparisons (both average and worst-case), where `N` is `distance(rng)`. + +[endsect] + + diff --git a/doc/reference/algorithm/sort_heap.qbk b/doc/reference/algorithm/sort_heap.qbk new file mode 100644 index 0000000..9a24887 --- /dev/null +++ b/doc/reference/algorithm/sort_heap.qbk @@ -0,0 +1,55 @@ +[section:sort_heap sort_heap] + +[heading Prototype] + +`` +template +void sort_heap(RandomAccessRange& rng); + +template +void sort_heap(const RandomAccessRange& rng); + +template +void sort_heap(RandomAccessRange& rng, Compare pred); + +template +void sort_heap(const RandomAccessRange& rng, Compare pred); +`` + +[heading Description] + +`sort_heap` turns a heap into a sorted range. + +The ordering relationship is determined by using `operator<` in the non-predicate versions, and by evaluating `pred` in the predicate versions. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/heap_algorithm.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `RandomAccessRange` is mutable. +* `RandomAccessRange`'s value type is a model of the `LessThanComparableConcept`. +* The ordering of objects of type `RandomAccessRange`'s value type is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. + +[*For the predicate versions:] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `RandomAccessRange` is mutable. +* `Compare` is a model of the `StrictWeakOrderingConcept`. +* `RandomAccessRange`'s value type is convertible to both of `Compare`'s argument types. + +[heading Precondition:] + +`rng` is a heap. + +[heading Complexity] + +At most `N * log(N)` comparisons, where `N` is `distance(rng)`. + +[endsect] + + diff --git a/doc/reference/algorithm/stable_partition.qbk b/doc/reference/algorithm/stable_partition.qbk new file mode 100644 index 0000000..b68aa11 --- /dev/null +++ b/doc/reference/algorithm/stable_partition.qbk @@ -0,0 +1,56 @@ +[section:stable_partition Range Algorithm - stable_partition] + +[heading Prototype] + +`` +template +typename range_iterator::type +stable_partition(ForwardRange& rng, UnaryPredicate pred); + +template +typename range_iterator::type +stable_partition(const ForwardRange& rng, UnaryPredicate pred); + +template< + range_return_value re, + class ForwardRange, + class UnaryPredicate +> +typename range_return::type +stable_partition(ForwardRange& rng, UnaryPredicate pred); + +template< + range_return_value re, + class ForwardRange, + class UnaryPredicate +> +typename range_return::type +stable_partition(const ForwardRange& rng, UnaryPredicate pred); +`` + +[heading Description] + +`stable_partition` reorders the elements in the range `rng` base on the function object `pred`. Once this function has completed all of the elements that satisfy `pred` appear before all of the elements that fail to satisfy it. `stable_partition` differs from `partition` because it preserves relative order. It is stable. + +For the versions that return an iterator, the return value is the iterator to the first element that fails to satisfy `pred`. + +For versions that return a `range_return`, the `found` iterator is the iterator to the first element that fails to satisfy `pred`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/stable_partition.hpp` + +[heading Requirements] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `ForwardRange` is mutable. +* `UnaryPredicate` is a model of the `PredicateConcept`. + +[heading Complexity] + +Best case: `O(N)` where `N` is `distance(rng)`. +Worst case: `N * log(N)` swaps, where `N` is `distance(rng)`. + +[endsect] + + diff --git a/doc/reference/algorithm/stable_sort.qbk b/doc/reference/algorithm/stable_sort.qbk new file mode 100644 index 0000000..11431b5 --- /dev/null +++ b/doc/reference/algorithm/stable_sort.qbk @@ -0,0 +1,54 @@ +[section:stable_sort Range Algorithm - stable_sort] + +[heading Prototype] + +`` +template +RandomAccessRange& stable_sort(RandomAccessRange& rng); + +template +const RandomAccessRange& stable_sort(const RandomAccessRange& rng); + +template +RandomAccessRange& stable_sort(RandomAccessRange& rng, BinaryPredicate pred); + +template +const RandomAccessRange& stable_sort(const RandomAccessRange& rng, BinaryPredicate pred); +`` + +[heading Description] + +`stable_sort` sorts the elements in `rng` into ascending order. `stable_sort` is guaranteed to be stable. The order is preserved for equivalent elements. + +For versions of the `stable_sort` function without a predicate ascending order is defined by `operator<()` such that for all adjacent elements `[x,y]`, `y < x == false`. + +For versions of the `stable_sort` function with a predicate, ascending order is designed by `pred` such that for all adjacent elements `[x,y]`, `pred(y,x) == false`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/stable_sort.hpp` + +[heading Requirements] + +[*For versions of stable_sort without a predicate] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `RandomAccessRange` is mutable. +* `RandomAccessRange`'s value type is a model of the `LessThanComparableConcept`. +* The ordering relation on `RandomAccessRange`'s value type is a [*strict weak ordering], as defined in the `LessThanComparableConcept` requirements. + +[*For versions of stable_sort with a predicate:] + +* `RandomAccessRange` is a model of the __random_access_range__ Concept. +* `RandomAccessRange` is mutable. +* `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`. +* `RandomAccessRange`'s value type is convertible to both of `BinaryPredicate`'s argument types. + +[heading Complexity] + +Best case: `O(N)` where `N` is `distance(rng)`. +Worst case: `O(N log(N)^2)` comparisons, where `N` is `distance(rng)`. + +[endsect] + + diff --git a/doc/reference/algorithm/transform.qbk b/doc/reference/algorithm/transform.qbk new file mode 100644 index 0000000..0a9c68c --- /dev/null +++ b/doc/reference/algorithm/transform.qbk @@ -0,0 +1,83 @@ +[section:transform Range Algorithm - transform] + +[heading Prototype] + +`` +template< + class SinglePassRange1, + class OutputIterator, + class UnaryOperation +> +OutputIterator transform(const SinglePassRange1& rng, + OutputIterator out, + UnaryOperation fun); + +template< + class SinglePassRange1, + class SinglePassRange2, + class OutputIterator, + class BinaryOperation +> +OutputIterator transform(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out, + BinaryOperation fun); +`` + +[heading Description] + +[*UnaryOperation version:] + +`transform` assigns the value `y` to each element `[out, out + distance(rng)), y = fun(x)` where `x` is the corresponding value to `y` in `rng1`. The return value is `out + distance(rng)`. + +[*BinaryOperation version:] + +`transform` assigns the value `z` to each element `[out, out + min(distance(rng1), distance(rng2))), z = fun(x,y)` where `x` is the corresponding value in `rng1` and `y` is the corresponding value in `rng2`. This version of `transform` stops upon reaching either the end of `rng1`, or the end of `rng2`. Hence there isn't a requirement for `distance(rng1) == distance(rng2)` since there is a safe guaranteed behaviour, unlike with the iterator counterpart in the standard library. + +The return value is `out + min(distance(rng1), distance(rng2))`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/transform.hpp` + +[heading Requirements] + +[*For the unary versions of transform:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `OutputIterator` is a model of the `OutputIteratorConcept`. +* `UnaryOperation` is a model of the `UnaryFunctionConcept`. +* `SinglePassRange1`'s value type must be convertible to `UnaryFunction`'s argument type. +* `UnaryFunction`'s result type must be convertible to a type in `OutputIterator`'s set of value types. + +[*For the binary versions of transform:] + +* `SinglePassRange1` is a model of the __single_pass_range__ Concept. +* `SinglePassRange2` is a model of the __single_pass_range__ Concept. +* `OutputIterator` is a model of the `OutputIteratorConcept`. +* `BinaryOperation` is a model of the `BinaryFunctionConcept`. +* `SinglePassRange1`'s value type must be convertible to `BinaryFunction`'s first argument type. +* `SinglePassRange2`'s value type must be convertible to `BinaryFunction`'s second argument type. +* `BinaryOperation`'s result type must be convertible to a type in `OutputIterator`'s set of value types. + +[heading Precondition:] + +[*For the unary version of transform:] + +* `out` is not an iterator within the range `[begin(rng1) + 1, end(rng1))`. +* `[out, out + distance(rng1))` is a valid range. + +[*For the binary version of transform:] + +* `out` is not an iterator within the range `[begin(rng1) + 1, end(rng1))`. +* `out` is not an iterator within the range `[begin(rng2) + 1, end(rng2))`. +* `[out, out + min(distance(rng1), distance(rng2)))` is a valid range. + + +[heading Complexity] + +Linear. The operation is applied exactly `distance(rng1)` for the unary version and `min(distance(rng1), distance(rng2))` for the binary version. + +[endsect] + + diff --git a/doc/reference/algorithm/unique.qbk b/doc/reference/algorithm/unique.qbk new file mode 100644 index 0000000..b5d55b4 --- /dev/null +++ b/doc/reference/algorithm/unique.qbk @@ -0,0 +1,72 @@ +[section:unique Range Algorithm - unique] + +[heading Prototype] + +`` +template +typename range_return::type +unique(ForwardRange& rng); + +template +typename range_return::type +unique(const ForwardRange& rng); + +template +typename range_return::type +unique(ForwardRange& rng, BinaryPredicate pred); + +template +typename range_return::type +unique(const ForwardRange& rng, BinaryPredicate pred); + +template +typename range_return::type +unique(ForwardRange& rng); + +template +typename range_return::type +unique(const ForwardRange& rng); + +template +typename range_return::type +unique(ForwardRange& rng, BinaryPredicate pred); + +template +typename range_return::type +unique(const ForwardRange& rng, BinaryPredicate pred); +`` + +[heading Description] + +`unique` removes all but the first element of each sequence of duplicate encountered in `rng`. + +Elements in the range `[new_last, end(rng))` are dereferenceable but undefined. + +Equality is determined by the predicate if one is supplied, or by `operator==()` for `ForwardRange`'s value type. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/unique.hpp` + +[heading Requirements] + +[*For the non-predicate versions of unique:] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `ForwardRange` is mutable. +* `ForwardRange`'s value type is a model of the `EqualityComparableConcept`. + +[*For the predicate versions of unique:] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `ForwardRange` is mutable. +* `BinaryPredicate` is a model of the `BinaryPredicateConcept`. +* `ForwardRange`'s value type is convertible to `BinaryPredicate`'s first argument type and to `BinaryPredicate`'s second argument type. + +[heading Complexity] + +Linear. `O(N)` where `N` is `distance(rng)`. Exactly `distance(rng)` comparisons are performed. + +[endsect] + + diff --git a/doc/reference/algorithm/upper_bound.qbk b/doc/reference/algorithm/upper_bound.qbk new file mode 100644 index 0000000..7882410 --- /dev/null +++ b/doc/reference/algorithm/upper_bound.qbk @@ -0,0 +1,65 @@ +[section:upper_bound upper_bound] + +[heading Prototype] + +`` +template +typename range_iterator::type +upper_bound(ForwardRange& rng, Value val); + +template< + range_return_value re, + class ForwardRange, + class Value + > +typename range_return::type +upper_bound(ForwardRange& rng, Value val); +`` + +[heading Description] + +The versions of `upper_bound` that return an iterator, returns the first iterator in the range `rng` such that: +without predicate - `val < *i` is `true`, +with predicate - `pred(val, *i)` is `true`. + +`end(rng)` is returned if no such iterator exists. + +The versions of `upper_bound` that return a `range_return`, defines `found` in the same manner as the returned iterator described above. + +[heading Definition] + +Defined in the header file `boost/range/algorithm/upper_bound.hpp` + +[heading Requirements] + +[*For the non-predicate versions:] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `Value` is a model of the `LessThanComparableConcept`. +* The ordering of objects of type `Value` is a [*/strict weak ordering/], as defined in the `LessThanComparableConcept` requirements. +* `ForwardRange`'s value type is the same type as `Value`. + +[*For the predicate versions:] + +* `ForwardRange` is a model of the __forward_range__ Concept. +* `BinaryPredicate` is a model of the `StrictWeakOrderingConcept`. +* `ForwardRange`'s value type is the same type as `Value`. +* `ForwardRange`'s value type is convertible to both of `BinaryPredicate`'s argument types. + +[heading Precondition:] + +[*For the non-predicate versions:] + +`rng` is sorted in ascending order according to `operator<`. + +[*For the predicate versions:] + +`rng` is sorted in ascending order according to `pred`. + +[heading Complexity] + +For ranges that model the __random_access_range__ Concept the complexity is `O(log N)`, where `N` is `distance(rng)`. For all other range types the complexity is `O(N)`. + +[endsect] + + diff --git a/doc/reference/algorithm_ext/erase.qbk b/doc/reference/algorithm_ext/erase.qbk new file mode 100644 index 0000000..64c48a8 --- /dev/null +++ b/doc/reference/algorithm_ext/erase.qbk @@ -0,0 +1,30 @@ +[section:erase erase] + +[heading Prototype] + +`` +template< + class Container, + class SinglePassRange + > +void erase(Container& target, + iterator_range to_erase); +`` + +[heading Description] + +`erase` the iterator range `to_erase` from the container `target`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm_ext/erase.hpp` + +[heading Requirements] + +# `Container` supports erase of an iterator range. + +[heading Complexity] + +Linear. Proprotional to `distance(to_erase)`. + +[endsect] diff --git a/doc/reference/algorithm_ext/for_each.qbk b/doc/reference/algorithm_ext/for_each.qbk new file mode 100644 index 0000000..47b5d40 --- /dev/null +++ b/doc/reference/algorithm_ext/for_each.qbk @@ -0,0 +1,68 @@ +[section:for_each for_each] + +[heading Prototype] + +`` +template< + class SinglePassRange1, + class SinglePassRange2, + class BinaryFunction + > +BinaryFunction for_each(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + BinaryFunction fn); + +template< + class SinglePassRange1, + class SinglePassRange2, + class BinaryFunction + > +BinaryFunction for_each(const SinglePassRange1& rng1, + SinglePassRange2& rng2, + BinaryFunction fn); + +template< + class SinglePassRange1, + class SinglePassRange2, + class BinaryFunction + > +BinaryFunction for_each(SinglePassRange1& rng1, + const SinglePassRange2& rng2, + BinaryFunction fn); + +template< + class SinglePassRange1, + class SinglePassRange2, + class BinaryFunction + > +BinaryFunction for_each(SinglePassRange1& rng1, + SinglePassRange2& rng2, + BinaryFunction fn); +`` + +[heading Description] + +`for_each` traverses forward through `rng1` and `rng2` simultaneously. +For each iteration, the element `x` is used from `rng1` and the corresponding +element `y` is used from `rng2` to invoke `fn(x,y)`. + +Iteration is stopped upon reaching the end of the shorter of `rng1`, or `rng2`. +It is safe to call this function with unequal length ranges. + +[heading Definition] + +Defined in the header file `boost/range/algorithm_ext/for_each.hpp` + +[heading Requirements] + +# `SinglePassRange1` is a model of the __single_pass_range__ Concept. +# `SinglePassRange2` is a model of the __single_pass_range__ Concept. +# `BinaryFunction` is a model of the `BinaryFunctionConcept`. +# `SinglePassRange1`'s value type is convertible to `BinaryFunction`'s first argument type. +# `SinglepassRange2`'s value type is convertible to `BinaryFunction`'s second argument type. + +[heading Complexity] + +Linear. Exactly `min(distance(rng1), distance(rng2))` applications of `BinaryFunction`. + +[endsect] diff --git a/doc/reference/algorithm_ext/insert.qbk b/doc/reference/algorithm_ext/insert.qbk new file mode 100644 index 0000000..1d9c567 --- /dev/null +++ b/doc/reference/algorithm_ext/insert.qbk @@ -0,0 +1,33 @@ +[section:insert insert] + +[heading Prototype] + +`` +template< + class Container, + class SinglePassRange + > +void insert(Container& target, + typename Container::iterator before, + const SinglePassRange& from); +`` + +[heading Description] + +`insert` all of the elements in the range `from` before the `before` iterator into `target`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm_ext/insert.hpp` + +[heading Requirements] + +# `SinglePassRange` is a model of the __single_pass_range__ Concept. +# `Container` supports insert at a specified position. +# `SinglePassRange`'s value type is convertible to `Container`'s value type. + +[heading Complexity] + +Linear. `distance(from)` assignments are performed. + +[endsect] diff --git a/doc/reference/algorithm_ext/iota.qbk b/doc/reference/algorithm_ext/iota.qbk new file mode 100644 index 0000000..37aba15 --- /dev/null +++ b/doc/reference/algorithm_ext/iota.qbk @@ -0,0 +1,28 @@ +[section:for_each for_each] + +[heading Prototype] + +`` +template +iota(SinglePassRange& rng, Value x); +`` + +[heading Description] + +`iota` traverses forward through `rng`, each element `y` in `rng` is assigned a value equivalent +to `x + boost::distance(boost::begin(rng), it)` + +[heading Definition] + +Defined in the header file `boost/range/algorithm_ext/iota.hpp` + +[heading Requirements] + +# `SinglePassRange` is a model of the __single_pass_range__ Concept. +# `Value` is a model of the `Incrementable` Concept. + +[heading Complexity] + +Linear. Exactly `distance(rng)` assignments into `rng`. + +[endsect] diff --git a/doc/reference/algorithm_ext/overwrite.qbk b/doc/reference/algorithm_ext/overwrite.qbk new file mode 100644 index 0000000..b9307ff --- /dev/null +++ b/doc/reference/algorithm_ext/overwrite.qbk @@ -0,0 +1,34 @@ +[section:overwrite overwrite] + +[heading Prototype] + +`` +template< + class SinglePassRange1, + class SinglePassRange2 + > +void overwrite(const SinglePassRange1& from, + SinglePassRange2& to); +`` + +[heading Description] + +`overwrite` assigns the values from the range `from` into the range `to`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm_ext/overwrite.hpp` + +[heading Requirements] + +# `SinglePassRange1` is a model of the __single_pass_range__ Concept. +# `SinglePassRange2` is a model of the __single_pass_range__ Concept. +# `SinglePassRange2` is mutable. +# `distance(SinglePassRange1) <= distance(SinglePassRange2)` +# `SinglePassRange1`'s value type is convertible to `SinglePassRange2`'s value type. + +[heading Complexity] + +Linear. `distance(rng1)` assignments are performed. + +[endsect] diff --git a/doc/reference/algorithm_ext/push_back.qbk b/doc/reference/algorithm_ext/push_back.qbk new file mode 100644 index 0000000..f3c8952 --- /dev/null +++ b/doc/reference/algorithm_ext/push_back.qbk @@ -0,0 +1,32 @@ +[section:push_back push_back] + +[heading Prototype] + +`` +template< + class Container, + class SinglePassRange + > +void push_back(Container& target, + const SinglePassRange& from); +`` + +[heading Description] + +`push_back` all of the elements in the range `from` to the back of the container `target`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm_ext/push_back.hpp` + +[heading Requirements] + +# `SinglePassRange` is a model of the __single_pass_range__ Concept. +# `Container` supports insert at `end()`. +# `SinglePassRange`'s value type is convertible to `Container`'s value type. + +[heading Complexity] + +Linear. `distance(from)` assignments are performed. + +[endsect] diff --git a/doc/reference/algorithm_ext/push_front.qbk b/doc/reference/algorithm_ext/push_front.qbk new file mode 100644 index 0000000..d827105 --- /dev/null +++ b/doc/reference/algorithm_ext/push_front.qbk @@ -0,0 +1,32 @@ +[section:push_front push_front] + +[heading Prototype] + +`` +template< + class Container, + class SinglePassRange + > +void push_front(Container& target, + const SinglePassRange& from); +`` + +[heading Description] + +`push_front` all of the elements in the range `from` to the front of the container `target`. + +[heading Definition] + +Defined in the header file `boost/range/algorithm_ext/push_front.hpp` + +[heading Requirements] + +# `SinglePassRange` is a model of the __single_pass_range__ Concept. +# `Container` supports insert at `begin()`. +# `SinglePassRange`'s value type is convertible to `Container`'s value type. + +[heading Complexity] + +Linear. `distance(from)` assignments are performed. + +[endsect] diff --git a/doc/reference/algorithm_ext/remove_erase.qbk b/doc/reference/algorithm_ext/remove_erase.qbk new file mode 100644 index 0000000..0164768 --- /dev/null +++ b/doc/reference/algorithm_ext/remove_erase.qbk @@ -0,0 +1,31 @@ +[section:remove_erase remove_erase] + +[heading Prototype] + +`` +template< + class Container, + class T + > +void remove_erase(Container& target, + const T& val); +`` + +[heading Description] + +`remove_erase` actually eliminates the elements equal to `val` from the container. This +is in contrast to the `remove` algorithm which merely rearranges elements. + +[heading Definition] + +Defined in the header file `boost/range/algorithm_ext/erase.hpp` + +[heading Requirements] + +# `Container` supports erase of an iterator range. + +[heading Complexity] + +Linear. Proportional to `distance(target)`s. + +[endsect] diff --git a/doc/reference/algorithm_ext/remove_erase_if.qbk b/doc/reference/algorithm_ext/remove_erase_if.qbk new file mode 100644 index 0000000..f0ae749 --- /dev/null +++ b/doc/reference/algorithm_ext/remove_erase_if.qbk @@ -0,0 +1,32 @@ +[section:remove_erase_if remove_erase_if] + +[heading Prototype] + +`` +template< + class Container, + class Pred + > +void remove_erase(Container& target, + Pred pred); +`` + +[heading Description] + +`remove_erase_if` removes the elements `x` that satisfy `pred(x)` from the container. +This is in contrast to the `erase` algorithm which merely rearranges elements. + +[heading Definition] + +Defined in the header file `boost/range/algorithm_ext/erase.hpp` + +[heading Requirements] + +# `Container` supports erase of an iterator range. +# `Pred` is a model of the `Predicate` Concept. + +[heading Complexity] + +Linear. Proportional to `distance(target)`s. + +[endsect] diff --git a/doc/reference/algorithms.qbk b/doc/reference/algorithms.qbk new file mode 100644 index 0000000..00b3edb --- /dev/null +++ b/doc/reference/algorithms.qbk @@ -0,0 +1,163 @@ +[section:algorithms Range Algorithm] + +[section:range_algorithm_introduction Introduction and motivation] +In its most simple form a [*Range Algorithm] (or range-based algorithm) is simply an iterator-based algorithm where the /two/ iterator arguments have been replaced by /one/ range argument. For example, we may write + +`` +#include +#include + +std::vector vec = ...; +boost::sort(vec); +`` + +instead of + +`` +std::sort(vec.begin(), vec.end()); +`` + +However, the return type of range algorithms is almost always different from that of existing iterator-based algorithms. + +One group of algorithms, like `boost::sort()`, will simply return the same range so that we can continue to pass the range around and/or further modify it. Because of this we may write +`` +boost:unique(boost::sort(vec)); +`` +to first sort the range and then run `unique()` on the sorted range. + +Algorithms like `boost::unique()` fall into another group of algorithms that return (potentially) narrowed views of the original range. By default `boost::unique(rng)` returns the range `[boost::begin(rng), found)` where `found` denotes the iterator returned by `std::unique(boost::begin(rng), boost::end(rng))` + +Therefore exactly the unique values can be copied by writing +`` +boost::copy(boost::unique(boost::sort(vec)), + std::ostream_iterator(std::cout)); +`` + +Algorithms like `boost::unique` usually return the same range: `[boost::begin(rng), found)`. However, this behaviour may be changed by supplying the algorithms with a template argument: + +[table + [[Expression] [Return]] + [[`boost::unique(rng)`] [returns a single iterator like `std::unique`]] + [[`boost::unique(rng)`] [returns the range `[boost::begin(rng), found)` (this is the default)]] + [[`boost::unique(rng)`] [returns the range `[boost::begin(rng), boost::next(found))`]] + [[`boost::unique(rng)`] [returns the range `[found, boost::end(rng))`]] + [[`boost::unique(rng)`] [returns the range `[boost::next(found),boost::end(rng))`]] + [[`boost::unique(rng)`] [returns the entire original range.]] +] + +This functionality has the following advantages: + +# it allows for ['*seamless functional-style programming*] where you do not need to use named local variables to store intermediate results +# it is very ['*safe*] because the algorithm can verify out-of-bounds conditions and handle tricky conditions that lead to empty ranges + +For example, consider how easy we may erase the duplicates in a sorted container: + +`` +std::vector vec = ...; +boost::erase(vec, boost::unique(boost::sort(vec))); +`` + +Notice the use of `boost::return_found_end`. What if we wanted to erase all the duplicates except one of them? In old-fashined STL-programming we might write + +`` +// assume 'vec' is already sorted +std::vector::iterator i = std::unique(vec.begin(), vec.end()); + +// remember this check or you get into problems +if (i != vec.end()) + ++i; + +vec.erase(i, vec.end()); +`` + +The same task may be accomplished simply with +`` +boost::erase(vec, boost::unique(vec)); +`` +and there is no need to worry about generating an invalid range. Furthermore, if the container is complex, calling `vec.begin()` several times will be more expensive than using a range algorithm. + +[endsect] + +[section:range_algorithm_mutating_algorithms Mutating algorithms] +[include algorithm/copy.qbk] +[include algorithm/copy_backward.qbk] +[include algorithm/fill.qbk] +[include algorithm/generate.qbk] +[include algorithm/inplace_merge.qbk] +[include algorithm/merge.qbk] +[include algorithm/nth_element.qbk] +[include algorithm/partial_sort.qbk] +[include algorithm/partition.qbk] +[include algorithm/random_shuffle.qbk] +[include algorithm/remove.qbk] +[include algorithm/remove_if.qbk] +[include algorithm/replace.qbk] +[include algorithm/replace_if.qbk] +[include algorithm/rotate.qbk] +[include algorithm/sort.qbk] +[include algorithm/stable_partition.qbk] +[include algorithm/stable_sort.qbk] +[include algorithm/transform.qbk] +[include algorithm/unique.qbk] +[endsect] + +[section:range_algorithm_non_mutating_algorithms Non-mutating algorithms] +[include algorithm/adjacent_find.qbk] +[include algorithm/binary_search.qbk] +[include algorithm/count.qbk] +[include algorithm/equal.qbk] +[include algorithm/equal_range.qbk] +[include algorithm/for_each.qbk] +[include algorithm/find.qbk] +[include algorithm/find_end.qbk] +[include algorithm/find_first_of.qbk] +[include algorithm/find_if.qbk] +[include algorithm/lexicographical_compare.qbk] +[include algorithm/lower_bound.qbk] +[include algorithm/max_element.qbk] +[include algorithm/min_element.qbk] +[include algorithm/mismatch.qbk] +[include algorithm/search.qbk] +[include algorithm/upper_bound.qbk] +[endsect] + +[section:set_algorithms Set algorithms] +[include algorithm/includes.qbk] +[include algorithm/set_union.qbk] +[include algorithm/set_intersection.qbk] +[include algorithm/set_difference.qbk] +[include algorithm/set_symmetric_difference.qbk] +[endsect] + +[section:heap_algorithms Heap algorithms] +[include algorithm/push_heap.qbk] +[include algorithm/pop_heap.qbk] +[include algorithm/make_heap.qbk] +[endsect] + +[section:permutation_algorithms Permutation algorithms] +[include algorithm/next_permutation.qbk] +[include algorithm/prev_permutation.qbk] +[endsect] + +[section:range_algorithm_new_algorithms New algorithms] +[include algorithm_ext/erase.qbk] +[include algorithm_ext/for_each.qbk] +[include algorithm_ext/insert.qbk] +[include algorithm_ext/iota.qbk] +[include algorithm_ext/overwrite.qbk] +[include algorithm_ext/push_back.qbk] +[include algorithm_ext/push_front.qbk] +[include algorithm_ext/remove_erase.qbk] +[include algorithm_ext/remove_erase_if.qbk] +[endsect] + +[section:range_numeric Numeric algorithms] +[include numeric/accumulate.qbk] +[include numeric/adjacent_difference.qbk] +[include numeric/inner_product.qbk] +[include numeric/partial_sum.qbk] +[endsect] + +[endsect] + diff --git a/doc/reference/extending.qbk b/doc/reference/extending.qbk new file mode 100644 index 0000000..13b0b5e --- /dev/null +++ b/doc/reference/extending.qbk @@ -0,0 +1,318 @@ +[section:extending Extending the library] + +[section:method_1 Method 1: provide member functions and nested types] + +This procedure assumes that you have control over the types that should be made conformant to a Range concept. If not, see [link range.reference.extending.method_2 method 2]. + +The primary templates in this library are implemented such that standard containers will work automatically and so will __boost_array__. Below is given an overview of which member functions and member types a class must specify to be useable as a certain Range concept. + +[table + [[Member function] [Related concept ]] + [[`begin()` ] [__single_pass_range__]] + [[`end()` ] [__single_pass_range__]] +] + +Notice that `rbegin()` and `rend()` member functions are not needed even though the container can support bidirectional iteration. + +The required member types are: + +[table + [[Member type ] [Related concept ]] + [[`iterator` ] [__single_pass_range__]] + [[`const_iterator`] [__single_pass_range__]] +] + +Again one should notice that member types `reverse_iterator` and `const_reverse_iterator` are not needed. + +[endsect] + +[section:method_2 Method 2: provide free-standing functions and specialize metafunctions] + +This procedure assumes that you cannot (or do not wish to) change the types that should be made conformant to a Range concept. If this is not true, see [link range.reference.extending.method_1 method 1]. + +The primary templates in this library are implemented such that certain functions are found via argument-dependent-lookup (ADL). Below is given an overview of which free-standing functions a class must specify to be useable as a certain Range concept. Let `x` be a variable (`const` or `mutable`) of the class in question. + +[table + [[Function ] [Related concept ]] + [[`range_begin(x)`] [__single_pass_range__]] + [[`range_end(x)` ] [__single_pass_range__]] +] + +`range_begin()` and `range_end()` must be overloaded for both `const` and `mutable` reference arguments. + +You must also specialize two metafunctions for your type `X`: + +[table + [[Metafunction ] [Related concept ]] + [[`boost::range_mutable_iterator`] [__single_pass_range__]] + [[`boost::range_const_iterator`] [__single_pass_range__]] +] + +A complete example is given here: + +`` + #include + #include // for std::iterator_traits, std::distance() + + namespace Foo + { + // + // Our sample UDT. A 'Pair' + // will work as a range when the stored + // elements are iterators. + // + template< class T > + struct Pair + { + T first, last; + }; + + } // namespace 'Foo' + + namespace boost + { + // + // Specialize metafunctions. We must include the range.hpp header. + // We must open the 'boost' namespace. + // + + template< class T > + struct range_mutable_iterator< Foo::Pair > + { + typedef T type; + }; + + template< class T > + struct range_const_iterator< Foo::Pair > + { + // + // Remark: this is defined similar to 'range_iterator' + // because the 'Pair' type does not distinguish + // between an iterator and a const_iterator. + // + typedef T type; + }; + + } // namespace 'boost' + + namespace Foo + { + // + // The required functions. These should be defined in + // the same namespace as 'Pair', in this case + // in namespace 'Foo'. + // + + template< class T > + inline T range_begin( Pair& x ) + { + return x.first; + } + + template< class T > + inline T range_begin( const Pair& x ) + { + return x.first; + } + + template< class T > + inline T range_end( Pair& x ) + { + return x.last; + } + + template< class T > + inline T range_end( const Pair& x ) + { + return x.last; + } + + } // namespace 'Foo' + + #include + + int main(int argc, const char* argv[]) + { + typedef std::vector::iterator iter; + std::vector vec; + Foo::Pair pair = { vec.begin(), vec.end() }; + const Foo::Pair& cpair = pair; + // + // Notice that we call 'begin' etc with qualification. + // + iter i = boost::begin( pair ); + iter e = boost::end( pair ); + i = boost::begin( cpair ); + e = boost::end( cpair ); + boost::range_difference< Foo::Pair >::type s = boost::size( pair ); + s = boost::size( cpair ); + boost::range_reverse_iterator< const Foo::Pair >::type + ri = boost::rbegin( cpair ), + re = boost::rend( cpair ); + + return 0; + } +`` + +[endsect] + +[section:method_3 Method 3: provide range adaptor implementations] + +[section:method_3_1 Method 3.1: Implement a Range Adaptor without arguments] + +To implement a Range Adaptor without arguments (e.g. reversed) you need to: + +# Provide a range for your return type, for example: +`` +#include +#include + +template< typename R > +struct reverse_range : + boost::iterator_range< + boost::reverse_iterator< + typename boost::range_iterator::type> > +{ +private: + typedef boost::iterator_range< + boost::reverse_iterator< + typename boost::range_iterator::type> > base; + +public: + typedef boost::reverse_iterator< + typename boost::range_iterator::type > iterator; + + reverse_range(R& r) + : base(iterator(boost::end(r)), iterator(boost::begin(r))) + { } +}; +`` + +# Provide a tag to uniquely identify your adaptor in the `operator|` function overload set +`` +namespace detail { + struct reverse_forwarder {}; +} +`` + +# Implement `operator|` +`` +template< class BidirectionalRng > +inline reverse_range +operator|( BidirectionalRng& r, detail::reverse_forwarder ) +{ + return reverse_range( r ); +} + +template< class BidirectionalRng > +inline reverse_range +operator|( const BidirectionalRng& r, detail::reverse_forwarder ) +{ + return reverse_range( r ); +} +`` + +[endsect] + +[section:method_3_2 Method 3.2: Implement a Range Adaptor with arguments] + +# Provide a range for your return type, for example: +`` +#include +#include +#include + +template +class replace_value +{ +public: + typedef const Value& result_type; + typedef const Value& argument_type; + + replace_value(const Value& from, const Value& to) + : m_from(from), m_to(to) + { + } + + const Value& operator()(const Value& x) const + { + return (x == m_from) ? m_to : x; + } +private: + Value m_from; + Value m_to; +}; + +template +class replace_range +: public boost::iterator_range< + boost::transform_iterator< + replace_value::type>, + typename boost::range_iterator::type> > +{ +private: + typedef typename boost::range_value::type value_type; + typedef typename boost::range_iterator::type iterator_base; + typedef replace_value Fn; + typedef boost::transform_iterator replaced_iterator; + typedef boost::iterator_range base_t; + +public: + replace_range(Range& rng, value_type from, value_type to) + : base_t(replaced_iterator(boost::begin(rng), Fn(from,to)), + replaced_iterator(boost::end(rng), Fn(from,to))) + { + } + }; +`` + +# Implement a holder class to hold the arguments required to construct the RangeAdaptor. + +The holder combines multiple parameters into one that can be passed as the right operand of `operator|()`. + +`` +template +class replace_holder : public boost::range_detail::holder2 +{ +public: + replace_holder(const T& from, const T& to) + : boost::range_detail::holder2(from, to) + { } +private: + void operator=(const replace_holder&); +}; +`` + +# Define an instance of the holder with the name of the adaptor + +`` +static boost::range_detail::forwarder2 +replaced = boost::range_detail::forwarder2(); +`` + +# Define `operator|` + +`` +template +inline replace_range +operator|(SinglePassRange& rng, + const replace_holder::type>& f) +{ + return replace_range(rng, f.val1, f.val2); +} + +template +inline replace_range +operator|(const SinglePassRange& rng, + const replace_holder::type>& f) +{ + return replace_range(rng, f.val1, f.val2); +} +`` + +[endsect] + +[endsect] + +[endsect] + diff --git a/doc/reference/numeric/accumulate.qbk b/doc/reference/numeric/accumulate.qbk new file mode 100644 index 0000000..e642305 --- /dev/null +++ b/doc/reference/numeric/accumulate.qbk @@ -0,0 +1,56 @@ +[section:accumulate accumulate] + +[heading Prototype] + +`` +template< + class SinglePassRange, + class Value + > +Value accumulate(const SinglePassRange& source_rng, + Value init); + +template< + class SinglePassRange, + class Value, + class BinaryOperation + > +Value accumulate(const SinglePassRange& source_rng, + Value init, + BinaryOperation op); +`` + +[heading Description] + +`accumulate` is a generalisation of summation. It computes a binary operation (`operator+` +in the non-predicate version) of `init` and all of the elements in `rng`. + +The return value is the resultant value of the above algorithm. + +[heading Definition] + +Defined in the header file `boost/range/numeric.hpp` + +[heading Requirements] + +[heading For the first version] + +# `SinglePassRange` is a model of the __single_pass_range__ Concept. +# `Value` is a model of the `AssignableConcept`. +# An `operator+` is defined for a left-hand operand of type `Value` and a right-hand operance of the `SinglePassRange` value type. +# The return type of the above operator is convertible to `Value`. + +[heading For the second version] + +# `SinglePassRange` is a model of the __single_pass_range__ Concept. +# `Value` is a model of the `AssignableConcept`. +# `BinaryOperation` is a model of the `BinaryFunctionConcept`. +# `Value` is convertible to `BinaryOperation`'s first argument type. +# `SinglePassRange`'s value type is convertible to `BinaryOperation`'s second argument type. +# The return type of `BinaryOperation` is convertible to `Value`. + +[heading Complexity] + +Linear. Exactly `distance(source_rng)`. + +[endsect] diff --git a/doc/reference/numeric/adjacent_difference.qbk b/doc/reference/numeric/adjacent_difference.qbk new file mode 100644 index 0000000..f7ea1f7 --- /dev/null +++ b/doc/reference/numeric/adjacent_difference.qbk @@ -0,0 +1,63 @@ +[section:adjacent_difference adjacent_difference] + +[heading Prototype] + +`` +template< + class SinglePassRange, + class OutputIterator + > +OutputIterator adjacent_difference( + const SinglePassRange& source_rng, + OutputIterator out_it); + +template< + class SinglePassRange, + class OutputIterator, + class BinaryOperation + > +OutputIterator adjacent_difference( + const SinglePassRange& source_rng, + OutputIterator out_it, + BinaryOperation op); +`` + +[heading Description] + +`adjacent_difference` calculates the differences of adjacent_elements in `rng`. + +The first version of `adjacent_difference` uses `operator-()` to calculate the differences. +The second version uses `BinaryOperation` instead of `operator-()`. + +[heading Definition] + +Defined in the header file `boost/range/numeric.hpp` + +[heading Requirements] + +[heading For the first version] + +# `SinglePassRange` is a model of the __single_pass_range__ Concept. +# `OutputIterator` is a model of the `OutputIteratorConcept`. +# If `x` and `y` are objects of `SinglePassRange`'s value type, then `x - y` is defined. +# The value type of `SinglePassRange` is convertible to a type in `OutputIterator`'s set of value types. +# The return type of `x - y` is convertible to a type in `OutputIterator`'s set of value types. + +[heading For the second version] + +# `SinglePassRange` is a model of the __single_pass_range__ Concept. +# `OutputIterator` is a model of the `OutputIteratorConcept`. +# `BinaryOperation` is a model of the `BinaryFunctionConcept`. +# The value type of `SinglePassRange` is convertible to `BinaryOperation`'s first and second argument types. +# The value type of `SinglePassRange` is convertible to a type in `OutputIterator`'s set of value types. +# The result type of `BinaryOperation` is convertible to a type in `OutputIterator`'s set of value types. + +[heading Precondition:] + +`[result, result + distance(rng))` is a valid range. + +[heading Complexity] + +Linear. If `empty(rng)` then zero applications, otherwise `distance(rng) - 1` applications are performed. + +[endsect] diff --git a/doc/reference/numeric/inner_product.qbk b/doc/reference/numeric/inner_product.qbk new file mode 100644 index 0000000..2b42f8d --- /dev/null +++ b/doc/reference/numeric/inner_product.qbk @@ -0,0 +1,67 @@ +[section:inner_product inner_product] + +[heading Prototype] + +`` +template + Value inner_product( const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + Value init ); + +template + Value inner_product( const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + Value init, + BinaryOperation1 op1 ); +`` + +[heading Description] + +`inner_product` calculates a generalised inner product of the range `rng1` and `rng2`. + +For further information on the `inner_product` algorithm please see __sgi_inner_product__. + +[heading Definition] + +Defined in the header file `boost/range/numeric.hpp` + +[heading Requirements] + +[heading For the first version] + +# `SinglePassRange1` is a model of the __single_pass_range__ Concept. +# `SinglePassRange2` is a model of the __single_pass_range__ Concept. +# `Value` is a model of the `AssignableConcept`. +# If `x` is an object of type `Value`, `y` is an object of `SinglePassRange1`'s value +type, and `z` is an object of `SinglePassRange2`'s value type, then `x + y * z` +is defined. +# The result type of the expression `x + y * z` is convertible to `Value`. + +[heading For the second version] + +# `SinglePassRange1` is a model of the __single_pass_range__ Concept. +# `SinglePassRange2` is a model of the __single_pass_range__ Concept. +# `Value` is a model of the `AssignableConcept`. +# `BinaryOperation1` is a model of the `BinaryFunctionConcept`. +# `BinaryOperation2` is a model of the `BinaryFunctionConcept`. +# The value type of `SinglePassRange1` is convertible to the first argument type of `BinaryOperation2`. +# The value type of `SinglePassRange2` is convertible to the second argument type of `BinaryOperation2`. +# `Value` is convertible to the value type of `BinaryOperation1`. +# The return type of `BinaryOperation2` is convertible to the second argument type of `BinaryOperation1`. +# The return type of `BinaryOperation1` is convertible to `Value`. + +[heading Precondition:] + +`distance(rng2) >= distance(rng1)` is a valid range. + +[heading Complexity] + +Linear. Exactly `distance(rng)`. + +[endsect] diff --git a/doc/reference/numeric/partial_sum.qbk b/doc/reference/numeric/partial_sum.qbk new file mode 100644 index 0000000..aa556e2 --- /dev/null +++ b/doc/reference/numeric/partial_sum.qbk @@ -0,0 +1,55 @@ +[section:partial_sum partial_sum] + +[heading Prototype] + +`` +template +OutputIterator partial_sum(const SinglePassRange& rng, + OutputIterator out_it); + +template +OutputIterator partial_sum(const SinglePassRange& rng, + OutputIterator out_it, + BinaryOperation op); +`` + +[heading Description] + +`partial_sum` calculates a generalised partial sum of `rng` in the same manner as +`std::partial_sum(boost::begin(rng), boost::end(rng), out_it)`. See __sgi_partial_sum__. + + +[heading Definition] + +Defined in the header file `boost/range/numeric.hpp` + +[heading Requirements] + +[heading For the first version] + +# `SinglePassRange` is a model of the __single_pass_range__ Concept. +# `OutputIterator` is a model of the `OutputIteratorConcept`. +# If `x` and `y` are objects of `SinglePassRange`'s value type, then `x + y` is defined. +# The return type of `x + y` is convertible to the value type of `SinglePassRange`. +# The value type of `SinglePassRange` is convertible to a type in `OutputIterator`'s set of value types. + +[heading For the second version] + +# `SinglePassRange` is a model of the __single_pass_range__ Concept. +# `OutputIterator` is a model of the `OutputIteratorConcept`. +# `BinaryOperation` is a model of the `BinaryFunctionConcept`. +# The result type of `BinaryOperation` is convertible to the value type of `SinglePassRange`. +# The value type of `SinglePassRange` is convertible to a type in `OutputIterator`'s set of value types. + +[heading Precondition:] + +`[result, result + distance(rng))` is a valid range. + +[heading Complexity] + +Linear. If `empty(rng)` then zero applications, otherwise `distance(rng) - 1` applications are performed. + +[endsect] diff --git a/doc/reference/overview.qbk b/doc/reference/overview.qbk new file mode 100644 index 0000000..48b3ee6 --- /dev/null +++ b/doc/reference/overview.qbk @@ -0,0 +1,14 @@ +[section Overview] + +Three types of objects are currently supported by the library: + +* standard-like containers +* `std::pair` +* built-in arrays + +Even though the behavior of the primary templates are exactly such that standard containers will be supported by default, the requirements are much lower than the standard container requirements. For example, the utility class __iterator_range__ implements the __minimal_interface__ required to make the class a __forward_range__. + +Please also see __range_concepts__ for more details. + +[endsect] + diff --git a/doc/reference/ranges.qbk b/doc/reference/ranges.qbk new file mode 100644 index 0000000..aaee7d8 --- /dev/null +++ b/doc/reference/ranges.qbk @@ -0,0 +1,8 @@ +[section:ranges Provided Ranges] + +[include ranges/counting_range.qbk] +[include ranges/istream_range.qbk] +[include ranges/irange.qbk] + +[endsect] + diff --git a/doc/reference/ranges/counting_range.qbk b/doc/reference/ranges/counting_range.qbk new file mode 100644 index 0000000..c9484b8 --- /dev/null +++ b/doc/reference/ranges/counting_range.qbk @@ -0,0 +1,31 @@ +[section:counting_range counting_range] + +[heading Prototype] + +`` +template< class Incrementable > inline +iterator_range< counting_iterator > +counting_range(Incrementable first, Incrementable last); + +template< class SinglePassRange > inline +iterator_range< counting_iterator::type > +counting_range(const SinglePassRange& rng); + +template< class SinglePassRange > inline +iterator_range< counting_iterator::type > +counting_range(SinglePassRange& rng); +`` + +[heading Description] + +`counting_range` is a function to generator that generates an `iterator_range` wrapping a `counting_iterator` (from Boost.Iterator). + +[heading Definition] + +Defined in header file `boost/range/counting_range.hpp` + +[heading Requirements] + +# `Incrementable` is a model of the `Incrementable` Concept. + +[endsect] diff --git a/doc/reference/ranges/irange.qbk b/doc/reference/ranges/irange.qbk new file mode 100644 index 0000000..bd9efc4 --- /dev/null +++ b/doc/reference/ranges/irange.qbk @@ -0,0 +1,35 @@ +[section:irange irange] + +[heading Prototype] + +`` +template +integer_range< range_detail::integer_iterator > +irange(Integer first, Integer last); + +template +integer_range< range_detail::integer_iterator_with_step > +irange(Integer first, Integer last, StepSize step_size); +`` + +[heading Description] + +`irange` is a function to generate an Integer Range. + +`irange` allows treating integers as a model of the __random_access_range__ Concept. It should be noted that the `first` and `last` parameters denoted a half-open range. + +[heading Definition] + +Defined in the header file `boost/range/irange.hpp` + +[heading Requirements] + +# `Integer` is a model of the `Integer` Concept. +# `StepSize` is a model of the `SignedInteger` Concept. + +[heading Complexity] + +Constant. Since this function generates a new range the most significant performance cost is incurred through the iteration of the generated range. + +[endsect] + diff --git a/doc/reference/ranges/istream_range.qbk b/doc/reference/ranges/istream_range.qbk new file mode 100644 index 0000000..2b195e7 --- /dev/null +++ b/doc/reference/ranges/istream_range.qbk @@ -0,0 +1,19 @@ +[section:istream_range istream_range] + +[heading Prototype] + +`` +template< class Type, class Elem, class Traits > inline +iterator_range< std::istream_iterator > +istream_range(std::basic_istream& in); +`` + +[heading Description] + +`istream_range` is a function to generator that generates an `iterator_range` wrapping a `std::istream_iterator`. + +[heading Definition] + +Defined in header file `boost/range/istream_range.hpp` + +[endsect] diff --git a/doc/reference/semantics.qbk b/doc/reference/semantics.qbk new file mode 100644 index 0000000..47d15c9 --- /dev/null +++ b/doc/reference/semantics.qbk @@ -0,0 +1,185 @@ +[section Semantics] + +[heading notation] + +[table + [[Type ] [Object] [Describes ]] + [[`X` ] [`x` ] [any type ]] + [[`T` ] [`t` ] [denotes behavior of the primary templates]] + [[`P` ] [`p` ] [denotes `std::pair` ]] + [[`A[sz]`] [`a` ] [denotes an array of type `A` of size `sz`]] + [[`Char*`] [`s` ] [denotes either `char*` or `wchar_t*` ]] +] + +[section Metafunctions] + +[table + [[Expression] [Return type] [Complexity]] + [ + [`range_iterator::type`] + [`` + T::iterator + P::first_type + A* + ``] + [compile time] + ] + [ + [`range_iterator::type`] + [`` + T::const_iterator + P::first_type + const A* + ``] + [compile time] + ] + [ + [`range_value::type`] + [`boost::iterator_value::type>::type`] + [compile time] + ] + [ + [`range_reference::type`] + [`boost::iterator_reference::type>::type`] + [compile time] + ] + [ + [`range_pointer::type`] + [`boost::iterator_pointer::type>::type`] + [compile time] + ] + [ + [`range_category::type`] + [`boost::iterator_category::type>::type`] + [compile time] + ] + [ + [`range_difference::type`] + [`boost::iterator_category::type>::type`] + [compile time] + ] + [ + [`range_reverse_iterator::type`] + [`boost::reverse_iterator::type>`] + [compile time] + ] + [ + [`range_reverse_iterator::type`] + [`boost::reverse_iterator::type`] + [compile time] + ] +] + +[endsect] + +[section Functions] + +[table + [[Expression] [Return type] [Returns] [Complexity]] + + [ + [`begin(x)`] + [`range_iterator::type`] + [ + `p.first` if `p` is of type `std::pair` + `a` if `a` is an array + `range_begin(x)` if that expression would invoke a function found by ADL + `t.begin()` otherwise + ] + [constant time] + ] + [ + [`end(x)`] + [`range_iterator::type`] + [ + `p.second` if `p` is of type `std::pair` + `a + sz` if `a` is an array of size `sz` + `range_end(x)` if that expression would invoke a function found by ADL + `t.end()` otherwise + ] + [constant time] + ] + [ + [`empty(x)`] + [`bool`] + [`boost::begin(x) == boost::end(x)`] + [constant time] + ] + [ + [`distance(x)`] + [`range_difference::type`] + [`std::distance(boost::begin(x),boost::end(x))`] + [-] + ] + [ + [`size(x)`] + [`range_difference::type`] + [`boost::end(x) - boost::begin(x)`] + [constant time] + ] + [ + [`rbegin(x)`] + [`range_reverse_iterator::type`] + [`range_reverse_iterator::type(boost::end(x))`] + [constant time] + ] + [ + [`rend(x)`] + [`range_reverse_iterator::type`] + [`range_reverse_iterator::type(boost::begin(x))`] + [constant time] + ] + [ + [`const_begin(x)`] + [`range_iterator::type`] + [`range_iterator::type(boost::begin(x))`] + [constant time] + ] + [ + [`const_end(x)`] + [`range_iterator::type`] + [`range_iterator::type(boost::end(x))`] + [constant time] + ] + [ + [`const_rbegin(x)`] + [`range_reverse_iterator::type`] + [`range_reverse_iterator::type(boost::rbegin(x))`] + [constant time] + ] + [ + [`const_rend(x)`] + [`range_reverse_iterator::type`] + [`range_reverse_iterator::type(boost::rend(x))`] + [constant time] + ] + [ + [`as_literal(x)`] + [`iterator_range` where `U` is `Char*` if `x` is a pointer to a string and `U` is `range_iterator::type` otherwise] + [ + `[s,s + std::char_traits::length(s))` if `s` is a `Char*` or an array of `Char` `[boost::begin(x),boost::end(x))` otherwise + ] + [ + linear time for pointers to a string or arrays of `Char`, constant time otherwise + ] + ] + [ + [`as_array(x)`] + [`iterator_range`] + [`[boost::begin(x),boost::end(x))`] + ] +] + +The special `const_`-named functions are useful when you want to document clearly that your code is read-only. + +`as_literal()` can be used ['*internally*] in string algorithm libraries such that arrays of characters are handled correctly. + +`as_array()` can be used with string algorithm libraries to make it clear that arrays of characters are handled like an array and not like a string. + +Notice that the above functions should always be called with qualification (`boost::`) to prevent ['*unintended*] Argument Dependent Lookup (ADL). + +[endsect] + +[endsect] + + diff --git a/doc/reference/synopsis.qbk b/doc/reference/synopsis.qbk new file mode 100644 index 0000000..5848bd2 --- /dev/null +++ b/doc/reference/synopsis.qbk @@ -0,0 +1,143 @@ +[section Synopsis] + +`` +namespace boost +{ + // + // Single Pass Range metafunctions + // + + template< class T > + struct range_iterator; + + template< class T > + struct range_value; + + template< class T > + struct range_reference; + + template< class T > + struct range_pointer; + + template< class T > + struct range_category; + + // + // Forward Range metafunctions + // + + template< class T > + struct range_difference; + + // + // Bidirectional Range metafunctions + // + + template< class T > + struct range_reverse_iterator; + + // + // Single Pass Range functions + // + + template< class T > + typename range_iterator::type + begin( T& r ); + + template< class T > + typename range_iterator::type + begin( const T& r ); + + template< class T > + typename range_iterator::type + end( T& r ); + + template< class T > + typename range_iterator::type + end( const T& r ); + + template< class T > + bool + empty( const T& r ); + + // + // Forward Range functions + // + + template< class T > + typename range_difference::type + distance( const T& r ); + + // + // Bidirectional Range functions + // + + template< class T > + typename range_reverse_iterator::type + rbegin( T& r ); + + template< class T > + typename range_reverse_iterator::type + rbegin( const T& r ); + + template< class T > + typename range_reverse_iterator::type + rend( T& r ); + + template< class T > + typename range_reverse_iterator::type + rend( const T& r ); + + // + // Random Access Range functions + // + + template< class T > + typename range_difference::type + size( const T& r ); + + // + // Special const Range functions + // + + template< class T > + typename range_iterator::type + const_begin( const T& r ); + + template< class T > + typename range_iterator::type + const_end( const T& r ); + + template< class T > + typename range_reverse_iterator::type + const_rbegin( const T& r ); + + template< class T > + typename range_reverse_iterator::type + const_rend( const T& r ); + + // + // String utilities + // + + template< class T > + iterator_range< ... see below ... > + as_literal( T& r ); + + template< class T > + iterator_range< ... see below ... > + as_literal( const T& r ); + + template< class T > + iterator_range< typename range_iterator::type > + as_array( T& r ); + + template< class T > + iterator_range< typename range_iterator::type > + as_array( const T& r ); + +} // namespace 'boost' +`` + +[endsect] + diff --git a/doc/style.qbk b/doc/style.qbk new file mode 100644 index 0000000..779fd5c --- /dev/null +++ b/doc/style.qbk @@ -0,0 +1,45 @@ +[section:style_guide Terminology and style guidelines] + +The use of a consistent terminology is as important for __ranges__ and range-based algorithms as it is for iterators and iterator-based algorithms. If a conventional set of names are adopted, we can avoid misunderstandings and write generic function prototypes that are [*/self-documenting/]. + +Since ranges are characterized by a specific underlying iterator type, we get a type of range for each type of iterator. Hence we can speak of the following types of ranges: + +* [*/Value access/] category: + * Readable Range + * Writeable Range + * Swappable Range + * Lvalue Range +* [*/Traversal/] category: + * __single_pass_range__ + * __forward_range__ + * __bidirectional_range__ + * __random_access_range__ + +Notice how we have used the categories from the __new_style_iterators__. + +Notice that an iterator (and therefore an range) has one [*/traversal/] property and one or more properties from the [*/value access/] category. So in reality we will mostly talk about mixtures such as + +* Random Access Readable Writeable Range +* Forward Lvalue Range + +By convention, we should always specify the [*/traversal/] property first as done above. This seems reasonable since there will only be one [*/traversal/] property, but perhaps many [*/value access/] properties. + +It might, however, be reasonable to specify only one category if the other category does not matter. For example, the __iterator_range__ can be constructed from a Forward Range. This means that we do not care about what [*/value access/] properties the Range has. Similarly, a Readable Range will be one that has the lowest possible [*/traversal/] property (Single Pass). + +As another example, consider how we specify the interface of `std::sort()`. Algorithms are usually more cumbersome to specify the interface of since both [*/traversal/] and [*/value access/] properties must be exactly defined. The iterator-based version looks like this: + +`` + template< class RandomAccessTraversalReadableWritableIterator > + void sort( RandomAccessTraversalReadableWritableIterator first, + RandomAccessTraversalReadableWritableIterator last ); +`` + +For ranges the interface becomes + +`` + template< class RandomAccessReadableWritableRange > + void sort( RandomAccessReadableWritableRange& r ); +`` + +[endsect] + diff --git a/doc/upgrade.qbk b/doc/upgrade.qbk new file mode 100644 index 0000000..016f89c --- /dev/null +++ b/doc/upgrade.qbk @@ -0,0 +1,30 @@ +[section:upgrade Upgrade version of Boost.Range] + +[section:upgrade_from_1_42 Upgrade from version 1.42] + +New features: + +# __range_adaptors__ +# __range_algorithms__ + +Removed: + +# `iterator_range` no longer has a `is_singular` member function. The singularity restrictions have been removed from the `iterator_range` class since this added restrictions to ranges of iterators whose default constructors were not singular. Previously the `is_singular` member function always returned `false` in release build configurations, hence it is not anticipated that this interface change will produce difficulty in upgrading. + + +[endsect] + +[section:upgrade_from_1_34 Upgrade from version 1.34] + +Boost version 1.35 introduced some larger refactorings of the library: + +# Direct support for character arrays was abandoned in favor of uniform treatment of all arrays. Instead string algorithms can use the new function __as_literal__`()`. +# __size__ now requires a __random_access_range__. The old behavior is provided as __distance__`()`. +# `range_size::type` has been completely removed in favor of `range_difference::type` +# `boost_range_begin()` and `boost_range_end()` have been renamed `range_begin()` and `range_end()` respectively. +# `range_result_iterator::type` and `range_reverse_result_iterator::type` have been renamed `range_iterator::type` and `range_reverse_iterator::type`. +# The procedure that makes a custom type work with the library has been greatly simplified. See __extending_for_udts__ for details. + +[endsect] + +[endsect] diff --git a/doc/utilities.qbk b/doc/utilities.qbk new file mode 100644 index 0000000..20ce6b6 --- /dev/null +++ b/doc/utilities.qbk @@ -0,0 +1,296 @@ +[section:utilities Utilities] + +Having an abstraction that encapsulates a pair of iterators is very useful. The standard library uses `std::pair` in some circumstances, but that class is cumbersome to use because we need to specify two template arguments, and for all range algorithm purposes we must enforce the two template arguments to be the same. Moreover, `std::pair` is hardly self-documenting whereas more domain specific class names are. Therefore these two classes are provided: + +* Class `iterator_range` +* Class `sub_range` +* Function `join` + +The `iterator_range` class is templated on an __forward_traversal_iterator__ and should be used whenever fairly general code is needed. The `sub_range` class is templated on an __forward_range__ and it is less general, but a bit easier to use since its template argument is easier to specify. The biggest difference is, however, that a `sub_range` can propagate constness because it knows what a corresponding `const_iterator` is. + +Both classes can be used as ranges since they implement the __minimal_interface__ required for this to work automatically. + +[section:iterator_range Class `iterator_range`] + +The intention of the `iterator_range` class is to encapsulate two iterators so they fulfill the __forward_range__ concept. A few other functions are also provided for convenience. + +If the template argument is not a model of __forward_traversal_iterator__, one can still use a subset of the interface. In particular, `size()` requires Random Access Traversal Iterators whereas `empty()` only requires Single Pass Iterators. + +Recall that many default constructed iterators are [*/singular/] and hence can only be assigned, but not compared or incremented or anything. However, if one creates a default constructed `iterator_range`, then one can still call all its member functions. This design decision avoids the `iterator_range` imposing limitations upon ranges of iterators that are not singular. Any singularity limitation is simply propogated from the underlying iterator type. + + +[h4 Synopsis] + +`` +namespace boost +{ + template< class ForwardTraversalIterator > + class iterator_range + { + public: // Forward Range types + typedef ForwardTraversalIterator iterator; + typedef ForwardTraversalIterator const_iterator; + typedef iterator_difference::type difference_type; + + public: // construction, assignment + template< class ForwardTraversalIterator2 > + iterator_range( ForwardTraversalIterator2 Begin, ForwardTraversalIterator2 End ); + + template< class ForwardRange > + iterator_range( ForwardRange& r ); + + template< class ForwardRange > + iterator_range( const ForwardRange& r ); + + template< class ForwardRange > + iterator_range& operator=( ForwardRange& r ); + + template< class ForwardRange > + iterator_range& operator=( const ForwardRange& r ); + + public: // Forward Range functions + iterator begin() const; + iterator end() const; + + public: // convenience + operator unspecified_bool_type() const; + bool equal( const iterator_range& ) const; + value_type& front() const; + value_type& back() const; + iterator_range& advance_begin(difference_type n); + iterator_range& advance_end(difference_type n); + bool empty() const; + // for Random Access Range only: + reference operator[]( difference_type at ) const; + value_type operator()( difference_type at ) const; + size_type size() const; + }; + + // stream output + template< class ForwardTraversalIterator, class T, class Traits > + std::basic_ostream& + operator<<( std::basic_ostream& Os, + const iterator_range& r ); + + // comparison + template< class ForwardTraversalIterator, class ForwardTraversalIterator2 > + bool operator==( const iterator_range& l, + const iterator_range& r ); + + template< class ForwardTraversalIterator, class ForwardRange > + bool operator==( const iterator_range& l, + const ForwardRange& r ); + + template< class ForwardTraversalIterator, class ForwardRange > + bool operator==( const ForwardRange& l, + const iterator_range& r ); + + template< class ForwardTraversalIterator, class ForwardTraversalIterator2 > + bool operator!=( const iterator_range& l, + const iterator_range& r ); + + template< class ForwardTraversalIterator, class ForwardRange > + bool operator!=( const iterator_range& l, + const ForwardRange& r ); + + template< class ForwardTraversalIterator, class ForwardRange > + bool operator!=( const ForwardRange& l, + const iterator_range& r ); + + template< class ForwardTraversalIterator, class ForwardTraversalIterator2 > + bool operator<( const iterator_range& l, + const iterator_range& r ); + + template< class ForwardTraversalIterator, class ForwardRange > + bool operator<( const iterator_range& l, + const ForwardRange& r ); + + template< class ForwardTraversalIterator, class ForwardRange > + bool operator<( const ForwardRange& l, + const iterator_range& r ); + + // external construction + template< class ForwardTraversalIterator > + iterator_range< ForwardTraversalIterator > + make_iterator_range( ForwardTraversalIterator Begin, + ForwardTraversalIterator End ); + + template< class ForwardRange > + iterator_range< typename range_iterator::type > + make_iterator_range( ForwardRange& r ); + + template< class ForwardRange > + iterator_range< typename range_iterator::type > + make_iterator_range( const ForwardRange& r ); + + template< class Range > + iterator_range< typename range_iterator::type > + make_iterator_range( Range& r, + typename range_difference::type advance_begin, + typename range_difference::type advance_end ); + + template< class Range > + iterator_range< typename range_iterator::type > + make_iterator_range( const Range& r, + typename range_difference::type advance_begin, + typename range_difference::type advance_end ); + + // convenience + template< class Sequence, class ForwardRange > + Sequence copy_range( const ForwardRange& r ); + +} // namespace 'boost' +`` + +If an instance of `iterator_range` is constructed by a client with two iterators, the client must ensure that the two iterators delimit a valid closed-open range [begin,end). + +It is worth noticing that the templated constructors and assignment operators allow conversion from `iterator_range` to `iterator_range`. Similarly, since the comparison operators have two template arguments, we can compare ranges whenever the iterators are comparable; for example when we are dealing with const and non-const iterators from the same container. + +[h4 Details member functions] + +`operator unspecified_bool_type() const;` + +[:['[*Returns]] `!empty();`] + +`bool equal( iterator_range& r ) const;` + +[:['[*Returns]] `begin() == r.begin() && end() == r.end();`] + +[h4 Details functions] + +`bool operator==( const ForwardRange1& l, const ForwardRange2& r );` + +[:['[*Returns]] `size(l) != size(r) ? false : std::equal( begin(l), end(l), begin(r) );`] + +`bool operator!=( const ForwardRange1& l, const ForwardRange2& r );` + +[:['[*Returns]] `!( l == r );`] + +`bool operator<( const ForwardRange1& l, const ForwardRange2& r );` + +[:['[*Returns]] `std::lexicographical_compare( begin(l), end(l), begin(r), end(r) );`] + +`` +iterator_range make_iterator_range( Range& r, + typename range_difference::type advance_begin, + typename range_difference::type advance_end ); +`` + +[:['[*Effects:]]] + +`` + iterator new_begin = begin( r ), + iterator new_end = end( r ); + std::advance( new_begin, advance_begin ); + std::advance( new_end, advance_end ); + return make_iterator_range( new_begin, new_end ); +`` + +`Sequence copy_range( const ForwardRange& r );` + +[:['[*Returns]] `Sequence( begin(r), end(r) );`] + +[endsect] + +[section:sub_range Class `sub_range`] + +The `sub_range` class inherits all its functionality from the __iterator_range__ class. The `sub_range` class is often easier to use because one must specify the __forward_range__ template argument instead of an iterator. Moreover, the `sub_range` class can propagate constness since it knows what a corresponding `const_iterator` is. + +[h4 Synopsis] + +`` +namespace boost +{ + template< class ForwardRange > + class sub_range : public iterator_range< typename range_iterator::type > + { + public: + typedef typename range_iterator::type iterator; + typedef typename range_iterator::type const_iterator; + typedef typename iterator_difference::type difference_type; + + public: // construction, assignment + template< class ForwardTraversalIterator > + sub_range( ForwardTraversalIterator Begin, ForwardTraversalIterator End ); + + template< class ForwardRange2 > + sub_range( ForwardRange2& r ); + + template< class ForwardRange2 > + sub_range( const Range2& r ); + + template< class ForwardRange2 > + sub_range& operator=( ForwardRange2& r ); + + template< class ForwardRange2 > + sub_range& operator=( const ForwardRange2& r ); + + public: // Forward Range functions + iterator begin(); + const_iterator begin() const; + iterator end(); + const_iterator end() const; + + public: // convenience + value_type& front(); + const value_type& front() const; + value_type& back(); + const value_type& back() const; + // for Random Access Range only: + value_type& operator[]( size_type at ); + const value_type& operator[]( size_type at ) const; + + public: + // rest of interface inherited from iterator_range + }; + +} // namespace 'boost' +`` + +The class should be trivial to use as seen below. Imagine that we have an algorithm that searches for a sub-string in a string. The result is an iterator_range, that delimits the match. We need to store the result from this algorithm. Here is an example of how we can do it with and without `sub_range` + +`` +std::string str("hello"); +iterator_range ir = find_first( str, "ll" ); +sub_range sub = find_first( str, "ll" ); +`` + +[endsect] + +[section:join Function join] + +The intention of the `join` function is to join two ranges into one longer range. + +The resultant range will have the lowest common traversal of the two ranges supplied as parameters. + +Note that the joined range incurs a performance cost due to the need to check if the end of a range has been reached internally during traversal. + +[h4 Synposis] +`` +template +iterator_range::type, + typename range_iterator::type, + typename add_const< + typename range_value::type>::type> +> +join(const SinglePassRange1& rng1, const SinglePassRange2& rng2) + +template +iterator_range::type, + typename range_iterator::type, + typename range_value::type> +> +join(SinglePassRange1& rng1, SinglePassRange2& rng2); +`` + +[h4 Example] + +The expression `join(irange(0,5), irange(5,10))` would evaluate to a range representing an integer range `[0,10)` + + +[endsect] + +[endsect] + diff --git a/include/boost/range/adaptor/adjacent_filtered.hpp b/include/boost/range/adaptor/adjacent_filtered.hpp new file mode 100644 index 0000000..4f0bb75 --- /dev/null +++ b/include/boost/range/adaptor/adjacent_filtered.hpp @@ -0,0 +1,255 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_ADJACENT_FILTER_IMPL_HPP +#define BOOST_RANGE_ADAPTOR_ADJACENT_FILTER_IMPL_HPP + +#include +#ifdef BOOST_MSVC +#pragma warning( push ) +#pragma warning( disable : 4355 ) +#endif + +#include +#include +#include +#include +#include +#include + + +namespace boost +{ + + namespace range_detail + { + template< class Iter, class R > + class skip_iterator + : public boost::iterator_adaptor< skip_iterator, Iter > + { + private: + typedef boost::iterator_adaptor< skip_iterator, Iter > + base_t; + + R* range; + + public: + typedef Iter wrapped_iter_t; + + // + // The iterators are bound to the lifetime of the + // range and may not exist on their own. Hence it makes no + // sense to e.g. wrap them in reverse_iterators + // (that can OTOH be done in advance). + // + typedef std::input_iterator_tag iterator_category; + + explicit skip_iterator( R* r, Iter i ) + : base_t(i), range(r) {} + + template< class OtherIter, class R2> + skip_iterator( const skip_iterator& other ) + : base_t( other.base() ) {} + + R* get_range() const { return range; } + + private: + friend class boost::iterator_core_access; + + void increment() + { + BOOST_ASSERT( range != 0 ); + range->increment_impl( this->base_reference() ); + } + + // + // Not needed ... just apply a reverse_iterator + // + void decrement() + { + BOOST_ASSERT( false && "you can't decrement an adjacent_filter_iterator" ); + } + + template< class D > + void advance( D n ) + { + BOOST_ASSERT( false ); + } + + }; + + template< class P, class R > + struct adjacent_filter_range + : iterator_range< skip_iterator< + BOOST_DEDUCED_TYPENAME range_iterator::type, + adjacent_filter_range + > + > + { + private: + typedef skip_iterator< + BOOST_DEDUCED_TYPENAME range_iterator::type, + adjacent_filter_range + > + skip_iter; + typedef iterator_range + base_range; + + typedef BOOST_DEDUCED_TYPENAME range_iterator::type raw_iterator; + + P m_bi_pred; + + // Get the first element in the half-open range that + // passes the filter predicate. + // The adjacent_filter_range must only contain values that pass + // through the filter. + static raw_iterator to_valid(raw_iterator it, raw_iterator last, const P& bi_pred, bool default_pass) + { + if (it != last) + { + if (default_pass) + { + raw_iterator nxt = ::boost::next(it); + while (nxt != last && !bi_pred(*it, *nxt)) + { + ++it; + ++nxt; + } + } + else + { + raw_iterator nxt = ::boost::next(it); + for(; nxt != last; ++it, ++nxt) + { + if (bi_pred(*it, *nxt)) + { + break; + } + } + if (nxt == last) + { + it = last; + } + } + } + return it; + } + + public: + adjacent_filter_range( const P& p, R& r, bool default_pass ) + : base_range( skip_iter( this, to_valid(boost::begin(r), boost::end(r), p, default_pass)), + skip_iter( this, boost::end(r) ) ), + m_bi_pred( p ), + m_default_pass(default_pass) + { + } + + void increment_impl( raw_iterator& current ) + { + BOOST_ASSERT( current != this->end().base() ); + + current = to_valid(::boost::next(current), this->end().base(), m_bi_pred, m_default_pass); + } + + private: + bool m_default_pass; + }; + + template< class T > + struct adjacent_holder : holder + { + adjacent_holder( T r ) : holder(r) + { } + }; + + template< class T > + struct adjacent_excl_holder : holder + { + adjacent_excl_holder( T r ) : holder(r) + { } + }; + + template< class ForwardRng, class BinPredicate > + inline adjacent_filter_range + operator|( ForwardRng& r, + const adjacent_holder& f ) + { + return adjacent_filter_range( f.val, r, true ); + } + + template< class ForwardRng, class BinPredicate > + inline adjacent_filter_range + operator|( const ForwardRng& r, + const adjacent_holder& f ) + { + return adjacent_filter_range( f.val, r, true ); + } + + template< class ForwardRng, class BinPredicate > + inline adjacent_filter_range + operator|( ForwardRng& r, + const adjacent_excl_holder& f ) + { + return adjacent_filter_range( f.val, r, false ); + } + + template< class ForwardRng, class BinPredicate > + inline adjacent_filter_range + operator|( const ForwardRng& r, + const adjacent_excl_holder& f ) + { + return adjacent_filter_range( f.val, r, false ); + } + + } // 'range_detail' + + // Bring adjacent_filter_range into the boost namespace so that users of + // this library may specify the return type of the '|' operator and + // adjacent_filter() + using range_detail::adjacent_filter_range; + + namespace adaptors + { + namespace + { + const range_detail::forwarder + adjacent_filtered = + range_detail::forwarder(); + + const range_detail::forwarder + adjacent_filtered_excl = + range_detail::forwarder(); + } + + template + inline adjacent_filter_range + adjacent_filter(ForwardRng& rng, BinPredicate filter_pred, bool default_pass = true) + { + return adjacent_filter_range(filter_pred, rng, default_pass); + } + + template + inline adjacent_filter_range + adjacent_filter(const ForwardRng& rng, BinPredicate filter_pred, bool default_pass = true) + { + return adjacent_filter_range(filter_pred, rng, default_pass); + } + + } // 'adaptors' + +} + +#ifdef BOOST_MSVC +#pragma warning( pop ) +#endif + +#endif diff --git a/include/boost/range/adaptor/argument_fwd.hpp b/include/boost/range/adaptor/argument_fwd.hpp new file mode 100755 index 0000000..357056b --- /dev/null +++ b/include/boost/range/adaptor/argument_fwd.hpp @@ -0,0 +1,80 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_ARGUMENT_FWD_HPP +#define BOOST_RANGE_ADAPTOR_ARGUMENT_FWD_HPP + +#include + +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable : 4512) // assignment operator could not be generated +#endif + +namespace boost +{ + namespace range_detail + { + template< class T > + struct holder + { + T val; + holder( T t ) : val(t) + { } + }; + + template< class T > + struct holder2 + { + T val1, val2; + holder2( T t, T u ) : val1(t), val2(u) + { } + }; + + template< template class Holder > + struct forwarder + { + template< class T > + Holder operator()( T t ) const + { + return Holder(t); + } + }; + + template< template class Holder > + struct forwarder2 + { + template< class T > + Holder operator()( T t, T u ) const + { + return Holder(t,u); + } + }; + + template< template class Holder > + struct forwarder2TU + { + template< class T, class U > + Holder operator()( T t, U u ) const + { + return Holder(t, u); + } + }; + + + } + +} + +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + +#endif diff --git a/include/boost/range/adaptor/copied.hpp b/include/boost/range/adaptor/copied.hpp new file mode 100755 index 0000000..1862b5f --- /dev/null +++ b/include/boost/range/adaptor/copied.hpp @@ -0,0 +1,58 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_COPIED_HPP +#define BOOST_RANGE_ADAPTOR_COPIED_HPP + +#include +#include +#include +#include + +namespace boost +{ + namespace adaptors + { + struct copied + { + copied(std::size_t t_, std::size_t u_) + : t(t_), u(u_) {} + + std::size_t t; + std::size_t u; + }; + + template< class CopyableRandomAccessRng > + inline CopyableRandomAccessRng + operator|( const CopyableRandomAccessRng& r, const copied& f ) + { + iterator_range< + BOOST_DEDUCED_TYPENAME range_iterator::type > + temp( adaptors::slice( r, f.t, f.u ) ); + return CopyableRandomAccessRng( temp.begin(), temp.end() ); + } + + template + inline CopyableRandomAccessRange + copy(const CopyableRandomAccessRange& rng, std::size_t t, std::size_t u) + { + iterator_range< + BOOST_DEDUCED_TYPENAME range_iterator::type> temp( + adaptors::slice(rng, t, u)); + + return CopyableRandomAccessRange( temp.begin(), temp.end() ); + } + } // 'adaptors' + +} + +#endif diff --git a/include/boost/range/adaptor/define_adaptor.hpp b/include/boost/range/adaptor/define_adaptor.hpp new file mode 100644 index 0000000..d68c64e --- /dev/null +++ b/include/boost/range/adaptor/define_adaptor.hpp @@ -0,0 +1,117 @@ +#ifndef BOOST_RANGE_DEFINE_ADAPTOR_HPP_INCLUDED +#define BOOST_RANGE_DEFINE_ADAPTOR_HPP_INCLUDED + +#include + +#define BOOST_DEFINE_RANGE_ADAPTOR( adaptor_name, range_adaptor ) \ + struct adaptor_name##_forwarder {}; \ + \ + template range_adaptor \ + operator|(Range& rng, adaptor_name##_forwarder) \ + { \ + return range_adaptor ( rng ); \ + } \ + \ + template range_adaptor \ + operator|(const Range& rng, adaptor_name##_forwarder) \ + { \ + return range_adaptor ( rng ); \ + } \ + \ + static adaptor_name##_forwarder adaptor_name = adaptor_name##_forwarder(); \ + \ + template \ + range_adaptor \ + make_##adaptor_name(Range& rng) \ + { \ + return range_adaptor (rng); \ + } \ + \ + template \ + range_adaptor \ + make_##adaptor_name(const Range& rng) \ + { \ + return range_adaptor (rng); \ + } + +#define BOOST_DEFINE_RANGE_ADAPTOR_1( adaptor_name, range_adaptor, adaptor_class ) \ + template range_adaptor \ + operator|(Range& rng, const adaptor_name & args) \ + { \ + return range_adaptor (rng, args.arg1); \ + } \ + template range_adaptor \ + operator|(const Range& rng, const adaptor_name & args) \ + { \ + return range_adaptor (rng, args.arg1); \ + } \ + template \ + range_adaptor \ + make_##adaptor_name(Range& rng, Arg1 arg1) \ + { \ + return range_adaptor(rng, arg1); \ + } + +#define BOOST_DEFINE_RANGE_ADAPTOR_1( adaptor_name, range_adaptor, arg1_type ) \ + struct adaptor_name \ + { \ + explicit adaptor_name (arg1_type arg1_) \ + : arg1(arg1_) {} \ + arg1_type arg1; \ + }; \ + \ + template range_adaptor \ + operator|(Range& rng, adaptor_name args) \ + { \ + return range_adaptor (rng, args.arg1); \ + } \ + \ + template range_adaptor \ + operator|(const Range& rng, adaptor_name args) \ + { \ + return range_adaptor (rng, args.arg1); \ + } \ + \ + template \ + range_adaptor \ + make_##adaptor_name(Range& rng, arg1_type arg1) \ + { \ + return range_adaptor (rng, arg1); \ + } \ + \ + template \ + range_adaptor \ + make_##adaptor_name(const Range& rng, arg1_type arg1) \ + { \ + return range_adaptor (rng, arg1); \ + } + +#define BOOST_RANGE_ADAPTOR_2( adaptor_name, range_adaptor, arg1_type, arg2_type ) \ + struct adaptor_name \ + { \ + explicit adaptor_name (arg1_type arg1_, arg2_type arg2_) \ + : arg1(arg1_), arg2(arg2_) {} \ + arg1_type arg1; \ + arg2_type arg2; \ + }; \ + \ + template range_adaptor \ + operator|(Range& rng, adaptor_name args) \ + { \ + return range_adaptor (rng, args.arg1, args.arg2); \ + } \ + template \ + range_adaptor \ + make_##adaptor_name(Range& rng, arg1_type arg1, arg2_type arg2) \ + { \ + return range_adaptor (rng, arg1, arg2); \ + } \ + template \ + range_adaptor \ + make_##adaptor_name(const Range& rng, arg1_type arg1, arg2_type arg2) \ + { \ + return range_adaptor (rng, arg1, arg2); \ + } + + +#endif // include guard diff --git a/include/boost/range/adaptor/filtered.hpp b/include/boost/range/adaptor/filtered.hpp new file mode 100755 index 0000000..1bc4799 --- /dev/null +++ b/include/boost/range/adaptor/filtered.hpp @@ -0,0 +1,101 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_FILTERED_HPP +#define BOOST_RANGE_ADAPTOR_FILTERED_HPP + +#include +#include +#include + +namespace boost +{ + namespace range_detail + { + template< class P, class R > + struct filter_range : + boost::iterator_range< + boost::filter_iterator< P, + BOOST_DEDUCED_TYPENAME range_iterator::type + > + > + { + private: + typedef boost::iterator_range< + boost::filter_iterator< P, + BOOST_DEDUCED_TYPENAME range_iterator::type + > + > base; + public: + filter_range( P p, R& r ) + : base( make_filter_iterator( p, boost::begin(r), boost::end(r) ), + make_filter_iterator( p, boost::end(r), boost::end(r) ) ) + { } + }; + + template< class T > + struct filter_holder : holder + { + filter_holder( T r ) : holder(r) + { } + }; + + template< class InputRng, class Predicate > + inline filter_range + operator|( InputRng& r, + const filter_holder& f ) + { + return filter_range( f.val, r ); + } + + template< class InputRng, class Predicate > + inline filter_range + operator|( const InputRng& r, + const filter_holder& f ) + { + return filter_range( f.val, r ); + } + + } // 'range_detail' + + // Unusual use of 'using' is intended to bring filter_range into the boost namespace + // while leaving the mechanics of the '|' operator in range_detail and maintain + // argument dependent lookup. + // filter_range logically needs to be in the boost namespace to allow user of + // the library to define the return type for filter() + using range_detail::filter_range; + + namespace adaptors + { + namespace + { + const range_detail::forwarder + filtered = + range_detail::forwarder(); + } + + template + inline filter_range + filter(InputRange& rng, Predicate filter_pred) + { + return range_detail::filter_range( filter_pred, rng ); + } + + template + inline filter_range + filter(const InputRange& rng, Predicate filter_pred) + { + return range_detail::filter_range( filter_pred, rng ); + } + } // 'adaptors' + +} + +#endif diff --git a/include/boost/range/adaptor/indexed.hpp b/include/boost/range/adaptor/indexed.hpp new file mode 100755 index 0000000..7050185 --- /dev/null +++ b/include/boost/range/adaptor/indexed.hpp @@ -0,0 +1,156 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_INDEXED_IMPL_HPP +#define BOOST_RANGE_ADAPTOR_INDEXED_IMPL_HPP + +#include +#ifdef BOOST_MSVC +#pragma warning( push ) +#pragma warning( disable : 4355 ) +#endif + +#include +#include +#include +#include +#include + + + +namespace boost +{ + namespace adaptors + { + // This structure exists to carry the parameters from the '|' operator + // to the index adapter. The expression rng | indexed(1) instantiates + // this structure and passes it as the right-hand operand to the + // '|' operator. + struct indexed + { + explicit indexed(std::size_t x) : val(x) {} + std::size_t val; + }; + } + + namespace range_detail + { + template< class Iter > + class indexed_iterator + : public boost::iterator_adaptor< indexed_iterator, Iter > + { + private: + typedef boost::iterator_adaptor< indexed_iterator, Iter > + base; + + typedef BOOST_DEDUCED_TYPENAME base::difference_type index_type; + + index_type m_index; + + public: + explicit indexed_iterator( Iter i, index_type index ) + : base(i), m_index(index) + { + BOOST_ASSERT( m_index >= 0 && "Indexed Iterator out of bounds" ); + } + + index_type index() const + { + return m_index; + } + + private: + friend class boost::iterator_core_access; + + void increment() + { + ++m_index; + ++(this->base_reference()); + } + + + void decrement() + { + BOOST_ASSERT( m_index > 0 && "Indexed Iterator out of bounds" ); + --m_index; + --(this->base_reference()); + } + + void advance( index_type n ) + { + m_index += n; + BOOST_ASSERT( m_index >= 0 && "Indexed Iterator out of bounds" ); + this->base_reference() += n; + } + }; + + template< class Rng > + struct indexed_range : + iterator_range< indexed_iterator::type> > + { + private: + typedef indexed_iterator::type> + iter_type; + typedef iterator_range + base; + public: + template< class Index > + indexed_range( Index i, Rng& r ) + : base( iter_type(boost::begin(r), i), iter_type(boost::end(r),i) ) + { } + }; + + } // 'range_detail' + + // Make this available to users of this library. It will sometimes be + // required since it is the return type of operator '|' and + // index(). + using range_detail::indexed_range; + + namespace adaptors + { + template< class SinglePassRange > + inline indexed_range + operator|( SinglePassRange& r, + const indexed& f ) + { + return indexed_range( f.val, r ); + } + + template< class SinglePassRange > + inline indexed_range + operator|( const SinglePassRange& r, + const indexed& f ) + { + return indexed_range( f.val, r ); + } + + template + inline indexed_range + index(SinglePassRange& rng, Index index_value) + { + return indexed_range(index_value, rng); + } + + template + inline indexed_range + index(const SinglePassRange& rng, Index index_value) + { + return indexed_range(index_value, rng); + } + } // 'adaptors' + +} + +#ifdef BOOST_MSVC +#pragma warning( pop ) +#endif + +#endif diff --git a/include/boost/range/adaptor/indirected.hpp b/include/boost/range/adaptor/indirected.hpp new file mode 100644 index 0000000..5b13cfb --- /dev/null +++ b/include/boost/range/adaptor/indirected.hpp @@ -0,0 +1,88 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_INDIRECTED_HPP +#define BOOST_RANGE_ADAPTOR_INDIRECTED_HPP + +#include +#include + +namespace boost +{ + namespace range_detail + { + template< class R > + struct indirect_range : + public boost::iterator_range< + boost::indirect_iterator< + BOOST_DEDUCED_TYPENAME range_iterator::type + > + > + { + private: + typedef boost::iterator_range< + boost::indirect_iterator< + BOOST_DEDUCED_TYPENAME range_iterator::type + > + > + base; + + public: + explicit indirect_range( R& r ) + : base( r ) + { } + }; + + struct indirect_forwarder {}; + + template< class InputRng > + inline indirect_range + operator|( InputRng& r, indirect_forwarder ) + { + return indirect_range( r ); + } + + template< class InputRng > + inline indirect_range + operator|( const InputRng& r, indirect_forwarder ) + { + return indirect_range( r ); + } + + } // 'range_detail' + + using range_detail::indirect_range; + + namespace adaptors + { + namespace + { + const range_detail::indirect_forwarder indirected = + range_detail::indirect_forwarder(); + } + + template + inline indirect_range + indirect(InputRange& rng) + { + return indirect_range(rng); + } + + template + inline indirect_range + indirect(const InputRange& rng) + { + return indirect_range(rng); + } + } // 'adaptors' + +} + +#endif diff --git a/include/boost/range/adaptor/map.hpp b/include/boost/range/adaptor/map.hpp new file mode 100755 index 0000000..f790e1a --- /dev/null +++ b/include/boost/range/adaptor/map.hpp @@ -0,0 +1,188 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_MAP_HPP +#define BOOST_RANGE_ADAPTOR_MAP_HPP + +#include +#include +#include + +namespace boost +{ + namespace range_detail + { + struct map_keys_forwarder {}; + struct map_values_forwarder {}; + + template< class Map > + struct select_first + { + typedef BOOST_DEDUCED_TYPENAME Map::value_type pair_t; + typedef const BOOST_DEDUCED_TYPENAME pair_t::first_type& + result_type; + + result_type operator()( const pair_t& r ) const + { + return r.first; + } + }; + + template< class Map > + struct select_second_mutable + { + typedef BOOST_DEDUCED_TYPENAME Map::value_type pair_t; + typedef BOOST_DEDUCED_TYPENAME pair_t::second_type& result_type; + + result_type operator()( pair_t& r ) const + { + return r.second; + } + }; + + template< class Map > + struct select_second_const + { + typedef BOOST_DEDUCED_TYPENAME Map::value_type pair_t; + typedef const BOOST_DEDUCED_TYPENAME pair_t::second_type& + result_type; + + result_type operator()( const pair_t& r ) const + { + return r.second; + } + }; + + template + class select_first_range + : public transform_range< + select_first, + const StdPairRng> + { + typedef transform_range, const StdPairRng> base; + public: + typedef select_first transform_fn_type; + typedef const StdPairRng source_range_type; + + select_first_range(transform_fn_type fn, source_range_type& rng) + : base(fn, rng) + { + } + + select_first_range(const base& other) : base(other) {} + }; + + template + class select_second_mutable_range + : public transform_range< + select_second_mutable, + StdPairRng> + { + typedef transform_range, StdPairRng> base; + public: + typedef select_second_mutable transform_fn_type; + typedef StdPairRng source_range_type; + + select_second_mutable_range(transform_fn_type fn, source_range_type& rng) + : base(fn, rng) + { + } + + select_second_mutable_range(const base& other) : base(other) {} + }; + + template + class select_second_const_range + : public transform_range< + select_second_const, + const StdPairRng> + { + typedef transform_range, const StdPairRng> base; + public: + typedef select_second_const transform_fn_type; + typedef const StdPairRng source_range_type; + + select_second_const_range(transform_fn_type fn, source_range_type& rng) + : base(fn, rng) + { + } + + select_second_const_range(const base& other) : base(other) {} + }; + + template< class StdPairRng > + inline select_first_range + operator|( const StdPairRng& r, map_keys_forwarder ) + { + return operator|( r, + boost::adaptors::transformed( select_first() ) ); + } + + template< class StdPairRng > + inline select_second_mutable_range + operator|( StdPairRng& r, map_values_forwarder ) + { + return operator|( r, + boost::adaptors::transformed( select_second_mutable() ) ); + } + + template< class StdPairRng > + inline select_second_const_range + operator|( const StdPairRng& r, map_values_forwarder ) + { + return operator|( r, + boost::adaptors::transformed( select_second_const() ) ); + } + + } // 'range_detail' + + using range_detail::select_first_range; + using range_detail::select_second_mutable_range; + using range_detail::select_second_const_range; + + namespace adaptors + { + namespace + { + const range_detail::map_keys_forwarder map_keys = + range_detail::map_keys_forwarder(); + + const range_detail::map_values_forwarder map_values = + range_detail::map_values_forwarder(); + } + + template + inline select_first_range + keys(const StdPairRange& rng) + { + return select_first_range( + range_detail::select_first(), rng ); + } + + template + inline select_second_const_range + values(const StdPairRange& rng) + { + return select_second_const_range( + range_detail::select_second_const(), rng ); + } + + template + inline select_second_mutable_range + values(StdPairRange& rng) + { + return select_second_mutable_range( + range_detail::select_second_mutable(), rng ); + } + } // 'adaptors' + +} + +#endif diff --git a/include/boost/range/adaptor/replaced.hpp b/include/boost/range/adaptor/replaced.hpp new file mode 100644 index 0000000..bdc0a2d --- /dev/null +++ b/include/boost/range/adaptor/replaced.hpp @@ -0,0 +1,134 @@ +// Boost.Range library +// +// Copyright Neil Groves 2007. 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_ADAPTOR_REPLACED_IMPL_HPP_INCLUDED +#define BOOST_RANGE_ADAPTOR_REPLACED_IMPL_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range_detail + { + template< class Value > + class replace_value + { + public: + typedef const Value& result_type; + typedef const Value& first_argument_type; + + replace_value(const Value& from, const Value& to) + : m_from(from), m_to(to) + { + } + + const Value& operator()(const Value& x) const + { + return (x == m_from) ? m_to : x; + } + + private: + Value m_from; + Value m_to; + }; + + template< class R > + class replace_range : + public boost::iterator_range< + boost::transform_iterator< + replace_value< BOOST_DEDUCED_TYPENAME range_value::type >, + BOOST_DEDUCED_TYPENAME range_iterator::type > > + { + private: + typedef replace_value< BOOST_DEDUCED_TYPENAME range_value::type > Fn; + + typedef boost::iterator_range< + boost::transform_iterator< + replace_value< BOOST_DEDUCED_TYPENAME range_value::type >, + BOOST_DEDUCED_TYPENAME range_iterator::type > > base_t; + + public: + typedef BOOST_DEDUCED_TYPENAME range_value::type value_type; + + replace_range( R& r, value_type from, value_type to ) + : base_t( make_transform_iterator( boost::begin(r), Fn(from, to) ), + make_transform_iterator( boost::end(r), Fn(from, to) ) ) + { } + }; + + template< class T > + class replace_holder : public holder2 + { + public: + replace_holder( const T& from, const T& to ) + : holder2(from, to) + { } + private: + // not assignable + void operator=(const replace_holder&); + }; + + template< class InputRng > + inline replace_range + operator|( InputRng& r, + const replace_holder::type>& f ) + { + return replace_range(r, f.val1, f.val2); + } + + template< class InputRng > + inline replace_range + operator|( const InputRng& r, + const replace_holder::type>& f ) + { + return replace_range(r, f.val1, f.val2); + } + } // 'range_detail' + + using range_detail::replace_range; + + namespace adaptors + { + namespace + { + const range_detail::forwarder2 + replaced = + range_detail::forwarder2(); + } + + template + inline replace_range + replace(InputRange& rng, + BOOST_DEDUCED_TYPENAME range_value::type from, + BOOST_DEDUCED_TYPENAME range_value::type to) + { + return replace_range(rng, from, to); + } + + template + inline replace_range + replace(const InputRange& rng, + BOOST_DEDUCED_TYPENAME range_value::type from, + BOOST_DEDUCED_TYPENAME range_value::type to) + { + return replace_range(rng, from ,to); + } + + } // 'adaptors' +} // 'boost' + +#endif // include guard diff --git a/include/boost/range/adaptor/replaced_if.hpp b/include/boost/range/adaptor/replaced_if.hpp new file mode 100644 index 0000000..22264a2 --- /dev/null +++ b/include/boost/range/adaptor/replaced_if.hpp @@ -0,0 +1,136 @@ +// Boost.Range library +// +// Copyright Neil Groves 2007. 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_ADAPTOR_REPLACED_IF_IMPL_HPP_INCLUDED +#define BOOST_RANGE_ADAPTOR_REPLACED_IF_IMPL_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range_detail + { + template< class Pred, class Value > + class replace_value_if + { + public: + typedef const Value& result_type; + typedef const Value& first_argument_type; + + replace_value_if(const Pred& pred, const Value& to) + : m_pred(pred), m_to(to) + { + } + + const Value& operator()(const Value& x) const + { + return m_pred(x) ? m_to : x; + } + + private: + Pred m_pred; + Value m_to; + }; + + template< class Pred, class R > + class replace_if_range : + public boost::iterator_range< + boost::transform_iterator< + replace_value_if< Pred, BOOST_DEDUCED_TYPENAME range_value::type >, + BOOST_DEDUCED_TYPENAME range_iterator::type > > + { + private: + typedef replace_value_if< Pred, BOOST_DEDUCED_TYPENAME range_value::type > Fn; + + typedef boost::iterator_range< + boost::transform_iterator< + replace_value_if< Pred, BOOST_DEDUCED_TYPENAME range_value::type >, + BOOST_DEDUCED_TYPENAME range_iterator::type > > base_t; + + public: + typedef BOOST_DEDUCED_TYPENAME range_value::type value_type; + + replace_if_range( R& r, const Pred& pred, value_type to ) + : base_t( make_transform_iterator( boost::begin(r), Fn(pred, to) ), + make_transform_iterator( boost::end(r), Fn(pred, to) ) ) + { } + }; + + template< class Pred, class T > + class replace_if_holder + { + public: + replace_if_holder( const Pred& pred, const T& to ) + : m_pred(pred), m_to(to) + { } + + const Pred& pred() const { return m_pred; } + const T& to() const { return m_to; } + + private: + Pred m_pred; + T m_to; + }; + + template< class Pred, class InputRng > + inline replace_if_range + operator|( InputRng& r, + const replace_if_holder::type>& f ) + { + return replace_if_range(r, f.pred(), f.to()); + } + + template< class Pred, class InputRng > + inline replace_if_range + operator|( const InputRng& r, + const replace_if_holder::type>& f ) + { + return replace_if_range(r, f.pred(), f.to()); + } + } // 'range_detail' + + using range_detail::replace_if_range; + + namespace adaptors + { + namespace + { + const range_detail::forwarder2TU + replaced_if = + range_detail::forwarder2TU(); + } + + template + inline replace_if_range + replace_if(InputRange& rng, Pred pred, + BOOST_DEDUCED_TYPENAME range_value::type to) + { + return range_detail::replace_if_range(rng, pred, to); + } + + template + inline replace_if_range + replace_if(const InputRange& rng, Pred pred, + BOOST_DEDUCED_TYPENAME range_value::type to) + { + return range_detail::replace_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 new file mode 100755 index 0000000..afe7517 --- /dev/null +++ b/include/boost/range/adaptor/reversed.hpp @@ -0,0 +1,90 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_REVERSED_HPP +#define BOOST_RANGE_ADAPTOR_REVERSED_HPP + +#include +#include + +namespace boost +{ + namespace range_detail + { + template< class R > + struct reverse_range : + public boost::iterator_range< + boost::reverse_iterator< + BOOST_DEDUCED_TYPENAME range_iterator::type + > + > + { + private: + typedef boost::iterator_range< + boost::reverse_iterator< + BOOST_DEDUCED_TYPENAME range_iterator::type + > + > + base; + + public: + typedef boost::reverse_iterator::type> iterator; + + reverse_range( R& r ) + : base( iterator(boost::end(r)), iterator(boost::begin(r)) ) + { } + }; + + struct reverse_forwarder {}; + + template< class BidirectionalRng > + inline reverse_range + operator|( BidirectionalRng& r, reverse_forwarder ) + { + return reverse_range( r ); + } + + template< class BidirectionalRng > + inline reverse_range + operator|( const BidirectionalRng& r, reverse_forwarder ) + { + return reverse_range( r ); + } + + } // 'range_detail' + + using range_detail::reverse_range; + + namespace adaptors + { + namespace + { + const range_detail::reverse_forwarder reversed = + range_detail::reverse_forwarder(); + } + + template + inline reverse_range + reverse(BidirectionalRange& rng) + { + return reverse_range(rng); + } + + template + inline reverse_range + reverse(const BidirectionalRange& rng) + { + return reverse_range(rng); + } + } // 'adaptors' + +} // 'boost' + +#endif diff --git a/include/boost/range/adaptor/sliced.hpp b/include/boost/range/adaptor/sliced.hpp new file mode 100755 index 0000000..eb506e0 --- /dev/null +++ b/include/boost/range/adaptor/sliced.hpp @@ -0,0 +1,71 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_SLICED_HPP +#define BOOST_RANGE_ADAPTOR_SLICED_HPP + +#include +#include +#include + +namespace boost +{ + namespace adaptors + { + struct sliced + { + sliced(std::size_t t_, std::size_t u_) + : t(t_), u(u_) {} + std::size_t t; + std::size_t u; + }; + + template< class RandomAccessRange > + inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > + slice( RandomAccessRange& rng, std::size_t t, std::size_t u ) + { + BOOST_ASSERT( t <= u && "error in slice indices" ); + BOOST_ASSERT( static_cast(boost::size(rng)) >= u && + "second slice index out of bounds" ); + + return boost::make_iterator_range( rng, t, u - boost::size(rng) ); + } + + template< class RandomAccessRange > + inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > + slice( const RandomAccessRange& rng, std::size_t t, std::size_t u ) + { + BOOST_ASSERT( t <= u && "error in slice indices" ); + BOOST_ASSERT( static_cast(boost::size(rng)) >= u && + "second slice index out of bounds" ); + + return boost::make_iterator_range( rng, t, u - boost::size(rng) ); + } + + template< class RandomAccessRange > + inline iterator_range< + BOOST_DEDUCED_TYPENAME range_iterator::type > + operator|( RandomAccessRange& r, const sliced& f ) + { + return adaptors::slice( r, f.t, f.u ); + } + + template< class RandomAccessRange > + inline iterator_range< + BOOST_DEDUCED_TYPENAME range_iterator::type > + operator|( const RandomAccessRange& r, const sliced& f ) + { + return adaptors::slice( r, f.t, f.u ); + } + + } // namespace adaptors +} // namespace boost + +#endif diff --git a/include/boost/range/adaptor/strided.hpp b/include/boost/range/adaptor/strided.hpp new file mode 100755 index 0000000..0c394b2 --- /dev/null +++ b/include/boost/range/adaptor/strided.hpp @@ -0,0 +1,149 @@ +// Boost.Range library +// +// Copyright Neil Groves 2007. 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_ADAPTOR_STRIDED_HPP_INCLUDED +#define BOOST_RANGE_ADAPTOR_STRIDED_HPP_INCLUDED + +#include +#include +#include +#include + +namespace boost +{ + namespace range_detail + { + + template + class strided_iterator + : public iterator_adaptor< + strided_iterator, + BaseIterator> + { + friend class iterator_core_access; + + typedef iterator_adaptor, BaseIterator> super_t; + + public: + typedef BOOST_DEDUCED_TYPENAME std::iterator_traits::difference_type difference_type; + + strided_iterator() : m_stride() { } + + strided_iterator(const strided_iterator& other) + : super_t(other), m_stride(other.m_stride) { } + + explicit strided_iterator(BaseIterator base_it, difference_type stride) + : super_t(base_it), m_stride(stride) { } + + strided_iterator& + operator=(const strided_iterator& other) + { + super_t::operator=(other); + + // Is the interoperation of the stride safe? + m_stride = other.m_stride; + return *this; + } + + void increment() { std::advance(this->base_reference(), m_stride); } + + void decrement() { std::advance(this->base_reference(), -m_stride); } + + void advance(difference_type n) { std::advance(this->base_reference(), n * m_stride); } + + difference_type + distance_to(const strided_iterator& other) const + { + return std::distance(this->base_reference(), other.base_reference()) / m_stride; + } + + // Using the compiler generated copy constructor and + // and assignment operator + + private: + difference_type m_stride; + }; + + template inline + strided_iterator + make_strided_iterator( + const BaseIterator& first, + BOOST_DEDUCED_TYPENAME std::iterator_traits::difference_type stride) + { + return strided_iterator(first, stride); + } + + template< class Rng > + class strided_range + : public iterator_range::type> > + { + typedef range_detail::strided_iterator::type> iter_type; + typedef iterator_range super_t; + public: + template< typename Difference > + strided_range(Difference stride, Rng& rng) + : super_t(make_strided_iterator(boost::begin(rng), stride), + make_strided_iterator(boost::end(rng), stride)) + { + } + }; + + template + class strided_holder : public holder + { + public: + strided_holder(Difference value) : holder(value) {} + }; + + template + inline strided_range + operator|(Rng& rng, const strided_holder& stride) + { + return strided_range(stride.val, rng); + } + + template + inline strided_range + operator|(const Rng& rng, const strided_holder& stride) + { + return strided_range(stride.val, rng); + } + + } // namespace range_detail + + using range_detail::strided_range; + + namespace adaptors + { + + namespace + { + const range_detail::forwarder + strided = range_detail::forwarder(); + } + + template + inline strided_range + stride(Range& rng, Difference step) + { + return strided_range(step, rng); + } + + template + inline strided_range + stride(const Range& rng, Difference step) + { + return strided_range(step, rng); + } + + } // namespace 'adaptors' +} // namespace 'boost' + +#endif diff --git a/include/boost/range/adaptor/tokenized.hpp b/include/boost/range/adaptor/tokenized.hpp new file mode 100755 index 0000000..c81d515 --- /dev/null +++ b/include/boost/range/adaptor/tokenized.hpp @@ -0,0 +1,137 @@ +// Boost.Range library +// +// 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) +// +// For more information, see http://www.boost.org/libs/range/ +// + +#ifndef BOOST_RANGE_ADAPTOR_TOKENIZED_HPP +#define BOOST_RANGE_ADAPTOR_TOKENIZED_HPP + +#include +#include + +namespace boost +{ + namespace range_detail + { + + template< class R > + struct token_range : + public boost::iterator_range< + boost::regex_token_iterator< + BOOST_DEDUCED_TYPENAME range_iterator::type + > + > + { + private: + typedef + boost::regex_token_iterator< + BOOST_DEDUCED_TYPENAME range_iterator::type + > + regex_iter; + + typedef BOOST_DEDUCED_TYPENAME regex_iter::regex_type + regex_type; + + typedef boost::iterator_range + base; + + public: + template< class Regex, class Submatch, class Flag > + token_range( R& r, const Regex& re, const Submatch& sub, Flag f ) + : base( regex_iter( boost::begin(r), boost::end(r), + regex_type(re), sub, f ), + regex_iter() ) + { } + }; + + template< class T, class U, class V > + struct regex_holder + { + const T& re; + const U& sub; + V f; + + regex_holder( const T& rex, const U& subm, V flag ) : + re(rex), sub(subm), f(flag) + { } + private: + // Not assignable + void operator=(const regex_holder&); + }; + + struct regex_forwarder + { + template< class Regex > + regex_holder + operator()( const Regex& re, + int submatch = 0, + regex_constants::match_flag_type f = + regex_constants::match_default ) const + { + return regex_holder( re, submatch, f ); + } + + template< class Regex, class Submatch > + regex_holder + operator()( const Regex& re, + const Submatch& sub, + regex_constants::match_flag_type f = + regex_constants::match_default ) const + { + return regex_holder( re, sub, f ); + } + }; + + template< class BidirectionalRng, class R, class S, class F > + inline token_range + operator|( BidirectionalRng& r, + const regex_holder& f ) + { + return token_range( r, f.re, f.sub, f.f ); + } + + template< class BidirectionalRng, class R, class S, class F > + inline token_range + operator|( const BidirectionalRng& r, + const regex_holder& f ) + { + return token_range( r, f.re, f.sub, f.f ); + } + + } // 'range_detail' + + using range_detail::token_range; + + namespace adaptors + { + namespace + { + const range_detail::regex_forwarder tokenized = + range_detail::regex_forwarder(); + } + + template + inline token_range + tokenize(BidirectionalRange& rng, const Regex& reg, const Submatch& sub, Flag f) + { + return token_range(rng, reg, sub, f); + } + + template + inline token_range + tokenize(const BidirectionalRange& rng, const Regex& reg, const Submatch& sub, Flag f) + { + return token_range(rng, reg, sub, f); + } + } // 'adaptors' + +} + +#endif diff --git a/include/boost/range/adaptor/transformed.hpp b/include/boost/range/adaptor/transformed.hpp new file mode 100755 index 0000000..0eeaee7 --- /dev/null +++ b/include/boost/range/adaptor/transformed.hpp @@ -0,0 +1,103 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_TRANSFORMED_HPP +#define BOOST_RANGE_ADAPTOR_TRANSFORMED_HPP + +#include +#include +#include + +namespace boost +{ + namespace range_detail + { + + template< class F, class R > + struct transform_range : + public boost::iterator_range< + boost::transform_iterator< F, + BOOST_DEDUCED_TYPENAME range_iterator::type + > + > + { + private: + typedef boost::iterator_range< + boost::transform_iterator< F, + BOOST_DEDUCED_TYPENAME range_iterator::type + > + > + base; + + public: + typedef F transform_fn_type; + typedef R source_range_type; + + transform_range( F f, R& r ) + : base( make_transform_iterator( boost::begin(r), f ), + make_transform_iterator( boost::end(r), f ) ) + + { } + }; + + template< class T > + struct transform_holder : holder + { + transform_holder( T r ) : holder(r) + { } + }; + + template< class InputRng, class UnaryFunction > + inline transform_range + operator|( InputRng& r, + const transform_holder& f ) + { + return transform_range( f.val, r ); + } + + template< class InputRng, class UnaryFunction > + inline transform_range + operator|( const InputRng& r, + const transform_holder& f ) + { + return transform_range( f.val, r ); + } + + } // 'range_detail' + + using range_detail::transform_range; + + namespace adaptors + { + namespace + { + const range_detail::forwarder + transformed = + range_detail::forwarder(); + } + + template + inline transform_range + transform(InputRange& rng, UnaryFunction fn) + { + return transform_range(fn, rng); + } + + template + inline transform_range + transform(const InputRange& rng, UnaryFunction fn) + { + return transform_range(fn, rng); + } + } // 'adaptors' + +} + +#endif diff --git a/include/boost/range/adaptor/uniqued.hpp b/include/boost/range/adaptor/uniqued.hpp new file mode 100755 index 0000000..28a30f2 --- /dev/null +++ b/include/boost/range/adaptor/uniqued.hpp @@ -0,0 +1,90 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. 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_ADAPTOR_UNIQUED_IMPL_HPP +#define BOOST_RANGE_ADAPTOR_UNIQUED_IMPL_HPP + +#include + +namespace boost +{ + + namespace range_detail + { + struct unique_forwarder { }; + + struct unique_not_equal_to + { + typedef bool result_type; + + template< class T > + bool operator()( const T& l, const T& r ) const + { + return !(l == r); + } + }; + + template + class unique_range : public adjacent_filter_range + { + typedef adjacent_filter_range base; + public: + explicit unique_range(ForwardRng& rng) + : base(unique_not_equal_to(), rng, true) + { + } + }; + + template< class ForwardRng > + inline unique_range + operator|( ForwardRng& r, + unique_forwarder ) + { + return unique_range(r); + } + + template< class ForwardRng > + inline unique_range + operator|( const ForwardRng& r, + unique_forwarder ) + { + return unique_range(r); + } + + } // 'range_detail' + + using range_detail::unique_range; + + namespace adaptors + { + namespace + { + const range_detail::unique_forwarder uniqued = + range_detail::unique_forwarder(); + } + + template + inline unique_range + unique(ForwardRange& rng) + { + return unique_range(rng); + } + + template + inline unique_range + unique(const ForwardRange& rng) + { + return unique_range(rng); + } + } // 'adaptors' + +} + +#endif diff --git a/include/boost/range/adaptors.hpp b/include/boost/range/adaptors.hpp new file mode 100755 index 0000000..a1fad4f --- /dev/null +++ b/include/boost/range/adaptors.hpp @@ -0,0 +1,29 @@ +// Boost.Range library +// +// Copyright Neil Groves 2007. +// Copyright Thorsten Ottosen 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) +// +// For more information, see http://www.boost.org/libs/range/ +// + +#ifndef BOOST_RANGE_ADAPTORS_HPP +#define BOOST_RANGE_ADAPTORS_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif diff --git a/include/boost/range/algorithm.hpp b/include/boost/range/algorithm.hpp new file mode 100755 index 0000000..b7d8dd7 --- /dev/null +++ b/include/boost/range/algorithm.hpp @@ -0,0 +1,104 @@ +/////////////////////////////////////////////////////////////////////////////// +/// \file algorithm.hpp +/// Includes the range-based versions of the algorithms in the +/// C++ standard header file +// +///////////////////////////////////////////////////////////////////////////// + +// Copyright 2009 Neil Groves. +// 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) +// +// Acknowledgements: +// This code uses combinations of ideas, techniques and code snippets +// from: Thorsten Ottosen, Eric Niebler, Jeremy Siek, +// and Vladimir Prus' +// +// The original mutating algorithms that served as the first version +// were originally written by Vladimir Prus' +// code from Boost Wiki + +#if defined(_MSC_VER) && _MSC_VER >= 1000 +#pragma once +#endif + +#ifndef BOOST_RANGE_ALGORITHM_HPP_INCLUDED_01012009 +#define BOOST_RANGE_ALGORITHM_HPP_INCLUDED_01012009 + +#include +#include +#include +#include +#include +#include +#include + +// Non-mutating algorithms +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Mutating algorithms +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Binary search +#include +#include +#include +#include + +// Set operations of sorted ranges +#include + +// Heap operations +#include + +// Minimum and Maximum +#include +#include + +// Permutations +#include + +#endif // include guard + diff --git a/include/boost/range/algorithm/adjacent_find.hpp b/include/boost/range/algorithm/adjacent_find.hpp new file mode 100755 index 0000000..1b88dae --- /dev/null +++ b/include/boost/range/algorithm/adjacent_find.hpp @@ -0,0 +1,125 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_ADJACENT_FIND_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_ADJACENT_FIND_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function adjacent_find +/// +/// range-based version of the adjacent_find std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template< typename ForwardRange > +inline typename range_iterator::type +adjacent_find(ForwardRange & rng) +{ + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + return std::adjacent_find(boost::begin(rng),boost::end(rng)); +} + +/// \overload +template< typename ForwardRange > +inline typename range_iterator::type +adjacent_find(const ForwardRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + return std::adjacent_find(boost::begin(rng),boost::end(rng)); +} + +/// \overload +template< typename ForwardRange, typename BinaryPredicate > +inline typename range_iterator::type +adjacent_find(ForwardRange & rng, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + BOOST_RANGE_CONCEPT_ASSERT((BinaryPredicateConcept::type, + typename range_value::type>)); + return std::adjacent_find(boost::begin(rng),boost::end(rng),pred); +} + +/// \overload +template< typename ForwardRange, typename BinaryPredicate > +inline typename range_iterator::type +adjacent_find(const ForwardRange& rng, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + BOOST_RANGE_CONCEPT_ASSERT((BinaryPredicateConcept::type, + typename range_value::type>)); + return std::adjacent_find(boost::begin(rng),boost::end(rng),pred); +} + +// range_return overloads + +/// \overload +template< range_return_value re, typename ForwardRange > +inline typename range_return::type +adjacent_find(ForwardRange & rng) +{ + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + return range_return:: + pack(std::adjacent_find(boost::begin(rng),boost::end(rng)), + rng); +} + +/// \overload +template< range_return_value re, typename ForwardRange > +inline typename range_return::type +adjacent_find(const ForwardRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + return range_return:: + pack(std::adjacent_find(boost::begin(rng),boost::end(rng)), + rng); +} + +/// \overload +template< range_return_value re, typename ForwardRange, typename BinaryPredicate > +inline typename range_return::type +adjacent_find(ForwardRange& rng, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + BOOST_RANGE_CONCEPT_ASSERT((BinaryPredicateConcept::type, + typename range_value::type>)); + return range_return:: + pack(std::adjacent_find(boost::begin(rng),boost::end(rng),pred), + rng); +} + +/// \overload +template< range_return_value re, typename ForwardRange, typename BinaryPredicate > +inline typename range_return::type +adjacent_find(const ForwardRange& rng, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + return range_return:: + pack(std::adjacent_find(boost::begin(rng),boost::end(rng),pred), + rng); +} + + } // namespace range + using range::adjacent_find; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/binary_search.hpp b/include/boost/range/algorithm/binary_search.hpp new file mode 100755 index 0000000..bb64ec8 --- /dev/null +++ b/include/boost/range/algorithm/binary_search.hpp @@ -0,0 +1,49 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_BINARY_SEARCH_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_BINARY_SEARCH_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function binary_search +/// +/// range-based version of the binary_search std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template +inline bool binary_search(const ForwardRange& rng, const Value& val) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::binary_search(boost::begin(rng), boost::end(rng), val); +} + +/// \overload +template +inline bool binary_search(const ForwardRange& rng, const Value& val, + BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::binary_search(boost::begin(rng), boost::end(rng), val, pred); +} + + } // namespace range + using range::binary_search; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/copy.hpp b/include/boost/range/algorithm/copy.hpp new file mode 100644 index 0000000..dc5a0c3 --- /dev/null +++ b/include/boost/range/algorithm/copy.hpp @@ -0,0 +1,41 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_COPY_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_COPY_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function copy +/// +/// range-based version of the copy std algorithm +/// +/// \pre SinglePassRange is a model of the SinglePassRangeConcept +/// \pre OutputIterator is a model of the OutputIteratorConcept +template< class SinglePassRange, class OutputIterator > +inline OutputIterator copy(const SinglePassRange& rng, OutputIterator out) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::copy(boost::begin(rng),boost::end(rng),out); +} + + } // namespace range + using range::copy; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/copy_backward.hpp b/include/boost/range/algorithm/copy_backward.hpp new file mode 100755 index 0000000..52dc922 --- /dev/null +++ b/include/boost/range/algorithm/copy_backward.hpp @@ -0,0 +1,43 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_COPY_BACKWARD_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_COPY_BACKWARD_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function copy_backward +/// +/// range-based version of the copy_backwards std algorithm +/// +/// \pre BidirectionalRange is a model of the BidirectionalRangeConcept +/// \pre BidirectionalTraversalWriteableIterator is a model of the BidirectionalIteratorConcept +/// \pre BidirectionalTraversalWriteableIterator is a model of the WriteableIteratorConcept +template< class BidirectionalRange, class BidirectionalTraversalWriteableIterator > +inline BidirectionalTraversalWriteableIterator +copy_backward(const BidirectionalRange& rng, + BidirectionalTraversalWriteableIterator out) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + return std::copy_backward(boost::begin(rng), boost::end(rng), out); +} + + } // namespace range + using range::copy_backward; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/count.hpp b/include/boost/range/algorithm/count.hpp new file mode 100755 index 0000000..8316ce0 --- /dev/null +++ b/include/boost/range/algorithm/count.hpp @@ -0,0 +1,50 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_COUNT_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_COUNT_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function count +/// +/// range-based version of the count std algorithm +/// +/// \pre SinglePassRange is a model of the SinglePassRangeConcept +template< class SinglePassRange, class Value > +inline BOOST_DEDUCED_TYPENAME range_difference::type +count(SinglePassRange& rng, const Value& val) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::count(boost::begin(rng), boost::end(rng), val); +} + +/// \overload +template< class SinglePassRange, class Value > +inline BOOST_DEDUCED_TYPENAME range_difference::type +count(const SinglePassRange& rng, const Value& val) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::count(boost::begin(rng), boost::end(rng), val); +} + + } // namespace range + using range::count; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/count_if.hpp b/include/boost/range/algorithm/count_if.hpp new file mode 100755 index 0000000..ae17b0e --- /dev/null +++ b/include/boost/range/algorithm/count_if.hpp @@ -0,0 +1,51 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_COUNT_IF_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_COUNT_IF_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function count_if +/// +/// range-based version of the count_if std algorithm +/// +/// \pre SinglePassRange is a model of the SinglePassRangeConcept +/// \pre UnaryPredicate is a model of the UnaryPredicateConcept +template< class SinglePassRange, class UnaryPredicate > +inline BOOST_DEDUCED_TYPENAME boost::range_difference::type +count_if(SinglePassRange& rng, UnaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::count_if(boost::begin(rng), boost::end(rng), pred); +} + +/// \overload +template< class SinglePassRange, class UnaryPredicate > +inline BOOST_DEDUCED_TYPENAME boost::range_difference::type +count_if(const SinglePassRange& rng, UnaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::count_if(boost::begin(rng), boost::end(rng), pred); +} + + } // namespace range + using range::count_if; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/equal.hpp b/include/boost/range/algorithm/equal.hpp new file mode 100755 index 0000000..e210ef5 --- /dev/null +++ b/include/boost/range/algorithm/equal.hpp @@ -0,0 +1,188 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. +// 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_ALGORITHM_EQUAL_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_EQUAL_HPP_INCLUDED + +#include +#include +#include + +namespace boost +{ + namespace range_detail + { + // An implementation of equality comparison that is optimized for iterator + // traversal categories less than RandomAccessTraversal. + template< class SinglePassTraversalReadableIterator1, + class SinglePassTraversalReadableIterator2, + class IteratorCategoryTag1, + class IteratorCategoryTag2 > + inline bool equal_impl( SinglePassTraversalReadableIterator1 first1, + SinglePassTraversalReadableIterator1 last1, + SinglePassTraversalReadableIterator2 first2, + SinglePassTraversalReadableIterator2 last2, + IteratorCategoryTag1, + IteratorCategoryTag2 ) + { + do + { + // If we have reached the end of the left range then this is + // the end of the loop. They are equal if and only if we have + // simultaneously reached the end of the right range. + if (first1 == last1) + return first2 == last2; + + // If we have reached the end of the right range at this line + // it indicates that the right range is shorter than the left + // and hence the result is false. + if (first2 == last2) + return false; + + // continue looping if and only if the values are equal + } while(*first1++ == *first2++); + + // Reaching this line in the algorithm indicates that a value + // inequality has been detected. + return false; + } + + template< class SinglePassTraversalReadableIterator1, + class SinglePassTraversalReadableIterator2, + class IteratorCategoryTag1, + class IteratorCategoryTag2, + class BinaryPredicate > + inline bool equal_impl( SinglePassTraversalReadableIterator1 first1, + SinglePassTraversalReadableIterator1 last1, + SinglePassTraversalReadableIterator2 first2, + SinglePassTraversalReadableIterator2 last2, + BinaryPredicate pred, + IteratorCategoryTag1, + IteratorCategoryTag2 ) + { + do + { + // If we have reached the end of the left range then this is + // the end of the loop. They are equal if and only if we have + // simultaneously reached the end of the right range. + if (first1 == last1) + return first2 == last2; + + // If we have reached the end of the right range at this line + // it indicates that the right range is shorter than the left + // and hence the result is false. + if (first2 == last2) + return false; + + // continue looping if and only if the values are equal + } while(pred(*first1++, *first2++)); + + // Reaching this line in the algorithm indicates that a value + // inequality has been detected. + return false; + } + + // An implementation of equality comparison that is optimized for + // random access iterators. + template< class RandomAccessTraversalReadableIterator1, + class RandomAccessTraversalReadableIterator2 > + inline bool equal_impl( RandomAccessTraversalReadableIterator1 first1, + RandomAccessTraversalReadableIterator1 last1, + RandomAccessTraversalReadableIterator2 first2, + RandomAccessTraversalReadableIterator2 last2, + std::random_access_iterator_tag, + std::random_access_iterator_tag ) + { + return ((last1 - first1) == (last2 - first2)) + && std::equal(first1, last1, first2); + } + + template< class RandomAccessTraversalReadableIterator1, + class RandomAccessTraversalReadableIterator2, + class BinaryPredicate > + inline bool equal_impl( RandomAccessTraversalReadableIterator1 first1, + RandomAccessTraversalReadableIterator1 last1, + RandomAccessTraversalReadableIterator2 first2, + RandomAccessTraversalReadableIterator2 last2, + BinaryPredicate pred ) + { + return ((last1 - first1) == (last2 - first2)) + && std::equal(first1, last1, first2, pred); + } + + template< class SinglePassTraversalReadableIterator1, + class SinglePassTraversalReadableIterator2 > + inline bool equal( SinglePassTraversalReadableIterator1 first1, + SinglePassTraversalReadableIterator1 last1, + SinglePassTraversalReadableIterator2 first2, + SinglePassTraversalReadableIterator2 last2 ) + { + BOOST_DEDUCED_TYPENAME std::iterator_traits< SinglePassTraversalReadableIterator1 >::iterator_category tag1; + BOOST_DEDUCED_TYPENAME std::iterator_traits< SinglePassTraversalReadableIterator2 >::iterator_category tag2; + + return equal_impl(first1, last1, first2, last2, tag1, tag2); + } + + template< class SinglePassTraversalReadableIterator1, + class SinglePassTraversalReadableIterator2, + class BinaryPredicate > + inline bool equal( SinglePassTraversalReadableIterator1 first1, + SinglePassTraversalReadableIterator1 last1, + SinglePassTraversalReadableIterator2 first2, + SinglePassTraversalReadableIterator2 last2, + BinaryPredicate pred ) + { + BOOST_DEDUCED_TYPENAME std::iterator_traits< SinglePassTraversalReadableIterator1 >::iterator_category tag1; + BOOST_DEDUCED_TYPENAME std::iterator_traits< SinglePassTraversalReadableIterator2 >::iterator_category tag2; + + return equal_impl(first1, last1, first2, last2, pred, tag1, tag2); + } + + } // namespace range_detail + + namespace range + { + + /// \brief template function equal + /// + /// range-based version of the equal std algorithm + /// + /// \pre SinglePassRange1 is a model of the SinglePassRangeConcept + /// \pre SinglePassRange2 is a model of the SinglePassRangeConcept + /// \pre BinaryPredicate is a model of the BinaryPredicateConcept + template< class SinglePassRange1, class SinglePassRange2 > + inline bool equal( const SinglePassRange1& rng1, const SinglePassRange2& rng2 ) + { + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + return ::boost::range_detail::equal( + ::boost::begin(rng1), ::boost::end(rng1), + ::boost::begin(rng2), ::boost::end(rng2) ); + } + + /// \overload + template< class SinglePassRange1, class SinglePassRange2, class BinaryPredicate > + inline bool equal( const SinglePassRange1& rng1, const SinglePassRange2& rng2, + BinaryPredicate pred ) + { + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + return ::boost::range_detail::equal( + ::boost::begin(rng1), ::boost::end(rng1), + ::boost::begin(rng2), ::boost::end(rng2), + pred); + } + + } // namespace range + using range::equal; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/equal_range.hpp b/include/boost/range/algorithm/equal_range.hpp new file mode 100755 index 0000000..4aa4a54 --- /dev/null +++ b/include/boost/range/algorithm/equal_range.hpp @@ -0,0 +1,80 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_EQUAL_RANGE_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_EQUAL_RANGE_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function equal_range +/// +/// range-based version of the equal_range std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +/// \pre SortPredicate is a model of the BinaryPredicateConcept +template +inline std::pair< + BOOST_DEDUCED_TYPENAME boost::range_iterator::type, + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + > +equal_range(ForwardRange& rng, const Value& val) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::equal_range(boost::begin(rng), boost::end(rng), val); +} + +/// \overload +template +inline std::pair< + BOOST_DEDUCED_TYPENAME boost::range_iterator::type, + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + > +equal_range(const ForwardRange& rng, const Value& val) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::equal_range(boost::begin(rng), boost::end(rng), val); +} + +/// \overload +template +inline std::pair< + BOOST_DEDUCED_TYPENAME boost::range_iterator::type, + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + > +equal_range(ForwardRange& rng, const Value& val, SortPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::equal_range(boost::begin(rng), boost::end(rng), val, pred); +} + +/// \overload +template +inline std::pair< + BOOST_DEDUCED_TYPENAME boost::range_iterator::type, + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + > +equal_range(const ForwardRange& rng, const Value& val, SortPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::equal_range(boost::begin(rng), boost::end(rng), val, pred); +} + + } // namespace range + using range::equal_range; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/fill.hpp b/include/boost/range/algorithm/fill.hpp new file mode 100755 index 0000000..72c5d58 --- /dev/null +++ b/include/boost/range/algorithm/fill.hpp @@ -0,0 +1,40 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_FILL_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_FILL_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function fill +/// +/// range-based version of the fill std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +template< class ForwardRange, class Value > +inline ForwardRange& fill(ForwardRange& rng, const Value& val) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + std::fill(boost::begin(rng), boost::end(rng), val); + return rng; +} + + } // namespace range + using range::fill; +} + +#endif // include guard diff --git a/include/boost/range/algorithm/fill_n.hpp b/include/boost/range/algorithm/fill_n.hpp new file mode 100755 index 0000000..f827135 --- /dev/null +++ b/include/boost/range/algorithm/fill_n.hpp @@ -0,0 +1,42 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_FILL_N_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_FILL_N_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function fill_n +/// +/// range-based version of the fill_n std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +template< class ForwardRange, class Size, class Value > +inline ForwardRange& fill_n(ForwardRange& rng, Size n, const Value& val) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + BOOST_ASSERT( static_cast(std::distance(boost::begin(rng), boost::end(rng))) >= n ); + std::fill_n(boost::begin(rng), n, val); + return rng; +} + + } // namespace range + using range::fill_n; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/find.hpp b/include/boost/range/algorithm/find.hpp new file mode 100755 index 0000000..b4bf6d9 --- /dev/null +++ b/include/boost/range/algorithm/find.hpp @@ -0,0 +1,54 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_FIND_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_FIND_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function find +/// +/// range-based version of the find std algorithm +/// +/// \pre SinglePassRange is a model of the SinglePassRangeConcept +template< class SinglePassRange, class Value > +inline BOOST_DEDUCED_TYPENAME range_iterator::type +find( SinglePassRange& rng, const Value& val ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::find(boost::begin(rng), boost::end(rng), val); +} + +// range_return overloads + +/// \overload +template< range_return_value re, class SinglePassRange, class Value > +inline BOOST_DEDUCED_TYPENAME range_return::type +find( SinglePassRange& rng, const Value& val ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return range_return:: + pack(std::find(boost::begin(rng), boost::end(rng), val), + rng); +} + + } // namespace range + using range::find; +} + +#endif // include guard diff --git a/include/boost/range/algorithm/find_end.hpp b/include/boost/range/algorithm/find_end.hpp new file mode 100755 index 0000000..864d4b0 --- /dev/null +++ b/include/boost/range/algorithm/find_end.hpp @@ -0,0 +1,87 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_FIND_END_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_FIND_END_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function find_end +/// +/// range-based version of the find_end std algorithm +/// +/// \pre ForwardRange1 is a model of the ForwardRangeConcept +/// \pre ForwardRange2 is a model of the ForwardRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template< class ForwardRange1, class ForwardRange2 > +inline BOOST_DEDUCED_TYPENAME range_iterator< ForwardRange1 >::type +find_end(ForwardRange1 & rng1, const ForwardRange2& rng2) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + + return std::find_end(boost::begin(rng1),boost::end(rng1), + boost::begin(rng2),boost::end(rng2)); +} + +/// \overload +template< class ForwardRange1, class ForwardRange2, class BinaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_iterator::type +find_end(ForwardRange1 & rng1, const ForwardRange2& rng2, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + + return std::find_end(boost::begin(rng1),boost::end(rng1), + boost::begin(rng2),boost::end(rng2),pred); +} + +/// \overload +template< range_return_value re, class ForwardRange1, class ForwardRange2 > +inline BOOST_DEDUCED_TYPENAME range_return::type +find_end(ForwardRange1& rng1, const ForwardRange2& rng2) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + + return range_return:: + pack(std::find_end(boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2)), + rng1); +} + +/// \overload +template< range_return_value re, class ForwardRange1, class ForwardRange2, + class BinaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_return::type +find_end(ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + + return range_return:: + pack(std::find_end(boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), pred), + rng1); +} + + } // namespace range + using range::find_end; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/find_first_of.hpp b/include/boost/range/algorithm/find_first_of.hpp new file mode 100755 index 0000000..f7543b7 --- /dev/null +++ b/include/boost/range/algorithm/find_first_of.hpp @@ -0,0 +1,89 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_FIND_FIRST_OF_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_FIND_FIRST_OF_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function find_first_of +/// +/// range-based version of the find_first_of std algorithm +/// +/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept +/// \pre ForwardRange2 is a model of the ForwardRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template< class SinglePassRange1, class ForwardRange2 > +inline BOOST_DEDUCED_TYPENAME range_iterator::type +find_first_of(SinglePassRange1 & rng1, ForwardRange2 const & rng2) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + + return std::find_first_of(boost::begin(rng1),boost::end(rng1), + boost::begin(rng2),boost::end(rng2)); +} + +/// \overload +template< class SinglePassRange1, class ForwardRange2, class BinaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_iterator::type +find_first_of(SinglePassRange1 & rng1, ForwardRange2 const & rng2, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + + return std::find_first_of(boost::begin(rng1),boost::end(rng1), + boost::begin(rng2),boost::end(rng2),pred); +} + +// range return overloads +/// \overload +template< range_return_value re, class SinglePassRange1, class ForwardRange2 > +inline BOOST_DEDUCED_TYPENAME range_return::type +find_first_of(SinglePassRange1& rng1, const ForwardRange2& rng2) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + + return range_return:: + pack(std::find_first_of(boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2)), + rng1); +} + +/// \overload +template< range_return_value re, class SinglePassRange1, class ForwardRange2, + class BinaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_return::type +find_first_of(SinglePassRange1 & rng1, const ForwardRange2& rng2, + BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + + return range_return:: + pack(std::find_first_of(boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), pred), + rng1); +} + + } // namespace range + using range::find_first_of; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/find_if.hpp b/include/boost/range/algorithm/find_if.hpp new file mode 100755 index 0000000..3254d8c --- /dev/null +++ b/include/boost/range/algorithm/find_if.hpp @@ -0,0 +1,55 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_FIND_IF_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_FIND_IF_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function find_if +/// +/// range-based version of the find_if std algorithm +/// +/// \pre SinglePassRange is a model of the SinglePassRangeConcept +/// \pre UnaryPredicate is a model of the UnaryPredicateConcept +template< class SinglePassRange, class UnaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_iterator::type +find_if( SinglePassRange& rng, UnaryPredicate pred ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::find_if(boost::begin(rng), boost::end(rng), pred); +} + +// range_return overloads + +/// \overload +template< range_return_value re, class SinglePassRange, class UnaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_return::type +find_if( SinglePassRange& rng, UnaryPredicate pred ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return range_return:: + pack(std::find_if(boost::begin(rng), boost::end(rng), pred), + rng); +} + + } // namespace range + using range::find_if; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/for_each.hpp b/include/boost/range/algorithm/for_each.hpp new file mode 100755 index 0000000..714a06f --- /dev/null +++ b/include/boost/range/algorithm/for_each.hpp @@ -0,0 +1,48 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_FOR_EACH_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_FOR_EACH_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function for_each +/// +/// range-based version of the for_each std algorithm +/// +/// \pre SinglePassRange is a model of the SinglePassRangeConcept +/// \pre UnaryFunction is a model of the UnaryFunctionConcept +template< class SinglePassRange, class UnaryFunction > +inline UnaryFunction for_each(SinglePassRange & rng, UnaryFunction fun) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::for_each(boost::begin(rng),boost::end(rng),fun); +} + +/// \overload +template< class SinglePassRange, class UnaryFunction > +inline UnaryFunction for_each(const SinglePassRange& rng, UnaryFunction fun) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::for_each(boost::begin(rng), boost::end(rng), fun); +} + + } // namespace range + using range::for_each; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/generate.hpp b/include/boost/range/algorithm/generate.hpp new file mode 100755 index 0000000..97a0d9d --- /dev/null +++ b/include/boost/range/algorithm/generate.hpp @@ -0,0 +1,49 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_GENERATE_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_GENERATE_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { +/// \brief template function generate +/// +/// range-based version of the generate std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +/// \pre Generator is a model of the UnaryFunctionConcept +template< class ForwardRange, class Generator > +inline ForwardRange& generate( ForwardRange& rng, Generator gen ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + std::generate(boost::begin(rng), boost::end(rng), gen); + return rng; +} + +/// \overload +template< class ForwardRange, class Generator > +inline const ForwardRange& generate(const ForwardRange& rng, Generator gen) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + std::generate(boost::begin(rng), boost::end(rng), gen); + return rng; +} + + } // namespace range + using range::generate; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/heap_algorithm.hpp b/include/boost/range/algorithm/heap_algorithm.hpp new file mode 100755 index 0000000..857a30f --- /dev/null +++ b/include/boost/range/algorithm/heap_algorithm.hpp @@ -0,0 +1,178 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_HEAP_ALGORITHM_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_HEAP_ALGORITHM_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function push_heap +/// +/// range-based version of the push_heap std algorithm +/// +/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept +/// \pre Compare is a model of the BinaryPredicateConcept +template +inline void push_heap(RandomAccessRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::push_heap(boost::begin(rng), boost::end(rng)); +} + +/// \overload +template +inline void push_heap(const RandomAccessRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::push_heap(boost::begin(rng), boost::end(rng)); +} + +/// \overload +template +inline void push_heap(RandomAccessRange& rng, Compare comp_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::push_heap(boost::begin(rng), boost::end(rng), comp_pred); +} + +/// \overload +template +inline void push_heap(const RandomAccessRange& rng, Compare comp_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::push_heap(boost::begin(rng), boost::end(rng), comp_pred); +} + +/// \brief template function pop_heap +/// +/// range-based version of the pop_heap std algorithm +/// +/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept +/// \pre Compare is a model of the BinaryPredicateConcept +template +inline void pop_heap(RandomAccessRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::pop_heap(boost::begin(rng), boost::end(rng)); +} + +/// \overload +template +inline void pop_heap(const RandomAccessRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::pop_heap(boost::begin(rng),boost::end(rng)); +} + +/// \overload +template +inline void pop_heap(RandomAccessRange& rng, Compare comp_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::pop_heap(boost::begin(rng), boost::end(rng), comp_pred); +} + +/// \overload +template +inline void pop_heap(const RandomAccessRange& rng, Compare comp_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::pop_heap(boost::begin(rng), boost::end(rng), comp_pred); +} + +/// \brief template function make_heap +/// +/// range-based version of the make_heap std algorithm +/// +/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept +/// \pre Compare is a model of the BinaryPredicateConcept +template +inline void make_heap(RandomAccessRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::make_heap(boost::begin(rng), boost::end(rng)); +} + +/// \overload +template +inline void make_heap(const RandomAccessRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::make_heap(boost::begin(rng),boost::end(rng)); +} + +/// \overload +template +inline void make_heap(RandomAccessRange& rng, Compare comp_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::make_heap(boost::begin(rng), boost::end(rng), comp_pred); +} + +/// \overload +template +inline void make_heap(const RandomAccessRange& rng, Compare comp_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::make_heap(boost::begin(rng), boost::end(rng), comp_pred); +} + +/// \brief template function sort_heap +/// +/// range-based version of the sort_heap std algorithm +/// +/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept +/// \pre Compare is a model of the BinaryPredicateConcept +template +inline void sort_heap(RandomAccessRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::sort_heap(boost::begin(rng), boost::end(rng)); +} + +/// \overload +template +inline void sort_heap(const RandomAccessRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::sort_heap(boost::begin(rng), boost::end(rng)); +} + +/// \overload +template +inline void sort_heap(RandomAccessRange& rng, Compare comp_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::sort_heap(boost::begin(rng), boost::end(rng), comp_pred); +} + +/// \overload +template +inline void sort_heap(const RandomAccessRange& rng, Compare comp_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::sort_heap(boost::begin(rng), boost::end(rng), comp_pred); +} + + } // namespace range + using range::push_heap; + using range::pop_heap; + using range::make_heap; + using range::sort_heap; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/inplace_merge.hpp b/include/boost/range/algorithm/inplace_merge.hpp new file mode 100755 index 0000000..dfadbaa --- /dev/null +++ b/include/boost/range/algorithm/inplace_merge.hpp @@ -0,0 +1,74 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_INPLACE_MERGE_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_INPLACE_MERGE_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function inplace_merge +/// +/// range-based version of the inplace_merge std algorithm +/// +/// \pre BidirectionalRange is a model of the BidirectionalRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template +inline BidirectionalRange& inplace_merge(BidirectionalRange& rng, + BOOST_DEDUCED_TYPENAME range_iterator::type middle) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + std::inplace_merge(boost::begin(rng), middle, boost::end(rng)); + return rng; +} + +/// \overload +template +inline const BidirectionalRange& inplace_merge(const BidirectionalRange& rng, + BOOST_DEDUCED_TYPENAME boost::range_iterator::type middle) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + std::inplace_merge(boost::begin(rng), middle, boost::end(rng)); + return rng; +} + +/// \overload +template +inline BidirectionalRange& inplace_merge(BidirectionalRange& rng, + BOOST_DEDUCED_TYPENAME boost::range_iterator::type middle, + BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + std::inplace_merge(boost::begin(rng), middle, boost::end(rng), pred); + return rng; +} + +/// \overload +template +inline const BidirectionalRange& inplace_merge(const BidirectionalRange& rng, + BOOST_DEDUCED_TYPENAME boost::range_iterator::type middle, + BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + std::inplace_merge(boost::begin(rng), middle, boost::end(rng), pred); + return rng; +} + + } // namespace range + using range::inplace_merge; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/lexicographical_compare.hpp b/include/boost/range/algorithm/lexicographical_compare.hpp new file mode 100755 index 0000000..c6e4bc8 --- /dev/null +++ b/include/boost/range/algorithm/lexicographical_compare.hpp @@ -0,0 +1,58 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_LEXICOGRAPHICAL_COMPARE_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function lexicographic_compare +/// +/// range-based version of the lexicographic_compare std algorithm +/// +/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept +/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept +template +inline bool lexicographical_compare(const SinglePassRange1& rng1, + const SinglePassRange2& rng2) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::lexicographical_compare( + boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2)); +} + +/// \overload +template +inline bool lexicographical_compare(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::lexicographical_compare( + boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), pred); +} + + } // namespace range + using range::lexicographical_compare; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/lower_bound.hpp b/include/boost/range/algorithm/lower_bound.hpp new file mode 100755 index 0000000..5d3945e --- /dev/null +++ b/include/boost/range/algorithm/lower_bound.hpp @@ -0,0 +1,69 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_LOWER_BOUND_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_LOWER_BOUND_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function lower_bound +/// +/// range-based version of the lower_bound std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +template< class ForwardRange, class Value > +inline BOOST_DEDUCED_TYPENAME range_iterator::type +lower_bound( ForwardRange& rng, Value val ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::lower_bound(boost::begin(rng), boost::end(rng), val); +} +/// \overload +template< class ForwardRange, class Value, class SortPredicate > +inline BOOST_DEDUCED_TYPENAME range_iterator::type +lower_bound( ForwardRange& rng, Value val, SortPredicate pred ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::lower_bound(boost::begin(rng), boost::end(rng), val, pred); +} +/// \overload +template< range_return_value re, class ForwardRange, class Value > +inline BOOST_DEDUCED_TYPENAME range_return::type +lower_bound( ForwardRange& rng, Value val ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return:: + pack(std::lower_bound(boost::begin(rng), boost::end(rng), val), + rng); +} +/// \overload +template< range_return_value re, class ForwardRange, class Value, class SortPredicate > +inline BOOST_DEDUCED_TYPENAME range_return::type +lower_bound( ForwardRange& rng, Value val, SortPredicate pred ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return:: + pack(std::lower_bound(boost::begin(rng), boost::end(rng), val, pred), + rng); +} + + } // namespace range + using range::lower_bound; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/max_element.hpp b/include/boost/range/algorithm/max_element.hpp new file mode 100755 index 0000000..a0c1ffd --- /dev/null +++ b/include/boost/range/algorithm/max_element.hpp @@ -0,0 +1,115 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_MAX_ELEMENT_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_MAX_ELEMENT_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function max_element +/// +/// range-based version of the max_element std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template +inline BOOST_DEDUCED_TYPENAME range_iterator::type +max_element(ForwardRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::max_element(boost::begin(rng), boost::end(rng)); +} + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_iterator::type +max_element(const ForwardRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::max_element(boost::begin(rng), boost::end(rng)); +} + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_iterator::type +max_element(ForwardRange& rng, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::max_element(boost::begin(rng), boost::end(rng), pred); +} + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_iterator::type +max_element(const ForwardRange& rng, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::max_element(boost::begin(rng), boost::end(rng), pred); +} + +// range_return overloads + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_return::type +max_element(ForwardRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return::pack( + std::max_element(boost::begin(rng), boost::end(rng)), + rng); +} + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_return::type +max_element(const ForwardRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return::pack( + std::max_element(boost::begin(rng), boost::end(rng)), + rng); +} + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_return::type +max_element(ForwardRange& rng, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return::pack( + std::max_element(boost::begin(rng), boost::end(rng), pred), + rng); +} + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_return::type +max_element(const ForwardRange& rng, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return::pack( + std::max_element(boost::begin(rng), boost::end(rng), pred), + rng); +} + + } // namespace range + using range::max_element; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/merge.hpp b/include/boost/range/algorithm/merge.hpp new file mode 100755 index 0000000..c81b8c7 --- /dev/null +++ b/include/boost/range/algorithm/merge.hpp @@ -0,0 +1,61 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_MERGE_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_MERGE_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function merge +/// +/// range-based version of the merge std algorithm +/// +/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept +/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +/// +template +inline OutputIterator merge(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::merge(boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), out); +} + +/// \overload +template +inline OutputIterator merge(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out, + BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::merge(boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), out, pred); +} + + } // namespace range + using range::merge; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/min_element.hpp b/include/boost/range/algorithm/min_element.hpp new file mode 100755 index 0000000..c966b1e --- /dev/null +++ b/include/boost/range/algorithm/min_element.hpp @@ -0,0 +1,115 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_MIN_ELEMENT_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_MIN_ELEMENT_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function min_element +/// +/// range-based version of the min_element std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template +inline BOOST_DEDUCED_TYPENAME range_iterator::type +min_element(ForwardRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::min_element(boost::begin(rng), boost::end(rng)); +} + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_iterator::type +min_element(const ForwardRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::min_element(boost::begin(rng), boost::end(rng)); +} + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_iterator::type +min_element(ForwardRange& rng, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::min_element(boost::begin(rng), boost::end(rng), pred); +} + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_iterator::type +min_element(const ForwardRange& rng, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::min_element(boost::begin(rng), boost::end(rng), pred); +} + +// range_return overloads + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_return::type +min_element(ForwardRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return::pack( + std::min_element(boost::begin(rng), boost::end(rng)), + rng); +} + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_return::type +min_element(const ForwardRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return::pack( + std::min_element(boost::begin(rng), boost::end(rng)), + rng); +} + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_return::type +min_element(ForwardRange& rng, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return::pack( + std::min_element(boost::begin(rng), boost::end(rng), pred), + rng); +} + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_return::type +min_element(const ForwardRange& rng, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return::pack( + std::min_element(boost::begin(rng), boost::end(rng), pred), + rng); +} + + } // namespace range + using range::min_element; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/mismatch.hpp b/include/boost/range/algorithm/mismatch.hpp new file mode 100755 index 0000000..2819c33 --- /dev/null +++ b/include/boost/range/algorithm/mismatch.hpp @@ -0,0 +1,195 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_MISMATCH_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_MISMATCH_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range_detail + { + template< class SinglePassTraversalReadableIterator1, + class SinglePassTraversalReadableIterator2 > + inline std::pair + mismatch_impl(SinglePassTraversalReadableIterator1 first1, + SinglePassTraversalReadableIterator1 last1, + SinglePassTraversalReadableIterator2 first2, + SinglePassTraversalReadableIterator2 last2) + { + while (first1 != last1 && first2 != last2 && *first1 == *first2) + { + ++first1; + ++first2; + } + return std::pair(first1, first2); + } + + template< class SinglePassTraversalReadableIterator1, + class SinglePassTraversalReadableIterator2, + class BinaryPredicate > + inline std::pair + mismatch_impl(SinglePassTraversalReadableIterator1 first1, + SinglePassTraversalReadableIterator1 last1, + SinglePassTraversalReadableIterator2 first2, + SinglePassTraversalReadableIterator2 last2, + BinaryPredicate pred) + { + while (first1 != last1 && first2 != last2 && pred(*first1, *first2)) + { + ++first1; + ++first2; + } + return std::pair(first1, first2); + } + } // namespace range_detail + + namespace range + { +/// \brief template function mismatch +/// +/// range-based version of the mismatch std algorithm +/// +/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept +/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template< class SinglePassRange1, class SinglePassRange2 > +inline std::pair< + BOOST_DEDUCED_TYPENAME range_iterator::type, + BOOST_DEDUCED_TYPENAME range_iterator::type > +mismatch(SinglePassRange1& rng1, const SinglePassRange2 & rng2) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + return ::boost::range_detail::mismatch_impl( + ::boost::begin(rng1), ::boost::end(rng1), + ::boost::begin(rng2), ::boost::end(rng2)); +} + +/// \overload +template< class SinglePassRange1, class SinglePassRange2 > +inline std::pair< + BOOST_DEDUCED_TYPENAME range_iterator::type, + BOOST_DEDUCED_TYPENAME range_iterator::type > +mismatch(const SinglePassRange1& rng1, const SinglePassRange2& rng2) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + return ::boost::range_detail::mismatch_impl( + ::boost::begin(rng1), ::boost::end(rng1), + ::boost::begin(rng2), ::boost::end(rng2)); +} + +/// \overload +template< class SinglePassRange1, class SinglePassRange2 > +inline std::pair< + BOOST_DEDUCED_TYPENAME range_iterator::type, + BOOST_DEDUCED_TYPENAME range_iterator::type > +mismatch(SinglePassRange1& rng1, SinglePassRange2 & rng2) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + return ::boost::range_detail::mismatch_impl( + ::boost::begin(rng1), ::boost::end(rng1), + ::boost::begin(rng2), ::boost::end(rng2)); +} + +/// \overload +template< class SinglePassRange1, class SinglePassRange2 > +inline std::pair< + BOOST_DEDUCED_TYPENAME range_iterator::type, + BOOST_DEDUCED_TYPENAME range_iterator::type > +mismatch(const SinglePassRange1& rng1, SinglePassRange2& rng2) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + return ::boost::range_detail::mismatch_impl( + ::boost::begin(rng1), ::boost::end(rng1), + ::boost::begin(rng2), ::boost::end(rng2)); +} + + +/// \overload +template< class SinglePassRange1, class SinglePassRange2, class BinaryPredicate > +inline std::pair< + BOOST_DEDUCED_TYPENAME range_iterator::type, + BOOST_DEDUCED_TYPENAME range_iterator::type > +mismatch(SinglePassRange1& rng1, const SinglePassRange2& rng2, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + return ::boost::range_detail::mismatch_impl( + ::boost::begin(rng1), ::boost::end(rng1), + ::boost::begin(rng2), ::boost::end(rng2), pred); +} + +/// \overload +template< class SinglePassRange1, class SinglePassRange2, class BinaryPredicate > +inline std::pair< + BOOST_DEDUCED_TYPENAME range_iterator::type, + BOOST_DEDUCED_TYPENAME range_iterator::type > +mismatch(const SinglePassRange1& rng1, const SinglePassRange2& rng2, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + return ::boost::range_detail::mismatch_impl( + ::boost::begin(rng1), ::boost::end(rng1), + ::boost::begin(rng2), ::boost::end(rng2), pred); +} + +/// \overload +template< class SinglePassRange1, class SinglePassRange2, class BinaryPredicate > +inline std::pair< + BOOST_DEDUCED_TYPENAME range_iterator::type, + BOOST_DEDUCED_TYPENAME range_iterator::type > +mismatch(SinglePassRange1& rng1, SinglePassRange2& rng2, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + return ::boost::range_detail::mismatch_impl( + ::boost::begin(rng1), ::boost::end(rng1), + ::boost::begin(rng2), ::boost::end(rng2), pred); +} + +/// \overload +template< class SinglePassRange1, class SinglePassRange2, class BinaryPredicate > +inline std::pair< + BOOST_DEDUCED_TYPENAME range_iterator::type, + BOOST_DEDUCED_TYPENAME range_iterator::type > +mismatch(const SinglePassRange1& rng1, SinglePassRange2& rng2, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + return ::boost::range_detail::mismatch_impl( + ::boost::begin(rng1), ::boost::end(rng1), + ::boost::begin(rng2), ::boost::end(rng2), pred); +} + + } // namespace range + using range::mismatch; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/nth_element.hpp b/include/boost/range/algorithm/nth_element.hpp new file mode 100755 index 0000000..3e06baf --- /dev/null +++ b/include/boost/range/algorithm/nth_element.hpp @@ -0,0 +1,70 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_NTH_ELEMENT_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_NTH_ELEMENT_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function nth_element +/// +/// range-based version of the nth_element std algorithm +/// +/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template +inline void nth_element(RandomAccessRange& rng, + BOOST_DEDUCED_TYPENAME range_iterator::type nth) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::nth_element(boost::begin(rng), nth, boost::end(rng)); +} + +/// \overload +template +inline void nth_element(const RandomAccessRange& rng, + BOOST_DEDUCED_TYPENAME range_iterator::type nth) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::nth_element(boost::begin(rng),nth,boost::end(rng)); +} + +/// \overload +template +inline void nth_element(RandomAccessRange& rng, + BOOST_DEDUCED_TYPENAME range_iterator::type nth, + BinaryPredicate sort_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::nth_element(boost::begin(rng), nth, boost::end(rng), sort_pred); +} + +/// \overload +template +inline void nth_element(const RandomAccessRange& rng, + BOOST_DEDUCED_TYPENAME range_iterator::type nth, + BinaryPredicate sort_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::nth_element(boost::begin(rng),nth,boost::end(rng), sort_pred); +} + + } // namespace range + using range::nth_element; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/partial_sort.hpp b/include/boost/range/algorithm/partial_sort.hpp new file mode 100755 index 0000000..e38c4be --- /dev/null +++ b/include/boost/range/algorithm/partial_sort.hpp @@ -0,0 +1,71 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_PARTIAL_SORT_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_PARTIAL_SORT_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function partial_sort +/// +/// range-based version of the partial_sort std algorithm +/// +/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template +inline void partial_sort(RandomAccessRange& rng, + BOOST_DEDUCED_TYPENAME range_iterator::type middle) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::partial_sort(boost::begin(rng), middle, boost::end(rng)); +} + +/// \overload +template +inline void partial_sort(const RandomAccessRange& rng, + BOOST_DEDUCED_TYPENAME range_iterator::type middle) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::partial_sort(boost::begin(rng), middle, boost::end(rng)); +} + +/// \overload +template +inline void partial_sort(RandomAccessRange& rng, + BOOST_DEDUCED_TYPENAME range_iterator::type middle, + BinaryPredicate sort_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::partial_sort(boost::begin(rng), middle, boost::end(rng), + sort_pred); +} + +/// \overload +template +inline void partial_sort(const RandomAccessRange& rng, + BOOST_DEDUCED_TYPENAME range_iterator::type middle, + BinaryPredicate sort_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::partial_sort(boost::begin(rng), middle, boost::end(rng), sort_pred); +} + + } // namespace range + using range::partial_sort; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/partial_sort_copy.hpp b/include/boost/range/algorithm/partial_sort_copy.hpp new file mode 100755 index 0000000..8cf3510 --- /dev/null +++ b/include/boost/range/algorithm/partial_sort_copy.hpp @@ -0,0 +1,64 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_PARTIAL_SORT_COPY_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_PARTIAL_SORT_COPY_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function partial_sort_copy +/// +/// range-based version of the partial_sort_copy std algorithm +/// +/// \pre SinglePassRange is a model of the SinglePassRangeConcept +/// \pre RandomAccessRange is a model of the Mutable_RandomAccessRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template +inline typename range_iterator::type +partial_sort_copy(const SinglePassRange& rng1, RandomAccessRange& rng2) +{ + BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept)); + BOOST_RANGE_CONCEPT_ASSERT((WriteableRandomAccessRangeConcept)); + BOOST_RANGE_CONCEPT_ASSERT((range_detail::SameTypeConcept::type, typename range_value::type>)); + BOOST_RANGE_CONCEPT_ASSERT((LessThanComparableConcept::type>)); + + return std::partial_sort_copy(boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2)); +} + +/// \overload +template +inline typename range_iterator::type +partial_sort_copy(const SinglePassRange& rng1, RandomAccessRange& rng2, + BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept)); + BOOST_RANGE_CONCEPT_ASSERT((WriteableRandomAccessRangeConcept)); + BOOST_RANGE_CONCEPT_ASSERT((range_detail::SameTypeConcept::type, typename range_value::type>)); + BOOST_RANGE_CONCEPT_ASSERT((BinaryPredicateConcept::type, typename range_value::type>)); + + return std::partial_sort_copy(boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), pred); +} + + } // namespace range + using range::partial_sort_copy; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/partition.hpp b/include/boost/range/algorithm/partition.hpp new file mode 100755 index 0000000..05f41da --- /dev/null +++ b/include/boost/range/algorithm/partition.hpp @@ -0,0 +1,74 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_PARTITION__HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_PARTITION__HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function partition +/// +/// range-based version of the partition std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +template +inline BOOST_DEDUCED_TYPENAME range_iterator::type +partition(ForwardRange& rng, UnaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::partition(boost::begin(rng),boost::end(rng),pred); +} + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_iterator::type +partition(const ForwardRange& rng, UnaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::partition(boost::begin(rng),boost::end(rng),pred); +} + +// range_return overloads + +/// \overload +template< range_return_value re, class ForwardRange, + class UnaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_return::type +partition(ForwardRange& rng, UnaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return boost::range_return:: + pack(std::partition(boost::begin(rng), boost::end(rng), pred), rng); +} + +/// \overload +template< range_return_value re, class ForwardRange, + class UnaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_return::type +partition(const ForwardRange& rng, UnaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return boost::range_return:: + pack(std::partition(boost::begin(rng), boost::end(rng), pred), rng); +} + + } // namespace range + using range::partition; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/permutation.hpp b/include/boost/range/algorithm/permutation.hpp new file mode 100755 index 0000000..75388cc --- /dev/null +++ b/include/boost/range/algorithm/permutation.hpp @@ -0,0 +1,108 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_PERMUTATION_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_PERMUTATION_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function next_permutation +/// +/// range-based version of the next_permutation std algorithm +/// +/// \pre BidirectionalRange is a model of the BidirectionalRangeConcept +/// \pre Compare is a model of the BinaryPredicateConcept +template +inline bool next_permutation(BidirectionalRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + return std::next_permutation(boost::begin(rng), boost::end(rng)); +} + +/// \overload +template +inline bool next_permutation(const BidirectionalRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + return std::next_permutation(boost::begin(rng), boost::end(rng)); +} + +/// \overload +template +inline bool next_permutation(BidirectionalRange& rng, Compare comp_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + return std::next_permutation(boost::begin(rng), boost::end(rng), + comp_pred); +} + +/// \overload +template +inline bool next_permutation(const BidirectionalRange& rng, + Compare comp_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + return std::next_permutation(boost::begin(rng), boost::end(rng), + comp_pred); +} + +/// \brief template function prev_permutation +/// +/// range-based version of the prev_permutation std algorithm +/// +/// \pre BidirectionalRange is a model of the BidirectionalRangeConcept +/// \pre Compare is a model of the BinaryPredicateConcept +template +inline bool prev_permutation(BidirectionalRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + return std::prev_permutation(boost::begin(rng), boost::end(rng)); +} + +/// \overload +template +inline bool prev_permutation(const BidirectionalRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + return std::prev_permutation(boost::begin(rng), boost::end(rng)); +} + +/// \overload +template +inline bool prev_permutation(BidirectionalRange& rng, Compare comp_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + return std::prev_permutation(boost::begin(rng), boost::end(rng), + comp_pred); +} + +/// \overload +template +inline bool prev_permutation(const BidirectionalRange& rng, + Compare comp_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + return std::prev_permutation(boost::begin(rng), boost::end(rng), + comp_pred); +} + + } // namespace range + using range::next_permutation; + using range::prev_permutation; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/random_shuffle.hpp b/include/boost/range/algorithm/random_shuffle.hpp new file mode 100755 index 0000000..eeae3d7 --- /dev/null +++ b/include/boost/range/algorithm/random_shuffle.hpp @@ -0,0 +1,68 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_RANDOM_SHUFFLE_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_RANDOM_SHUFFLE_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function random_shuffle +/// +/// range-based version of the random_shuffle std algorithm +/// +/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept +/// \pre Generator is a model of the UnaryFunctionConcept +template +inline RandomAccessRange& random_shuffle(RandomAccessRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::random_shuffle(boost::begin(rng), boost::end(rng)); + return rng; +} + +/// \overload +template +inline const RandomAccessRange& random_shuffle(const RandomAccessRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::random_shuffle(boost::begin(rng),boost::end(rng)); + return rng; +} + +/// \overload +template +inline RandomAccessRange& random_shuffle(RandomAccessRange& rng, Generator& gen) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::random_shuffle(boost::begin(rng), boost::end(rng), gen); + return rng; +} + +/// \overload +template +inline const RandomAccessRange& random_shuffle(const RandomAccessRange& rng, Generator& gen) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::random_shuffle(boost::begin(rng), boost::end(rng), gen); + return rng; +} + + } // namespace range + using range::random_shuffle; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/remove.hpp b/include/boost/range/algorithm/remove.hpp new file mode 100755 index 0000000..699a7cd --- /dev/null +++ b/include/boost/range/algorithm/remove.hpp @@ -0,0 +1,74 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_REMOVE_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_REMOVE_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function remove +/// +/// range-based version of the remove std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +template< class ForwardRange, class Value > +inline BOOST_DEDUCED_TYPENAME range_iterator::type +remove(ForwardRange& rng, const Value& val) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::remove(boost::begin(rng),boost::end(rng),val); +} + +/// \overload +template< class ForwardRange, class Value > +inline BOOST_DEDUCED_TYPENAME range_iterator::type +remove(const ForwardRange& rng, const Value& val) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::remove(boost::begin(rng),boost::end(rng),val); +} + +// range_return overloads + +/// \overload +template< range_return_value re, class ForwardRange, class Value > +inline BOOST_DEDUCED_TYPENAME range_return::type +remove(ForwardRange& rng, const Value& val) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return::pack( + std::remove(boost::begin(rng), boost::end(rng), val), + rng); +} + +/// \overload +template< range_return_value re, class ForwardRange, class Value > +inline BOOST_DEDUCED_TYPENAME range_return::type +remove(const ForwardRange& rng, const Value& val) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return::pack( + std::remove(boost::begin(rng), boost::end(rng), val), + rng); +} + + } // namespace range + using range::remove; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/remove_copy.hpp b/include/boost/range/algorithm/remove_copy.hpp new file mode 100755 index 0000000..0d3d83d --- /dev/null +++ b/include/boost/range/algorithm/remove_copy.hpp @@ -0,0 +1,44 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_REMOVE_COPY_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_REMOVE_COPY_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function remove_copy +/// +/// range-based version of the remove_copy std algorithm +/// +/// \pre SinglePassRange is a model of the SinglePassRangeConcept +/// \pre OutputIterator is a model of the OutputIteratorConcept +/// \pre Value is a model of the EqualityComparableConcept +/// \pre Objects of type Value can be compared for equality with objects of +/// InputIterator's value type. +template< class SinglePassRange, class OutputIterator, class Value > +inline OutputIterator +remove_copy(SinglePassRange& rng, OutputIterator out_it, const Value& val) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::remove_copy(boost::begin(rng), boost::end(rng), out_it, val); +} + + } // namespace range + using range::remove_copy; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/remove_copy_if.hpp b/include/boost/range/algorithm/remove_copy_if.hpp new file mode 100755 index 0000000..665b359 --- /dev/null +++ b/include/boost/range/algorithm/remove_copy_if.hpp @@ -0,0 +1,38 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_REMOVE_COPY_IF_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_REMOVE_COPY_IF_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + /// \brief template function remove_copy_if + /// + /// range-based version of the remove_copy_if std algorithm + /// + /// \pre SinglePassRange is a model of the SinglePassRangeConcept + /// \pre OutputIterator is a model of the OutputIteratorConcept + /// \pre Predicate is a model of the PredicateConcept + /// \pre InputIterator's value type is convertible to Predicate's argument type + /// \pre out_it is not an iterator in the range rng + template< class SinglePassRange, class OutputIterator, class Predicate > + inline OutputIterator + remove_copy_if(SinglePassRange& rng, OutputIterator out_it, Predicate pred) + { + boost::function_requires< SinglePassRangeConcept >(); + return std::remove_copy_if(boost::begin(rng), boost::end(rng), out_it, pred); + } +} + +#endif // include guard diff --git a/include/boost/range/algorithm/remove_if.hpp b/include/boost/range/algorithm/remove_if.hpp new file mode 100755 index 0000000..babcddc --- /dev/null +++ b/include/boost/range/algorithm/remove_if.hpp @@ -0,0 +1,75 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_REMOVE_IF_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_REMOVE_IF_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function remove_if +/// +/// range-based version of the remove_if std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +/// \pre UnaryPredicate is a model of the UnaryPredicateConcept +template< class ForwardRange, class UnaryPredicate > +inline BOOST_DEDUCED_TYPENAME boost::range_iterator::type +remove_if(ForwardRange& rng, UnaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::remove_if(boost::begin(rng), boost::end(rng), pred); +} + +/// \overload +template< class ForwardRange, class UnaryPredicate > +inline BOOST_DEDUCED_TYPENAME boost::range_iterator::type +remove_if(const ForwardRange& rng, UnaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::remove_if(boost::begin(rng),boost::end(rng),pred); +} + +// range_return overloads + +/// \overload +template< range_return_value re, class ForwardRange, class UnaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_return::type +remove_if(ForwardRange& rng, UnaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return::pack( + std::remove_if(boost::begin(rng), boost::end(rng), pred), + rng); +} + +/// \overload +template< range_return_value re, class ForwardRange, class UnaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_return::type +remove_if(const ForwardRange& rng, UnaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return::pack( + std::remove_if(boost::begin(rng), boost::end(rng), pred), + rng); +} + + } // namespace range + using range::remove_if; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/replace.hpp b/include/boost/range/algorithm/replace.hpp new file mode 100755 index 0000000..44d3e4c --- /dev/null +++ b/include/boost/range/algorithm/replace.hpp @@ -0,0 +1,53 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_REPLACE_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_REPLACE_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function replace +/// +/// range-based version of the replace std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +template< class ForwardRange, class Value > +inline ForwardRange& +replace(ForwardRange& rng, const Value& what, + const Value& with_what) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + std::replace(boost::begin(rng), boost::end(rng), what, with_what); + return rng; +} + +/// \overload +template< class ForwardRange, class Value > +inline const ForwardRange& +replace(const ForwardRange& rng, const Value& what, + const Value& with_what) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + std::replace(boost::begin(rng), boost::end(rng), what, with_what); + return rng; +} + + } // namespace range + using range::replace; +} // namespace boost; + +#endif // include guard diff --git a/include/boost/range/algorithm/replace_copy.hpp b/include/boost/range/algorithm/replace_copy.hpp new file mode 100755 index 0000000..36c91ce --- /dev/null +++ b/include/boost/range/algorithm/replace_copy.hpp @@ -0,0 +1,42 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_REPLACE_COPY_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_REPLACE_COPY_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function replace_copy +/// +/// range-based version of the replace_copy std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +template< class ForwardRange, class OutputIterator, class Value > +inline OutputIterator +replace_copy(ForwardRange& rng, OutputIterator out_it, const Value& what, + const Value& with_what) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::replace_copy(boost::begin(rng), boost::end(rng), out_it, + what, with_what); +} + + } // namespace range + using range::replace_copy; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/replace_copy_if.hpp b/include/boost/range/algorithm/replace_copy_if.hpp new file mode 100755 index 0000000..5d4bfb6 --- /dev/null +++ b/include/boost/range/algorithm/replace_copy_if.hpp @@ -0,0 +1,46 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_REPLACE_COPY_IF_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_REPLACE_COPY_IF_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function replace_copy_if +/// +/// range-based version of the replace_copy_if std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +/// \pre Predicate is a model of the PredicateConcept +/// \pre Value is convertible to Predicate's argument type +/// \pre Value is Assignable +/// \pre Value is convertible to a type in OutputIterator's set of value types. +template< class ForwardRange, class OutputIterator, class Predicate, class Value > +inline OutputIterator +replace_copy_if(ForwardRange& rng, OutputIterator out_it, Predicate pred, + const Value& with_what) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::replace_copy_if(boost::begin(rng), boost::end(rng), out_it, + pred, with_what); +} + + } // namespace range + using range::replace_copy_if; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/replace_if.hpp b/include/boost/range/algorithm/replace_if.hpp new file mode 100755 index 0000000..93d5a1f --- /dev/null +++ b/include/boost/range/algorithm/replace_if.hpp @@ -0,0 +1,54 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_REPLACE_IF_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_REPLACE_IF_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function replace_if +/// +/// range-based version of the replace_if std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +/// \pre UnaryPredicate is a model of the UnaryPredicateConcept +template< class ForwardRange, class UnaryPredicate, class Value > +inline ForwardRange& + replace_if(ForwardRange& rng, UnaryPredicate pred, + const Value& val) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + std::replace_if(boost::begin(rng), boost::end(rng), pred, val); + return rng; +} + +/// \overload +template< class ForwardRange, class UnaryPredicate, class Value > +inline const ForwardRange& + replace_if(const ForwardRange& rng, UnaryPredicate pred, + const Value& val) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + std::replace_if(boost::begin(rng), boost::end(rng), pred, val); + return rng; +} + + } // namespace range + using range::replace_if; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/reverse.hpp b/include/boost/range/algorithm/reverse.hpp new file mode 100755 index 0000000..20a7eb1 --- /dev/null +++ b/include/boost/range/algorithm/reverse.hpp @@ -0,0 +1,50 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_REVERSE_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_REVERSE_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function reverse +/// +/// range-based version of the reverse std algorithm +/// +/// \pre BidirectionalRange is a model of the BidirectionalRangeConcept +template +inline BidirectionalRange& reverse(BidirectionalRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + std::reverse(boost::begin(rng), boost::end(rng)); + return rng; +} + +/// \overload +template +inline const BidirectionalRange& reverse(const BidirectionalRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + std::reverse(boost::begin(rng), boost::end(rng)); + return rng; +} + + } // namespace range + using range::reverse; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/reverse_copy.hpp b/include/boost/range/algorithm/reverse_copy.hpp new file mode 100755 index 0000000..381f157 --- /dev/null +++ b/include/boost/range/algorithm/reverse_copy.hpp @@ -0,0 +1,48 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_REVERSE_COPY_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_REVERSE_COPY_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function reverse_copy +/// +/// range-based version of the reverse_copy std algorithm +/// +/// \pre BidirectionalRange is a model of the BidirectionalRangeConcept +template +inline OutputIterator reverse_copy(BidirectionalRange& rng, OutputIterator out) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + return std::reverse_copy(boost::begin(rng), boost::end(rng), out); +} + +/// \overload +template +inline OutputIterator reverse_copy(const BidirectionalRange& rng, OutputIterator out) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + return std::reverse_copy(boost::begin(rng), boost::end(rng), out); +} + + } // namespace range + using range::reverse_copy; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/rotate.hpp b/include/boost/range/algorithm/rotate.hpp new file mode 100755 index 0000000..2372a00 --- /dev/null +++ b/include/boost/range/algorithm/rotate.hpp @@ -0,0 +1,52 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_ROTATE_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_ROTATE_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function rotate +/// +/// range-based version of the rotate std algorithm +/// +/// \pre Rng meets the requirements for a Forward range +template +inline ForwardRange& rotate(ForwardRange& rng, + typename range_iterator::type middle) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + std::rotate(boost::begin(rng), middle, boost::end(rng)); + return rng; +} + +/// \overload +template +inline const ForwardRange& + rotate(const ForwardRange& rng, + typename range_iterator::type middle) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + std::rotate(boost::begin(rng), middle, boost::end(rng)); + return rng; +} + + } // namespace range + using range::rotate; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/rotate_copy.hpp b/include/boost/range/algorithm/rotate_copy.hpp new file mode 100755 index 0000000..9030f73 --- /dev/null +++ b/include/boost/range/algorithm/rotate_copy.hpp @@ -0,0 +1,44 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_ROTATE_COPY_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_ROTATE_COPY_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + + /// \brief template function rotate + /// + /// range-based version of the rotate std algorithm + /// + /// \pre Rng meets the requirements for a Forward range + template + inline OutputIterator rotate_copy( + const ForwardRange& rng, + typename range_iterator::type middle, + OutputIterator target + ) + { + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::rotate_copy(boost::begin(rng), middle, boost::end(rng), target); + } + + } // namespace range + using range::rotate_copy; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/search.hpp b/include/boost/range/algorithm/search.hpp new file mode 100755 index 0000000..45d7ade --- /dev/null +++ b/include/boost/range/algorithm/search.hpp @@ -0,0 +1,136 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_SEARCH_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_SEARCH_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function search +/// +/// range-based version of the search std algorithm +/// +/// \pre ForwardRange1 is a model of the ForwardRangeConcept +/// \pre ForwardRange2 is a model of the ForwardRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template< class ForwardRange1, class ForwardRange2 > +inline BOOST_DEDUCED_TYPENAME range_iterator::type +search(ForwardRange1& rng1, const ForwardRange2& rng2) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::search(boost::begin(rng1),boost::end(rng1), + boost::begin(rng2),boost::end(rng2)); +} + +/// \overload +template< class ForwardRange1, class ForwardRange2 > +inline BOOST_DEDUCED_TYPENAME range_iterator::type +search(const ForwardRange1& rng1, const ForwardRange2& rng2) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::search(boost::begin(rng1),boost::end(rng1), + boost::begin(rng2),boost::end(rng2)); +} + +/// \overload +template< class ForwardRange1, class ForwardRange2, class BinaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_iterator::type +search(ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::search(boost::begin(rng1),boost::end(rng1), + boost::begin(rng2),boost::end(rng2),pred); +} + +/// \overload +template< class ForwardRange1, class ForwardRange2, class BinaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_iterator::type +search(const ForwardRange1& rng1, const ForwardRange2& rng2, + BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::search(boost::begin(rng1),boost::end(rng1), + boost::begin(rng2),boost::end(rng2),pred); +} + +// range_return overloads + +/// \overload +template< range_return_value re, class ForwardRange1, class ForwardRange2 > +inline BOOST_DEDUCED_TYPENAME range_return::type +search(ForwardRange1& rng1, const ForwardRange2& rng2) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return:: + pack(std::search(boost::begin(rng1),boost::end(rng1), + boost::begin(rng2),boost::end(rng2)), + rng1); +} + +/// \overload +template< range_return_value re, class ForwardRange1, class ForwardRange2 > +inline BOOST_DEDUCED_TYPENAME range_return::type +search(const ForwardRange1& rng1, const ForwardRange2& rng2) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return:: + pack(std::search(boost::begin(rng1),boost::end(rng1), + boost::begin(rng2),boost::end(rng2)), + rng1); +} + +/// \overload +template< range_return_value re, class ForwardRange1, class ForwardRange2, + class BinaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_return::type +search(ForwardRange1& rng1, const ForwardRange2& rng2, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return:: + pack(std::search(boost::begin(rng1),boost::end(rng1), + boost::begin(rng2),boost::end(rng2),pred), + rng1); +} + +/// \overload +template< range_return_value re, class ForwardRange1, class ForwardRange2, + class BinaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_return::type +search(const ForwardRange1& rng1, const ForwardRange2& rng2, + BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return:: + pack(std::search(boost::begin(rng1),boost::end(rng1), + boost::begin(rng2),boost::end(rng2),pred), + rng1); +} + + } // namespace range + using range::search; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/search_n.hpp b/include/boost/range/algorithm/search_n.hpp new file mode 100755 index 0000000..cd0340b --- /dev/null +++ b/include/boost/range/algorithm/search_n.hpp @@ -0,0 +1,145 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_SEARCH_N_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_SEARCH_N_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function search +/// +/// range-based version of the search std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +/// \pre Integer is an integral type +/// \pre Value is a model of the EqualityComparableConcept +/// \pre ForwardRange's value type is a model of the EqualityComparableConcept +/// \pre Object's of ForwardRange's value type can be compared for equality with Objects of type Value +template< typename ForwardRange, typename Integer, typename Value > +inline typename range_iterator::type +search_n(ForwardRange& rng, Integer count, const Value& value) +{ + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + return std::search_n(boost::begin(rng),boost::end(rng), count, value); +} + +/// \overload +template< typename ForwardRange, typename Integer, typename Value > +inline typename range_iterator::type +search_n(const ForwardRange& rng, Integer count, const Value& value) +{ + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + return std::search_n(boost::begin(rng), boost::end(rng), count, value); +} + +/// \overload +template< typename ForwardRange, typename Integer, class Value, + typename BinaryPredicate > +inline typename range_iterator::type +search_n(ForwardRange& rng, Integer count, const Value& value, + BinaryPredicate binary_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + BOOST_RANGE_CONCEPT_ASSERT((BinaryPredicateConcept::type, const Value&>)); + return std::search_n(boost::begin(rng), boost::end(rng), + count, value, binary_pred); +} + +/// \overload +template< typename ForwardRange, typename Integer, typename Value, + typename BinaryPredicate > +inline typename range_iterator::type +search_n(const ForwardRange& rng, Integer count, const Value& value, + BinaryPredicate binary_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + BOOST_RANGE_CONCEPT_ASSERT((BinaryPredicateConcept::type, const Value&>)); + return std::search_n(boost::begin(rng), boost::end(rng), + count, value, binary_pred); +} + +// range_return overloads + +/// \overload +template< range_return_value re, typename ForwardRange, typename Integer, + typename Value > +inline typename range_return::type +search_n(ForwardRange& rng, Integer count, const Value& value) +{ + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + return range_return:: + pack(std::search_n(boost::begin(rng),boost::end(rng), + count, value), + rng); +} + +/// \overload +template< range_return_value re, typename ForwardRange, typename Integer, + class Value > +inline typename range_return::type +search_n(const ForwardRange& rng, Integer count, const Value& value) +{ + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + return range_return:: + pack(std::search_n(boost::begin(rng), boost::end(rng), + count, value), + rng); +} + +/// \overload +template< range_return_value re, typename ForwardRange, typename Integer, + typename Value, typename BinaryPredicate > +inline typename range_return::type +search_n(ForwardRange& rng, Integer count, const Value& value, + BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + BOOST_RANGE_CONCEPT_ASSERT((BinaryPredicateConcept::type, + const Value&>)); + return range_return:: + pack(std::search_n(boost::begin(rng), boost::end(rng), + count, value, pred), + rng); +} + +/// \overload +template< range_return_value re, typename ForwardRange, typename Integer, + typename Value, typename BinaryPredicate > +inline typename range_return::type +search_n(const ForwardRange& rng, Integer count, const Value& value, + BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept)); + BOOST_RANGE_CONCEPT_ASSERT((BinaryPredicateConcept::type, + const Value&>)); + return range_return:: + pack(std::search_n(boost::begin(rng), boost::end(rng), + count, value, pred), + rng); +} + + } // namespace range + using range::search_n; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/set_algorithm.hpp b/include/boost/range/algorithm/set_algorithm.hpp new file mode 100755 index 0000000..82ef8ec --- /dev/null +++ b/include/boost/range/algorithm/set_algorithm.hpp @@ -0,0 +1,198 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_SET_ALGORITHM_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_SET_ALGORITHM_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function includes +/// +/// range-based version of the includes std algorithm +/// +/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept +/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template +inline bool includes(const SinglePassRange1& rng1, + const SinglePassRange2& rng2) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::includes(boost::begin(rng1),boost::end(rng1), + boost::begin(rng2),boost::end(rng2)); +} + +/// \overload +template +inline bool includes(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::includes(boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), pred); +} + +/// \brief template function set_union +/// +/// range-based version of the set_union std algorithm +/// +/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept +/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template +inline OutputIterator set_union(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::set_union(boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), out); +} + +/// \overload +template +inline OutputIterator set_union(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out, + BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::set_union(boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), out, pred); +} + +/// \brief template function set_intersection +/// +/// range-based version of the set_intersection std algorithm +/// +/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept +/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template +inline OutputIterator set_intersection(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::set_intersection(boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), out); +} + +/// \overload +template +inline OutputIterator set_intersection(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out, + BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::set_intersection(boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), + out, pred); +} + +/// \brief template function set_difference +/// +/// range-based version of the set_difference std algorithm +/// +/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept +/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template +inline OutputIterator set_difference(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::set_difference(boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), out); +} + +/// \overload +template +inline OutputIterator set_difference(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out, + BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::set_difference( + boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), out, pred); +} + +/// \brief template function set_symmetric_difference +/// +/// range-based version of the set_symmetric_difference std algorithm +/// +/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept +/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template +inline OutputIterator +set_symmetric_difference(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::set_symmetric_difference(boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), out); +} + +/// \overload +template +inline OutputIterator +set_symmetric_difference(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out, + BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::set_symmetric_difference( + boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), out, pred); +} + + } // namespace range + using range::includes; + using range::set_union; + using range::set_intersection; + using range::set_difference; + using range::set_symmetric_difference; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/sort.hpp b/include/boost/range/algorithm/sort.hpp new file mode 100755 index 0000000..a160907 --- /dev/null +++ b/include/boost/range/algorithm/sort.hpp @@ -0,0 +1,68 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_SORT_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_SORT_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function sort +/// +/// range-based version of the sort std algorithm +/// +/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template +inline RandomAccessRange& sort(RandomAccessRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::sort(boost::begin(rng), boost::end(rng)); + return rng; +} + +/// \overload +template +inline const RandomAccessRange& sort(const RandomAccessRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::sort(boost::begin(rng),boost::end(rng)); + return rng; +} + +/// \overload +template +inline RandomAccessRange& sort(RandomAccessRange& rng, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::sort(boost::begin(rng), boost::end(rng), pred); + return rng; +} + +/// \overload +template +inline const RandomAccessRange& sort(const RandomAccessRange& rng, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::sort(boost::begin(rng), boost::end(rng), pred); + return rng; +} + + } // namespace range + using range::sort; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/stable_partition.hpp b/include/boost/range/algorithm/stable_partition.hpp new file mode 100755 index 0000000..24febfc --- /dev/null +++ b/include/boost/range/algorithm/stable_partition.hpp @@ -0,0 +1,73 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_STABLE_PARTITION_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_STABLE_PARTITION_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function stable_partition +/// +/// range-based version of the stable_partition std algorithm +/// +/// \pre BidirectionalRange is a model of the BidirectionalRangeConcept +/// \pre UnaryPredicate is a model of the UnaryPredicateConcept +template +inline BOOST_DEDUCED_TYPENAME range_iterator::type +stable_partition(BidirectionalRange& rng, UnaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + return std::stable_partition(boost::begin(rng), boost::end(rng), pred); +} + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_iterator::type +stable_partition(const BidirectionalRange& rng, UnaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + return std::stable_partition(boost::begin(rng),boost::end(rng),pred); +} + +// range_return overloads +template +inline BOOST_DEDUCED_TYPENAME range_return::type +stable_partition(BidirectionalRange& rng, UnaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + return range_return::pack( + std::stable_partition(boost::begin(rng), boost::end(rng), pred), + rng); +} + +/// \overload +template +inline BOOST_DEDUCED_TYPENAME range_return::type +stable_partition(const BidirectionalRange& rng, UnaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept )); + return range_return::pack( + std::stable_partition(boost::begin(rng),boost::end(rng),pred), + rng); +} + + } // namespace range + using range::stable_partition; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/stable_sort.hpp b/include/boost/range/algorithm/stable_sort.hpp new file mode 100755 index 0000000..d18da4d --- /dev/null +++ b/include/boost/range/algorithm/stable_sort.hpp @@ -0,0 +1,68 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_STABLE_SORT_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_STABLE_SORT_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function stable_sort +/// +/// range-based version of the stable_sort std algorithm +/// +/// \pre RandomAccessRange is a model of the RandomAccessRangeConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template +inline RandomAccessRange& stable_sort(RandomAccessRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::stable_sort(boost::begin(rng), boost::end(rng)); + return rng; +} + +/// \overload +template +inline const RandomAccessRange& stable_sort(const RandomAccessRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::stable_sort(boost::begin(rng), boost::end(rng)); + return rng; +} + +/// \overload +template +inline RandomAccessRange& stable_sort(RandomAccessRange& rng, BinaryPredicate sort_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::stable_sort(boost::begin(rng), boost::end(rng), sort_pred); + return rng; +} + +/// \overload +template +inline const RandomAccessRange& stable_sort(const RandomAccessRange& rng, BinaryPredicate sort_pred) +{ + BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept )); + std::stable_sort(boost::begin(rng), boost::end(rng), sort_pred); + return rng; +} + + } // namespace range + using range::stable_sort; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/swap_ranges.hpp b/include/boost/range/algorithm/swap_ranges.hpp new file mode 100755 index 0000000..1acee0d --- /dev/null +++ b/include/boost/range/algorithm/swap_ranges.hpp @@ -0,0 +1,87 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_SWAP_RANGES_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_SWAP_RANGES_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range_detail + { + template + void swap_ranges_impl(Iterator1 it1, Iterator1 last1, + Iterator2 it2, Iterator2 last2, + single_pass_traversal_tag, + single_pass_traversal_tag) + { + ignore_unused_variable_warning(last2); + for (; it1 != last1; ++it1, ++it2) + { + BOOST_ASSERT( it2 != last2 ); + std::iter_swap(it1, it2); + } + } + + template + void swap_ranges_impl(Iterator1 it1, Iterator1 last1, + Iterator2 it2, Iterator2 last2, + random_access_traversal_tag, + random_access_traversal_tag) + { + ignore_unused_variable_warning(last2); + BOOST_ASSERT( last2 - it2 >= last1 - it1 ); + std::swap_ranges(it1, last1, it2); + } + + template + void swap_ranges_impl(Iterator1 first1, Iterator1 last1, + Iterator2 first2, Iterator2 last2) + { + swap_ranges_impl(first1, last1, first2, last2, + typename iterator_traversal::type(), + typename iterator_traversal::type()); + } + } // namespace range_detail + + namespace range + { + +/// \brief template function swap_ranges +/// +/// range-based version of the swap_ranges std algorithm +/// +/// \pre SinglePassRange1 is a model of the SinglePassRangeConcept +/// \pre SinglePassRange2 is a model of the SinglePassRangeConcept +template< typename SinglePassRange1, typename SinglePassRange2 > +inline SinglePassRange2& +swap_ranges(SinglePassRange1& range1, SinglePassRange2& range2) +{ + BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept)); + BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept)); + + boost::range_detail::swap_ranges_impl( + boost::begin(range1), boost::end(range1), + boost::begin(range2), boost::end(range2)); + + return range2; +} + + } // namespace range + using range::swap_ranges; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/transform.hpp b/include/boost/range/algorithm/transform.hpp new file mode 100755 index 0000000..28f423d --- /dev/null +++ b/include/boost/range/algorithm/transform.hpp @@ -0,0 +1,97 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_TRANSFORM_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_TRANSFORM_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + + /// \brief template function transform + /// + /// range-based version of the transform std algorithm + /// + /// \pre SinglePassRange1 is a model of the SinglePassRangeConcept + /// \pre SinglePassRange2 is a model of the SinglePassRangeConcept + /// \pre OutputIterator is a model of the OutputIteratorConcept + /// \pre UnaryOperation is a model of the UnaryFunctionConcept + /// \pre BinaryOperation is a model of the BinaryFunctionConcept + template< class SinglePassRange1, + class OutputIterator, + class UnaryOperation > + inline OutputIterator + transform(const SinglePassRange1& rng, + OutputIterator out, + UnaryOperation fun) + { + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::transform(boost::begin(rng),boost::end(rng),out,fun); + } + + } // namespace range + + namespace range_detail + { + template< class SinglePassTraversalReadableIterator1, + class SinglePassTraversalReadableIterator2, + class OutputIterator, + class BinaryFunction > + inline OutputIterator + transform_impl(SinglePassTraversalReadableIterator1 first1, + SinglePassTraversalReadableIterator1 last1, + SinglePassTraversalReadableIterator2 first2, + SinglePassTraversalReadableIterator2 last2, + OutputIterator out, + BinaryFunction fn) + { + for (; first1 != last1; ++first1, ++first2) + { + BOOST_ASSERT( first2 != last2 ); + *out = fn(*first1, *first2); + ++out; + } + return out; + } + } + + namespace range + { + + /// \overload + template< class SinglePassRange1, + class SinglePassRange2, + class OutputIterator, + class BinaryOperation > + inline OutputIterator + transform(const SinglePassRange1& rng1, + const SinglePassRange2& rng2, + OutputIterator out, + BinaryOperation fun) + { + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return range_detail::transform_impl( + boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), + out, fun); + } + + } // namespace range + using range::transform; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/unique.hpp b/include/boost/range/algorithm/unique.hpp new file mode 100755 index 0000000..be6eaf9 --- /dev/null +++ b/include/boost/range/algorithm/unique.hpp @@ -0,0 +1,107 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_UNIQUE_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_UNIQUE_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function unique +/// +/// range-based version of the unique std algorithm +/// +/// \pre Rng meets the requirements for a Forward range +template< range_return_value re, class ForwardRange > +inline BOOST_DEDUCED_TYPENAME range_return::type +unique( ForwardRange& rng ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return:: + pack( std::unique( boost::begin(rng), + boost::end(rng)), rng ); +} + +/// \overload +template< range_return_value re, class ForwardRange > +inline BOOST_DEDUCED_TYPENAME range_return::type +unique( const ForwardRange& rng ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return:: + pack( std::unique( boost::begin(rng), + boost::end(rng)), rng ); +} +/// \overload +template< range_return_value re, class ForwardRange, class BinaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_return::type +unique( ForwardRange& rng, BinaryPredicate pred ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return:: + pack(std::unique(boost::begin(rng), boost::end(rng), pred), + rng); +} +/// \overload +template< range_return_value re, class ForwardRange, class BinaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_return::type +unique( const ForwardRange& rng, BinaryPredicate pred ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return:: + pack(std::unique(boost::begin(rng), boost::end(rng), pred), + rng); +} + +/// \overload +template< class ForwardRange > +inline BOOST_DEDUCED_TYPENAME range_return::type +unique( ForwardRange& rng ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return ::boost::range::unique(rng); +} +/// \overload +template< class ForwardRange > +inline BOOST_DEDUCED_TYPENAME range_return::type +unique( const ForwardRange& rng ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return ::boost::range::unique(rng); +} +/// \overload +template< class ForwardRange, class BinaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_return::type +unique( ForwardRange& rng, BinaryPredicate pred ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return ::boost::range::unique(rng); +} +/// \overload +template< class ForwardRange, class BinaryPredicate > +inline BOOST_DEDUCED_TYPENAME range_iterator::type +unique( const ForwardRange& rng, BinaryPredicate pred ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return ::boost::range::unique(rng, pred); +} + + } // namespace range + using range::unique; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/unique_copy.hpp b/include/boost/range/algorithm/unique_copy.hpp new file mode 100755 index 0000000..0682d74 --- /dev/null +++ b/include/boost/range/algorithm/unique_copy.hpp @@ -0,0 +1,51 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_UNIQUE_COPY_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_UNIQUE_COPY_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function unique_copy +/// +/// range-based version of the unique_copy std algorithm +/// +/// \pre SinglePassRange is a model of the SinglePassRangeConcept +/// \pre OutputIterator is a model of the OutputIteratorConcept +/// \pre BinaryPredicate is a model of the BinaryPredicateConcept +template< class SinglePassRange, class OutputIterator > +inline OutputIterator +unique_copy( const SinglePassRange& rng, OutputIterator out_it ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::unique_copy(boost::begin(rng), boost::end(rng), out_it); +} +/// \overload +template< class SinglePassRange, class OutputIterator, class BinaryPredicate > +inline OutputIterator +unique_copy( const SinglePassRange& rng, OutputIterator out_it, + BinaryPredicate pred ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + return std::unique_copy(boost::begin(rng), boost::end(rng), out_it, pred); +} + + } // namespace range + using range::unique_copy; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm/upper_bound.hpp b/include/boost/range/algorithm/upper_bound.hpp new file mode 100755 index 0000000..8aa26bd --- /dev/null +++ b/include/boost/range/algorithm/upper_bound.hpp @@ -0,0 +1,71 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_UPPER_BOUND_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_UPPER_BOUND_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function upper_bound +/// +/// range-based version of the upper_bound std algorithm +/// +/// \pre ForwardRange is a model of the ForwardRangeConcept +template< class ForwardRange, class Value > +inline BOOST_DEDUCED_TYPENAME range_iterator::type +upper_bound( ForwardRange& rng, Value val ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::upper_bound(boost::begin(rng), boost::end(rng), val); +} +/// \overload +/// \overload +template< class ForwardRange, class Value, class SortPredicate > +inline BOOST_DEDUCED_TYPENAME range_iterator::type +upper_bound( ForwardRange& rng, Value val, SortPredicate pred ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return std::upper_bound(boost::begin(rng), boost::end(rng), val, pred); +} +/// \overload +template< range_return_value re, class ForwardRange, class Value > +inline BOOST_DEDUCED_TYPENAME range_return::type +upper_bound( ForwardRange& rng, Value val ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return:: + pack(std::upper_bound(boost::begin(rng), boost::end(rng), val), + rng); +} +/// \overload +template< range_return_value re, class ForwardRange, class Value, + class SortPredicate > +inline BOOST_DEDUCED_TYPENAME range_return::type +upper_bound( ForwardRange& rng, Value val, SortPredicate pred ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + return range_return:: + pack(std::upper_bound(boost::begin(rng), boost::end(rng), val, pred), + rng); +} + + } // namespace range + using range::upper_bound; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm_ext.hpp b/include/boost/range/algorithm_ext.hpp new file mode 100755 index 0000000..783d38a --- /dev/null +++ b/include/boost/range/algorithm_ext.hpp @@ -0,0 +1,28 @@ +// Boost.Range library +// +// Copyright Neil Groves 2007. 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) +// +// Copyright Thorsten Ottosen 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) +// +// For more information, see http://www.boost.org/libs/range/ +// +#ifndef BOOST_RANGE_ALGORITHM_EXT_HPP +#define BOOST_RANGE_ALGORITHM_EXT_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif diff --git a/include/boost/range/algorithm_ext/copy_n.hpp b/include/boost/range/algorithm_ext/copy_n.hpp new file mode 100755 index 0000000..ba7ad1c --- /dev/null +++ b/include/boost/range/algorithm_ext/copy_n.hpp @@ -0,0 +1,53 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_COPY_N_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_COPY_N_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +/// \brief template function copy +/// +/// range-based version of the copy std algorithm +/// +/// \pre SinglePassRange is a model of the SinglePassRangeConcept +/// \pre OutputIterator is a model of the OutputIteratorConcept +/// \pre 0 <= n < distance(rng) +template< class SinglePassRange, class Size, class OutputIterator > +inline OutputIterator copy_n(const SinglePassRange& rng, Size n, OutputIterator out) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_ASSERT( n < static_cast(boost::distance(rng)) ); + BOOST_ASSERT( n >= static_cast(0) ); + + BOOST_DEDUCED_TYPENAME range_iterator::type source = boost::begin(rng); + + for (Size i = 0; i < n; ++i, ++out, ++source) + *out = *source; + + return out; +} + + } // namespace range + using range::copy_n; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm_ext/erase.hpp b/include/boost/range/algorithm_ext/erase.hpp new file mode 100755 index 0000000..3b0e037 --- /dev/null +++ b/include/boost/range/algorithm_ext/erase.hpp @@ -0,0 +1,58 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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_ALGORITHM_EXT_ERASE_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_EXT_ERASE_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +template< class Container > +inline void erase( Container& on, + iterator_range to_erase ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + on.erase( boost::begin(to_erase), boost::end(to_erase) ); +} + +template< class Container, class T > +inline void remove_erase( Container& on, const T& val ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + on.erase( + std::remove(boost::begin(on), boost::end(on), val), + boost::end(on)); +} + +template< class Container, class Pred > +inline void remove_erase_if( Container& on, Pred pred ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + on.erase( + std::remove_if(boost::begin(on), boost::end(on), pred), + boost::end(on)); +} + + } // namespace range + using range::erase; + using range::remove_erase; + using range::remove_erase_if; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm_ext/for_each.hpp b/include/boost/range/algorithm_ext/for_each.hpp new file mode 100755 index 0000000..6a3b35c --- /dev/null +++ b/include/boost/range/algorithm_ext/for_each.hpp @@ -0,0 +1,86 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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_ALGORITHM_EXT_FOR_EACH_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_EXT_FOR_EACH_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range_detail + { + template + inline Fn2 for_each_impl(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, + Fn2 fn) + { + for (; first1 != last1 && first2 != last2; ++first1, ++first2) + { + fn(*first1, *first2); + } + return fn; + } + } + + namespace range + { + template + inline Fn2 for_each(const SinglePassRange1& rng1, const SinglePassRange2& rng2, Fn2 fn) + { + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + return ::boost::range_detail::for_each_impl( + ::boost::begin(rng1), ::boost::end(rng1), + ::boost::begin(rng2), ::boost::end(rng2), fn); + } + + template + inline Fn2 for_each(const SinglePassRange1& rng1, SinglePassRange2& rng2, Fn2 fn) + { + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + return ::boost::range_detail::for_each_impl( + ::boost::begin(rng1), ::boost::end(rng1), + ::boost::begin(rng2), ::boost::end(rng2), fn); + } + + template + inline Fn2 for_each(SinglePassRange1& rng1, const SinglePassRange2& rng2, Fn2 fn) + { + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + return ::boost::range_detail::for_each_impl( + ::boost::begin(rng1), ::boost::end(rng1), + ::boost::begin(rng2), ::boost::end(rng2), fn); + } + + template + inline Fn2 for_each(SinglePassRange1& rng1, SinglePassRange2& rng2, Fn2 fn) + { + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + return ::boost::range_detail::for_each_impl( + ::boost::begin(rng1), ::boost::end(rng1), + ::boost::begin(rng2), ::boost::end(rng2), fn); + } + } // namespace range + using range::for_each; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm_ext/insert.hpp b/include/boost/range/algorithm_ext/insert.hpp new file mode 100755 index 0000000..a887f15 --- /dev/null +++ b/include/boost/range/algorithm_ext/insert.hpp @@ -0,0 +1,41 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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_ALGORITHM_EXT_INSERT_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_EXT_INSERT_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +template< class Container, class Range > +inline void insert( Container& on, + BOOST_DEDUCED_TYPENAME Container::iterator before, + const Range& from ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_ASSERT( (void*)&on != (void*)&from && + "cannot copy from a container to itself" ); + on.insert( before, boost::begin(from), boost::end(from) ); +} + + } // namespace range + using range::insert; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm_ext/iota.hpp b/include/boost/range/algorithm_ext/iota.hpp new file mode 100644 index 0000000..4a03a59 --- /dev/null +++ b/include/boost/range/algorithm_ext/iota.hpp @@ -0,0 +1,39 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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_ALGORITHM_EXT_IOTA_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_EXT_IOTA_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +template< class ForwardRange, class Value > +inline void iota( ForwardRange& rng, Value x ) +{ + BOOST_CONCEPT_ASSERT(( ForwardRangeConcept )); + typedef BOOST_DEDUCED_TYPENAME range_iterator::type iterator_t; + + iterator_t last_target = ::boost::end(rng); + for (iterator_t target = ::boost::begin(rng); target != last_target; ++target, ++x) + *target = x; +} + + } // namespace range + using range::iota; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm_ext/is_sorted.hpp b/include/boost/range/algorithm_ext/is_sorted.hpp new file mode 100755 index 0000000..69ead10 --- /dev/null +++ b/include/boost/range/algorithm_ext/is_sorted.hpp @@ -0,0 +1,71 @@ +// Copyright Neil Groves 2009. 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_ALGORITHM_EXT_IS_SORTED_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_EXT_IS_SORTED_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range_detail + { + template + inline bool is_sorted(ForwardIterator first, ForwardIterator last) + { + for (ForwardIterator next = first; first != last && ++next != last; ++first) + if (*next < *first) + return false; + return true; + } + + template + inline bool is_sorted(ForwardIterator first, ForwardIterator last, BinaryPredicate pred) + { + for (ForwardIterator next = first; first != last && ++next != last; ++first) + if (pred(*next, *first)) + return false; + return true; + } + } + + namespace range + { + +/// \brief template function count +/// +/// range-based version of the count std algorithm +/// +/// \pre SinglePassRange is a model of the SinglePassRangeConcept +template +inline bool is_sorted(const SinglePassRange& rng) +{ + BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept)); + BOOST_RANGE_CONCEPT_ASSERT((LessThanComparableConcept::type>)); + return range_detail::is_sorted(boost::begin(rng), boost::end(rng)); +} + +/// \overload +template +inline bool is_sorted(const SinglePassRange& rng, BinaryPredicate pred) +{ + BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept)); + BOOST_RANGE_CONCEPT_ASSERT((BinaryPredicateConcept::type, BOOST_DEDUCED_TYPENAME range_value::type>)); + return range_detail::is_sorted(boost::begin(rng), boost::end(rng), pred); +} + + } // namespace range + using range::is_sorted; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm_ext/overwrite.hpp b/include/boost/range/algorithm_ext/overwrite.hpp new file mode 100755 index 0000000..d2cf4ed --- /dev/null +++ b/include/boost/range/algorithm_ext/overwrite.hpp @@ -0,0 +1,57 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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_ALGORITHM_EXT_OVERWRITE_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_EXT_OVERWRITE_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +template< class SinglePassRange1, class SinglePassRange2 > +inline void overwrite( const SinglePassRange1& from, SinglePassRange2& to ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + BOOST_DEDUCED_TYPENAME range_iterator::type + i = boost::begin(from), e = boost::end(from); + + BOOST_DEDUCED_TYPENAME range_iterator::type + out = boost::begin(to); + +#ifndef NDEBUG + BOOST_DEDUCED_TYPENAME range_iterator::type + last_out = boost::end(to); +#endif + + for( ; i != e; ++out, ++i ) + { +#ifndef NDEBUG + BOOST_ASSERT( out != last_out + && "out of bounds in boost::overwrite()" ); +#endif + *out = *i; + } +} + + } // namespace range + using range::overwrite; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm_ext/push_back.hpp b/include/boost/range/algorithm_ext/push_back.hpp new file mode 100755 index 0000000..e52de41 --- /dev/null +++ b/include/boost/range/algorithm_ext/push_back.hpp @@ -0,0 +1,39 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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_ALGORITHM_EXT_PUSH_BACK_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_EXT_PUSH_BACK_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +template< class Container, class Range > +inline void push_back( Container& on, const Range& from ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_ASSERT( (void*)&on != (void*)&from && + "cannot copy from a container to itself" ); + on.insert( on.end(), boost::begin(from), boost::end(from) ); +} + + } // namespace range + using range::push_back; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/algorithm_ext/push_front.hpp b/include/boost/range/algorithm_ext/push_front.hpp new file mode 100755 index 0000000..6ee269b --- /dev/null +++ b/include/boost/range/algorithm_ext/push_front.hpp @@ -0,0 +1,39 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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_ALGORITHM_EXT_PUSH_FRONT_HPP_INCLUDED +#define BOOST_RANGE_ALGORITHM_EXT_PUSH_FRONT_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range + { + +template< class Container, class Range > +inline void push_front( Container& on, const Range& from ) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_ASSERT( (void*)&on != (void*)&from && + "cannot copy from a container to itself" ); + on.insert( on.begin(), boost::begin(from), boost::end(from) ); +} + + } // namespace range + using range::push_front; +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/as_literal.hpp b/include/boost/range/as_literal.hpp index 2f04ca8..f67ead7 100644 --- a/include/boost/range/as_literal.hpp +++ b/include/boost/range/as_literal.hpp @@ -25,7 +25,7 @@ #include #include -#ifndef BOOST_NO_CWCHAR +#ifndef BOOST_NO_CWCHAR #include #endif @@ -38,41 +38,41 @@ namespace boost return strlen( s ); } -#ifndef BOOST_NO_CWCHAR +#ifndef BOOST_NO_CWCHAR inline std::size_t length( const wchar_t* s ) { return wcslen( s ); } -#endif +#endif // // Remark: the compiler cannot choose between T* and T[sz] // overloads, so we must put the T* internal to the // unconstrained version. - // + // inline bool is_char_ptr( char* ) { return true; } - + inline bool is_char_ptr( const char* ) { return true; } -#ifndef BOOST_NO_CWCHAR +#ifndef BOOST_NO_CWCHAR inline bool is_char_ptr( wchar_t* ) { return true; } - + inline bool is_char_ptr( const wchar_t* ) { return true; } #endif - + template< class T > inline long is_char_ptr( T /* r */ ) { @@ -80,30 +80,30 @@ namespace boost } template< class T > - inline iterator_range + inline iterator_range make_range( T* const r, bool ) { return iterator_range( r, r + length(r) ); } template< class T > - inline iterator_range::type> + inline iterator_range::type> make_range( T& r, long ) { return boost::make_iterator_range( r ); } } - + template< class Range > - inline iterator_range::type> + inline iterator_range::type> as_literal( Range& r ) { return range_detail::make_range( r, range_detail::is_char_ptr(r) ); } template< class Range > - inline iterator_range::type> + inline iterator_range::type> as_literal( const Range& r ) { return range_detail::make_range( r, range_detail::is_char_ptr(r) ); @@ -112,9 +112,9 @@ namespace boost template< class Char, std::size_t sz > inline iterator_range as_literal( Char (&arr)[sz] ) { - return range_detail::make_range( arr, range_detail::is_char_ptr(arr) ); + return range_detail::make_range( arr, range_detail::is_char_ptr(arr) ); } - + template< class Char, std::size_t sz > inline iterator_range as_literal( const Char (&arr)[sz] ) { diff --git a/include/boost/range/combine.hpp b/include/boost/range/combine.hpp new file mode 100755 index 0000000..31a540b --- /dev/null +++ b/include/boost/range/combine.hpp @@ -0,0 +1,310 @@ +#ifndef BOOST_RANGE_COMBINE_HPP +#define BOOST_RANGE_COMBINE_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace detail + { + struct void_ { typedef void_ type; }; + } + + template<> struct range_iterator + { + typedef tuples::null_type type; + }; + + namespace detail + { + inline tuples::null_type range_begin( void_& ) + { return tuples::null_type(); } + + inline tuples::null_type range_end( void_& ) + { return tuples::null_type(); } + + template< class T > + struct tuple_iter + { + typedef typename mpl::eval_if_c< is_same::value, + mpl::identity, + range_iterator >::type + type; + }; + + template< class Rng1, class Rng2 > + struct tuple_range + { + typedef typename mpl::eval_if_c< is_same::value, + void_, + mpl::identity >::type + type; + }; + + template + < + class R1, + class R2, + class R3, + class R4, + class R5, + class R6 + > + struct generate_tuple + { + typedef boost::tuple< typename tuple_iter::type, + typename tuple_iter::type, + typename tuple_iter::type, + typename tuple_iter::type, + typename tuple_iter::type, + typename tuple_iter::type > + type; + + static type begin( R1& r1, R2& r2, R3& r3, R4& r4, R5& r5, R6& r6 ) + { + return make_tuple( boost::begin(r1), + boost::begin(r2), + boost::begin(r3), + boost::begin(r4), + boost::begin(r5), + boost::begin(r6) ); + } + + static type end( R1& r1, R2& r2, R3& r3, R4& r4, R5& r5, R6& r6 ) + { + return make_tuple( boost::end(r1), + boost::end(r2), + boost::end(r3), + boost::end(r4), + boost::end(r5), + boost::end(r6) ); + } + }; + + template + < + class R1, + class R2 = void_, + class R3 = void_, + class R4 = void_, + class R5 = void_, + class R6 = void_ + > + struct zip_rng + : iterator_range< + zip_iterator< typename generate_tuple::type > + > + { + private: + typedef generate_tuple + generator; + typedef typename generator::type + tuple; + typedef zip_iterator + zip_iter; + typedef iterator_range + base; + + public: + zip_rng( R1& r1, R2& r2, R3& r3, R4& r4, R5& r5, R6& r6 ) + : base( zip_iter( generator::begin(r1,r2,r3,r4,r5,r6) ), + zip_iter( generator::end(r1,r2,r3,r4,r5,r6) ) ) + { + BOOST_ASSERT(boost::distance(r1) <= boost::distance(r2)); + BOOST_ASSERT(boost::distance(r1) <= boost::distance(r3)); + BOOST_ASSERT(boost::distance(r1) <= boost::distance(r4)); + BOOST_ASSERT(boost::distance(r1) <= boost::distance(r5)); + BOOST_ASSERT(boost::distance(r1) <= boost::distance(r6)); + } + + template< class Zip, class Rng > + zip_rng( Zip& z, Rng& r ) + : base( zip_iter( generator::begin( z, r ) ), + zip_iter( generator::end( z, r ) ) ) + { + + // @todo: tuple::begin( should be overloaded for this situation + } + + struct tuple_length : tuples::length + { }; + + template< unsigned N > + struct get + { + template< class Z, class R > + static typename tuples::element::type begin( Z& z, R& ) + { + return get( z.begin().get_iterator_tuple() ); + } + + template< class Z, class R > + static typename tuples::element::type end( Z& z, R& r ) + { + return get( z.end().get_iterator_tuple() ); + } + }; + + }; + + template< class Rng1, class Rng2 > + struct zip_range + : iterator_range< + zip_iterator< + tuple< typename range_iterator::type, + typename range_iterator::type > + > > + { + private: + typedef zip_iterator< + tuple< typename range_iterator::type, + typename range_iterator::type > + > + zip_iter; + typedef iterator_range + base; + + public: + zip_range( Rng1& r1, Rng2& r2 ) + : base( zip_iter( make_tuple(boost::begin(r1), + boost::begin(r2)) ), + zip_iter( make_tuple(boost::end(r1), + boost::end(r2)) ) ) + { + BOOST_ASSERT(boost::distance(r1) <= boost::distance(r2)); + } + }; + + template< class Rng1, class Rng2, class Rng3 > + struct zip_range3 + : iterator_range< + zip_iterator< + tuple< typename range_iterator::type, + typename range_iterator::type, + typename range_iterator::type > + > > + { + private: + typedef zip_iterator< + tuple< typename range_iterator::type, + typename range_iterator::type, + typename range_iterator::type > + > + zip_iter; + typedef iterator_range + base; + + public: + zip_range3( Rng1& r1, Rng2& r2, Rng3& r3 ) + : base( zip_iter( make_tuple(boost::begin(r1), + boost::begin(r2), + boost::begin(r3)) ), + zip_iter( make_tuple(boost::end(r1), + boost::end(r2), + boost::end(r3)) ) + ) + { + BOOST_ASSERT(distance(r1) <= distance(r2)); + BOOST_ASSERT(distance(r1) <= distance(r3)); + } + }; + + + struct combine_tag {}; + + template< class Rng > + inline zip_rng + operator&( combine_tag, Rng& r ) + { + return zip_rng(r); + } + + template< class Rng > + inline iterator_range + operator&( combine_tag, const Rng& r ) + { + return iterator_range(r); + } + + template + < + class R1, + class R2, + class R3, + class R4, + class R5, + class Rng + > + inline typename zip_rng::next + operator&( const zip_rng& zip, + Rng& r ) + { + return zip_rng::next( zip, r ); + } + + // + // This one should be able to be made generic + // + // template + // < + // class R1, + // class R2 = void, + // class R3 = void, + // class R4 = void, + // class R5 = void, + // class R6 = void + // > + // inline zip_range::type + // x + // + // + /* + template< class Rng1, class Rng2, class Rng3 > + inline zip_range3 + operator&( const zip_range& r1, const Rng3& r3 ) + { + return zip_range3( + }*/ + + } // namespace 'detail' + + template< class Rng1, class Rng2 > + inline detail::zip_range combine( Rng1& r1, Rng2& r2 ) + { + return detail::zip_range(r1,r2); + } + + template< class Rng1, class Rng2 > + inline detail::zip_range combine( const Rng1& r1, Rng2& r2 ) + { + return detail::zip_range(r1,r2); + } + + template< class Rng1, class Rng2 > + inline detail::zip_range combine( Rng1& r1, const Rng2& r2 ) + { + return detail::zip_range(r1,r2); + } + + template< class Rng1, class Rng2 > + inline detail::zip_range combine( const Rng1& r1, const Rng2& r2 ) + { + return detail::zip_range(r1,r2); + } + + // + // @todo: find a solution that scales better + // instead of adding 6 overloads! + // +} + +#endif diff --git a/include/boost/range/concepts.hpp b/include/boost/range/concepts.hpp old mode 100755 new mode 100644 index 53a88dc..8e4d2cf --- a/include/boost/range/concepts.hpp +++ b/include/boost/range/concepts.hpp @@ -1,5 +1,10 @@ // Boost.Range library concept checks // +// Copyright Neil Groves 2009. Use, modification and distribution +// are 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) +// // Copyright Daniel Walker 2006. Use, modification and distribution // are subject to the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -15,6 +20,9 @@ #include #include #include +#include +#include +#include /*! * \file @@ -29,20 +37,15 @@ * concept. * * \code - * function_requires >(); + * BOOST_CONCEPT_ASSERT((ForwardRangeConcept)); * \endcode * - * An additional concept check is required for the value access - * property of the range. For example to check for a - * ForwardReadableRange, the following code is required. + * A different concept check is required to ensure writeable value + * access. For example to check for a ForwardRange that can be written + * to, the following code is required. * * \code - * function_requires >(); - * function_requires< - * ReadableIteratorConcept< - * typename range_iterator::type - * > - * >(); + * BOOST_CONCEPT_ASSERT((WriteableForwardRangeConcept)); * \endcode * * \see http://www.boost.org/libs/range/doc/range.html for details @@ -55,84 +58,272 @@ namespace boost { - //! Check if a type T models the SinglePassRange range concept. - template - struct SinglePassRangeConcept - { - typedef typename range_iterator::type range_const_iterator; - typedef typename range_iterator::type range_iterator; + namespace range_detail { - void constraints() +#ifndef BOOST_RANGE_ENABLE_CONCEPT_ASSERT + +// List broken compiler versions here: + #ifdef __GNUC__ + // GNUC 4.2 has strange issues correctly detecting compliance with the Concepts + // hence the least disruptive approach is to turn-off the concept checking for + // this version of the compiler. + #if __GNUC__ == 4 && __GNUC_MINOR__ == 2 + #define BOOST_RANGE_ENABLE_CONCEPT_ASSERT 0 + #endif + #endif + + #ifdef __BORLANDC__ + #define BOOST_RANGE_ENABLE_CONCEPT_ASSERT 0 + #endif + + #ifdef __PATHCC__ + #define BOOST_RANGE_ENABLE_CONCEPT_ASSERT 0 + #endif + +// Default to using the concept asserts unless we have defined it off +// during the search for black listed compilers. + #ifndef BOOST_RANGE_ENABLE_CONCEPT_ASSERT + #define BOOST_RANGE_ENABLE_CONCEPT_ASSERT 1 + #endif + +#endif + +#if BOOST_RANGE_ENABLE_CONCEPT_ASSERT + #define BOOST_RANGE_CONCEPT_ASSERT( x ) BOOST_CONCEPT_ASSERT( x ) +#else + #define BOOST_RANGE_CONCEPT_ASSERT( x ) +#endif + + // Rationale for the inclusion of redefined iterator concept + // classes: + // + // The Range algorithms often do not require that the iterators are + // Assignable, but the correct standard conformant iterators + // do require the iterators to be a model of the Assignable concept. + // Iterators that contains a functor that is not assignable therefore + // are not correct models of the standard iterator concepts, + // despite being adequate for most algorithms. An example of this + // use case is the combination of the boost::adaptors::filtered + // class with a boost::lambda::bind generated functor. + // Ultimately modeling the range concepts using composition + // with the Boost.Iterator concepts would render the library + // incompatible with many common Boost.Lambda expressions. + template + struct IncrementableIteratorConcept : CopyConstructible { - function_requires< - boost_concepts::SinglePassIteratorConcept< - range_iterator - > - >(); - i = boost::begin(a); - i = boost::end(a); - const_constraints(a); - } - - void const_constraints(const T& a) +#if BOOST_RANGE_ENABLE_CONCEPT_ASSERT + typedef BOOST_DEDUCED_TYPENAME iterator_traversal::type traversal_category; + + BOOST_RANGE_CONCEPT_ASSERT(( + Convertible< + traversal_category, + incrementable_traversal_tag + >)); + + BOOST_CONCEPT_USAGE(IncrementableIteratorConcept) + { + ++i; + (void)i++; + } + private: + Iterator i; +#endif + }; + + template + struct SinglePassIteratorConcept + : IncrementableIteratorConcept + , EqualityComparable { - ci = boost::begin(a); - ci = boost::end(a); +#if BOOST_RANGE_ENABLE_CONCEPT_ASSERT + BOOST_RANGE_CONCEPT_ASSERT(( + Convertible< + BOOST_DEDUCED_TYPENAME SinglePassIteratorConcept::traversal_category, + single_pass_traversal_tag + >)); +#endif + }; + + template + struct ForwardIteratorConcept + : SinglePassIteratorConcept + , DefaultConstructible + { +#if BOOST_RANGE_ENABLE_CONCEPT_ASSERT + typedef BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits::difference_type difference_type; + + BOOST_MPL_ASSERT((is_integral)); + BOOST_MPL_ASSERT_RELATION(std::numeric_limits::is_signed, ==, true); + + BOOST_RANGE_CONCEPT_ASSERT(( + Convertible< + BOOST_DEDUCED_TYPENAME ForwardIteratorConcept::traversal_category, + forward_traversal_tag + >)); +#endif + }; + + template + struct BidirectionalIteratorConcept + : ForwardIteratorConcept + { + #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT + BOOST_RANGE_CONCEPT_ASSERT(( + Convertible< + BOOST_DEDUCED_TYPENAME BidirectionalIteratorConcept::traversal_category, + bidirectional_traversal_tag + >)); + + BOOST_CONCEPT_USAGE(BidirectionalIteratorConcept) + { + --i; + (void)i--; + } + private: + Iterator i; + #endif + }; + + template + struct RandomAccessIteratorConcept + : BidirectionalIteratorConcept + { + #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT + BOOST_RANGE_CONCEPT_ASSERT(( + Convertible< + BOOST_DEDUCED_TYPENAME RandomAccessIteratorConcept::traversal_category, + random_access_traversal_tag + >)); + + BOOST_CONCEPT_USAGE(RandomAccessIteratorConcept) + { + i += n; + i = i + n; + i = n + i; + i -= n; + i = i - n; + n = i - j; + } + private: + BOOST_DEDUCED_TYPENAME RandomAccessIteratorConcept::difference_type n; + Iterator i; + Iterator j; + #endif + }; + + } // namespace range_detail + + //! Check if a type T models the SinglePassRange range concept. + template + struct SinglePassRangeConcept + { +#if BOOST_RANGE_ENABLE_CONCEPT_ASSERT + typedef BOOST_DEDUCED_TYPENAME range_iterator::type const_iterator; + typedef BOOST_DEDUCED_TYPENAME range_iterator::type iterator; + + BOOST_RANGE_CONCEPT_ASSERT((range_detail::SinglePassIteratorConcept)); + BOOST_RANGE_CONCEPT_ASSERT((range_detail::SinglePassIteratorConcept)); + + BOOST_CONCEPT_USAGE(SinglePassRangeConcept) + { + // This has been modified from assigning to this->i + // (where i was a member variable) to improve + // compatibility with Boost.Lambda + iterator i1 = boost::begin(*m_range); + iterator i2 = boost::end(*m_range); + + ignore_unused_variable_warning(i1); + ignore_unused_variable_warning(i2); + + const_constraints(*m_range); } - T a; - range_iterator i; - range_const_iterator ci; + + private: + void const_constraints(const T& const_range) + { + const_iterator ci1 = boost::begin(const_range); + const_iterator ci2 = boost::end(const_range); + + ignore_unused_variable_warning(ci1); + ignore_unused_variable_warning(ci2); + } + + // Rationale: + // The type of m_range is T* rather than T because it allows + // T to be an abstract class. The other obvious alternative of + // T& produces a warning on some compilers. + T* m_range; +#endif }; //! Check if a type T models the ForwardRange range concept. - template - struct ForwardRangeConcept + template + struct ForwardRangeConcept : SinglePassRangeConcept { - void constraints() +#if BOOST_RANGE_ENABLE_CONCEPT_ASSERT + BOOST_RANGE_CONCEPT_ASSERT((range_detail::ForwardIteratorConcept)); + BOOST_RANGE_CONCEPT_ASSERT((range_detail::ForwardIteratorConcept)); +#endif + }; + + template + struct WriteableRangeConcept + { +#if BOOST_RANGE_ENABLE_CONCEPT_ASSERT + typedef BOOST_DEDUCED_TYPENAME range_iterator::type iterator; + + BOOST_CONCEPT_USAGE(WriteableRangeConcept) { - function_requires< - SinglePassRangeConcept - >(); - function_requires< - boost_concepts::ForwardTraversalConcept< - typename range_iterator::type - > - >(); + *i = v; } + private: + iterator i; + BOOST_DEDUCED_TYPENAME range_value::type v; +#endif + }; + + //! Check if a type T models the WriteableForwardRange range concept. + template + struct WriteableForwardRangeConcept + : ForwardRangeConcept + , WriteableRangeConcept + { }; //! Check if a type T models the BidirectionalRange range concept. - template - struct BidirectionalRangeConcept + template + struct BidirectionalRangeConcept : ForwardRangeConcept + { +#if BOOST_RANGE_ENABLE_CONCEPT_ASSERT + BOOST_RANGE_CONCEPT_ASSERT((BidirectionalIteratorConcept)); + BOOST_RANGE_CONCEPT_ASSERT((BidirectionalIteratorConcept)); +#endif + }; + + //! Check if a type T models the WriteableBidirectionalRange range concept. + template + struct WriteableBidirectionalRangeConcept + : BidirectionalRangeConcept + , WriteableRangeConcept { - void constraints() - { - function_requires< - ForwardRangeConcept - >(); - function_requires< - boost_concepts::BidirectionalTraversalConcept< - typename range_iterator::type - > - >(); - } }; //! Check if a type T models the RandomAccessRange range concept. - template - struct RandomAccessRangeConcept + template + struct RandomAccessRangeConcept : BidirectionalRangeConcept + { +#if BOOST_RANGE_ENABLE_CONCEPT_ASSERT + BOOST_RANGE_CONCEPT_ASSERT((RandomAccessIteratorConcept)); + BOOST_RANGE_CONCEPT_ASSERT((RandomAccessIteratorConcept)); +#endif + }; + + //! Check if a type T models the WriteableRandomAccessRange range concept. + template + struct WriteableRandomAccessRangeConcept + : RandomAccessRangeConcept + , WriteableRangeConcept { - void constraints() - { - function_requires< - BidirectionalRangeConcept - >(); - function_requires< - boost_concepts::RandomAccessTraversalConcept< - typename range_iterator::type - > - >(); - } }; } // namespace boost diff --git a/include/boost/range/const_iterator.hpp b/include/boost/range/const_iterator.hpp old mode 100755 new mode 100644 index 195f9d4..875320f --- a/include/boost/range/const_iterator.hpp +++ b/include/boost/range/const_iterator.hpp @@ -21,6 +21,7 @@ #include #else +#include #include #include #include @@ -31,11 +32,13 @@ namespace boost // default ////////////////////////////////////////////////////////////////////////// + namespace range_detail { + BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( const_iterator ) + } + template< typename C > - struct range_const_iterator - { - typedef BOOST_DEDUCED_TYPENAME C::const_iterator type; - }; + struct range_const_iterator : range_detail::extract_const_iterator + {}; ////////////////////////////////////////////////////////////////////////// // pair diff --git a/include/boost/range/counting_range.hpp b/include/boost/range/counting_range.hpp new file mode 100755 index 0000000..c1ca5ec --- /dev/null +++ b/include/boost/range/counting_range.hpp @@ -0,0 +1,69 @@ +// Boost.Range library +// +// Copyright Neil Groves 2008. Use, modification and +// distribution is subject to the Boost Software Licence, 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_COUNTING_RANGE_HPP_INCLUDED +#define BOOST_RANGE_COUNTING_RANGE_HPP_INCLUDED + +#include +#if BOOST_MSVC >= 1400 +#pragma warning(push) +#pragma warning(disable : 4244) +#endif + +#include +#include +#include +#include + +namespace boost +{ + + template + inline iterator_range > + counting_range(Value first, Value last) + { + typedef counting_iterator counting_iterator_t; + typedef iterator_range result_t; + return result_t(counting_iterator_t(first), + counting_iterator_t(last)); + } + + template + inline iterator_range::type> > + counting_range(const Range& rng) + { + typedef counting_iterator::type> counting_iterator_t; + typedef iterator_range result_t; + return boost::empty(rng) + ? result_t() + : result_t( + counting_iterator_t(*boost::begin(rng)), + counting_iterator_t(*boost::prior(boost::end(rng)))); + } + + template + inline iterator_range::type> > + counting_range(Range& rng) + { + typedef counting_iterator::type> counting_iterator_t; + typedef iterator_range result_t; + return boost::empty(rng) + ? result_t() + : result_t( + counting_iterator_t(*boost::begin(rng)), + counting_iterator_t(*boost::prior(boost::end(rng)))); + } +} // namespace boost + +#if BOOST_MSVC >= 1400 +#pragma warning(pop) +#endif + +#endif // include guard diff --git a/include/boost/range/detail/demote_iterator_traversal_tag.hpp b/include/boost/range/detail/demote_iterator_traversal_tag.hpp new file mode 100755 index 0000000..4351c85 --- /dev/null +++ b/include/boost/range/detail/demote_iterator_traversal_tag.hpp @@ -0,0 +1,79 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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_DETAIL_DEMOTE_ITERATOR_TRAVERSAL_TAG_HPP_INCLUDED +#define BOOST_RANGE_DETAIL_DEMOTE_ITERATOR_TRAVERSAL_TAG_HPP_INCLUDED + +#include + +namespace boost +{ + namespace range_detail + { + +template +struct demote_iterator_traversal_tag +{ +}; + +#define BOOST_DEMOTE_TRAVERSAL_TAG( Tag1, Tag2, ResultTag ) \ +template<> struct demote_iterator_traversal_tag< Tag1 , Tag2 > \ +{ \ + typedef ResultTag type; \ +}; + +BOOST_DEMOTE_TRAVERSAL_TAG( no_traversal_tag, no_traversal_tag, no_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( no_traversal_tag, incrementable_traversal_tag, no_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( no_traversal_tag, single_pass_traversal_tag, no_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( no_traversal_tag, forward_traversal_tag, no_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( no_traversal_tag, bidirectional_traversal_tag, no_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( no_traversal_tag, random_access_traversal_tag, no_traversal_tag ) + +BOOST_DEMOTE_TRAVERSAL_TAG( incrementable_traversal_tag, no_traversal_tag, no_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( incrementable_traversal_tag, incrementable_traversal_tag, incrementable_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( incrementable_traversal_tag, single_pass_traversal_tag, incrementable_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( incrementable_traversal_tag, forward_traversal_tag, incrementable_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( incrementable_traversal_tag, bidirectional_traversal_tag, incrementable_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( incrementable_traversal_tag, random_access_traversal_tag, incrementable_traversal_tag ) + +BOOST_DEMOTE_TRAVERSAL_TAG( single_pass_traversal_tag, no_traversal_tag, no_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( single_pass_traversal_tag, incrementable_traversal_tag, incrementable_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( single_pass_traversal_tag, single_pass_traversal_tag, single_pass_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( single_pass_traversal_tag, forward_traversal_tag, single_pass_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( single_pass_traversal_tag, bidirectional_traversal_tag, single_pass_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( single_pass_traversal_tag, random_access_traversal_tag, single_pass_traversal_tag ) + +BOOST_DEMOTE_TRAVERSAL_TAG( forward_traversal_tag, no_traversal_tag, no_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( forward_traversal_tag, incrementable_traversal_tag, incrementable_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( forward_traversal_tag, single_pass_traversal_tag, single_pass_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( forward_traversal_tag, forward_traversal_tag, forward_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( forward_traversal_tag, bidirectional_traversal_tag, forward_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( forward_traversal_tag, random_access_traversal_tag, forward_traversal_tag ) + +BOOST_DEMOTE_TRAVERSAL_TAG( bidirectional_traversal_tag, no_traversal_tag, no_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( bidirectional_traversal_tag, incrementable_traversal_tag, incrementable_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( bidirectional_traversal_tag, single_pass_traversal_tag, single_pass_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( bidirectional_traversal_tag, forward_traversal_tag, forward_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( bidirectional_traversal_tag, bidirectional_traversal_tag, bidirectional_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( bidirectional_traversal_tag, random_access_traversal_tag, bidirectional_traversal_tag ) + +BOOST_DEMOTE_TRAVERSAL_TAG( random_access_traversal_tag, no_traversal_tag, no_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( random_access_traversal_tag, incrementable_traversal_tag, incrementable_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( random_access_traversal_tag, single_pass_traversal_tag, single_pass_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( random_access_traversal_tag, forward_traversal_tag, forward_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( random_access_traversal_tag, bidirectional_traversal_tag, bidirectional_traversal_tag ) +BOOST_DEMOTE_TRAVERSAL_TAG( random_access_traversal_tag, random_access_traversal_tag, random_access_traversal_tag ) + +#undef BOOST_DEMOTE_TRAVERSAL_TAG + + } // namespace range_detail +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/detail/extract_optional_type.hpp b/include/boost/range/detail/extract_optional_type.hpp new file mode 100755 index 0000000..8292e34 --- /dev/null +++ b/include/boost/range/detail/extract_optional_type.hpp @@ -0,0 +1,52 @@ +// Boost.Range library +// +// Copyright Arno Schoedl & Neil Groves 2009. +// 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_DETAIL_EXTRACT_OPTIONAL_TYPE_HPP_INCLUDED +#define BOOST_RANGE_DETAIL_EXTRACT_OPTIONAL_TYPE_HPP_INCLUDED + +#if defined(_MSC_VER) && (_MSC_VER >= 1200) +# pragma once +#endif + +#include + +#ifdef BOOST_NO_PARTIAL_TEMPLATE_SPECIALIZATION + +#define BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( a_typedef ) \ + template< typename C > \ + struct extract_ ## a_typedef \ + { \ + typedef BOOST_DEDUCED_TYPENAME C::a_typedef type; \ + }; + +#else + +namespace boost { + namespace range_detail { + template< typename T > struct exists { typedef void type; }; + } +} + +// Defines extract_some_typedef which exposes T::some_typedef as +// extract_some_typedef::type if T::some_typedef exists. Otherwise +// extract_some_typedef is empty. +#define BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( a_typedef ) \ + template< typename C, typename Enable=void > \ + struct extract_ ## a_typedef \ + {}; \ + template< typename C > \ + struct extract_ ## a_typedef< C \ + , BOOST_DEDUCED_TYPENAME boost::range_detail::exists< BOOST_DEDUCED_TYPENAME C::a_typedef >::type \ + > { \ + typedef BOOST_DEDUCED_TYPENAME C::a_typedef type; \ + }; + +#endif + +#endif // include guard diff --git a/include/boost/range/detail/implementation_help.hpp b/include/boost/range/detail/implementation_help.hpp index ca12fa4..1f7d163 100644 --- a/include/boost/range/detail/implementation_help.hpp +++ b/include/boost/range/detail/implementation_help.hpp @@ -21,13 +21,13 @@ #include #endif -namespace boost +namespace boost { namespace range_detail { template inline void boost_range_silence_warning( const T& ) { } - + ///////////////////////////////////////////////////////////////////// // end() help ///////////////////////////////////////////////////////////////////// @@ -36,7 +36,7 @@ namespace boost { return s + strlen( s ); } - + #ifndef BOOST_NO_CWCHAR inline const wchar_t* str_end( const wchar_t* s, const wchar_t* ) { @@ -51,7 +51,7 @@ namespace boost ; return s; } -#endif +#endif template< class Char > inline Char* str_end( Char* s ) @@ -64,7 +64,7 @@ namespace boost { return boost_range_array + sz; } - + template< class T, std::size_t sz > inline const T* array_end( const T BOOST_RANGE_ARRAY_REF()[sz] ) { @@ -74,7 +74,7 @@ namespace boost ///////////////////////////////////////////////////////////////////// // size() help ///////////////////////////////////////////////////////////////////// - + template< class Char > inline std::size_t str_size( const Char* const& s ) { @@ -96,7 +96,7 @@ namespace boost } } // namespace 'range_detail' - + } // namespace 'boost' diff --git a/include/boost/range/detail/join_iterator.hpp b/include/boost/range/detail/join_iterator.hpp new file mode 100644 index 0000000..792f834 --- /dev/null +++ b/include/boost/range/detail/join_iterator.hpp @@ -0,0 +1,357 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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_DETAIL_JOIN_ITERATOR_HPP_INCLUDED +#define BOOST_RANGE_DETAIL_JOIN_ITERATOR_HPP_INCLUDED + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace range_detail + { + +template +struct join_iterator_link +{ +private: + class reference_count_t + { + public: + reference_count_t() : m_count(0u) {} + reference_count_t(const reference_count_t&) : m_count(0u) {} + reference_count_t& operator=(const reference_count_t&) { return *this; } + + void increment() { ++m_count; } + bool decrement() { return --m_count ? false : true; } + + private: + unsigned int m_count; + }; + +public: + join_iterator_link(Iterator1 last1, Iterator2 first2) + : last1(last1) + , first2(first2) + { + } + + void add_reference() const + { + count.increment(); + } + + bool release_reference() const + { + return count.decrement(); + } + + Iterator1 last1; + Iterator2 first2; + +private: + join_iterator_link() /* = delete */ ; + + mutable reference_count_t count; +}; + +} // range_detail + +template +inline void intrusive_ptr_add_ref(const range_detail::join_iterator_link* p) +{ + p->add_reference(); +} + +template +inline void intrusive_ptr_release(const range_detail::join_iterator_link* p) +{ + if (p->release_reference()) + delete p; +} + +namespace range_detail +{ + +class join_iterator_begin_tag {}; +class join_iterator_end_tag {}; + +template +class join_iterator_union +{ +public: + typedef Iterator1 iterator1_t; + typedef Iterator2 iterator2_t; + + join_iterator_union() {} + join_iterator_union(unsigned int /*selected*/, const iterator1_t& it1, const iterator2_t& it2) : m_it1(it1), m_it2(it2) {} + + iterator1_t& it1() { return m_it1; } + const iterator1_t& it1() const { return m_it1; } + + iterator2_t& it2() { return m_it2; } + const iterator2_t& it2() const { return m_it2; } + + Reference dereference(unsigned int selected) const + { + return selected ? *m_it2 : *m_it1; + } + + bool equal(const join_iterator_union& other, unsigned int selected) const + { + return selected + ? m_it2 == other.m_it2 + : m_it1 == other.m_it1; + } + +private: + iterator1_t m_it1; + iterator2_t m_it2; +}; + +template +class join_iterator_union +{ +public: + typedef Iterator iterator1_t; + typedef Iterator iterator2_t; + + join_iterator_union() {} + + join_iterator_union(unsigned int selected, const iterator1_t& it1, const iterator2_t& it2) + : m_it(selected ? it2 : it1) + { + } + + iterator1_t& it1() { return m_it; } + const iterator1_t& it1() const { return m_it; } + + iterator2_t& it2() { return m_it; } + const iterator2_t& it2() const { return m_it; } + + Reference dereference(unsigned int) const + { + return *m_it; + } + + bool equal(const join_iterator_union& other, unsigned int selected) const + { + return m_it == other.m_it; + } + +private: + iterator1_t m_it; +}; + +template::type + , typename Reference = typename iterator_reference::type + , typename Traversal = typename demote_iterator_traversal_tag< + typename iterator_traversal::type + , typename iterator_traversal::type>::type +> +class join_iterator + : public iterator_facade, ValueType, Traversal, Reference> +{ + typedef join_iterator_link link_t; + typedef join_iterator_union iterator_union; +public: + typedef Iterator1 iterator1_t; + typedef Iterator2 iterator2_t; + + join_iterator() : m_section(0u) {} + + join_iterator(unsigned int section, Iterator1 current1, Iterator1 last1, Iterator2 first2, Iterator2 current2) + : m_section(section) + , m_it(section, current1, current2) + , m_link(new link_t(last1, first2)) + { + } + + template + join_iterator(Range1& r1, Range2& r2, join_iterator_begin_tag) + : m_section(boost::empty(r1) ? 1u : 0u) + , m_it(boost::empty(r1) ? 1u : 0u, boost::begin(r1), boost::begin(r2)) + , m_link(new link_t(boost::end(r1), boost::begin(r2))) + { + } + + template + join_iterator(const Range1& r1, const Range2& r2, join_iterator_begin_tag) + : m_section(boost::empty(r1) ? 1u : 0u) + , m_it(boost::empty(r1) ? 1u : 0u, boost::const_begin(r1), boost::const_begin(r2)) + , m_link(new link_t(boost::const_end(r1), boost::const_begin(r2))) + { + } + + template + join_iterator(Range1& r1, Range2& r2, join_iterator_end_tag) + : m_section(1u) + , m_it(1u, boost::end(r1), boost::end(r2)) + , m_link(new link_t(boost::end(r1), boost::begin(r2))) + { + } + + template + join_iterator(const Range1& r1, const Range2& r2, join_iterator_end_tag) + : m_section(1u) + , m_it(1u, boost::const_end(r1), boost::const_end(r2)) + , m_link(new link_t(boost::const_end(r1), boost::const_begin(r2))) + { + } + +private: + void increment() + { + if (m_section) + ++m_it.it2(); + else + { + ++m_it.it1(); + if (m_it.it1() == m_link->last1) + { + m_it.it2() = m_link->first2; + m_section = 1u; + } + } + } + + void decrement() + { + if (m_section) + { + if (m_it.it2() == m_link->first2) + { + m_it.it1() = boost::prior(m_link->last1); + m_section = 0u; + } + else + --m_it.it2(); + } + else + --m_it.it1(); + } + + typename join_iterator::reference dereference() const + { + return m_it.dereference(m_section); + } + + bool equal(const join_iterator& other) const + { + return m_section == other.m_section + && m_it.equal(other.m_it, m_section); + } + + void advance(typename join_iterator::difference_type offset) + { + if (m_section) + advance_from_range2(offset); + else + advance_from_range1(offset); + } + + typename join_iterator::difference_type distance_to(const join_iterator& other) const + { + typename join_iterator::difference_type result; + if (m_section) + { + if (other.m_section) + result = other.m_it.it2() - m_it.it2(); + else + { + result = (m_link->first2 - m_it.it2()) + + (other.m_it.it1() - m_link->last1); + + BOOST_ASSERT( result <= 0 ); + } + } + else + { + if (other.m_section) + { + result = (m_link->last1 - m_it.it1()) + + (other.m_it.it2() - m_link->first2); + } + else + result = other.m_it.it1() - m_it.it1(); + } + return result; + } + + void advance_from_range2(typename join_iterator::difference_type offset) + { + typedef typename join_iterator::difference_type difference_t; + BOOST_ASSERT( m_section == 1u ); + if (offset < 0) + { + difference_t r2_dist = m_link->first2 - m_it.it2(); + BOOST_ASSERT( r2_dist <= 0 ); + if (offset >= r2_dist) + std::advance(m_it.it2(), offset); + else + { + difference_t r1_dist = offset - r2_dist; + BOOST_ASSERT( r1_dist <= 0 ); + m_it.it1() = m_link->last1 + r1_dist; + m_section = 0u; + } + } + else + std::advance(m_it.it2(), offset); + } + + void advance_from_range1(typename join_iterator::difference_type offset) + { + typedef typename join_iterator::difference_type difference_t; + BOOST_ASSERT( m_section == 0u ); + if (offset > 0) + { + difference_t r1_dist = m_link->last1 - m_it.it1(); + BOOST_ASSERT( r1_dist >= 0 ); + if (offset < r1_dist) + std::advance(m_it.it1(), offset); + else + { + difference_t r2_dist = offset - r1_dist; + BOOST_ASSERT( r2_dist >= 0 ); + m_it.it2() = m_link->first2 + r2_dist; + m_section = 1u; + } + } + else + std::advance(m_it.it1(), offset); + } + + unsigned int m_section; + iterator_union m_it; + intrusive_ptr m_link; + + friend class ::boost::iterator_core_access; +}; + + } // namespace range_detail + +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/detail/misc_concept.hpp b/include/boost/range/detail/misc_concept.hpp new file mode 100755 index 0000000..74cb919 --- /dev/null +++ b/include/boost/range/detail/misc_concept.hpp @@ -0,0 +1,33 @@ +// Boost.Range library concept checks +// +// Copyright Neil Groves 2009. Use, modification and distribution +// are 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) +// +#ifndef BOOST_RANGE_DETAIL_MISC_CONCEPT_HPP_INCLUDED +#define BOOST_RANGE_DETAIL_MISC_CONCEPT_HPP_INCLUDED + +#include + +namespace boost +{ + namespace range_detail + { + template + class SameTypeConcept + { + public: + BOOST_CONCEPT_USAGE(SameTypeConcept) + { + same_type(a,b); + } + private: + template void same_type(T,T) {} + T1 a; + T2 b; + }; + } +} + +#endif // include guard diff --git a/include/boost/range/detail/range_return.hpp b/include/boost/range/detail/range_return.hpp new file mode 100755 index 0000000..52a6073 --- /dev/null +++ b/include/boost/range/detail/range_return.hpp @@ -0,0 +1,180 @@ +// Copyright Neil Groves 2009. 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_DETAIL_RANGE_RETURN_HPP_INCLUDED +#define BOOST_RANGE_DETAIL_RANGE_RETURN_HPP_INCLUDED + +#include +#include +#include + +namespace boost +{ + enum range_return_value + { + // (*) indicates the most common values + return_found, // only the found resulting iterator (*) + return_next, // next(found) iterator + return_prior, // prior(found) iterator + return_begin_found, // [begin, found) range (*) + return_begin_next, // [begin, next(found)) range + return_begin_prior, // [begin, prior(found)) range + return_found_end, // [found, end) range (*) + return_next_end, // [next(found), end) range + return_prior_end, // [prior(found), end) range + return_begin_end // [begin, end) range + }; + + template< class SinglePassRange, range_return_value > + struct range_return + { + typedef boost::iterator_range< + BOOST_DEDUCED_TYPENAME range_iterator::type > type; + + static type pack(BOOST_DEDUCED_TYPENAME range_iterator::type found, + SinglePassRange& rng) + { + return type(found, boost::end(rng)); + } + }; + + template< class SinglePassRange > + struct range_return< SinglePassRange, return_found > + { + typedef BOOST_DEDUCED_TYPENAME range_iterator::type type; + + static type pack(type found, SinglePassRange&) + { + return found; + } + }; + + template< class SinglePassRange > + struct range_return< SinglePassRange, return_next > + { + typedef BOOST_DEDUCED_TYPENAME range_iterator::type type; + + static type pack(type found, SinglePassRange& rng) + { + return found == boost::end(rng) + ? found + : boost::next(found); + } + }; + + template< class BidirectionalRange > + struct range_return< BidirectionalRange, return_prior > + { + typedef BOOST_DEDUCED_TYPENAME range_iterator::type type; + + static type pack(type found, BidirectionalRange& rng) + { + return found == boost::begin(rng) + ? found + : boost::prior(found); + } + }; + + template< class SinglePassRange > + struct range_return< SinglePassRange, return_begin_found > + { + typedef boost::iterator_range< + BOOST_DEDUCED_TYPENAME range_iterator::type > type; + + static type pack(BOOST_DEDUCED_TYPENAME range_iterator::type found, + SinglePassRange& rng) + { + return type(boost::begin(rng), found); + } + }; + + template< class SinglePassRange > + struct range_return< SinglePassRange, return_begin_next > + { + typedef boost::iterator_range< + BOOST_DEDUCED_TYPENAME range_iterator::type > type; + + static type pack(BOOST_DEDUCED_TYPENAME range_iterator::type found, + SinglePassRange& rng) + { + return type( boost::begin(rng), + found == boost::end(rng) ? found : boost::next(found) ); + } + }; + + template< class BidirectionalRange > + struct range_return< BidirectionalRange, return_begin_prior > + { + typedef boost::iterator_range< + BOOST_DEDUCED_TYPENAME range_iterator::type > type; + + static type pack(BOOST_DEDUCED_TYPENAME range_iterator::type found, + BidirectionalRange& rng) + { + return type( boost::begin(rng), + found == boost::begin(rng) ? found : boost::prior(found) ); + } + }; + + template< class SinglePassRange > + struct range_return< SinglePassRange, return_found_end > + { + typedef boost::iterator_range< + BOOST_DEDUCED_TYPENAME range_iterator::type > type; + + static type pack(BOOST_DEDUCED_TYPENAME range_iterator::type found, + SinglePassRange& rng) + { + return type(found, boost::end(rng)); + } + }; + + template< class SinglePassRange > + struct range_return< SinglePassRange, return_next_end > + { + typedef boost::iterator_range< + BOOST_DEDUCED_TYPENAME range_iterator::type > type; + + static type pack(BOOST_DEDUCED_TYPENAME range_iterator::type found, + SinglePassRange& rng) + { + return type( found == boost::end(rng) ? found : boost::next(found), + boost::end(rng) ); + } + }; + + template< class BidirectionalRange > + struct range_return< BidirectionalRange, return_prior_end > + { + typedef boost::iterator_range< + BOOST_DEDUCED_TYPENAME range_iterator::type > type; + + static type pack(BOOST_DEDUCED_TYPENAME range_iterator::type found, + BidirectionalRange& rng) + { + return type( found == boost::begin(rng) ? found : boost::prior(found), + boost::end(rng) ); + } + }; + + template< class SinglePassRange > + struct range_return< SinglePassRange, return_begin_end > + { + typedef boost::iterator_range< + BOOST_DEDUCED_TYPENAME range_iterator::type > type; + + static type pack(BOOST_DEDUCED_TYPENAME range_iterator::type found, + SinglePassRange& rng) + { + return type(boost::begin(rng), boost::end(rng)); + } + }; + +} + +#endif // include guard diff --git a/include/boost/range/irange.hpp b/include/boost/range/irange.hpp new file mode 100644 index 0000000..ee25d45 --- /dev/null +++ b/include/boost/range/irange.hpp @@ -0,0 +1,204 @@ +// Boost.Range library +// +// Copyright Neil Groves 2010. 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_IRANGE_HPP_INCLUDED +#define BOOST_RANGE_IRANGE_HPP_INCLUDED + +#include +#include +#include + +namespace boost +{ + namespace range_detail + { + // integer_iterator is an iterator over an integer sequence that + // is bounded only by the limits of the underlying integer + // representation. + // + // This is useful for implementing the irange(first, last) + // function. + // + // Note: + // This use of this iterator and irange is appreciably less + // performant than the corresponding hand-written integer + // loop on many compilers. + template + class integer_iterator + : public boost::iterator_facade< + integer_iterator, + Integer, + boost::random_access_traversal_tag, + Integer, + std::ptrdiff_t + > + { + typedef boost::iterator_facade< + integer_iterator, + Integer, + boost::random_access_traversal_tag, + Integer, + std::ptrdiff_t + > base_t; + public: + typedef typename base_t::value_type value_type; + typedef typename base_t::difference_type difference_type; + typedef typename base_t::reference reference; + + integer_iterator() : m_value() {} + explicit integer_iterator(value_type x) : m_value(x) {} + + private: + void increment() + { + ++m_value; + } + + void decrement() + { + --m_value; + } + + void advance(difference_type offset) + { + m_value += offset; + } + + difference_type distance_to(const integer_iterator& other) const + { + return other.m_value - m_value; + } + + bool equal(const integer_iterator& other) const + { + return m_value == other.m_value; + } + + reference dereference() const + { + return m_value; + } + + friend class ::boost::iterator_core_access; + value_type m_value; + }; + + // integer_iterator_with_step is similar in nature to the + // integer_iterator but provides the ability to 'move' in + // a number of steps specified at construction time. + // + // The three variable implementation provides the best guarantees + // of loop termination upon various combinations of input. + // + // While this design is less performant than some less + // safe alternatives, the use of ranges and iterators to + // perform counting will never be optimal anyhow, hence + // if optimal performance is desired a handcoded loop + // is the solution. + template + class integer_iterator_with_step + : public boost::iterator_facade< + integer_iterator_with_step, + Integer, + boost::random_access_traversal_tag, + Integer, + std::ptrdiff_t + > + { + typedef boost::iterator_facade< + integer_iterator_with_step, + Integer, + boost::random_access_traversal_tag, + Integer, + std::ptrdiff_t + > base_t; + public: + typedef typename base_t::value_type value_type; + typedef typename base_t::difference_type difference_type; + typedef typename base_t::reference reference; + + integer_iterator_with_step(value_type first, value_type step, difference_type step_size) + : m_first(first) + , m_step(step) + , m_step_size(step_size) + { + BOOST_ASSERT( step >= 0 ); + BOOST_ASSERT( step_size != 0 ); + } + + private: + void increment() + { + ++m_step; + } + + void decrement() + { + --m_step; + } + + void advance(difference_type offset) + { + m_step += offset; + } + + difference_type distance_to(const integer_iterator_with_step& other) const + { + return other.m_step - m_step; + } + + bool equal(const integer_iterator_with_step& other) const + { + return m_step == other.m_step; + } + + reference dereference() const + { + return m_first + (m_step * m_step_size); + } + + friend class ::boost::iterator_core_access; + value_type m_first; + value_type m_step; + difference_type m_step_size; + }; + + } // namespace range_detail + + template + iterator_range< range_detail::integer_iterator > + irange(Integer first, Integer last) + { + BOOST_ASSERT( first <= last ); + return boost::iterator_range< range_detail::integer_iterator >( + range_detail::integer_iterator(first), + range_detail::integer_iterator(last)); + } + + template + iterator_range< range_detail::integer_iterator_with_step > + irange(Integer first, Integer last, StepSize step_size) + { + BOOST_ASSERT( step_size != 0 ); + BOOST_ASSERT( (step_size > 0) ? (last >= first) : (last <= first) ); + typedef typename range_detail::integer_iterator_with_step iterator_t; + + const std::ptrdiff_t last_step + = (static_cast(last) - static_cast(first)) + / (static_cast(step_size)); + + return boost::iterator_range< iterator_t >( + iterator_t(first, 0, step_size), + iterator_t(first, last_step, step_size)); + } + +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/istream_range.hpp b/include/boost/range/istream_range.hpp new file mode 100755 index 0000000..fac17a4 --- /dev/null +++ b/include/boost/range/istream_range.hpp @@ -0,0 +1,34 @@ +// Boost.Range library +// +// Copyright Neil Groves 2008. Use, modification and +// distribution is subject to the Boost Software Licence, 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_ISTREAM_RANGE_HPP_INCLUDED +#define BOOST_RANGE_ISTREAM_RANGE_HPP_INCLUDED + +/*! + * \file istream_range.hpp + */ + +#include +#include +#include + +namespace boost +{ + template inline + range > + istream_range(std::basic_istream& in) + { + return range >( + std::istream_iterator(in), + std::istream_iterator()); + } +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/iterator.hpp b/include/boost/range/iterator.hpp old mode 100755 new mode 100644 index 21798c5..ec73ddc --- a/include/boost/range/iterator.hpp +++ b/include/boost/range/iterator.hpp @@ -25,46 +25,46 @@ namespace boost { -#if BOOST_WORKAROUND(BOOST_MSVC, == 1310) +#if BOOST_WORKAROUND(BOOST_MSVC, == 1310) - namespace range_detail_vc7_1 - { - template< typename C, typename Sig = void(C) > - struct range_iterator - { - typedef BOOST_RANGE_DEDUCED_TYPENAME - mpl::eval_if_c< is_const::value, - range_const_iterator< typename remove_const::type >, - range_mutable_iterator >::type type; - }; - - template< typename C, typename T > - struct range_iterator< C, void(T[]) > - { - typedef T* type; - }; - } - -#endif + namespace range_detail_vc7_1 + { + template< typename C, typename Sig = void(C) > + struct range_iterator + { + typedef BOOST_RANGE_DEDUCED_TYPENAME + mpl::eval_if_c< is_const::value, + range_const_iterator< typename remove_const::type >, + range_mutable_iterator >::type type; + }; + + template< typename C, typename T > + struct range_iterator< C, void(T[]) > + { + typedef T* type; + }; + } + +#endif template< typename C > struct range_iterator { #if BOOST_WORKAROUND(BOOST_MSVC, == 1310) - - typedef BOOST_RANGE_DEDUCED_TYPENAME - range_detail_vc7_1::range_iterator::type type; - -#else - typedef BOOST_RANGE_DEDUCED_TYPENAME - mpl::eval_if_c< is_const::value, + typedef BOOST_RANGE_DEDUCED_TYPENAME + range_detail_vc7_1::range_iterator::type type; + +#else + + typedef BOOST_RANGE_DEDUCED_TYPENAME + mpl::eval_if_c< is_const::value, range_const_iterator< typename remove_const::type >, range_mutable_iterator >::type type; - -#endif + +#endif }; - + } // namespace boost //#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION diff --git a/include/boost/range/iterator_range.hpp b/include/boost/range/iterator_range.hpp index d118224..dfcd4d2 100644 --- a/include/boost/range/iterator_range.hpp +++ b/include/boost/range/iterator_range.hpp @@ -1,659 +1,16 @@ // Boost.Range library // -// Copyright Thorsten Ottosen & Pavol Droba 2003-2004. Use, modification and -// distribution is subject to the Boost Software License, Version -// 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// Copyright Neil Groves 2009. +// 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_ITERATOR_RANGE_HPP_INCLUDED +#define BOOST_RANGE_ITERATOR_RANGE_HPP_INCLUDED -#ifndef BOOST_RANGE_ITERATOR_RANGE_HPP -#define BOOST_RANGE_ITERATOR_RANGE_HPP - -#include // Define __STL_CONFIG_H, if appropriate. -#include - -#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) - #pragma warning( push ) - #pragma warning( disable : 4996 ) -#endif - -// From boost/dynamic_bitset.hpp; thanks to Matthias Troyer for Cray X1 patch. -#ifndef BOOST_OLD_IOSTREAMS -# if defined(__STL_CONFIG_H) && \ - !defined (__STL_USE_NEW_IOSTREAMS) && !defined(__crayx1) \ - /**/ -# define BOOST_OLD_IOSTREAMS -# endif -#endif // #ifndef BOOST_OLD_IOSTREAMS - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifndef _STLP_NO_IOSTREAMS -# ifndef BOOST_OLD_IOSTREAMS -# include -# else -# include -# endif -#endif // _STLP_NO_IOSTREAMS -#include - -/*! \file - Defines the \c iterator_class and related functions. - \c iterator_range is a simple wrapper of iterator pair idiom. It provides - a rich subset of Container interface. -*/ - - -namespace boost -{ - namespace iterator_range_detail - { - // - // The functions adl_begin and adl_end are implemented in a separate - // class for gcc-2.9x - // - template - struct iterator_range_impl { - template< class ForwardRange > - static IteratorT adl_begin( ForwardRange& r ) - { - return IteratorT( boost::begin( r ) ); - } - - template< class ForwardRange > - static IteratorT adl_end( ForwardRange& r ) - { - return IteratorT( boost::end( r ) ); - } - }; - - template< class Left, class Right > - inline bool equal( const Left& l, const Right& r ) - { - typedef BOOST_DEDUCED_TYPENAME boost::range_difference::type sz_type; - - sz_type l_size = boost::distance( l ), - r_size = boost::distance( r ); - - if( l_size != r_size ) - return false; - - return std::equal( boost::begin(l), boost::end(l), - boost::begin(r) ); - } - - template< class Left, class Right > - inline bool less_than( const Left& l, const Right& r ) - { - return std::lexicographical_compare( boost::begin(l), - boost::end(l), - boost::begin(r), - boost::end(r) ); - } - - struct range_tag { }; - struct const_range_tag { }; - - } - -// iterator range template class -----------------------------------------// - - //! iterator_range class - /*! - An \c iterator_range delimits a range in a sequence by beginning and ending iterators. - An iterator_range can be passed to an algorithm which requires a sequence as an input. - For example, the \c toupper() function may be used most frequently on strings, - but can also be used on iterator_ranges: - - \code - boost::tolower( find( s, "UPPERCASE STRING" ) ); - \endcode - - Many algorithms working with sequences take a pair of iterators, - delimiting a working range, as an arguments. The \c iterator_range class is an - encapsulation of a range identified by a pair of iterators. - It provides a collection interface, - so it is possible to pass an instance to an algorithm requiring a collection as an input. - */ - template - class iterator_range - { - protected: // Used by sub_range - //! implementation class - typedef iterator_range_detail::iterator_range_impl impl; - public: - - //! this type - typedef iterator_range type; - //BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(value_type); - - //! Encapsulated value type - typedef BOOST_DEDUCED_TYPENAME - iterator_value::type value_type; - - //! Difference type - typedef BOOST_DEDUCED_TYPENAME - iterator_difference::type difference_type; - - //! Size type - typedef std::size_t size_type; // note: must be unsigned - - //! This type - typedef iterator_range this_type; - - //! Refence type - // - // Needed because value-type is the same for - // const and non-const iterators - // - typedef BOOST_DEDUCED_TYPENAME - iterator_reference::type reference; - - //! const_iterator type - /*! - There is no distinction between const_iterator and iterator. - These typedefs are provides to fulfill container interface - */ - typedef IteratorT const_iterator; - //! iterator type - typedef IteratorT iterator; - - private: // for return value of operator()() - typedef BOOST_DEDUCED_TYPENAME - boost::mpl::if_< boost::is_abstract, - reference, value_type >::type abstract_value_type; - - public: - iterator_range() : m_Begin( iterator() ), m_End( iterator() ) - #ifndef NDEBUG - , singular( true ) - #endif - { } - - //! Constructor from a pair of iterators - template< class Iterator > - iterator_range( Iterator Begin, Iterator End ) : - m_Begin(Begin), m_End(End) - #ifndef NDEBUG - , singular(false) - #endif - {} - - //! Constructor from a Range - template< class Range > - iterator_range( const Range& r ) : - m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) ) - #ifndef NDEBUG - , singular(false) - #endif - {} - - //! Constructor from a Range - template< class Range > - iterator_range( Range& r ) : - m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) ) - #ifndef NDEBUG - , singular(false) - #endif - {} - - //! Constructor from a Range - template< class Range > - iterator_range( const Range& r, iterator_range_detail::const_range_tag ) : - m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) ) - #ifndef NDEBUG - , singular(false) - #endif - {} - - //! Constructor from a Range - template< class Range > - iterator_range( Range& r, iterator_range_detail::range_tag ) : - m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) ) - #ifndef NDEBUG - , singular(false) - #endif - {} - - #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) - this_type& operator=( const this_type& r ) - { - m_Begin = r.begin(); - m_End = r.end(); - - #ifndef NDEBUG - singular = r.singular; - #endif - return *this; - } - #endif - - template< class Iterator > - iterator_range& operator=( const iterator_range& r ) - { - m_Begin = r.begin(); - m_End = r.end(); - #ifndef NDEBUG - singular = r.is_singular(); - #endif - return *this; - } - - template< class ForwardRange > - iterator_range& operator=( ForwardRange& r ) - { - m_Begin = impl::adl_begin( r ); - m_End = impl::adl_end( r ); - #ifndef NDEBUG - singular = false; - #endif - return *this; - } - - template< class ForwardRange > - iterator_range& operator=( const ForwardRange& r ) - { - m_Begin = impl::adl_begin( r ); - m_End = impl::adl_end( r ); - #ifndef NDEBUG - singular = false; - #endif - return *this; - } - - IteratorT begin() const - { - BOOST_ASSERT( !is_singular() ); - return m_Begin; - } - - IteratorT end() const - { - BOOST_ASSERT( !is_singular() ); - return m_End; - } - - difference_type size() const - { - BOOST_ASSERT( !is_singular() ); - return m_End - m_Begin; - } - - bool empty() const - { - BOOST_ASSERT( !is_singular() ); - return m_Begin == m_End; - } - -#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) - operator bool() const - { - return !empty(); - } -#else - typedef iterator (iterator_range::*unspecified_bool_type) () const; - operator unspecified_bool_type() const - { - return empty() ? 0: &iterator_range::end; - } -#endif - - bool equal( const iterator_range& r ) const - { - BOOST_ASSERT( !is_singular() ); - return m_Begin == r.m_Begin && m_End == r.m_End; - } - - -#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING - - bool operator==( const iterator_range& r ) const - { - BOOST_ASSERT( !is_singular() ); - return iterator_range_detail::equal( *this, r ); - } - - bool operator!=( const iterator_range& r ) const - { - BOOST_ASSERT( !is_singular() ); - return !operator==(r); - } - - bool operator<( const iterator_range& r ) const - { - BOOST_ASSERT( !is_singular() ); - return iterator_range_detail::less_than( *this, r ); - } - -#endif - - public: // convenience - reference front() const - { - BOOST_ASSERT( !empty() ); - return *m_Begin; - } - - reference back() const - { - BOOST_ASSERT( !empty() ); - IteratorT last( m_End ); - return *--last; - } - - reference operator[]( difference_type at ) const - { - BOOST_ASSERT( at >= 0 && at < size() ); - return m_Begin[at]; - } - - // - // When storing transform iterators, operator[]() - // fails because it returns by reference. Therefore - // operator()() is provided for these cases. - // - abstract_value_type operator()( difference_type at ) const - { - BOOST_ASSERT( at >= 0 && at < size() ); - return m_Begin[at]; - } - - iterator_range& advance_begin( difference_type n ) - { - BOOST_ASSERT( !is_singular() ); - std::advance( m_Begin, n ); - return *this; - } - - iterator_range& advance_end( difference_type n ) - { - BOOST_ASSERT( !is_singular() ); - std::advance( m_End, n ); - return *this; - } - - private: - // begin and end iterators - IteratorT m_Begin; - IteratorT m_End; - - #ifndef NDEBUG - bool singular; - #endif - - public: - bool is_singular() const - { - #ifndef NDEBUG - return singular; - #else - return false; - #endif - } - - protected: - // - // Allow subclasses an easy way to access the - // base type - // - typedef iterator_range iterator_range_; - }; - -// iterator range free-standing operators ---------------------------// - -#ifndef _STLP_NO_IOSTREAMS -# ifndef BOOST_OLD_IOSTREAMS - - //! iterator_range output operator - /*! - Output the range to an ostream. Elements are outputed - in a sequence without separators. - */ - template< typename IteratorT, typename Elem, typename Traits > - inline std::basic_ostream& operator<<( - std::basic_ostream& Os, - const iterator_range& r ) - { - std::copy( r.begin(), r.end(), - std::ostream_iterator< BOOST_DEDUCED_TYPENAME - iterator_value::type, - Elem, Traits>(Os) ); - return Os; - } - -# else - - //! iterator_range output operator - /*! - Output the range to an ostream. Elements are outputed - in a sequence without separators. - */ - template< typename IteratorT > - inline std::ostream& operator<<( - std::ostream& Os, - const iterator_range& r ) - { - std::copy( r.begin(), r.end(), std::ostream_iterator(Os)); - return Os; - } - -# endif -#endif // _STLP_NO_IOSTREAMS - - ///////////////////////////////////////////////////////////////////// - // comparison operators - ///////////////////////////////////////////////////////////////////// - - template< class IteratorT, class ForwardRange > - inline bool operator==( const ForwardRange& l, - const iterator_range& r ) - { - return iterator_range_detail::equal( l, r ); - } - - template< class IteratorT, class ForwardRange > - inline bool operator!=( const ForwardRange& l, - const iterator_range& r ) - { - return !iterator_range_detail::equal( l, r ); - } - - template< class IteratorT, class ForwardRange > - inline bool operator<( const ForwardRange& l, - const iterator_range& r ) - { - return iterator_range_detail::less_than( l, r ); - } - -#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING -#else - template< class Iterator1T, class Iterator2T > - inline bool operator==( const iterator_range& l, - const iterator_range& r ) - { - return iterator_range_detail::equal( l, r ); - } - - template< class IteratorT, class ForwardRange > - inline bool operator==( const iterator_range& l, - const ForwardRange& r ) - { - return iterator_range_detail::equal( l, r ); - } - - - template< class Iterator1T, class Iterator2T > - inline bool operator!=( const iterator_range& l, - const iterator_range& r ) - { - return !iterator_range_detail::equal( l, r ); - } - - template< class IteratorT, class ForwardRange > - inline bool operator!=( const iterator_range& l, - const ForwardRange& r ) - { - return !iterator_range_detail::equal( l, r ); - } - - - template< class Iterator1T, class Iterator2T > - inline bool operator<( const iterator_range& l, - const iterator_range& r ) - { - return iterator_range_detail::less_than( l, r ); - } - - template< class IteratorT, class ForwardRange > - inline bool operator<( const iterator_range& l, - const ForwardRange& r ) - { - return iterator_range_detail::less_than( l, r ); - } - -#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING - -// iterator range utilities -----------------------------------------// - - //! iterator_range construct helper - /*! - Construct an \c iterator_range from a pair of iterators - - \param Begin A begin iterator - \param End An end iterator - \return iterator_range object - */ - template< typename IteratorT > - inline iterator_range< IteratorT > - make_iterator_range( IteratorT Begin, IteratorT End ) - { - return iterator_range( Begin, End ); - } - -#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING - - template< typename Range > - inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > - make_iterator_range( Range& r ) - { - return iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > - ( boost::begin( r ), boost::end( r ) ); - } - -#else - //! iterator_range construct helper - /*! - Construct an \c iterator_range from a \c Range containing the begin - and end iterators. - */ - template< class ForwardRange > - inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > - make_iterator_range( ForwardRange& r ) - { - return iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > - ( r, iterator_range_detail::range_tag() ); - } - - template< class ForwardRange > - inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > - make_iterator_range( const ForwardRange& r ) - { - return iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > - ( r, iterator_range_detail::const_range_tag() ); - } - -#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING - - namespace iterator_range_detail - { - template< class Range > - inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > - make_range_impl( Range& r, - BOOST_DEDUCED_TYPENAME range_difference::type advance_begin, - BOOST_DEDUCED_TYPENAME range_difference::type advance_end ) - { - // - // Not worth the effort - // - //if( advance_begin == 0 && advance_end == 0 ) - // return make_iterator_range( r ); - // - - BOOST_DEDUCED_TYPENAME range_iterator::type - new_begin = boost::begin( r ), - new_end = boost::end( r ); - std::advance( new_begin, advance_begin ); - std::advance( new_end, advance_end ); - return make_iterator_range( new_begin, new_end ); - } - } - -#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING - - template< class Range > - inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > - make_iterator_range( Range& r, - BOOST_DEDUCED_TYPENAME range_difference::type advance_begin, - BOOST_DEDUCED_TYPENAME range_difference::type advance_end ) - { - //BOOST_ASSERT( advance_begin - advance_end <= size(r) && "creating invalid range" ); - return iterator_range_detail::make_range_impl( r, advance_begin, advance_end ); - } - -#else - - template< class Range > - inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > - make_iterator_range( Range& r, - BOOST_DEDUCED_TYPENAME range_difference::type advance_begin, - BOOST_DEDUCED_TYPENAME range_difference::type advance_end ) - { - //BOOST_ASSERT( advance_begin - advance_end <= size(r) && "creating invalid range" ); - return iterator_range_detail::make_range_impl( r, advance_begin, advance_end ); - } - - template< class Range > - inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > - make_iterator_range( const Range& r, - BOOST_DEDUCED_TYPENAME range_difference::type advance_begin, - BOOST_DEDUCED_TYPENAME range_difference::type advance_end ) - { - //BOOST_ASSERT( advance_begin - advance_end <= size(r) && "creating invalid range" ); - return iterator_range_detail::make_range_impl( r, advance_begin, advance_end ); - } - -#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING - - //! copy a range into a sequence - /*! - Construct a new sequence of the specified type from the elements - in the given range - - \param Range An input range - \return New sequence - */ - template< typename SeqT, typename Range > - inline SeqT copy_range( const Range& r ) - { - return SeqT( boost::begin( r ), boost::end( r ) ); - } - -} // namespace 'boost' - -#undef BOOST_OLD_IOSTREAMS - -#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) - #pragma warning( pop ) -#endif - -#endif +#include "boost/range/iterator_range_core.hpp" +#include "boost/range/iterator_range_io.hpp" +#endif // include guard diff --git a/include/boost/range/iterator_range_core.hpp b/include/boost/range/iterator_range_core.hpp new file mode 100755 index 0000000..c1822fb --- /dev/null +++ b/include/boost/range/iterator_range_core.hpp @@ -0,0 +1,554 @@ +// Boost.Range library +// +// Copyright Neil Groves & Thorsten Ottosen & Pavol Droba 2003-2004. +// 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_ITERATOR_RANGE_CORE_HPP_INCLUDED +#define BOOST_RANGE_ITERATOR_RANGE_CORE_HPP_INCLUDED + +#include // Define __STL_CONFIG_H, if appropriate. +#include + +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) + #pragma warning( push ) + #pragma warning( disable : 4996 ) +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/*! \file + Defines the \c iterator_class and related functions. + \c iterator_range is a simple wrapper of iterator pair idiom. It provides + a rich subset of Container interface. +*/ + + +namespace boost +{ + namespace iterator_range_detail + { + // + // The functions adl_begin and adl_end are implemented in a separate + // class for gcc-2.9x + // + template + struct iterator_range_impl { + template< class ForwardRange > + static IteratorT adl_begin( ForwardRange& r ) + { + return IteratorT( boost::begin( r ) ); + } + + template< class ForwardRange > + static IteratorT adl_end( ForwardRange& r ) + { + return IteratorT( boost::end( r ) ); + } + }; + + template< class Left, class Right > + inline bool less_than( const Left& l, const Right& r ) + { + return std::lexicographical_compare( boost::begin(l), + boost::end(l), + boost::begin(r), + boost::end(r) ); + } + + // This version is maintained since it is used in other boost libraries + // such as Boost.Assign + template< class Left, class Right > + inline bool equal(const Left& l, const Right& r) + { + return boost::equal(l, r); + } + + struct range_tag { }; + struct const_range_tag { }; + + } + +// iterator range template class -----------------------------------------// + + //! iterator_range class + /*! + An \c iterator_range delimits a range in a sequence by beginning and ending iterators. + An iterator_range can be passed to an algorithm which requires a sequence as an input. + For example, the \c toupper() function may be used most frequently on strings, + but can also be used on iterator_ranges: + + \code + boost::tolower( find( s, "UPPERCASE STRING" ) ); + \endcode + + Many algorithms working with sequences take a pair of iterators, + delimiting a working range, as an arguments. The \c iterator_range class is an + encapsulation of a range identified by a pair of iterators. + It provides a collection interface, + so it is possible to pass an instance to an algorithm requiring a collection as an input. + */ + template + class iterator_range + { + protected: // Used by sub_range + //! implementation class + typedef iterator_range_detail::iterator_range_impl impl; + public: + + //! this type + typedef iterator_range type; + //BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(value_type); + + //! Encapsulated value type + typedef BOOST_DEDUCED_TYPENAME + iterator_value::type value_type; + + //! Difference type + typedef BOOST_DEDUCED_TYPENAME + iterator_difference::type difference_type; + + //! Size type + typedef std::size_t size_type; // note: must be unsigned + + //! This type + typedef iterator_range this_type; + + //! Reference type + // + // Needed because value-type is the same for + // const and non-const iterators + // + typedef BOOST_DEDUCED_TYPENAME + iterator_reference::type reference; + + //! const_iterator type + /*! + There is no distinction between const_iterator and iterator. + These typedefs are provides to fulfill container interface + */ + typedef IteratorT const_iterator; + //! iterator type + typedef IteratorT iterator; + + private: // for return value of operator()() + typedef BOOST_DEDUCED_TYPENAME + boost::mpl::if_< boost::is_abstract, + reference, value_type >::type abstract_value_type; + + public: + iterator_range() : m_Begin( iterator() ), m_End( iterator() ) + { } + + //! Constructor from a pair of iterators + template< class Iterator > + iterator_range( Iterator Begin, Iterator End ) : + m_Begin(Begin), m_End(End) + {} + + //! Constructor from a Range + template< class Range > + iterator_range( const Range& r ) : + m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) ) + {} + + //! Constructor from a Range + template< class Range > + iterator_range( Range& r ) : + m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) ) + {} + + //! Constructor from a Range + template< class Range > + iterator_range( const Range& r, iterator_range_detail::const_range_tag ) : + m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) ) + {} + + //! Constructor from a Range + template< class Range > + iterator_range( Range& r, iterator_range_detail::range_tag ) : + m_Begin( impl::adl_begin( r ) ), m_End( impl::adl_end( r ) ) + {} + + #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) + this_type& operator=( const this_type& r ) + { + m_Begin = r.begin(); + m_End = r.end(); + return *this; + } + #endif + + template< class Iterator > + iterator_range& operator=( const iterator_range& r ) + { + m_Begin = r.begin(); + m_End = r.end(); + return *this; + } + + template< class ForwardRange > + iterator_range& operator=( ForwardRange& r ) + { + m_Begin = impl::adl_begin( r ); + m_End = impl::adl_end( r ); + return *this; + } + + template< class ForwardRange > + iterator_range& operator=( const ForwardRange& r ) + { + m_Begin = impl::adl_begin( r ); + m_End = impl::adl_end( r ); + return *this; + } + + IteratorT begin() const + { + return m_Begin; + } + + IteratorT end() const + { + return m_End; + } + + difference_type size() const + { + return m_End - m_Begin; + } + + bool empty() const + { + return m_Begin == m_End; + } + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) + operator bool() const + { + return !empty(); + } +#else + typedef iterator (iterator_range::*unspecified_bool_type) () const; + operator unspecified_bool_type() const + { + return empty() ? 0: &iterator_range::end; + } +#endif + + bool equal( const iterator_range& r ) const + { + return m_Begin == r.m_Begin && m_End == r.m_End; + } + + +#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + + bool operator==( const iterator_range& r ) const + { + return boost::equal( *this, r ); + } + + bool operator!=( const iterator_range& r ) const + { + return !operator==(r); + } + + bool operator<( const iterator_range& r ) const + { + return iterator_range_detail::less_than( *this, r ); + } + +#endif + + public: // convenience + reference front() const + { + BOOST_ASSERT( !empty() ); + return *m_Begin; + } + + reference back() const + { + BOOST_ASSERT( !empty() ); + IteratorT last( m_End ); + return *--last; + } + + +#ifdef __SUNPRO_CC + reference operator[]( difference_type at ) const + { + BOOST_ASSERT( at >= 0 && at < size() ); + return m_Begin[at]; + } +#else + BOOST_DEDUCED_TYPENAME boost::detail::operator_brackets_result::type + operator[]( difference_type at ) const + { + BOOST_ASSERT( at >= 0 && at < size() ); + + typedef boost::detail::use_operator_brackets_proxy use_proxy; + return boost::detail::make_operator_brackets_result(m_Begin + at, use_proxy()); + } +#endif + + // + // When storing transform iterators, operator[]() + // fails because it returns by reference. Therefore + // operator()() is provided for these cases. + // + abstract_value_type operator()( difference_type at ) const + { + BOOST_ASSERT( at >= 0 && at < size() ); + return m_Begin[at]; + } + + iterator_range& advance_begin( difference_type n ) + { + std::advance( m_Begin, n ); + return *this; + } + + iterator_range& advance_end( difference_type n ) + { + std::advance( m_End, n ); + return *this; + } + + private: + // begin and end iterators + IteratorT m_Begin; + IteratorT m_End; + + protected: + // + // Allow subclasses an easy way to access the + // base type + // + typedef iterator_range iterator_range_; + }; + +// iterator range free-standing operators ---------------------------// + + ///////////////////////////////////////////////////////////////////// + // comparison operators + ///////////////////////////////////////////////////////////////////// + + template< class IteratorT, class ForwardRange > + inline bool operator==( const ForwardRange& l, + const iterator_range& r ) + { + return boost::equal( l, r ); + } + + template< class IteratorT, class ForwardRange > + inline bool operator!=( const ForwardRange& l, + const iterator_range& r ) + { + return !boost::equal( l, r ); + } + + template< class IteratorT, class ForwardRange > + inline bool operator<( const ForwardRange& l, + const iterator_range& r ) + { + return iterator_range_detail::less_than( l, r ); + } + +#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING +#else + template< class Iterator1T, class Iterator2T > + inline bool operator==( const iterator_range& l, + const iterator_range& r ) + { + return boost::equal( l, r ); + } + + template< class IteratorT, class ForwardRange > + inline bool operator==( const iterator_range& l, + const ForwardRange& r ) + { + return boost::equal( l, r ); + } + + + template< class Iterator1T, class Iterator2T > + inline bool operator!=( const iterator_range& l, + const iterator_range& r ) + { + return !boost::equal( l, r ); + } + + template< class IteratorT, class ForwardRange > + inline bool operator!=( const iterator_range& l, + const ForwardRange& r ) + { + return !boost::equal( l, r ); + } + + + template< class Iterator1T, class Iterator2T > + inline bool operator<( const iterator_range& l, + const iterator_range& r ) + { + return iterator_range_detail::less_than( l, r ); + } + + template< class IteratorT, class ForwardRange > + inline bool operator<( const iterator_range& l, + const ForwardRange& r ) + { + return iterator_range_detail::less_than( l, r ); + } + +#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING + +// iterator range utilities -----------------------------------------// + + //! iterator_range construct helper + /*! + Construct an \c iterator_range from a pair of iterators + + \param Begin A begin iterator + \param End An end iterator + \return iterator_range object + */ + template< typename IteratorT > + inline iterator_range< IteratorT > + make_iterator_range( IteratorT Begin, IteratorT End ) + { + return iterator_range( Begin, End ); + } + +#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + + template< typename Range > + inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > + make_iterator_range( Range& r ) + { + return iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > + ( boost::begin( r ), boost::end( r ) ); + } + +#else + //! iterator_range construct helper + /*! + Construct an \c iterator_range from a \c Range containing the begin + and end iterators. + */ + template< class ForwardRange > + inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > + make_iterator_range( ForwardRange& r ) + { + return iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > + ( r, iterator_range_detail::range_tag() ); + } + + template< class ForwardRange > + inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > + make_iterator_range( const ForwardRange& r ) + { + return iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > + ( r, iterator_range_detail::const_range_tag() ); + } + +#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING + + namespace iterator_range_detail + { + template< class Range > + inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > + make_range_impl( Range& r, + BOOST_DEDUCED_TYPENAME range_difference::type advance_begin, + BOOST_DEDUCED_TYPENAME range_difference::type advance_end ) + { + // + // Not worth the effort + // + //if( advance_begin == 0 && advance_end == 0 ) + // return make_iterator_range( r ); + // + + BOOST_DEDUCED_TYPENAME range_iterator::type + new_begin = boost::begin( r ), + new_end = boost::end( r ); + std::advance( new_begin, advance_begin ); + std::advance( new_end, advance_end ); + return make_iterator_range( new_begin, new_end ); + } + } + +#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + + template< class Range > + inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > + make_iterator_range( Range& r, + BOOST_DEDUCED_TYPENAME range_difference::type advance_begin, + BOOST_DEDUCED_TYPENAME range_difference::type advance_end ) + { + //BOOST_ASSERT( advance_begin - advance_end <= size(r) && "creating invalid range" ); + return iterator_range_detail::make_range_impl( r, advance_begin, advance_end ); + } + +#else + + template< class Range > + inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > + make_iterator_range( Range& r, + BOOST_DEDUCED_TYPENAME range_difference::type advance_begin, + BOOST_DEDUCED_TYPENAME range_difference::type advance_end ) + { + //BOOST_ASSERT( advance_begin - advance_end <= size(r) && "creating invalid range" ); + return iterator_range_detail::make_range_impl( r, advance_begin, advance_end ); + } + + template< class Range > + inline iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > + make_iterator_range( const Range& r, + BOOST_DEDUCED_TYPENAME range_difference::type advance_begin, + BOOST_DEDUCED_TYPENAME range_difference::type advance_end ) + { + //BOOST_ASSERT( advance_begin - advance_end <= size(r) && "creating invalid range" ); + return iterator_range_detail::make_range_impl( r, advance_begin, advance_end ); + } + +#endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING + + //! copy a range into a sequence + /*! + Construct a new sequence of the specified type from the elements + in the given range + + \param Range An input range + \return New sequence + */ + template< typename SeqT, typename Range > + inline SeqT copy_range( const Range& r ) + { + return SeqT( boost::begin( r ), boost::end( r ) ); + } + +} // namespace 'boost' + +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) + #pragma warning( pop ) +#endif + +#endif + diff --git a/include/boost/range/iterator_range_io.hpp b/include/boost/range/iterator_range_io.hpp new file mode 100755 index 0000000..51e3a4f --- /dev/null +++ b/include/boost/range/iterator_range_io.hpp @@ -0,0 +1,93 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. +// 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_ITERATOR_RANGE_IO_HPP_INCLUDED +#define BOOST_RANGE_ITERATOR_RANGE_IO_HPP_INCLUDED + +#include +#include + +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) + #pragma warning( push ) + #pragma warning( disable : 4996 ) +#endif + +// From boost/dynamic_bitset.hpp; thanks to Matthias Troyer for Cray X1 patch. +#ifndef BOOST_OLD_IOSTREAMS +# if defined(__STL_CONFIG_H) && \ + !defined (__STL_USE_NEW_IOSTREAMS) && !defined(__crayx1) \ + /**/ +# define BOOST_OLD_IOSTREAMS +# endif +#endif // #ifndef BOOST_OLD_IOSTREAMS + +#ifndef _STLP_NO_IOSTREAMS +# ifndef BOOST_OLD_IOSTREAMS +# include +# else +# include +# endif +#endif // _STLP_NO_IOSTREAMS + +#include +#include +#include +#include + +namespace boost +{ + +#ifndef _STLP_NO_IOSTREAMS +# ifndef BOOST_OLD_IOSTREAMS + + //! iterator_range output operator + /*! + Output the range to an ostream. Elements are outputed + in a sequence without separators. + */ + template< typename IteratorT, typename Elem, typename Traits > + inline std::basic_ostream& operator<<( + std::basic_ostream& Os, + const iterator_range& r ) + { + std::copy( r.begin(), r.end(), + std::ostream_iterator< BOOST_DEDUCED_TYPENAME + iterator_value::type, + Elem, Traits>(Os) ); + return Os; + } + +# else + + //! iterator_range output operator + /*! + Output the range to an ostream. Elements are outputed + in a sequence without separators. + */ + template< typename IteratorT > + inline std::ostream& operator<<( + std::ostream& Os, + const iterator_range& r ) + { + std::copy( r.begin(), r.end(), std::ostream_iterator(Os)); + return Os; + } + +# endif +#endif // _STLP_NO_IOSTREAMS + +} // namespace boost + +#undef BOOST_OLD_IOSTREAMS + +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) + #pragma warning(pop) +#endif + +#endif // include guard diff --git a/include/boost/range/join.hpp b/include/boost/range/join.hpp new file mode 100644 index 0000000..374df86 --- /dev/null +++ b/include/boost/range/join.hpp @@ -0,0 +1,68 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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_JOIN_HPP_INCLUDED +#define BOOST_RANGE_JOIN_HPP_INCLUDED + +#include +#include +#include +#include + +namespace boost +{ + +template +iterator_range::type, + BOOST_DEDUCED_TYPENAME range_iterator::type, + BOOST_DEDUCED_TYPENAME add_const< + BOOST_DEDUCED_TYPENAME range_value::type>::type> +> +join(const SinglePassRange1& r1, const SinglePassRange2& r2) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + typedef range_detail::join_iterator< + BOOST_DEDUCED_TYPENAME range_iterator::type, + BOOST_DEDUCED_TYPENAME range_iterator::type, + BOOST_DEDUCED_TYPENAME add_const< + BOOST_DEDUCED_TYPENAME range_value::type>::type> iterator_t; + + return iterator_range( + iterator_t(r1, r2, range_detail::join_iterator_begin_tag()), + iterator_t(r1, r2, range_detail::join_iterator_end_tag())); +} + +template +iterator_range::type, + BOOST_DEDUCED_TYPENAME range_iterator::type, + BOOST_DEDUCED_TYPENAME range_value::type> +> +join(SinglePassRange1& r1, SinglePassRange2& r2) +{ + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept )); + + typedef range_detail::join_iterator< + BOOST_DEDUCED_TYPENAME range_iterator::type, + BOOST_DEDUCED_TYPENAME range_iterator::type, + BOOST_DEDUCED_TYPENAME range_value::type> iterator_t; + + return iterator_range( + iterator_t(r1, r2, range_detail::join_iterator_begin_tag()), + iterator_t(r1, r2, range_detail::join_iterator_end_tag())); +} + +} // namespace boost + +#endif // include guard diff --git a/include/boost/range/mutable_iterator.hpp b/include/boost/range/mutable_iterator.hpp old mode 100755 new mode 100644 index 2f45c16..7beca66 --- a/include/boost/range/mutable_iterator.hpp +++ b/include/boost/range/mutable_iterator.hpp @@ -21,6 +21,7 @@ #include #else +#include #include #include #include @@ -31,11 +32,13 @@ namespace boost // default ////////////////////////////////////////////////////////////////////////// + namespace range_detail { + BOOST_RANGE_EXTRACT_OPTIONAL_TYPE( iterator ) + } + template< typename C > - struct range_mutable_iterator - { - typedef BOOST_DEDUCED_TYPENAME C::iterator type; - }; + struct range_mutable_iterator : range_detail::extract_iterator + {}; ////////////////////////////////////////////////////////////////////////// // pair diff --git a/include/boost/range/numeric.hpp b/include/boost/range/numeric.hpp new file mode 100755 index 0000000..17e2cfe --- /dev/null +++ b/include/boost/range/numeric.hpp @@ -0,0 +1,117 @@ +/////////////////////////////////////////////////////////////////////////////// +/// \file algorithm.hpp +/// Contains range-based versions of the std algorithms +// +///////////////////////////////////////////////////////////////////////////// +// Copyright 2009 Neil Groves. +// 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) +// + +// Copyright 2006 Thorsten Ottosen. +// 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) +// +// 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) + +#if defined(_MSC_VER) && _MSC_VER >= 1000 + #pragma once +#endif + +#ifndef BOOST_RANGE_NUMERIC_HPP +#define BOOST_RANGE_NUMERIC_HPP + +#include +#include +#include +#include +#include +#include + + +namespace boost +{ + template< class SinglePassRange, class Value > + inline Value accumulate( const SinglePassRange& rng, Value init ) + { + boost::function_requires< SinglePassRangeConcept >(); + return std::accumulate( boost::begin(rng), boost::end(rng), init ); + } + + template< class SinglePassRange, class Value, class BinaryOperation > + inline Value accumulate( const SinglePassRange& rng, Value init, BinaryOperation op ) + { + boost::function_requires< SinglePassRangeConcept >(); + return std::accumulate( boost::begin(rng), boost::end(rng), init, op ); + } + + + template< class SinglePassRange1, class SinglePassRange2, class Value > + inline Value inner_product( const SinglePassRange1& rng1, const SinglePassRange2& rng2, Value init ) + { + boost::function_requires< SinglePassRangeConcept >(); + boost::function_requires< SinglePassRangeConcept >(); + BOOST_ASSERT( boost::distance(rng2) >= boost::distance(rng1) ); + return std::inner_product( boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), init ); + } + + template< class SinglePassRange1, + class SinglePassRange2, + class Value, + class BinaryOperation1, class BinaryOperation2 > + inline Value inner_product( const SinglePassRange1& rng1, const SinglePassRange2& rng2, + Value init, + BinaryOperation1 op1, BinaryOperation2 op2 ) + { + boost::function_requires< SinglePassRangeConcept >(); + boost::function_requires< SinglePassRangeConcept >(); + BOOST_ASSERT( boost::distance(rng2) >= boost::distance(rng1) ); + + return std::inner_product( boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), init, op1, op2 ); + } + + template< class SinglePassRange, class OutputIterator > + inline OutputIterator partial_sum ( const SinglePassRange& rng, + OutputIterator result ) + { + boost::function_requires< SinglePassRangeConcept >(); + return std::partial_sum( boost::begin(rng), boost::end(rng), result ); + } + + template< class SinglePassRange, class OutputIterator, class BinaryOperation > + inline OutputIterator partial_sum ( const SinglePassRange& rng, OutputIterator result, + BinaryOperation op ) + { + boost::function_requires< SinglePassRangeConcept >(); + return std::partial_sum( boost::begin(rng), boost::end(rng), result, op ); + } + + template< class SinglePassRange, class OutputIterator > + inline OutputIterator adjacent_difference ( const SinglePassRange& rng, + OutputIterator result ) + { + boost::function_requires< SinglePassRangeConcept >(); + return std::adjacent_difference( boost::begin(rng), boost::end(rng), + result ); + } + + template< class SinglePassRange, class OutputIterator, class BinaryOperation > + inline OutputIterator adjacent_difference ( const SinglePassRange& rng, + OutputIterator result, + BinaryOperation op ) + { + boost::function_requires< SinglePassRangeConcept >(); + return std::adjacent_difference( boost::begin(rng), boost::end(rng), + result, op ); + } + +} + +#endif diff --git a/include/boost/range/size.hpp b/include/boost/range/size.hpp old mode 100755 new mode 100644 index 311a692..2b572d4 --- a/include/boost/range/size.hpp +++ b/include/boost/range/size.hpp @@ -20,7 +20,7 @@ #include #include -namespace boost +namespace boost { template< class T > diff --git a/include/boost/range/sub_range.hpp b/include/boost/range/sub_range.hpp index dc66692..d5544b9 100644 --- a/include/boost/range/sub_range.hpp +++ b/include/boost/range/sub_range.hpp @@ -1,5 +1,6 @@ // Boost.Range library // +// Copyright Neil Groves 2009. // Copyright Thorsten Ottosen 2003-2004. Use, modification and // distribution is subject to the Boost Software License, Version // 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -11,7 +12,7 @@ #ifndef BOOST_RANGE_SUB_RANGE_HPP #define BOOST_RANGE_SUB_RANGE_HPP -#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) #pragma warning( push ) #pragma warning( disable : 4996 ) #endif @@ -22,15 +23,16 @@ #include #include #include +#include #include #include #include namespace boost { - - template< class ForwardRange > - class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > + + template< class ForwardRange > + class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME range_iterator::type > { typedef BOOST_DEDUCED_TYPENAME range_iterator::type iterator_t; typedef iterator_range< iterator_t > base; @@ -51,40 +53,40 @@ namespace boost reference >::type const_reference; public: - sub_range() : base() + sub_range() : base() + { } + +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) ) + sub_range( const sub_range& r ) + : base( static_cast( r ) ) { } - -#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) ) - sub_range( const sub_range& r ) - : base( static_cast( r ) ) - { } #endif template< class ForwardRange2 > - sub_range( ForwardRange2& r ) : - -#if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 ) - base( impl::adl_begin( r ), impl::adl_end( r ) ) -#else - base( r ) -#endif - { } - - template< class ForwardRange2 > - sub_range( const ForwardRange2& r ) : + sub_range( ForwardRange2& r ) : #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 ) base( impl::adl_begin( r ), impl::adl_end( r ) ) #else base( r ) -#endif +#endif + { } + + template< class ForwardRange2 > + sub_range( const ForwardRange2& r ) : + +#if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 ) + base( impl::adl_begin( r ), impl::adl_end( r ) ) +#else + base( r ) +#endif { } template< class Iter > sub_range( Iter first, Iter last ) : base( first, last ) { } - + template< class ForwardRange2 > sub_range& operator=( ForwardRange2& r ) { @@ -97,23 +99,23 @@ namespace boost { base::operator=( r ); return *this; - } + } sub_range& operator=( const sub_range& r ) { base::operator=( static_cast(r) ); - return *this; + return *this; } - + public: - + iterator begin() { return base::begin(); } const_iterator begin() const { return base::begin(); } iterator end() { return base::end(); } const_iterator end() const { return base::end(); } - difference_type size() const { return base::size(); } + difference_type size() const { return base::size(); } + - public: // convenience reference front() { @@ -151,14 +153,14 @@ namespace boost inline bool operator==( const sub_range& l, const sub_range& r ) { - return iterator_range_detail::equal( l, r ); + return boost::equal( l, r ); } template< class ForwardRange, class ForwardRange2 > inline bool operator!=( const sub_range& l, const sub_range& r ) { - return !iterator_range_detail::equal( l, r ); + return !boost::equal( l, r ); } template< class ForwardRange, class ForwardRange2 > @@ -171,7 +173,7 @@ namespace boost } // namespace 'boost' -#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) +#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) #pragma warning( pop ) #endif diff --git a/include/boost/range/unbounded_range.hpp b/include/boost/range/unbounded_range.hpp new file mode 100755 index 0000000..570a0a4 --- /dev/null +++ b/include/boost/range/unbounded_range.hpp @@ -0,0 +1,73 @@ +#ifndef BOOST_RANGE_UNBOUNDED_RANGE_HPP +#define BOOST_RANGE_UNBOUNDED_RANGE_HPP + +#include +#include + +namespace boost +{ + template< class Iter > + struct unbounded_iterator_range : iterator_range + { + explicit unbounded_iterator_range( Iter r ) + : iterator_range( r, r ) + { + // + // Remark: by storing the same iterator + // twice, we can still allow + // comparison to execute without leading to + // operations on singular iterators + // + } + + private: + + bool empty() const + { + return false; + } + // + // Hide members that are illegal to use. + // + /* + void end() const; + void size() const; + void empty() const; + void equal() const; + operator bool() const; + bool operator==( unbounded_iterator_range ); + bool operator!=( unbounded_iterator_range ); + template< class S > + void operator[]( S s ) const; + template< class D > + void advance_end( D d ) const; + void back() const; + */ + }; + + template< class Iter > + inline unbounded_iterator_range unbounded_range( Iter r ) + { + return unbounded_iterator_range(r); + } + + namespace detail + { + char is_unbounded_range( ... ); + template< class Iter > + long is_unbounded_range( const unbounded_iterator_range* ); + } + + template< class T > + struct is_unbounded_range + { + private: + static T* ptr_; + + public: + BOOST_STATIC_CONSTANT( bool, + value = sizeof(long) == sizeof(detail::is_unbounded_range(ptr_) ) ); + }; +} + +#endif diff --git a/index.html b/index.html index 3e5f4bb..2a17910 100644 --- a/index.html +++ b/index.html @@ -1,84 +1,13 @@ - + - + - -Boost.Range Documentation - + Boost.Range Documentation + + - - - - - -
-

Range Library

-
- -

- Copyright © 2003-2007 Thorsten Ottosen -

-

- Use, modification and distribution is subject to the Boost Software License, Version 1.0 - (see - http://www.boost.org/LICENSE_1_0.txt). -

- -

Overview

-

- Boost.Range is a collection of concepts and utilities that are particularly - useful for specifying and implementing generic algorithms. The documentation - consists of the following sections: -

- - - - -
-
-
-
-
-
-
-
-
-
-
-
- + Automatic redirection failed, please go to doc/html/index.html - - - - diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index c82a6c9..97600d5 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -1,5 +1,6 @@ # Boost.Range library # +# Copyright Neil Groves 2009 # Copyright Thorsten Ottosen 2003-2004. Use, modification and # distribution is subject to the Boost Software License, Version # 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -8,28 +9,133 @@ # For more information, see http://www.boost.org/libs/range/ # +# bring in rules for testing +import testing ; + +project + : requirements + /boost/test//boost_unit_test_framework/ + /boost/regex//boost_regex/ + static + multi + ; + rule range-test ( name : includes * ) { return [ - run $(name).cpp /boost/test//boost_unit_test_framework/static + run $(name).cpp /boost/test//boost_unit_test_framework /boost/regex//boost_regex/static + : : - : : gcc:"-Wall -Wunused " ] ; } test-suite range : - [ range-test array ] - [ range-test iterator_pair ] - [ range-test std_container ] - [ range-test string ] - [ range-test iterator_range ] - [ range-test sub_range ] - [ range-test partial_workaround ] - [ range-test algorithm_example ] - [ range-test reversible_range ] - [ range-test const_ranges ] - [ range-test extension_mechanism ] -# [ range-test mfc : $(VC71_ROOT)/atlmfc/include ] + [ range-test adaptor_test/adjacent_filtered ] + [ range-test adaptor_test/copied ] + [ range-test adaptor_test/filtered ] + [ range-test adaptor_test/indexed ] + [ range-test adaptor_test/indirected ] + [ range-test adaptor_test/map ] + [ range-test adaptor_test/replaced ] + [ range-test adaptor_test/replaced_if ] + [ range-test adaptor_test/reversed ] + [ range-test adaptor_test/sliced ] + [ range-test adaptor_test/strided ] + [ range-test adaptor_test/tokenized ] + [ range-test adaptor_test/transformed ] + [ range-test adaptor_test/uniqued ] + [ range-test adaptor_test/adjacent_filtered_example ] + [ range-test adaptor_test/copied_example ] + [ range-test adaptor_test/filtered_example ] + [ range-test adaptor_test/indexed_example ] + [ range-test adaptor_test/indirected_example ] + [ range-test adaptor_test/map_keys_example ] + [ range-test adaptor_test/map_values_example ] + [ range-test adaptor_test/replaced_example ] + [ range-test adaptor_test/replaced_if_example ] + [ range-test adaptor_test/reversed_example ] + [ range-test adaptor_test/sliced_example ] + [ range-test adaptor_test/strided_example ] + [ range-test adaptor_test/transformed_example ] + [ range-test adaptor_test/uniqued_example ] + [ range-test algorithm_test/adjacent_find ] + [ range-test algorithm_test/binary_search ] + [ range-test algorithm_test/copy ] + [ range-test algorithm_test/copy_backward ] + [ range-test algorithm_test/count ] + [ range-test algorithm_test/count_if ] + [ range-test algorithm_test/equal ] + [ range-test algorithm_test/equal_range ] + [ range-test algorithm_test/fill ] + [ range-test algorithm_test/find ] + [ range-test algorithm_test/find_if ] + [ range-test algorithm_test/find_end ] + [ range-test algorithm_test/find_first_of ] + [ range-test algorithm_test/for_each ] + [ range-test algorithm_test/generate ] + [ range-test algorithm_test/heap ] + [ range-test algorithm_test/includes ] + [ range-test algorithm_test/inplace_merge ] + [ range-test algorithm_test/lexicographical_compare ] + [ range-test algorithm_test/lower_bound ] + [ range-test algorithm_test/max_element ] + [ range-test algorithm_test/merge ] + [ range-test algorithm_test/min_element ] + [ range-test algorithm_test/mismatch ] + [ range-test algorithm_test/next_permutation ] + [ range-test algorithm_test/nth_element ] + [ range-test algorithm_test/partial_sort ] + [ range-test algorithm_test/partition ] + [ range-test algorithm_test/prev_permutation ] + [ range-test algorithm_test/random_shuffle ] + [ range-test algorithm_test/remove ] + [ range-test algorithm_test/remove_if ] + [ range-test algorithm_test/replace ] + [ range-test algorithm_test/replace_if ] + [ range-test algorithm_test/reverse ] + [ range-test algorithm_test/rotate ] + [ range-test algorithm_test/search ] + [ range-test algorithm_test/set_difference ] + [ range-test algorithm_test/set_intersection ] + [ range-test algorithm_test/set_symmetric_difference ] + [ range-test algorithm_test/set_union ] + [ range-test algorithm_test/sort ] + [ range-test algorithm_test/stable_partition ] + [ range-test algorithm_test/stable_sort ] + [ range-test algorithm_test/transform ] + [ range-test algorithm_test/unique ] + [ range-test algorithm_test/upper_bound ] + [ range-test algorithm_ext_test/copy_n ] + [ range-test algorithm_ext_test/erase ] + [ range-test algorithm_ext_test/for_each_ext ] + [ range-test algorithm_ext_test/insert ] + [ range-test algorithm_ext_test/iota ] + [ range-test algorithm_ext_test/is_sorted ] + [ range-test algorithm_ext_test/overwrite ] + [ range-test algorithm_ext_test/push_back ] + [ range-test algorithm_ext_test/push_front ] + [ range-test adl_conformance ] + [ range-test adl_conformance_no_using ] + [ range-test algorithm ] + [ range-test algorithm_example ] + [ range-test array ] +# [ range-test atl : $(VC71_ROOT)/atlmfc/include ] + [ range-test combine ] + [ range-test compat2 ] + [ range-test compat3 ] + [ range-test const_ranges ] + [ range-test counting_range ] + [ range-test extension_mechanism ] + [ range-test irange ] + [ range-test iterator_pair ] + [ range-test iterator_range ] +# [ range-test mfc : $(VC71_ROOT)/atlmfc/include ] + [ range-test join ] + [ range-test partial_workaround ] + [ range-test reversible_range ] + [ range-test std_container ] + [ range-test string ] + [ range-test sub_range ] ; diff --git a/test/adaptor_test/adjacent_filtered.cpp b/test/adaptor_test/adjacent_filtered.cpp new file mode 100644 index 0000000..48025ab --- /dev/null +++ b/test/adaptor_test/adjacent_filtered.cpp @@ -0,0 +1,110 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container > + void adjacent_filtered_test_impl( Container& c ) + { + using namespace boost::adaptors; + + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + // This is my preferred syntax using the | operator. + std::vector< value_t > test_result1 + = boost::copy_range< std::vector< value_t > >( + c | adjacent_filtered(std::not_equal_to< value_t >())); + + // This is an alternative syntax preferred by some. + std::vector< value_t > test_result2 + = boost::copy_range< std::vector< value_t > >( + adaptors::adjacent_filter(c, std::not_equal_to< value_t >())); + + // Calculate the reference result. + std::vector< value_t > reference_result; + typedef BOOST_DEDUCED_TYPENAME Container::const_iterator iter_t; + value_t prev_v = value_t(); + for (iter_t it = c.begin(); it != c.end(); ++it) + { + if (it == c.begin()) + { + reference_result.push_back(*it); + } + else if (*it != prev_v) + { + reference_result.push_back(*it); + } + prev_v = *it; + } + + BOOST_CHECK_EQUAL_COLLECTIONS( reference_result.begin(), + reference_result.end(), + test_result1.begin(), + test_result1.end() ); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference_result.begin(), + reference_result.end(), + test_result2.begin(), + test_result2.end() ); + } + + template< class Collection > + void adjacent_filtered_test_impl() + { + using namespace boost::assign; + + Collection c; + + // test empty collection + adjacent_filtered_test_impl(c); + + // test one element; + c += 1; + adjacent_filtered_test_impl(c); + + // test many elements; + c += 1,2,2,2,3,4,4,4,4,5,6,7,8,9,9; + adjacent_filtered_test_impl(c); + } + + void adjacent_filtered_test() + { + adjacent_filtered_test_impl< std::vector< int > >(); + adjacent_filtered_test_impl< std::list< int > >(); + adjacent_filtered_test_impl< std::set< int > >(); + adjacent_filtered_test_impl< std::multiset< int > >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.adjacent_filtered" ); + + test->add( BOOST_TEST_CASE( &boost::adjacent_filtered_test ) ); + + return test; +} diff --git a/test/adaptor_test/adjacent_filtered_example.cpp b/test/adaptor_test/adjacent_filtered_example.cpp new file mode 100644 index 0000000..b3538e8 --- /dev/null +++ b/test/adaptor_test/adjacent_filtered_example.cpp @@ -0,0 +1,58 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +namespace +{ + void adjacent_filtered_example_test() + { + using namespace boost::assign; + using namespace boost::adaptors; + + std::vector input; + input += 1,1,2,2,2,3,4,5,6; + + boost::copy( + input | adjacent_filtered(std::not_equal_to()), + std::ostream_iterator(std::cout, ",")); + + std::vector reference; + reference += 1,2,3,4,5,6; + + std::vector test; + boost::push_back(test, input | adjacent_filtered(std::not_equal_to())); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.adjacent_filtered_example" ); + + test->add( BOOST_TEST_CASE( &adjacent_filtered_example_test ) ); + + return test; +} \ No newline at end of file diff --git a/test/adaptor_test/copied.cpp b/test/adaptor_test/copied.cpp new file mode 100644 index 0000000..93f1cb7 --- /dev/null +++ b/test/adaptor_test/copied.cpp @@ -0,0 +1,84 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container > + void copied_test_impl( Container& c ) + { + using namespace boost::adaptors; + + // This is my preferred syntax using the | operator. + std::vector< int > test_result1; + boost::push_back(test_result1, c | copied(0u, c.size())); + + // This is the alternative syntax preferred by some. + std::vector< int > test_result2; + boost::push_back(test_result2, adaptors::copy(c, 0u, c.size())); + + BOOST_CHECK_EQUAL_COLLECTIONS( test_result1.begin(), test_result1.end(), + c.begin(), c.end() ); + + BOOST_CHECK_EQUAL_COLLECTIONS( test_result2.begin(), test_result2.end(), + c.begin(), c.end() ); + } + + template< class Container > + void copied_test_impl() + { + using namespace boost::assign; + + Container c; + + // test empty collection + copied_test_impl(c); + + // test one element + c += 1; + copied_test_impl(c); + + // test many elements + c += 1,2,2,2,3,4,4,4,4,5,6,7,8,9,9; + copied_test_impl(c); + } + + void copied_test() + { + copied_test_impl< std::vector< int > >(); + copied_test_impl< std::deque< int > >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.copied" ); + + test->add( BOOST_TEST_CASE( &boost::copied_test ) ); + + return test; +} diff --git a/test/adaptor_test/copied_example.cpp b/test/adaptor_test/copied_example.cpp new file mode 100644 index 0000000..f662a45 --- /dev/null +++ b/test/adaptor_test/copied_example.cpp @@ -0,0 +1,58 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 +#include +#include +#include +#include +#include + +#include + +#include +#include + +namespace +{ + void copied_example_test() + { + using namespace boost::assign; + using namespace boost::adaptors; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9,10; + + boost::copy( + input | copied(1, 5), + std::ostream_iterator(std::cout, ",")); + + + std::vector reference; + reference += 2,3,4,5; + + std::vector test; + boost::push_back(test, input | copied(1, 5)); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.copied_example" ); + + test->add( BOOST_TEST_CASE( &copied_example_test ) ); + + return test; +} \ No newline at end of file diff --git a/test/adaptor_test/filtered.cpp b/test/adaptor_test/filtered.cpp new file mode 100644 index 0000000..8e7b958 --- /dev/null +++ b/test/adaptor_test/filtered.cpp @@ -0,0 +1,135 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + struct always_false_pred + { + template< class T1 > + bool operator()(T1) const { return false; } + }; + + struct always_true_pred + { + template< class T1 > + bool operator()(T1) const { return true; } + }; + + struct is_even + { + template< class IntegerT > + bool operator()( IntegerT x ) const { return x % 2 == 0; } + }; + + struct is_odd + { + template< class IntegerT > + bool operator()( IntegerT x ) const { return x % 2 != 0; } + }; + + template< class Container, class Pred > + void filtered_test_impl( Container& c, Pred pred ) + { + using namespace boost::adaptors; + + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + // This is my preferred syntax using the | operator. + std::vector< value_t > test_result1; + boost::push_back(test_result1, c | filtered(pred)); + + // This is an alternative syntax preferred by some. + std::vector< value_t > test_result2; + boost::push_back(test_result2, adaptors::filter(c, pred)); + + // Calculate the reference result. + std::vector< value_t > reference_result; + typedef BOOST_DEDUCED_TYPENAME Container::const_iterator iter_t; + for (iter_t it = c.begin(); it != c.end(); ++it) + { + if (pred(*it)) + reference_result.push_back(*it); + } + + BOOST_CHECK_EQUAL_COLLECTIONS( reference_result.begin(), + reference_result.end(), + test_result1.begin(), + test_result1.end() ); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference_result.begin(), + reference_result.end(), + test_result2.begin(), + test_result2.end() ); + } + + template< class Container, class Pred > + void filtered_test_impl() + { + using namespace boost::assign; + + Container c; + + // test empty container + filtered_test_impl(c, Pred()); + + // test one element + c += 1; + filtered_test_impl(c, Pred()); + + // test many elements + c += 1,2,2,2,3,4,4,4,4,5,6,7,8,9,9; + filtered_test_impl(c, Pred()); + } + + template< class Container > + void filtered_test_all_predicates() + { + filtered_test_impl< Container, always_false_pred >(); + filtered_test_impl< Container, always_true_pred >(); + filtered_test_impl< Container, is_odd >(); + filtered_test_impl< Container, is_even >(); + } + + void filtered_test() + { + filtered_test_all_predicates< std::vector< int > >(); + filtered_test_all_predicates< std::list< int > >(); + filtered_test_all_predicates< std::set< int > >(); + filtered_test_all_predicates< std::multiset< int > >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.filtered" ); + + test->add( BOOST_TEST_CASE( &boost::filtered_test ) ); + + return test; +} diff --git a/test/adaptor_test/filtered_example.cpp b/test/adaptor_test/filtered_example.cpp new file mode 100644 index 0000000..6d0e262 --- /dev/null +++ b/test/adaptor_test/filtered_example.cpp @@ -0,0 +1,62 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace +{ + struct is_even + { + bool operator()( int x ) const { return x % 2 == 0; } + }; + + void filtered_example_test() + { + using namespace boost::assign; + using namespace boost::adaptors; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9; + + boost::copy( + input | filtered(is_even()), + std::ostream_iterator(std::cout, ",")); + + std::vector reference; + reference += 2,4,6,8; + + std::vector test; + boost::push_back(test, input | filtered(is_even())); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.filtered_example" ); + + test->add( BOOST_TEST_CASE( &filtered_example_test ) ); + + return test; +} diff --git a/test/adaptor_test/indexed.cpp b/test/adaptor_test/indexed.cpp new file mode 100644 index 0000000..2a9c45d --- /dev/null +++ b/test/adaptor_test/indexed.cpp @@ -0,0 +1,99 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include + +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container > + void indexed_test_impl( Container& c ) + { + using namespace boost::adaptors; + + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + // This is my preferred syntax using the | operator. + std::vector< value_t > test_result1; + boost::push_back(test_result1, c | indexed(0)); + + // This is an alternative syntax preferred by some. + std::vector< value_t > test_result2; + boost::push_back(test_result2, adaptors::index(c, 0)); + + BOOST_CHECK_EQUAL_COLLECTIONS( c.begin(), c.end(), + test_result1.begin(), test_result1.end() ); + + BOOST_CHECK_EQUAL_COLLECTIONS( c.begin(), c.end(), + test_result2.begin(), test_result2.end() ); + + boost::indexed_range< Container > test_result3 + = c | indexed(0); + + typedef BOOST_DEDUCED_TYPENAME boost::range_const_iterator< + boost::indexed_range< Container > >::type iter_t; + + iter_t it = test_result3.begin(); + for (std::size_t i = 0, count = c.size(); i < count; ++i) + { + BOOST_CHECK_EQUAL( i, static_cast(it.index()) ); + ++it; + } + + } + + template< class Container > + void indexed_test_impl() + { + using namespace boost::assign; + + Container c; + + // test empty container + indexed_test_impl(c); + + // test one element + c += 1; + indexed_test_impl(c); + + // test many elements + c += 1,2,2,2,3,4,4,4,4,5,6,7,8,9,9; + indexed_test_impl(c); + } + + void indexed_test() + { + indexed_test_impl< std::vector< int > >(); + indexed_test_impl< std::list< int > >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.indexed" ); + + test->add( BOOST_TEST_CASE( &boost::indexed_test ) ); + + return test; +} diff --git a/test/adaptor_test/indexed_example.cpp b/test/adaptor_test/indexed_example.cpp new file mode 100644 index 0000000..14837d2 --- /dev/null +++ b/test/adaptor_test/indexed_example.cpp @@ -0,0 +1,95 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace +{ + template + void display_element_and_index(Iterator first, Iterator last) + { + for (Iterator it = first; it != last; ++it) + { + std::cout << "Element = " << *it << " Index = " << it.index() << std::endl; + } + } + + template + void display_element_and_index(const SinglePassRange& rng) + { + display_element_and_index(boost::begin(rng), boost::end(rng)); + } + + template + void check_element_and_index( + Iterator1 test_first, + Iterator1 test_last, + Iterator2 reference_first, + Iterator2 reference_last) + { + BOOST_CHECK_EQUAL( std::distance(test_first, test_last), + std::distance(reference_first, reference_last) ); + + int reference_index = 0; + + Iterator1 test_it = test_first; + Iterator2 reference_it = reference_first; + for (; test_it != test_last; ++test_it, ++reference_it, ++reference_index) + { + BOOST_CHECK_EQUAL( *test_it, *reference_it ); + BOOST_CHECK_EQUAL( test_it.index(), reference_index ); + } + } + + template + void check_element_and_index( + const SinglePassRange1& test_rng, + const SinglePassRange2& reference_rng) + { + check_element_and_index(boost::begin(test_rng), boost::end(test_rng), + boost::begin(reference_rng), boost::end(reference_rng)); + } + + void indexed_example_test() + { + using namespace boost::assign; + using namespace boost::adaptors; + + std::vector input; + input += 10,20,30,40,50,60,70,80,90; + + display_element_and_index( input | indexed(0) ); + + check_element_and_index( + input | indexed(0), + input); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.indexed_example" ); + + test->add( BOOST_TEST_CASE( &indexed_example_test ) ); + + return test; +} diff --git a/test/adaptor_test/indirected.cpp b/test/adaptor_test/indirected.cpp new file mode 100644 index 0000000..fe3ebdf --- /dev/null +++ b/test/adaptor_test/indirected.cpp @@ -0,0 +1,99 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +namespace boost +{ + namespace + { + + template< class Container > + void indirected_test_impl( Container& c ) + { + using namespace boost::adaptors; + + // This is my preferred syntax using the | operator. + std::vector< int > test_result1; + boost::push_back(test_result1, c | indirected); + + // This is an alternative syntax preferred by some. + std::vector< int > test_result2; + boost::push_back(test_result2, adaptors::indirect(c)); + + // Calculate the reference result. + std::vector< int > reference_result; + typedef BOOST_DEDUCED_TYPENAME Container::const_iterator iter_t; + for (iter_t it = c.begin(); it != c.end(); ++it) + { + reference_result.push_back(**it); + } + + BOOST_CHECK_EQUAL_COLLECTIONS( reference_result.begin(), + reference_result.end(), + test_result1.begin(), + test_result1.end() ); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference_result.begin(), + reference_result.end(), + test_result2.begin(), + test_result2.end() ); + } + + template< class Container > + void indirected_test_impl() + { + using namespace boost::assign; + + Container c; + + indirected_test_impl(c); + + c += boost::shared_ptr(new int(1)); + indirected_test_impl(c); + + std::vector v; + v += 1,1,2,2,2,3,4,4,4,4,5,6,7,8,9,9; + for (std::vector::const_iterator it = v.begin(); it != v.end(); ++it) + { + c += boost::shared_ptr(new int(*it)); + } + indirected_test_impl(c); + } + + void indirected_test() + { + indirected_test_impl< std::vector< boost::shared_ptr< int > > >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.indirected" ); + + test->add( BOOST_TEST_CASE( &boost::indirected_test ) ); + + return test; +} diff --git a/test/adaptor_test/indirected_example.cpp b/test/adaptor_test/indirected_example.cpp new file mode 100644 index 0000000..8e607a6 --- /dev/null +++ b/test/adaptor_test/indirected_example.cpp @@ -0,0 +1,60 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace +{ + void indirected_example_test() + { + using namespace boost::adaptors; + + std::vector > input; + + for (int i = 0; i < 10; ++i) + input.push_back(boost::shared_ptr(new int(i))); + + boost::copy( + input | indirected, + std::ostream_iterator(std::cout, ",")); + + + std::vector reference; + for (int i = 0; i < 10; ++i) + reference.push_back(i); + + std::vector test; + boost::push_back(test, input | indirected); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.indirected_example" ); + + test->add( BOOST_TEST_CASE( &indirected_example_test ) ); + + return test; +} diff --git a/test/adaptor_test/map.cpp b/test/adaptor_test/map.cpp new file mode 100644 index 0000000..73859b4 --- /dev/null +++ b/test/adaptor_test/map.cpp @@ -0,0 +1,127 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include + +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container > + void map_test_keys( Container& c ) + { + using namespace boost::adaptors; + + std::vector keys; + boost::push_back(keys, c | map_keys); + + std::vector keys2; + boost::push_back(keys2, adaptors::keys(c)); + + std::vector reference_keys; + typedef BOOST_DEDUCED_TYPENAME Container::const_iterator iter_t; + for (iter_t it = c.begin(); it != c.end(); ++it) + { + reference_keys.push_back(it->first); + } + + BOOST_CHECK_EQUAL_COLLECTIONS( reference_keys.begin(), + reference_keys.end(), + keys.begin(), + keys.end() ); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference_keys.begin(), + reference_keys.end(), + keys2.begin(), + keys2.end() ); + } + + template< class Container > + void map_test_values( Container& c ) + { + using namespace boost::adaptors; + + std::vector values; + boost::push_back(values, c | map_values); + + std::vector values2; + boost::push_back(values2, adaptors::values(c)); + + std::vector reference_values; + typedef BOOST_DEDUCED_TYPENAME Container::const_iterator iter_t; + for (iter_t it = c.begin(); it != c.end(); ++it) + { + reference_values.push_back(it->second); + } + + BOOST_CHECK_EQUAL_COLLECTIONS( reference_values.begin(), + reference_values.end(), + values.begin(), + values.end() ); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference_values.begin(), + reference_values.end(), + values2.begin(), + values2.end() ); + } + + template< class Container > + void map_test_impl() + { + using namespace boost::assign; + + Container c; + + // Test empty + map_test_keys(c); + map_test_values(c); + + // Test one element + c.insert(std::make_pair(1,2)); + map_test_keys(c); + map_test_values(c); + + // Test many elements + for (int x = 2; x < 10; ++x) + { + c.insert(std::make_pair(x, x * 2)); + } + map_test_keys(c); + map_test_values(c); + } + + void map_test() + { + map_test_impl< std::map >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.map" ); + + test->add( BOOST_TEST_CASE( &boost::map_test ) ); + + return test; +} diff --git a/test/adaptor_test/map_keys_example.cpp b/test/adaptor_test/map_keys_example.cpp new file mode 100644 index 0000000..df85456 --- /dev/null +++ b/test/adaptor_test/map_keys_example.cpp @@ -0,0 +1,60 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace +{ + void map_keys_example_test() + { + using namespace boost::assign; + using namespace boost::adaptors; + + std::map input; + for (int i = 0; i < 10; ++i) + input.insert(std::make_pair(i, i * 10)); + + boost::copy( + input | map_keys, + std::ostream_iterator(std::cout, ",")); + + + std::vector reference; + reference += 0,1,2,3,4,5,6,7,8,9; + + std::vector test; + boost::push_back(test, input | map_keys); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.map_keys_example" ); + + test->add( BOOST_TEST_CASE( &map_keys_example_test ) ); + + return test; +} diff --git a/test/adaptor_test/map_values_example.cpp b/test/adaptor_test/map_values_example.cpp new file mode 100644 index 0000000..dfb32e9 --- /dev/null +++ b/test/adaptor_test/map_values_example.cpp @@ -0,0 +1,60 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace +{ + void map_values_example_test() + { + using namespace boost::assign; + using namespace boost::adaptors; + + std::map input; + for (int i = 0; i < 10; ++i) + input.insert(std::make_pair(i, i * 10)); + + boost::copy( + input | map_values, + std::ostream_iterator(std::cout, ",")); + + + std::vector reference; + reference += 0,10,20,30,40,50,60,70,80,90; + + std::vector test; + boost::push_back(test, input | map_values); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.map_values_example" ); + + test->add( BOOST_TEST_CASE( &map_values_example_test ) ); + + return test; +} diff --git a/test/adaptor_test/replaced.cpp b/test/adaptor_test/replaced.cpp new file mode 100644 index 0000000..d3eac81 --- /dev/null +++ b/test/adaptor_test/replaced.cpp @@ -0,0 +1,87 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include + +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container > + void replaced_test_impl( Container& c ) + { + using namespace boost::adaptors; + + const int value_to_replace = 1; + const int replacement_value = 0; + + std::vector< int > test_result1; + boost::push_back(test_result1, c | replaced(value_to_replace, replacement_value)); + + std::vector< int > test_result2; + boost::push_back(test_result2, adaptors::replace(c, value_to_replace, replacement_value)); + + std::vector< int > reference( c.begin(), c.end() ); + std::replace(reference.begin(), reference.end(), value_to_replace, replacement_value); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test_result1.begin(), test_result1.end() ); + } + + template< class Container > + void replaced_test_impl() + { + using namespace boost::assign; + + Container c; + + // Test empty + replaced_test_impl(c); + + // Test one + c += 1; + replaced_test_impl(c); + + // Test many + c += 1,1,1,2,2,2,3,3,3,3,3,4,5,6,6,6,7,8,9; + replaced_test_impl(c); + } + + void replaced_test() + { + replaced_test_impl< std::vector< int > >(); + replaced_test_impl< std::list< int > >(); + replaced_test_impl< std::set< int > >(); + replaced_test_impl< std::multiset< int > >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.replaced" ); + + test->add( BOOST_TEST_CASE( &boost::replaced_test ) ); + + return test; +} diff --git a/test/adaptor_test/replaced_example.cpp b/test/adaptor_test/replaced_example.cpp new file mode 100644 index 0000000..fc1d2db --- /dev/null +++ b/test/adaptor_test/replaced_example.cpp @@ -0,0 +1,58 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace +{ + void replaced_example_test() + { + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,2,5,2,7,2,9; + + boost::copy( + input | replaced(2, 10), + std::ostream_iterator(std::cout, ",")); + + + std::vector reference; + reference += 1,10,3,10,5,10,7,10,9; + + std::vector test; + boost::push_back(test, input | replaced(2, 10)); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.replaced_example" ); + + test->add( BOOST_TEST_CASE( &replaced_example_test ) ); + + return test; +} diff --git a/test/adaptor_test/replaced_if.cpp b/test/adaptor_test/replaced_if.cpp new file mode 100644 index 0000000..0bf227f --- /dev/null +++ b/test/adaptor_test/replaced_if.cpp @@ -0,0 +1,96 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include + +#include +#include +#include +#include + +namespace boost +{ + namespace + { + struct if_value_is_one + { + bool operator()(int x) const { return x == 1; } + }; + + template< class Container > + void replaced_if_test_impl( Container& c ) + { + using namespace boost::adaptors; + + if_value_is_one pred; + + const int replacement_value = 0; + + std::vector< int > test_result1; + boost::push_back(test_result1, c | replaced_if(pred, replacement_value)); + + std::vector< int > test_result2; + boost::push_back(test_result2, boost::adaptors::replace_if(c, pred, replacement_value)); + + std::vector< int > reference( c.begin(), c.end() ); + std::replace_if(reference.begin(), reference.end(), pred, replacement_value); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test_result1.begin(), test_result1.end() ); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test_result2.begin(), test_result2.end() ); + } + + template< class Container > + void replaced_if_test_impl() + { + using namespace boost::assign; + + Container c; + + // Test empty + replaced_if_test_impl(c); + + // Test one + c += 1; + replaced_if_test_impl(c); + + // Test many + c += 1,1,1,2,2,2,3,3,3,3,3,4,5,6,6,6,7,8,9; + replaced_if_test_impl(c); + } + + void replaced_if_test() + { + replaced_if_test_impl< std::vector< int > >(); + replaced_if_test_impl< std::list< int > >(); + replaced_if_test_impl< std::set< int > >(); + replaced_if_test_impl< std::multiset< int > >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.replaced_if" ); + + test->add( BOOST_TEST_CASE( &boost::replaced_if_test ) ); + + return test; +} diff --git a/test/adaptor_test/replaced_if_example.cpp b/test/adaptor_test/replaced_if_example.cpp new file mode 100644 index 0000000..c762c2f --- /dev/null +++ b/test/adaptor_test/replaced_if_example.cpp @@ -0,0 +1,62 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace +{ + struct is_even + { + bool operator()(int x) const { return x % 2 == 0; } + }; + + void replaced_if_example_test() + { + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9; + + boost::copy( + input | replaced_if(is_even(), 10), + std::ostream_iterator(std::cout, ",")); + + std::vector reference; + reference += 1,10,3,10,5,10,7,10,9; + + std::vector test; + boost::push_back(test, input | replaced_if(is_even(), 10)); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.replaced_if_example" ); + + test->add( BOOST_TEST_CASE( &replaced_if_example_test ) ); + + return test; +} diff --git a/test/adaptor_test/reversed.cpp b/test/adaptor_test/reversed.cpp new file mode 100644 index 0000000..6663b36 --- /dev/null +++ b/test/adaptor_test/reversed.cpp @@ -0,0 +1,84 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include + +#include +#include +#include +#include + +namespace boost +{ + template< class Container > + void reversed_test_impl( Container& c ) + { + using namespace boost::adaptors; + + std::vector< int > test_result1; + boost::push_back(test_result1, c | reversed); + + std::vector< int > test_result2; + boost::push_back(test_result2, adaptors::reverse(c)); + + std::vector< int > reference( c.rbegin(), c.rend() ); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test_result1.begin(), test_result1.end() ); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test_result2.begin(), test_result2.end() ); + } + + template< class Container > + void reversed_test_impl() + { + using namespace boost::assign; + + Container c; + + // Test empty + reversed_test_impl(c); + + // Test one + c += 1; + reversed_test_impl(c); + + // Test many + c += 1,1,1,2,2,2,2,2,3,3,3,3,3,3,4,5,6,7,8,9; + reversed_test_impl(c); + } + + void reversed_test() + { + reversed_test_impl< std::vector< int > >(); + reversed_test_impl< std::list< int > >(); + reversed_test_impl< std::set< int > >(); + reversed_test_impl< std::multiset< int > >(); + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.reversed" ); + + test->add( BOOST_TEST_CASE( &boost::reversed_test ) ); + + return test; +} diff --git a/test/adaptor_test/reversed_example.cpp b/test/adaptor_test/reversed_example.cpp new file mode 100644 index 0000000..553e7d7 --- /dev/null +++ b/test/adaptor_test/reversed_example.cpp @@ -0,0 +1,55 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace +{ + void reversed_example_test() + { + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9; + + boost::copy( + input | reversed, + std::ostream_iterator(std::cout, ",")); + + + std::vector test; + boost::push_back(test, input | reversed); + + BOOST_CHECK_EQUAL_COLLECTIONS( input.rbegin(), input.rend(), + test.begin(), test.end() ); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.reversed_example" ); + + test->add( BOOST_TEST_CASE( &reversed_example_test ) ); + + return test; +} diff --git a/test/adaptor_test/sliced.cpp b/test/adaptor_test/sliced.cpp new file mode 100644 index 0000000..f2221f6 --- /dev/null +++ b/test/adaptor_test/sliced.cpp @@ -0,0 +1,99 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include + +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container > + void sliced_test_impl( Container& c ) + { + using namespace boost::adaptors; + + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + std::vector< value_t > test_result1; + boost::push_back(test_result1, c | sliced(0u,c.size())); + + BOOST_CHECK_EQUAL_COLLECTIONS( test_result1.begin(), test_result1.end(), + c.begin(), c.end() ); + + std::vector< value_t > test_alt_result1; + boost::push_back(test_alt_result1, adaptors::slice(c, 0u, c.size())); + BOOST_CHECK_EQUAL_COLLECTIONS( test_alt_result1.begin(), test_alt_result1.end(), + c.begin(), c.end() ); + + BOOST_CHECK( boost::empty(c | sliced(0u, 0u)) ); + + const std::size_t half_count = c.size() / 2u; + if (half_count > 0u) + { + std::vector< value_t > test_result2; + boost::push_back(test_result2, c | sliced(0u, half_count)); + + BOOST_CHECK_EQUAL_COLLECTIONS( test_result2.begin(), test_result2.end(), + c.begin(), c.begin() + half_count ); + + std::vector< value_t > test_alt_result2; + boost::push_back(test_alt_result2, adaptors::slice(c, 0u, half_count)); + BOOST_CHECK_EQUAL_COLLECTIONS( test_alt_result2.begin(), test_alt_result2.end(), + c.begin(), c.begin() + half_count ); + } + } + + template< class Container > + void sliced_test_impl() + { + using namespace boost::assign; + + Container c; + + // Test empty + sliced_test_impl(c); + + // Test one element + c += 1; + sliced_test_impl(c); + + // Test many elements + c += 1,1,1,2,2,3,4,5,6,6,6,7,8,9; + sliced_test_impl(c); + } + + void sliced_test() + { + sliced_test_impl< std::vector< int > >(); + sliced_test_impl< std::deque< int > >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.sliced" ); + + test->add( BOOST_TEST_CASE( &boost::sliced_test ) ); + + return test; +} diff --git a/test/adaptor_test/sliced_example.cpp b/test/adaptor_test/sliced_example.cpp new file mode 100644 index 0000000..5761844 --- /dev/null +++ b/test/adaptor_test/sliced_example.cpp @@ -0,0 +1,58 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace +{ + void sliced_example_test() + { + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9; + + boost::copy( + input | sliced(2, 5), + std::ostream_iterator(std::cout, ",")); + + + std::vector reference; + reference += 3,4,5; + + std::vector test; + boost::push_back(test, input | sliced(2, 5)); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.sliced_example" ); + + test->add( BOOST_TEST_CASE( &sliced_example_test ) ); + + return test; +} diff --git a/test/adaptor_test/strided.cpp b/test/adaptor_test/strided.cpp new file mode 100644 index 0000000..e09e0fb --- /dev/null +++ b/test/adaptor_test/strided.cpp @@ -0,0 +1,111 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include + +#include +#include +#include + +namespace boost +{ + namespace + { + const int STRIDE_SIZE = 2; + + template< class Container > + void strided_test_impl( Container& c ) + { + using namespace boost::adaptors; + + BOOST_ASSERT( c.size() % STRIDE_SIZE == 0 ); + + Container reference; + + { + typedef BOOST_DEDUCED_TYPENAME Container::const_iterator iterator_t; + iterator_t it = c.begin(); + for (iterator_t last = c.end(); + it != last; it += STRIDE_SIZE) + { + reference.push_back(*it); + } + } + + Container test; + boost::push_back( test, c | strided(2) ); + + BOOST_CHECK_EQUAL_COLLECTIONS( test.begin(), test.end(), + reference.begin(), reference.end() ); + + Container test2; + boost::push_back( test2, adaptors::stride(c, 2) ); + + BOOST_CHECK_EQUAL_COLLECTIONS( test2.begin(), test2.end(), + reference.begin(), reference.end() ); + + // Test the const versions: + const Container& cc = c; + Container test3; + boost::push_back( test3, cc | strided(2) ); + + BOOST_CHECK_EQUAL_COLLECTIONS( test3.begin(), test3.end(), + reference.begin(), reference.end() ); + + Container test4; + boost::push_back( test4, adaptors::stride(cc, 2) ); + + BOOST_CHECK_EQUAL_COLLECTIONS( test4.begin(), test4.end(), + reference.begin(), reference.end() ); + } + + template< class Container > + void strided_test_impl() + { + using namespace boost::assign; + + Container c; + + // Test empty + strided_test_impl(c); + + // Test two elements + c += 1,2; + strided_test_impl(c); + + // Test many elements + c += 1,1,1,2,2,3,4,5,6,6,6,7,8,9; + strided_test_impl(c); + } + + void strided_test() + { + strided_test_impl< std::vector< int > >(); + strided_test_impl< std::deque< int > >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.strided" ); + + test->add( BOOST_TEST_CASE( &boost::strided_test ) ); + + return test; +} diff --git a/test/adaptor_test/strided_example.cpp b/test/adaptor_test/strided_example.cpp new file mode 100644 index 0000000..5754c53 --- /dev/null +++ b/test/adaptor_test/strided_example.cpp @@ -0,0 +1,58 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace +{ + void strided_example_test() + { + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9,10; + + boost::copy( + input | strided(2), + std::ostream_iterator(std::cout, ",")); + + + std::vector reference; + reference += 1,3,5,7,9; + + std::vector test; + boost::push_back(test, input | strided(2)); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.strided_example" ); + + test->add( BOOST_TEST_CASE( &strided_example_test ) ); + + return test; +} diff --git a/test/adaptor_test/tokenized.cpp b/test/adaptor_test/tokenized.cpp new file mode 100644 index 0000000..8180747 --- /dev/null +++ b/test/adaptor_test/tokenized.cpp @@ -0,0 +1,79 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include + +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Iterator, class Container > + void tokenized_test_impl( Container& c, std::size_t expected_result ) + { + using namespace boost::adaptors; + + std::vector< boost::sub_match< Iterator > > test_result1; + boost::push_back(test_result1, c | tokenized(boost::regex("\\b"))); + + BOOST_CHECK_EQUAL( test_result1.size(), expected_result ); + +// std::vector< boost::sub_match< Iterator > > test_result2; +// boost::push_back(test_result2, adaptors::tokenize(c, boost::regex("\\b"))); + +// BOOST_CHECK_EQUAL( test_result2.size(), expected_result ); + } + + template< class Container1, class Container2 > + void tokenized_test_impl() + { + Container1 c; + Container2& r = c; + + typedef typename boost::range_iterator::type It; + + // Test empty + tokenized_test_impl(r, 0u); + + // Test one element + c = "a"; + tokenized_test_impl(r, 2u); + + // Test many elements + c = "a b c d e f g hijlmnopqrstuvwxyz"; + tokenized_test_impl(r, 16u); + } + + void tokenized_test() + { +// tokenized_test_impl(); + tokenized_test_impl(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.tokenized" ); + + test->add( BOOST_TEST_CASE( &boost::tokenized_test ) ); + + return test; +} diff --git a/test/adaptor_test/transformed.cpp b/test/adaptor_test/transformed.cpp new file mode 100644 index 0000000..6b6121e --- /dev/null +++ b/test/adaptor_test/transformed.cpp @@ -0,0 +1,107 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include + +#include +#include +#include +#include + +namespace boost +{ + namespace + { + struct double_x + { + typedef int result_type; + int operator()(int x) const { return x * 2; } + }; + + struct halve_x + { + typedef int result_type; + int operator()(int x) const { return x / 2; } + }; + + template< class Container, class TransformFn > + void transformed_test_impl_core( Container& c, TransformFn fn ) + { + using namespace boost::adaptors; + + std::vector< int > test_result1; + boost::push_back(test_result1, c | transformed(fn)); + + std::vector< int > test_result2; + boost::push_back(test_result2, adaptors::transform(c, fn)); + + std::vector< int > reference; + std::transform(c.begin(), c.end(), std::back_inserter(reference), fn); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test_result1.begin(), test_result1.end() ); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test_result2.begin(), test_result2.end() ); + } + + template< class Container, class TransformFn > + void transformed_test_fn_impl() + { + using namespace boost::assign; + + Container c; + TransformFn fn; + + // Test empty + transformed_test_impl_core(c, fn); + + // Test one element + c += 1; + transformed_test_impl_core(c, fn); + + // Test many elements + c += 1,1,1,2,2,2,2,2,3,4,5,6,7,8,9; + transformed_test_impl_core(c, fn); + } + + template< class Container > + void transformed_test_impl() + { + transformed_test_fn_impl< Container, double_x >(); + transformed_test_fn_impl< Container, halve_x >(); + } + + void transformed_test() + { + transformed_test_impl< std::vector< int > >(); + transformed_test_impl< std::list< int > >(); + transformed_test_impl< std::set< int > >(); + transformed_test_impl< std::multiset< int > >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.transformed" ); + + test->add( BOOST_TEST_CASE( &boost::transformed_test ) ); + + return test; +} diff --git a/test/adaptor_test/transformed_example.cpp b/test/adaptor_test/transformed_example.cpp new file mode 100644 index 0000000..3d05c95 --- /dev/null +++ b/test/adaptor_test/transformed_example.cpp @@ -0,0 +1,64 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 +#include +#include +#include +#include +#include + +#include +#include + +#include + +namespace +{ + struct double_int + { + typedef int result_type; + int operator()(int x) const { return x * 2; } + }; + + void transformed_example_test() + { + using namespace boost::adaptors; + using namespace boost::assign; + + std::vector input; + input += 1,2,3,4,5,6,7,8,9,10; + + boost::copy( + input | transformed(double_int()), + std::ostream_iterator(std::cout, ",")); + + + std::vector reference; + reference += 2,4,6,8,10,12,14,16,18,20; + + std::vector test; + boost::push_back(test, input | transformed(double_int())); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.transformed_example" ); + + test->add( BOOST_TEST_CASE( &transformed_example_test ) ); + + return test; +} diff --git a/test/adaptor_test/uniqued.cpp b/test/adaptor_test/uniqued.cpp new file mode 100644 index 0000000..9c96744 --- /dev/null +++ b/test/adaptor_test/uniqued.cpp @@ -0,0 +1,89 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include + +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container > + void uniqued_test_impl( Container& c ) + { + using namespace boost::adaptors; + + std::vector< int > test_result1; + boost::push_back(test_result1, c | uniqued); + + std::vector< int > test_result2; + boost::push_back(test_result2, adaptors::unique(c)); + + std::vector< int > reference(c.begin(), c.end()); + reference.erase( + std::unique(reference.begin(), reference.end()), + reference.end()); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test_result1.begin(), test_result1.end() ); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test_result2.begin(), test_result2.end() ); + } + + template< class Container > + void uniqued_test_impl() + { + using namespace boost::assign; + + Container c; + + // Test empty + uniqued_test_impl(c); + + // Test one + c += 1; + uniqued_test_impl(c); + + // Test many + c += 1,1,1,2,2,2,2,2,3,3,3,3,4,5,6,6,6,7,7,7,8,8,9,9,9,9,9,10; + uniqued_test_impl(c); + } + + void uniqued_test() + { + uniqued_test_impl< std::vector< int > >(); + uniqued_test_impl< std::list< int > >(); + uniqued_test_impl< std::set< int > >(); + uniqued_test_impl< std::multiset< int > >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.uniqued" ); + + test->add( BOOST_TEST_CASE( &boost::uniqued_test ) ); + + return test; +} diff --git a/test/adaptor_test/uniqued_example.cpp b/test/adaptor_test/uniqued_example.cpp new file mode 100644 index 0000000..c48c54a --- /dev/null +++ b/test/adaptor_test/uniqued_example.cpp @@ -0,0 +1,57 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 +#include +#include +#include +#include +#include + +#include + +#include +#include + +namespace +{ + void uniqued_example_test() + { + using namespace boost::assign; + using namespace boost::adaptors; + + std::vector input; + input += 1,1,2,2,2,3,4,5,6; + + boost::copy( + input | uniqued, + std::ostream_iterator(std::cout, ",")); + + std::vector reference; + reference += 1,2,3,4,5,6; + + std::vector test; + boost::push_back( test, input | uniqued ); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.uniqued_example" ); + + test->add( BOOST_TEST_CASE( &uniqued_example_test ) ); + + return test; +} diff --git a/test/adaptors.cpp b/test/adaptors.cpp new file mode 100644 index 0000000..ed2f915 --- /dev/null +++ b/test/adaptors.cpp @@ -0,0 +1,238 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen 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) +// +// For more information, see http://www.boost.org/libs/range/ +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +template< class T > +struct less_than +{ + T val; + + less_than() : val(0) + {} + + less_than( T t ) : val(t) + {} + + bool operator()( const T& r ) const + { + return r < val; + } +}; + + + +template< class T > +struct multiply +{ + T val; + + typedef T& result_type; + + multiply( T t ) : val(t) + { } + + T& operator()( T& r ) const + { + return r *= 2; + } +}; + + + +template< class Rng > +void check_copy( Rng r ) +{ + // + // Make sure the generated iterators + // can actually be copied + // + Rng r2 = r; + r2 = r; +} + + + +template< class Rng > +void check() +{ + using namespace boost::adaptors; + + Rng rng = boost::assign::list_of(1)(2)(3)(4)(5).to_container( rng ); + Rng out; + + // + // test each alphabetically + // + BOOST_FOREACH( int i, rng | filtered( less_than(4) ) + /*| reversed*/ + | transformed( multiply(2) ) ) + { + out.push_back( i ); + } + + BOOST_CHECK_EQUAL( out.size(), 3u ); + BOOST_CHECK_EQUAL( *out.begin(), 2 ); + BOOST_CHECK_EQUAL( *boost::next(out.begin()), 4 ); + BOOST_CHECK_EQUAL( *boost::next(out.begin(),2), 6 ); + + rng = boost::assign::list_of(1)(1)(2)(2)(3)(3)(4)(5).to_container( rng ); + out.clear(); + /* + BOOST_FOREACH( int i, rng | adjacent_filtered( std::equal_to() ) + | uniqued ) + { + + out.push_back( i ); + }*/ + +} + + + +template< class IndirectRng > +void check_indirect() +{ + using namespace boost::adaptors; + + IndirectRng rng; + + std::vector< boost::shared_ptr< int > > holder; + + for( unsigned i = 0u; i != 20u; ++i ) + { + boost::shared_ptr v(new int(i)); + rng.push_back( v.get() ); + } + + BOOST_FOREACH( int& i, rng | indirected | reversed + | transformed( multiply(2) ) ) + { + i += 1; + } + + + +} + + + +template< class RandomAccessRng > +void check_random_access() +{ + using namespace boost::adaptors; + + RandomAccessRng rng(1, 20u); + RandomAccessRng out; + + BOOST_FOREACH( int i, rng | reversed + | transformed( multiply(2) ) + /* | sliced(0,15) */ ) + { + out.push_back( i ); + } + + + BOOST_FOREACH( int i, rng | copied(3u,13u) ) + { + out.push_back( i ); + } +} + + + +template< class Map > +void check_map() +{ + using namespace boost::adaptors; + + Map m; + m.insert( std::make_pair(1,2) ); + m.insert( std::make_pair(2,2) ); + m.insert( std::make_pair(3,2) ); + m.insert( std::make_pair(4,2) ); + m.insert( std::make_pair(5,2) ); + m.insert( std::make_pair(6,2) ); + m.insert( std::make_pair(7,2) ); + + std::vector keys + = boost::copy_range< std::vector >( m | map_keys ); + std::vector values + = boost::copy_range< std::vector >( m | map_values ); +} + + + +void check_regex() +{ + using namespace boost::adaptors; + std::string s("This is a string of tokens"); + std::vector tokens = + boost::copy_range< std::vector >( s | tokenized( "\\s+", -1 ) ); +} + + +void check_adaptors() +{ + check< std::vector >(); + check< std::list >(); + check_indirect< std::vector >(); + check_indirect< std::list >(); + + check_map< std::map >(); +// check_random_access< std::vector >(); + check_regex(); + + using namespace boost::adaptors; + std::vector vec(10u,20); + std::vector pvec; + std::map map; + + check_copy( vec | adjacent_filtered( std::equal_to() ) ); + // check_copy( vec | indexed ); + check_copy( vec | reversed ); + check_copy( vec | uniqued ); + check_copy( pvec | indirected ); + +// check_copy( vec | sliced(1,5) ); + // + // This does not return an iterator_range<>, so + // won't pass this test of implicit conversion + // check_copy( vec | copied(1,5) ); + // + check_copy( map | map_values ); + check_copy( map | map_keys ); + check_copy( std::string( "a string" ) | tokenized( "\\s+", -1 ) ); + check_copy( vec | filtered( less_than(2) ) ); + check_copy( vec | transformed( multiply(2) ) ); +} + +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + using namespace boost; + + test_suite* test = BOOST_TEST_SUITE( "Range Test Suite - Adaptors" ); + + test->add( BOOST_TEST_CASE( &check_adaptors ) ); + + return test; +} + + diff --git a/test/adl_conformance.cpp b/test/adl_conformance.cpp old mode 100755 new mode 100644 index b44b7c4..2d7f290 --- a/test/adl_conformance.cpp +++ b/test/adl_conformance.cpp @@ -27,38 +27,41 @@ enum adl_types global_namespace }; -namespace boost +// Use boost_test rather than boost as the namespace for this test +// to allow the test framework to use boost::begin() etc. without +// violating the One Defintion Rule. +namespace boost_test { namespace range_detail { template< class Range > inline typename Range::iterator begin( Range& r ) { - return boost_namespace; + return boost_namespace; } - + template< class Range > inline typename Range::iterator begin( const Range& r ) { - return boost_namespace; + return boost_namespace; } } - + template< class Range > inline typename Range::iterator begin( Range& r ) { using range_detail::begin; // create ADL hook return begin( r ); } - + template< class Range > inline typename Range::iterator begin( const Range& r ) { using range_detail::begin; // create ADL hook return begin( r ); } -} +} // 'boost_test' namespace find_templated @@ -74,7 +77,7 @@ namespace find_templated iterator end() { return unused; } iterator end() const { return unused; } }; - + // // A fully generic version here will create // ambiguity. @@ -84,7 +87,7 @@ namespace find_templated { return templated_namespace; } - + template< class T > inline typename range::iterator begin( const range& r ) { @@ -98,20 +101,20 @@ namespace find_non_templated struct range { typedef adl_types iterator; - + range() { /* allow const objects */ } iterator begin() { return unused; } iterator begin() const { return unused; } iterator end() { return unused; } iterator end() const { return unused; } }; - + inline range::iterator begin( range& r ) { return non_templated_namespace; } - - + + inline range::iterator begin( const range& r ) { return non_templated_namespace; @@ -132,12 +135,12 @@ struct range inline range::iterator begin( range& r ) { return global_namespace; -} +} inline range::iterator begin( const range& r ) { return global_namespace; -} +} void check_adl_conformance() { @@ -147,29 +150,29 @@ void check_adl_conformance() const find_non_templated::range r4; range r5; const range r6; - + // - // Notice how ADL kicks in even when we have qualified + // Notice how ADL kicks in even when we have qualified // notation! // - - BOOST_CHECK( boost::begin( r ) != boost_namespace ); - BOOST_CHECK( boost::begin( r2 ) != boost_namespace ); - BOOST_CHECK( boost::begin( r3 ) != boost_namespace ); - BOOST_CHECK( boost::begin( r4 ) != boost_namespace ); - BOOST_CHECK( boost::begin( r5 ) != boost_namespace ); - BOOST_CHECK( boost::begin( r6 ) != boost_namespace ); - - BOOST_CHECK_EQUAL( boost::begin( r ), templated_namespace ) ; - BOOST_CHECK_EQUAL( boost::begin( r2 ), templated_namespace ); - BOOST_CHECK_EQUAL( boost::begin( r3 ), non_templated_namespace ); - BOOST_CHECK_EQUAL( boost::begin( r4 ), non_templated_namespace ); - BOOST_CHECK_EQUAL( boost::begin( r5 ), global_namespace ); - BOOST_CHECK_EQUAL( boost::begin( r6 ), global_namespace ); + + BOOST_CHECK( boost_test::begin( r ) != boost_namespace ); + BOOST_CHECK( boost_test::begin( r2 ) != boost_namespace ); + BOOST_CHECK( boost_test::begin( r3 ) != boost_namespace ); + BOOST_CHECK( boost_test::begin( r4 ) != boost_namespace ); + BOOST_CHECK( boost_test::begin( r5 ) != boost_namespace ); + BOOST_CHECK( boost_test::begin( r6 ) != boost_namespace ); + + BOOST_CHECK_EQUAL( boost_test::begin( r ), templated_namespace ) ; + BOOST_CHECK_EQUAL( boost_test::begin( r2 ), templated_namespace ); + BOOST_CHECK_EQUAL( boost_test::begin( r3 ), non_templated_namespace ); + BOOST_CHECK_EQUAL( boost_test::begin( r4 ), non_templated_namespace ); + BOOST_CHECK_EQUAL( boost_test::begin( r5 ), global_namespace ); + BOOST_CHECK_EQUAL( boost_test::begin( r6 ), global_namespace ); } -#include +#include using boost::unit_test_framework::test_suite; diff --git a/test/algorithm.cpp b/test/algorithm.cpp new file mode 100644 index 0000000..1c0dbc3 --- /dev/null +++ b/test/algorithm.cpp @@ -0,0 +1,471 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen 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) +// +// For more information, see http://www.boost.org/libs/range/ +// +// (C) Copyright Eric Niebler 2004. +// Use, modification and distribution are 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) + +/* + Revision history: + 13 December 2004 : Initial version. +*/ + +#ifdef _MSC_VER +// The 'secure' library warnings produce so much noise that it makes it +// impossible to see more useful warnings. + #define _SCL_SECURE_NO_WARNINGS +#endif + +#ifdef _MSC_VER + // counting_iterator generates a warning about truncating an integer + #pragma warning(push) + #pragma warning(disable : 4244) +#endif +#include +#ifdef _MSC_VER + template ::boost::counting_iterator; + #pragma warning(pop) +#endif + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +/////////////////////////////////////////////////////////////////////////////// +// dummy function object, used with algorithms +// +struct null_fun +{ + template + void operator()(T const &t) const + { + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// dummy predicate, used with algorithms +// +struct null_pred +{ + template + bool operator()(T const &t) const + { + return t == T(); + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// dummy unary op, used with algorithms +// +struct null_op1 +{ + template + T const & operator()(T const & t) const + { + return t; + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// dummy binary op, used with algorithms +// +struct null_op2 +{ + template + T const & operator()(T const & t, U const & u) const + { + return t; + } +}; + +template +void test_random_algorithms(Rng & rng, std::random_access_iterator_tag) +{ + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iterator; + typedef BOOST_DEDUCED_TYPENAME boost::range_value::type value_type; + typedef BOOST_DEDUCED_TYPENAME boost::range_size::type size_type; + typedef BOOST_DEDUCED_TYPENAME boost::iterator_category::type iterator_category; + + // just make sure these compile (for now) + if(0) + { + boost::random_shuffle(rng); + + // Must be a value since random_shuffle must take the generator by + // reference to match the standard. + null_op1 rng_generator; + boost::random_shuffle(rng, rng_generator); + + boost::sort(rng); + boost::sort(rng, std::less()); + + boost::stable_sort(rng); + boost::stable_sort(rng, std::less()); + + boost::partial_sort(rng, boost::begin(rng)); + boost::partial_sort(rng, boost::begin(rng), std::less()); + + boost::nth_element(rng, boost::begin(rng)); + boost::nth_element(rng, boost::begin(rng), std::less()); + + boost::push_heap(rng); + boost::push_heap(rng, std::less()); + + boost::pop_heap(rng); + boost::pop_heap(rng, std::less()); + + boost::make_heap(rng); + boost::make_heap(rng, std::less()); + + boost::sort_heap(rng); + boost::sort_heap(rng, std::less()); + } +} + +template +void test_random_algorithms(Rng & rng, std::input_iterator_tag) +{ + // no-op +} + +template +void test_algorithms(Rng & rng) +{ + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iterator; + typedef BOOST_DEDUCED_TYPENAME boost::range_value::type value_type; + typedef BOOST_DEDUCED_TYPENAME boost::range_size::type size_type; + typedef BOOST_DEDUCED_TYPENAME boost::iterator_category::type iterator_category; + + // just make sure these compile (for now) + if(0) + { + value_type val = value_type(); + + value_type rng2[] = {value_type(),value_type(),value_type()}; + typedef value_type* iterator2; + + value_type out[100] = {}; + typedef value_type* out_iterator; + + null_fun f = null_fun(); + iterator i = iterator(); + bool b = bool(); + out_iterator o = out_iterator(); + size_type s = size_type(); + + f = boost::for_each(rng, null_fun()); + + i = boost::find(rng, val); + i = boost::find_if(rng, null_pred()); + + i = boost::find_end(rng, rng2); + i = boost::find_end(rng, rng2, std::equal_to()); + + i = boost::find_first_of(rng, rng2); + i = boost::find_first_of(rng, rng2, std::equal_to()); + + i = boost::adjacent_find(rng); + i = boost::adjacent_find(rng, std::equal_to()); + + s = boost::count(rng, val); + s = boost::count_if(rng, null_pred()); + + std::pair p1; + p1 = boost::mismatch(rng, rng2); + p1 = boost::mismatch(rng, rng2, std::equal_to()); + + b = boost::equal(rng, rng2); + b = boost::equal(rng, rng2, std::equal_to()); + + i = boost::search(rng, rng2); + i = boost::search(rng, rng2, std::equal_to()); + + o = boost::copy(rng, boost::begin(out)); + o = boost::copy_backward(rng, boost::end(out)); + + o = boost::transform(rng, boost::begin(out), null_op1()); + o = boost::transform(rng, rng2, boost::begin(out), null_op2()); + + boost::replace(rng, val, val); + boost::replace_if(rng, null_pred(), val); + +/* + o = boost::replace_copy(rng, boost::begin(out), val, val); + o = boost::replace_copy_if(rng, boost::begin(out), null_pred(), val); +*/ + + boost::fill(rng, val); + // + // size requires RandomAccess + // + //boost::fill_n(rng, boost::size(rng), val); + //boost::fill_n(rng, std::distance(boost::begin(rng),boost::end(rng)),val); + + boost::generate(rng, &std::rand); + // + // size requires RandomAccess + // + //boost::generate_n(rng, boost::size(rng), &std::rand); + //boost::generate_n(rng,std::distance(boost::begin(rng),boost::end(rng)), &std::rand); + + i = boost::remove(rng, val); + i = boost::remove_if(rng, null_pred()); + +/* + o = boost::remove_copy(rng, boost::begin(out), val); + o = boost::remove_copy_if(rng, boost::begin(out), null_pred()); +*/ + + typename boost::range_return::type rrng = boost::unique(rng); + rrng = boost::unique(rng, std::equal_to()); + +/* + o = boost::unique_copy(rng, boost::begin(out)); + o = boost::unique_copy(rng, boost::begin(out), std::equal_to()); +*/ + + boost::reverse(rng); + +/* + o = boost::reverse_copy(rng, boost::begin(out)); +*/ + + boost::rotate(rng, boost::begin(rng)); + +/* + o = boost::rotate_copy(rng, boost::begin(rng), boost::begin(out)); +*/ + + i = boost::partition(rng, null_pred()); + i = boost::stable_partition(rng, null_pred()); + +/* + o = boost::partial_sort_copy(rng, out); + o = boost::partial_sort_copy(rng, out, std::less()); +*/ + + i = boost::lower_bound(rng, val); + i = boost::lower_bound(rng, val, std::less()); + + i = boost::upper_bound(rng, val); + i = boost::upper_bound(rng, val, std::less()); + + std::pair p2; + p2 = boost::equal_range(rng, val); + p2 = boost::equal_range(rng, val, std::less()); + + b = boost::binary_search(rng, val); + b = boost::binary_search(rng, val, std::less()); + + boost::inplace_merge(rng, boost::begin(rng)); + boost::inplace_merge(rng, boost::begin(rng), std::less()); + + b = boost::includes(rng, rng2); + b = boost::includes(rng, rng2, std::equal_to()); + + o = boost::set_union(rng, rng2, boost::begin(out)); + o = boost::set_union(rng, rng2, boost::begin(out), std::equal_to()); + + o = boost::set_intersection(rng, rng2, boost::begin(out)); + o = boost::set_intersection(rng, rng2, boost::begin(out), std::equal_to()); + + o = boost::set_difference(rng, rng2, boost::begin(out)); + o = boost::set_difference(rng, rng2, boost::begin(out), std::equal_to()); + + o = boost::set_symmetric_difference(rng, rng2, boost::begin(out)); + o = boost::set_symmetric_difference(rng, rng2, boost::begin(out), std::equal_to()); + + i = boost::min_element(rng); + i = boost::min_element(rng, std::less()); + + i = boost::max_element(rng); + i = boost::max_element(rng, std::less()); + + b = boost::lexicographical_compare(rng, rng); + b = boost::lexicographical_compare(rng, rng, std::equal_to()); + + b = boost::next_permutation(rng); + b = boost::next_permutation(rng, std::less()); + + b = boost::prev_permutation(rng); + b = boost::prev_permutation(rng, std::less()); + + ///////////////////////////////////////////////////////////////////// + // numeric algorithms + ///////////////////////////////////////////////////////////////////// + + val = boost::accumulate( rng, val ); + val = boost::accumulate( rng, val, null_op2() ); + val = boost::inner_product( rng, rng, val ); + val = boost::inner_product( rng, rng, val, + null_op2(), null_op2() ); + o = boost::partial_sum( rng, boost::begin(out) ); + o = boost::partial_sum( rng, boost::begin(out), null_op2() ); + o = boost::adjacent_difference( rng, boost::begin(out) ); + o = boost::adjacent_difference( rng, boost::begin(out), + null_op2() ); + + } + + // test the algorithms that require a random-access range + test_random_algorithms(rng, iterator_category()); +} + +int* addr(int &i) { return &i; } +bool true_(int) { return true; } + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +void simple_compile_test() +{ + // int_iterator + typedef ::boost::counting_iterator int_iterator; + + // define come containers + std::list my_list(int_iterator(1),int_iterator(6)); + + + std::vector my_vector(int_iterator(1),int_iterator(6)); + + std::pair::iterator,std::vector::iterator> my_pair(my_vector.begin(),my_vector.end()); + + // test the algorithms with list and const list + test_algorithms(my_list); + test_algorithms(my_vector); + test_algorithms(my_pair); + + + std::vector v; + std::vector& cv = v; + + using namespace boost; + +#define BOOST_RANGE_RETURNS_TEST( function_name, cont ) \ + function_name (cont); \ + function_name (cont); \ + function_name (cont); \ + function_name (cont); \ + function_name (cont); \ + function_name (cont); \ + function_name (cont); \ + function_name (cont); \ + function_name (cont); \ + function_name (cont); + + BOOST_RANGE_RETURNS_TEST( adjacent_find, cv ); + BOOST_RANGE_RETURNS_TEST( adjacent_find, v ); + BOOST_RANGE_RETURNS_TEST( max_element, cv ); + BOOST_RANGE_RETURNS_TEST( max_element, v ); + BOOST_RANGE_RETURNS_TEST( min_element, cv ); + BOOST_RANGE_RETURNS_TEST( min_element, v ); + BOOST_RANGE_RETURNS_TEST( unique, v ); +#undef BOOST_RANGE_RETURNS_TEST + +#define BOOST_RANGE_RETURNS_TEST1( function_name, cont, arg1 ) \ + function_name (cont, arg1); \ + function_name (cont, arg1); \ + function_name (cont, arg1); \ + function_name (cont, arg1); \ + function_name (cont, arg1); \ + function_name (cont, arg1); \ + function_name (cont, arg1); \ + function_name (cont, arg1); \ + function_name (cont, arg1); \ + function_name (cont, arg1); + + BOOST_RANGE_RETURNS_TEST1( adjacent_find, cv, std::less() ); + BOOST_RANGE_RETURNS_TEST1( adjacent_find, v, std::less() ); + BOOST_RANGE_RETURNS_TEST1( find, cv, 0 ); + BOOST_RANGE_RETURNS_TEST1( find, v, 0 ); + BOOST_RANGE_RETURNS_TEST1( find_end, cv, cv ); + BOOST_RANGE_RETURNS_TEST1( find_end, cv, v ); + BOOST_RANGE_RETURNS_TEST1( find_end, v, cv ); + BOOST_RANGE_RETURNS_TEST1( find_end, v, v ); + BOOST_RANGE_RETURNS_TEST1( find_first_of, cv, cv ); + BOOST_RANGE_RETURNS_TEST1( find_first_of, cv, v ); + BOOST_RANGE_RETURNS_TEST1( find_first_of, v, cv ); + BOOST_RANGE_RETURNS_TEST1( find_first_of, v, v ); + BOOST_RANGE_RETURNS_TEST1( find_if, cv, std::negate() ); + BOOST_RANGE_RETURNS_TEST1( find_if, v, std::negate() ); + BOOST_RANGE_RETURNS_TEST1( search, cv, cv ); + BOOST_RANGE_RETURNS_TEST1( search, cv, v ); + BOOST_RANGE_RETURNS_TEST1( search, v, cv ); + BOOST_RANGE_RETURNS_TEST1( search, v, v ); + + BOOST_RANGE_RETURNS_TEST1( remove, v, 0 ); + BOOST_RANGE_RETURNS_TEST1( remove_if, v, std::negate() ); + + BOOST_RANGE_RETURNS_TEST1( lower_bound, cv, 0 ); + BOOST_RANGE_RETURNS_TEST1( lower_bound, v, 0 ); + BOOST_RANGE_RETURNS_TEST1( max_element, cv, std::less() ); + BOOST_RANGE_RETURNS_TEST1( max_element, v, std::less() ); + BOOST_RANGE_RETURNS_TEST1( min_element, cv, std::less() ); + BOOST_RANGE_RETURNS_TEST1( min_element, v, std::less() ); + BOOST_RANGE_RETURNS_TEST1( upper_bound, cv, 0 ); + BOOST_RANGE_RETURNS_TEST1( upper_bound, v, 0 ); + BOOST_RANGE_RETURNS_TEST1( partition, cv, std::negate() ); + BOOST_RANGE_RETURNS_TEST1( partition, v, std::negate() ); + BOOST_RANGE_RETURNS_TEST1( stable_partition, cv, std::negate() ); + BOOST_RANGE_RETURNS_TEST1( stable_partition, v, std::negate() ); + +#undef BOOST_RANGE_RETURNS_TEST1 + +#define BOOST_RANGE_RETURNS_TEST2( function_name, arg1, arg2 ) \ + function_name (v, arg1, arg2); \ + function_name (v, arg1, arg2); \ + function_name (v, arg1, arg2); \ + function_name (v, arg1, arg2); \ + function_name (v, arg1, arg2); \ + function_name (v, arg1, arg2); \ + function_name (v, arg1, arg2); \ + function_name (v, arg1, arg2); \ + function_name (v, arg1, arg2); \ + function_name (v, arg1, arg2); + + BOOST_RANGE_RETURNS_TEST2( find_end, v, std::less() ); + BOOST_RANGE_RETURNS_TEST2( find_first_of, v, std::less() ); + BOOST_RANGE_RETURNS_TEST2( search, v, std::less() ); + BOOST_RANGE_RETURNS_TEST2( lower_bound, 0, std::less() ); + BOOST_RANGE_RETURNS_TEST2( upper_bound, 0, std::less() ); + +#undef BOOST_RANGE_RETURNS_TEST2 +} + +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + using namespace boost; + + test_suite* test = BOOST_TEST_SUITE( "Range Test Suite - Algorithm" ); + + test->add( BOOST_TEST_CASE( &simple_compile_test ) ); + + return test; +} + diff --git a/test/algorithm_ext_test/copy_n.cpp b/test/algorithm_ext_test/copy_n.cpp new file mode 100644 index 0000000..854962f --- /dev/null +++ b/test/algorithm_ext_test/copy_n.cpp @@ -0,0 +1,60 @@ +// Boost.Range library +// +// Copyright Neil Groves 2010. 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 + +#include +#include + +#include +#include +#include +#include + +namespace +{ + template< class Container > + void test_copy_n_impl() + { + std::vector source; + for (std::size_t i = 0; i < 10; ++i) + source.push_back(i); + + for (std::size_t k = 0; k < 10; ++k) + { + std::vector reference; + for (std::size_t j = 0; j < k; ++j) + reference.push_back(j); + + Container test; + boost::copy_n(source, k, std::back_inserter(test)); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } + } + + void test_copy_n() + { + test_copy_n_impl< std::vector >(); + test_copy_n_impl< std::list >(); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm_ext.copy_n" ); + + test->add( BOOST_TEST_CASE( &test_copy_n ) ); + + return test; +} diff --git a/test/algorithm_ext_test/erase.cpp b/test/algorithm_ext_test/erase.cpp new file mode 100644 index 0000000..3bdf2da --- /dev/null +++ b/test/algorithm_ext_test/erase.cpp @@ -0,0 +1,128 @@ +// Boost.Range library +// +// Copyright Neil Groves 2010. 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 + +#include +#include + +#include +#include +#include +#include + +namespace +{ + template< class Container > + void test_erase_impl() + { + Container source; + for (int i = 0; i < 10; ++i) + source.push_back(i); + + Container reference(source); + Container test(source); + + typedef BOOST_DEDUCED_TYPENAME Container::iterator iterator_t; + + iterator_t first_ref = reference.begin(); + iterator_t last_ref = reference.end(); + + boost::iterator_range< iterator_t > test_range(test.begin(), test.end()); + + reference.erase(first_ref, last_ref); + boost::erase(test, test_range); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } + + void test_erase() + { + test_erase_impl >(); + test_erase_impl >(); + } + + template< class Container > + void test_remove_erase_impl() + { + Container source; + for (int i = 0; i < 10; ++i) + source.push_back(i); + + Container reference(source); + Container test(source); + + boost::remove_erase(test, 5); + + reference.erase( std::find(reference.begin(), reference.end(), 5) ); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } + + void test_remove_erase() + { + test_remove_erase_impl >(); + test_remove_erase_impl >(); + } + + struct is_even + { + typedef bool result_type; + typedef int argument_type; + bool operator()(int x) const { return x % 2 == 0; } + }; + + template< class Container > + void test_remove_erase_if_impl() + { + Container source; + for (int i = 0; i < 10; ++i) + source.push_back(i); + + Container reference; + typedef BOOST_DEDUCED_TYPENAME Container::const_iterator iterator_t; + iterator_t last_source = source.end(); + is_even pred; + for (iterator_t it_source = source.begin(); it_source != last_source; ++it_source) + { + if (!pred(*it_source)) + reference.push_back(*it_source); + } + + Container test(source); + boost::remove_erase_if(test, is_even()); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + + } + + void test_remove_erase_if() + { + test_remove_erase_if_impl >(); + test_remove_erase_if_impl >(); + } + +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm_ext.erase" ); + + test->add( BOOST_TEST_CASE( &test_erase ) ); + test->add( BOOST_TEST_CASE( &test_remove_erase ) ); + test->add( BOOST_TEST_CASE( &test_remove_erase_if ) ); + + return test; +} diff --git a/test/algorithm_ext_test/for_each_ext.cpp b/test/algorithm_ext_test/for_each_ext.cpp new file mode 100644 index 0000000..9df16c5 --- /dev/null +++ b/test/algorithm_ext_test/for_each_ext.cpp @@ -0,0 +1,98 @@ +// Boost.Range library +// +// Copyright Neil Groves 2010. 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 + +#include +#include + +#include +#include +#include +#include + +namespace +{ + struct MockBinaryFn + { + typedef void result_type; + typedef int first_argument_type; + typedef int second_argument_type; + + void operator()(int x, int y) + { + xs.push_back(x); + ys.push_back(y); + } + + std::vector xs; + std::vector ys; + }; + + template< class Range1, class Range2 > + void test_for_each_impl( Range1& rng1, Range2& rng2 ) + { + MockBinaryFn fn = boost::range::for_each(rng1, rng2, MockBinaryFn()); + + BOOST_CHECK_EQUAL_COLLECTIONS( ::boost::begin(rng1), ::boost::end(rng1), + fn.xs.begin(), fn.xs.end() ); + + BOOST_CHECK_EQUAL_COLLECTIONS( ::boost::begin(rng2), ::boost::end(rng2), + fn.ys.begin(), fn.ys.end() ); + } + + template< class Collection1, class Collection2 > + void test_for_each_impl(const int max_count) + { + Collection1 c1; + for (int i = 0; i < max_count; ++i) + c1.push_back(i); + + Collection2 c2; + for (int i = 0; i < max_count; ++i) + c2.push_back(i); + + test_for_each_impl(c1, c2); + + const Collection1& const_c1 = c1; + const Collection2& const_c2 = c2; + + test_for_each_impl(c1, const_c2); + test_for_each_impl(const_c1, c2); + test_for_each_impl(const_c1, const_c2); + } + + template< class Collection1, class Collection2 > + void test_for_each_impl() + { + test_for_each_impl< Collection1, Collection2 >(0); + test_for_each_impl< Collection1, Collection2 >(1); + test_for_each_impl< Collection1, Collection2 >(10); + } + + void test_for_each() + { + test_for_each_impl< std::vector, std::vector >(); + test_for_each_impl< std::list, std::list >(); + test_for_each_impl< std::vector, std::list >(); + test_for_each_impl< std::list, std::vector >(); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm_ext.for_each" ); + + test->add( BOOST_TEST_CASE( &test_for_each ) ); + + return test; +} diff --git a/test/algorithm_ext_test/insert.cpp b/test/algorithm_ext_test/insert.cpp new file mode 100644 index 0000000..ff1f706 --- /dev/null +++ b/test/algorithm_ext_test/insert.cpp @@ -0,0 +1,72 @@ +// Boost.Range library +// +// Copyright Neil Groves 2010. 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 + +#include +#include + +#include +#include +#include +#include +#include + +namespace +{ + template< class Container > + void test_insert_impl( int n ) + { + Container test; + boost::insert( test, test.end(), boost::irange(0, n) ); + + Container reference; + for (int i = 0; i < n; ++i) + reference.push_back(i); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + + // Do it again so that we are inserting into a non-empty target + boost::insert( test, test.end(), boost::irange(0, n) ); + + for (int j = 0; j < n; ++j) + reference.push_back(j); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } + + template< class Container > + void test_insert_impl() + { + test_insert_impl< Container >(0); + test_insert_impl< Container >(1); + test_insert_impl< Container >(2); + test_insert_impl< Container >(100); + } + + void test_insert() + { + test_insert_impl< std::vector >(); + test_insert_impl< std::list >(); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm_ext.insert" ); + + test->add( BOOST_TEST_CASE( &test_insert ) ); + + return test; +} diff --git a/test/algorithm_ext_test/iota.cpp b/test/algorithm_ext_test/iota.cpp new file mode 100644 index 0000000..64d9b0e --- /dev/null +++ b/test/algorithm_ext_test/iota.cpp @@ -0,0 +1,70 @@ +// Boost.Range library +// +// Copyright Neil Groves 2010. 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 + +#include +#include + +#include +#include +#include +#include + +namespace +{ + template< class Container > + void test_iota_impl(std::size_t n) + { + Container test; + test.resize( n ); + boost::iota( test, n ); + + Container reference; + reference.resize( n ); + std::size_t i = n; + typedef BOOST_DEDUCED_TYPENAME Container::iterator iterator_t; + iterator_t last = reference.end(); + for (iterator_t it = reference.begin(); it != last; ++it, ++i) + { + *it = i; + } + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + + } + + template< class Container > + void test_iota_impl() + { + test_iota_impl< Container >(0); + test_iota_impl< Container >(1); + test_iota_impl< Container >(2); + test_iota_impl< Container >(100); + } + + void test_iota() + { + test_iota_impl< std::vector >(); + test_iota_impl< std::list >(); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm_ext.iota" ); + + test->add( BOOST_TEST_CASE( &test_iota ) ); + + return test; +} diff --git a/test/algorithm_ext_test/is_sorted.cpp b/test/algorithm_ext_test/is_sorted.cpp new file mode 100644 index 0000000..bddc5f8 --- /dev/null +++ b/test/algorithm_ext_test/is_sorted.cpp @@ -0,0 +1,62 @@ +// Boost.Range library +// +// Copyright Neil Groves 2010. 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 + +#include +#include + +#include +#include +#include +#include + +namespace +{ + template< class Container > + void test_is_sorted_impl() + { + Container ascending; + Container descending; + + // Empty ranges are regarded as sorted against any predicate. + BOOST_CHECK( boost::is_sorted(ascending) ); + BOOST_CHECK( boost::is_sorted(ascending, std::less()) ); + BOOST_CHECK( boost::is_sorted(ascending, std::greater()) ); + + for (std::size_t i = 0; i < 10; ++i) + { + ascending.push_back(i); + descending.push_back(9 - i); + } + + BOOST_CHECK( boost::is_sorted(ascending) ); + BOOST_CHECK( !boost::is_sorted(descending) ); + BOOST_CHECK( !boost::is_sorted(ascending, std::greater()) ); + BOOST_CHECK( boost::is_sorted(descending, std::greater()) ); + } + + void test_is_sorted() + { + test_is_sorted_impl< std::vector >(); + test_is_sorted_impl< std::list >(); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm_ext.is_sorted" ); + + test->add( BOOST_TEST_CASE( &test_is_sorted ) ); + + return test; +} diff --git a/test/algorithm_ext_test/overwrite.cpp b/test/algorithm_ext_test/overwrite.cpp new file mode 100644 index 0000000..0d8604a --- /dev/null +++ b/test/algorithm_ext_test/overwrite.cpp @@ -0,0 +1,74 @@ +// Boost.Range library +// +// Copyright Neil Groves 2010. 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 + +#include +#include + +#include +#include +#include +#include + +namespace +{ + template< class Container > + void test_overwrite_impl(std::size_t n) + { + Container overwrite_source; + for (std::size_t i = 0; i < n; ++i) + overwrite_source.push_back(i); + + Container reference; + reference.resize(n); + std::copy(overwrite_source.begin(), overwrite_source.end(), reference.begin()); + + Container test; + test.resize(n); + boost::overwrite(overwrite_source, test); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + + test.clear(); + test.resize(n); + const Container& const_overwrite_source = overwrite_source; + boost::overwrite(const_overwrite_source, test); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } + + template< class Container > + void test_overwrite_impl() + { + test_overwrite_impl(0); + test_overwrite_impl(1); + test_overwrite_impl(10); + } + + void test_overwrite() + { + test_overwrite_impl< std::vector >(); + test_overwrite_impl< std::list >(); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm_ext.overwrite" ); + + test->add( BOOST_TEST_CASE( &test_overwrite ) ); + + return test; +} diff --git a/test/algorithm_ext_test/push_back.cpp b/test/algorithm_ext_test/push_back.cpp new file mode 100644 index 0000000..7e9d539 --- /dev/null +++ b/test/algorithm_ext_test/push_back.cpp @@ -0,0 +1,72 @@ +// Boost.Range library +// +// Copyright Neil Groves 2010. 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 + +#include +#include + +#include +#include +#include +#include +#include + +namespace +{ + template< class Container > + void test_push_back_impl(std::size_t n) + { + Container reference; + for (std::size_t i = 0; i < n; ++i) + reference.push_back(i); + + Container test; + boost::push_back(test, boost::irange(0, n)); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + + // Do it again to push onto non-empty container + for (std::size_t j = 0; j < n; ++j) + reference.push_back(j); + + boost::push_back(test, boost::irange(0, n)); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } + + template< class Container > + void test_push_back_impl() + { + test_push_back_impl< Container >(0); + test_push_back_impl< Container >(1); + test_push_back_impl< Container >(2); + test_push_back_impl< Container >(100); + } + + void test_push_back() + { + test_push_back_impl< std::vector >(); + test_push_back_impl< std::list >(); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm_ext.push_back" ); + + test->add( BOOST_TEST_CASE( &test_push_back ) ); + + return test; +} diff --git a/test/algorithm_ext_test/push_front.cpp b/test/algorithm_ext_test/push_front.cpp new file mode 100644 index 0000000..ebc09a8 --- /dev/null +++ b/test/algorithm_ext_test/push_front.cpp @@ -0,0 +1,71 @@ +// Boost.Range library +// +// Copyright Neil Groves 2010. 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 + +#include +#include + +#include +#include +#include +#include +#include + +namespace +{ + template< class Container > + void test_push_front_impl(std::size_t n) + { + Container reference; + for (std::size_t i = 0; i < n; ++i) + reference.push_back(i); + + Container test; + boost::push_front(test, boost::irange(0, n)); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + + // Do it again to push onto non-empty container + reference.insert(reference.begin(), reference.begin(), reference.end()); + + boost::push_front(test, boost::irange(0, n)); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } + + template< class Container > + void test_push_front_impl() + { + test_push_front_impl< Container >(0); + test_push_front_impl< Container >(1); + test_push_front_impl< Container >(2); + test_push_front_impl< Container >(100); + } + + void test_push_front() + { + test_push_front_impl< std::vector >(); + test_push_front_impl< std::list >(); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm_ext.push_front" ); + + test->add( BOOST_TEST_CASE( &test_push_front ) ); + + return test; +} diff --git a/test/algorithm_test/adjacent_find.cpp b/test/algorithm_test/adjacent_find.cpp new file mode 100644 index 0000000..914736b --- /dev/null +++ b/test/algorithm_test/adjacent_find.cpp @@ -0,0 +1,89 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container > + void test_adjacent_find_impl() + { + using namespace boost::assign; + + typedef BOOST_DEDUCED_TYPENAME Container::iterator iterator_t; + typedef BOOST_DEDUCED_TYPENAME Container::const_iterator const_iterator_t; + + Container cont; + const Container& cref_cont = cont; + + std::equal_to pred; + + BOOST_CHECK( boost::adjacent_find(cont) == cont.end() ); + BOOST_CHECK( boost::adjacent_find(cref_cont) == cref_cont.end() ); + BOOST_CHECK( boost::adjacent_find(cont, pred) == cont.end() ); + BOOST_CHECK( boost::adjacent_find(cref_cont, pred) == cref_cont.end() ); + + cont += 1; + BOOST_CHECK( boost::adjacent_find(cont) == cont.end() ); + BOOST_CHECK( boost::adjacent_find(cref_cont) == cref_cont.end() ); + BOOST_CHECK( boost::adjacent_find(cont, pred) == cont.end() ); + BOOST_CHECK( boost::adjacent_find(cref_cont, pred) == cref_cont.end() ); + + cont += 2,3,4,5,5,5,6,7,8,9; + iterator_t it = boost::adjacent_find(cont); + iterator_t it_pred = boost::adjacent_find(cont, pred); + BOOST_CHECK( it == it_pred ); + BOOST_CHECK( it != cont.end() ); + BOOST_CHECK( it == std::adjacent_find(cont.begin(), cont.end()) ); + if (it != cont.end()) + { + BOOST_CHECK( *it == 5 ); + } + const_iterator_t cit = boost::adjacent_find(cref_cont); + const_iterator_t cit_pred = boost::adjacent_find(cref_cont, pred); + BOOST_CHECK( cit == cit_pred ); + BOOST_CHECK( cit != cref_cont.end() ); + BOOST_CHECK( cit == std::adjacent_find(cref_cont.begin(), cref_cont.end()) ); + if (cit != cref_cont.end()) + { + BOOST_CHECK( *cit == 5 ); + } + } + + void test_adjacent_find() + { + test_adjacent_find_impl< std::vector >(); + test_adjacent_find_impl< std::list >(); + test_adjacent_find_impl< std::multiset >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.adjacent_find" ); + + test->add( BOOST_TEST_CASE( &boost::test_adjacent_find ) ); + + return test; +} diff --git a/test/algorithm_test/binary_search.cpp b/test/algorithm_test/binary_search.cpp new file mode 100644 index 0000000..e0aca31 --- /dev/null +++ b/test/algorithm_test/binary_search.cpp @@ -0,0 +1,122 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void test(Container& cont) + { + Container reference(cont); + Container test(cont); + + bool reference_result + = std::binary_search(reference.begin(), reference.end(), 5); + + bool test_result = boost::binary_search(test, 5); + + BOOST_CHECK( reference_result == test_result ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + } + + template + void sort_container(Container& cont, BinaryPredicate pred) + { + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + std::vector temp(cont.begin(), cont.end()); + std::sort(temp.begin(), temp.end(), pred); + cont.assign(temp.begin(), temp.end()); + } + + template + void test_pred(Container& cont, BinaryPredicate pred) + { + Container reference(cont); + Container test(cont); + + sort_container(reference, pred); + sort_container(test, pred); + + bool reference_result + = std::binary_search(reference.begin(), reference.end(), 5, + pred); + + bool test_result = boost::binary_search(test, 5, pred); + + BOOST_CHECK( reference_result == test_result ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + } + + template + void test_binary_search_impl() + { + using namespace boost::assign; + + Container cont; + + test(cont); + test_pred(cont, std::less()); + test_pred(cont, std::greater()); + + cont.clear(); + cont += 1; + test(cont); + test_pred(cont, std::less()); + test_pred(cont, std::greater()); + + cont.clear(); + cont += 1,2,3,4,5,6,7,8,9; + test(cont); + test_pred(cont, std::less()); + test_pred(cont, std::greater()); + } + + void test_binary_search() + { + test_binary_search_impl< std::vector >(); + test_binary_search_impl< std::list >(); + test_binary_search_impl< std::deque >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.binary_search" ); + + test->add( BOOST_TEST_CASE( &boost::test_binary_search ) ); + + return test; +} diff --git a/test/algorithm_test/copy.cpp b/test/algorithm_test/copy.cpp new file mode 100644 index 0000000..932d190 --- /dev/null +++ b/test/algorithm_test/copy.cpp @@ -0,0 +1,67 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container > + void test_copy_impl() + { + Container source; + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + std::vector target; + target.resize(source.size()); + + typedef BOOST_DEDUCED_TYPENAME range_iterator< std::vector >::type iterator_t; + iterator_t it = boost::copy(source, target.begin()); + + BOOST_CHECK( it == target.end() ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + target.begin(), target.end(), + source.begin(), source.end() + ); + } + + void test_copy() + { + test_copy_impl< std::vector >(); + test_copy_impl< std::list >(); + test_copy_impl< std::set >(); + test_copy_impl< std::multiset >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.copy" ); + + test->add( BOOST_TEST_CASE( &boost::test_copy ) ); + + return test; +} diff --git a/test/algorithm_test/copy_backward.cpp b/test/algorithm_test/copy_backward.cpp new file mode 100644 index 0000000..d66082a --- /dev/null +++ b/test/algorithm_test/copy_backward.cpp @@ -0,0 +1,64 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container > + void test_copy_backward_impl() + { + Container source; + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + std::vector target; + target.resize(source.size()); + + typedef BOOST_DEDUCED_TYPENAME range_iterator< std::vector >::type iterator_t; + iterator_t it = boost::copy_backward(source, target.begin()); + + BOOST_CHECK( it == target.end() ); + BOOST_CHECK_EQUAL_COLLECTIONS( target.begin(), target.end(), + source.rbegin(), source.rend() ); + } + + void test_copy_backward() + { + test_copy_backward_impl< std::vector >(); + test_copy_backward_impl< std::list >(); + test_copy_backward_impl< std::set >(); + test_copy_backward_impl< std::multiset >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.copy_backward" ); + + test->add( BOOST_TEST_CASE( &boost::test_copy_backward ) ); + + return test; +} diff --git a/test/algorithm_test/count.cpp b/test/algorithm_test/count.cpp new file mode 100644 index 0000000..d364710 --- /dev/null +++ b/test/algorithm_test/count.cpp @@ -0,0 +1,77 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container > + void test_count_impl() + { + using namespace boost::assign; + + Container cont; + const Container& cref_cont = cont; + + BOOST_CHECK_EQUAL( 0u, boost::count(cont, 0) ); + BOOST_CHECK_EQUAL( 0u, boost::count(cref_cont, 0) ); + + cont += 1; + BOOST_CHECK_EQUAL( 0u, boost::count(cont, 0) ); + BOOST_CHECK_EQUAL( 0u, boost::count(cref_cont, 0) ); + BOOST_CHECK_EQUAL( 1u, boost::count(cont, 1) ); + BOOST_CHECK_EQUAL( 1u, boost::count(cref_cont, 1) ); + + cont += 2,3,4,5,6,7,8,9; + BOOST_CHECK_EQUAL( 0u, boost::count(cont, 0) ); + BOOST_CHECK_EQUAL( 0u, boost::count(cref_cont, 0) ); + BOOST_CHECK_EQUAL( 1u, boost::count(cont, 1) ); + BOOST_CHECK_EQUAL( 1u, boost::count(cref_cont, 1) ); + + cont += 2; + BOOST_CHECK_EQUAL( 0u, boost::count(cont, 0) ); + BOOST_CHECK_EQUAL( 0u, boost::count(cref_cont, 0) ); + BOOST_CHECK_EQUAL( 1u, boost::count(cont, 1) ); + BOOST_CHECK_EQUAL( 1u, boost::count(cref_cont, 1) ); + BOOST_CHECK_EQUAL( 2u, boost::count(cont, 2) ); + BOOST_CHECK_EQUAL( 2u, boost::count(cref_cont, 2) ); + } + + void test_count() + { + test_count_impl< std::vector >(); + test_count_impl< std::list >(); + test_count_impl< std::multiset >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.count" ); + + test->add( BOOST_TEST_CASE( &boost::test_count ) ); + + return test; +} diff --git a/test/algorithm_test/count_if.cpp b/test/algorithm_test/count_if.cpp new file mode 100644 index 0000000..11526b4 --- /dev/null +++ b/test/algorithm_test/count_if.cpp @@ -0,0 +1,85 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include "../test_function/false_predicate.hpp" +#include "../test_function/equal_to_x.hpp" +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container > + void test_count_if_impl() + { + using namespace boost::range_test_function; + using namespace boost::assign; + + typedef equal_to_x pred_t; + + Container cont; + const Container& cref_cont = cont; + + BOOST_CHECK_EQUAL( 0u, boost::count_if(cont, pred_t(0)) ); + BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont, pred_t(0)) ); + + cont += 1; + BOOST_CHECK_EQUAL( 0u, boost::count_if(cont, pred_t(0)) ); + BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont, pred_t(0)) ); + BOOST_CHECK_EQUAL( 1u, boost::count_if(cont, pred_t(1)) ); + BOOST_CHECK_EQUAL( 1u, boost::count_if(cref_cont, pred_t(1)) ); + + cont += 2,3,4,5,6,7,8,9; + BOOST_CHECK_EQUAL( 0u, boost::count_if(cont, pred_t(0)) ); + BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont, pred_t(0)) ); + BOOST_CHECK_EQUAL( 1u, boost::count_if(cont, pred_t(1)) ); + BOOST_CHECK_EQUAL( 1u, boost::count_if(cref_cont, pred_t(1)) ); + + cont += 2; + BOOST_CHECK_EQUAL( 0u, boost::count_if(cont, pred_t(0)) ); + BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont, pred_t(0)) ); + BOOST_CHECK_EQUAL( 1u, boost::count_if(cont, pred_t(1)) ); + BOOST_CHECK_EQUAL( 1u, boost::count_if(cref_cont, pred_t(1)) ); + BOOST_CHECK_EQUAL( 2u, boost::count_if(cont, pred_t(2)) ); + BOOST_CHECK_EQUAL( 2u, boost::count_if(cref_cont, pred_t(2)) ); + + BOOST_CHECK_EQUAL( 0u, boost::count_if(cont, false_predicate()) ); + BOOST_CHECK_EQUAL( 0u, boost::count_if(cref_cont, false_predicate()) ); + } + + void test_count_if() + { + test_count_if_impl< std::vector >(); + test_count_if_impl< std::list >(); + test_count_if_impl< std::multiset >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.count_if" ); + + test->add( BOOST_TEST_CASE( &boost::test_count_if ) ); + + return test; +} diff --git a/test/algorithm_test/equal.cpp b/test/algorithm_test/equal.cpp new file mode 100644 index 0000000..d750706 --- /dev/null +++ b/test/algorithm_test/equal.cpp @@ -0,0 +1,103 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container1, class Container2 > + void test_equal_impl() + { + using namespace boost::assign; + + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container1_t; + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container2_t; + + container1_t mcont1; + container2_t mcont2; + + Container1& cont1 = mcont1; + Container2& cont2 = mcont2; + + BOOST_CHECK( boost::equal(cont1, cont2) ); + BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to()) ); + BOOST_CHECK( boost::equal(cont1, cont2, std::not_equal_to()) ); + + mcont1 += 1; + BOOST_CHECK( !boost::equal(cont1, cont2) ); + BOOST_CHECK( !boost::equal(cont1, cont2, std::equal_to()) ); + BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to()) ); + + mcont1.clear(); + mcont2 += 1; + BOOST_CHECK( !boost::equal(cont1, cont2) ); + BOOST_CHECK( !boost::equal(cont1, cont2, std::equal_to()) ); + BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to()) ); + + mcont1 += 1; + BOOST_CHECK( boost::equal(cont1, cont2) ); + BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to()) ); + BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to()) ); + + mcont1 += 2,3,4,5,6,7,8,9; + mcont2 += 2,3,4,5,6,7,8,9; + BOOST_CHECK( boost::equal(cont1, cont2) ); + BOOST_CHECK( boost::equal(cont1, cont2, std::equal_to()) ); + BOOST_CHECK( !boost::equal(cont1, cont2, std::not_equal_to()) ); + } + + template< class Container1, class Container2 > + void test_driver() + { + typedef Container1 container1_t; + typedef Container2 container2_t; + typedef BOOST_DEDUCED_TYPENAME boost::add_const::type const_container1_t; + typedef BOOST_DEDUCED_TYPENAME boost::add_const::type const_container2_t; + + test_equal_impl< const_container1_t, const_container2_t >(); + test_equal_impl< const_container1_t, container2_t >(); + test_equal_impl< container1_t, const_container2_t >(); + test_equal_impl< container1_t, container2_t >(); + } + + void test_equal() + { + test_driver< std::list, std::list >(); + test_driver< std::vector, std::vector >(); + test_driver< std::set, std::set >(); + test_driver< std::multiset, std::multiset >(); + test_driver< std::list, std::vector >(); + test_driver< std::vector, std::list >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.equal" ); + + test->add( BOOST_TEST_CASE( &boost::test_equal ) ); + + return test; +} diff --git a/test/algorithm_test/equal_range.cpp b/test/algorithm_test/equal_range.cpp new file mode 100644 index 0000000..652508c --- /dev/null +++ b/test/algorithm_test/equal_range.cpp @@ -0,0 +1,175 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void check_result( + const Container& reference, + Pair reference_pair, + const Container& test, + Pair test_pair + ) + { + typedef BOOST_DEDUCED_TYPENAME range_iterator::type + const_iterator_t; + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + + BOOST_CHECK_EQUAL( + std::distance(reference.begin(), reference_pair.first), + std::distance(test.begin(), test_pair.first) + ); + + BOOST_CHECK_EQUAL( + std::distance(reference.begin(), reference_pair.second), + std::distance(test.begin(), test_pair.second) + ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference_pair.first, reference_pair.second, + test_pair.first, test_pair.second + ); + } + + template + void test(Container& cont) + { + Container reference(cont); + Container test(cont); + + typedef BOOST_DEDUCED_TYPENAME range_iterator::type iterator_t; + typedef std::pair pair_t; + + pair_t reference_result + = std::equal_range(reference.begin(), reference.end(), 5); + + pair_t test_result = boost::equal_range(test, 5); + + check_result(reference, reference_result, + test, test_result); + } + + template + void sort_container(Container& cont, BinaryPredicate pred) + { + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + std::vector temp(cont.begin(), cont.end()); + std::sort(temp.begin(), temp.end(), pred); + cont.assign(temp.begin(), temp.end()); + } + + template + void test_pred(Container& cont, BinaryPredicate pred) + { + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container_t; + + container_t reference_temp(cont); + container_t test_temp(cont); + + sort_container(reference_temp, pred); + sort_container(test_temp, pred); + + Container reference(reference_temp); + Container test(test_temp); + + typedef BOOST_DEDUCED_TYPENAME range_iterator::type iterator_t; + typedef std::pair pair_t; + + pair_t reference_result + = std::equal_range(reference.begin(), reference.end(), 5, + BinaryPredicate()); + + pair_t test_result = boost::equal_range(test, 5, BinaryPredicate()); + + check_result(reference, reference_result, + test, test_result); + } + + template + void test_driver(const Container& cont) + { + Container mutable_cont(cont); + test(mutable_cont); + + test(cont); + } + + template + void test_pred_driver(const Container& cont, BinaryPredicate pred) + { + Container mutable_cont(cont); + test_pred(mutable_cont, pred); + + test_pred(cont, pred); + } + + template + void test_equal_range_impl() + { + using namespace boost::assign; + + Container cont; + + test_driver(cont); + test_pred_driver(cont, std::less()); + test_pred_driver(cont, std::greater()); + + cont.clear(); + cont += 1; + test_driver(cont); + test_pred_driver(cont, std::less()); + test_pred_driver(cont, std::greater()); + + cont.clear(); + cont += 1,2,3,4,5,6,7,8,9; + test_driver(cont); + test_pred_driver(cont, std::less()); + test_pred_driver(cont, std::greater()); + } + + void test_equal_range() + { + test_equal_range_impl< std::vector >(); + test_equal_range_impl< std::list >(); + test_equal_range_impl< std::deque >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.equal_range" ); + + test->add( BOOST_TEST_CASE( &boost::test_equal_range ) ); + + return test; +} diff --git a/test/algorithm_test/fill.cpp b/test/algorithm_test/fill.cpp new file mode 100644 index 0000000..93dba7e --- /dev/null +++ b/test/algorithm_test/fill.cpp @@ -0,0 +1,80 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container > + void test_fill_impl(Container& cont) + { + Container reference(cont); + std::fill(reference.begin(), reference.end(), 1); + + Container target(cont); + boost::fill(target, 1); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + target.begin(), target.end() ); + } + + template< class Container > + void test_fill_impl() + { + using namespace boost::assign; + + Container cont; + test_fill_impl(cont); + + cont.clear(); + cont += 2; + test_fill_impl(cont); + + cont.clear(); + cont += 1,2; + test_fill_impl(cont); + + cont.clear(); + cont += 1,2,3,4,5,6,7,8,9; + test_fill_impl(cont); + } + + void test_fill() + { + test_fill_impl< std::vector >(); + test_fill_impl< std::list >(); + test_fill_impl< std::deque >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.fill" ); + + test->add( BOOST_TEST_CASE( &boost::test_fill ) ); + + return test; +} diff --git a/test/algorithm_test/find.cpp b/test/algorithm_test/find.cpp new file mode 100644 index 0000000..6b3d532 --- /dev/null +++ b/test/algorithm_test/find.cpp @@ -0,0 +1,106 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include "../test_driver/range_return_test_driver.hpp" +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + class find_test_policy + { + public: + template + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + return boost::find(cont, 3); + } + + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy&, Container& cont) + { + return boost::find(cont, 3); + } + }; + + template + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::find(cont.begin(), cont.end(), 3); + } + }; + + template + void test_find_container() + { + using namespace boost::assign; + + typedef BOOST_DEDUCED_TYPENAME remove_const::type container_t; + + range_test::range_return_test_driver test_driver; + + container_t mcont; + Container& cont = mcont; + test_driver(cont, find_test_policy()); + + mcont.clear(); + mcont += 1; + test_driver(cont, find_test_policy()); + + mcont.clear(); + mcont += 1,2,3,4,5,6,7,8,9; + test_driver(cont, find_test_policy()); + } + + void test_find() + { + test_find_container< std::vector >(); + test_find_container< std::list >(); + test_find_container< std::deque >(); + + test_find_container< const std::vector >(); + test_find_container< const std::list >(); + test_find_container< const std::deque >(); + + std::vector vi; + const std::vector& cvi = vi; + std::vector::const_iterator it = boost::find(vi, 0); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find" ); + + test->add( BOOST_TEST_CASE( &boost::test_find ) ); + + return test; +} diff --git a/test/algorithm_test/find_end.cpp b/test/algorithm_test/find_end.cpp new file mode 100644 index 0000000..fb44e52 --- /dev/null +++ b/test/algorithm_test/find_end.cpp @@ -0,0 +1,181 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include "../test_driver/range_return_test_driver.hpp" +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + class find_end_test_policy + { + typedef Container2 container2_t; + public: + explicit find_end_test_policy(const Container2& cont) + : m_cont(cont) + { + } + + container2_t cont() { return m_cont; } + + template + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + return boost::find_end(cont, m_cont); + } + + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy& policy, Container& cont) + { + return boost::find_end(cont, policy.cont()); + } + }; + + template + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::find_end(cont.begin(), cont.end(), + m_cont.begin(), m_cont.end()); + } + + private: + Container2 m_cont; + }; + + template + class find_end_pred_test_policy + { + typedef Container2 container2_t; + public: + explicit find_end_pred_test_policy(const Container2& cont) + : m_cont(cont) + { + } + + container2_t& cont() { return m_cont; } + BinaryPredicate& pred() { return m_pred; } + + template + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + return boost::find_end(cont, m_cont, m_pred); + } + + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy& policy, Container& cont) + { + return boost::find_end(cont, policy.cont(), policy.pred()); + } + }; + + template + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::find_end(cont.begin(), cont.end(), + m_cont.begin(), m_cont.end(), + m_pred); + } + + private: + Container2 m_cont; + BinaryPredicate m_pred; + }; + + template + void run_tests(Container1& cont1, Container2& cont2) + { + range_test::range_return_test_driver test_driver; + test_driver(cont1, find_end_test_policy(cont2)); + test_driver(cont1, find_end_pred_test_policy >(cont2)); + test_driver(cont2, find_end_pred_test_policy >(cont2)); + } + + template + void test_find_end_impl() + { + using namespace boost::assign; + + typedef BOOST_DEDUCED_TYPENAME remove_const::type container1_t; + typedef BOOST_DEDUCED_TYPENAME remove_const::type container2_t; + + container1_t mcont1; + Container1& cont1 = mcont1; + container2_t mcont2; + Container2& cont2 = mcont2; + + run_tests(cont1, cont2); + + mcont1 += 1; + run_tests(cont1, cont2); + + mcont2 += 1; + run_tests(cont1, cont2); + + mcont1 += 2,3,4,5,6,7,8,9; + mcont2 += 2,3,4; + run_tests(cont1, cont2); + + mcont2.clear(); + mcont2 += 7,8,9; + run_tests(cont1, cont2); + } + + void test_find_end() + { + test_find_end_impl< std::vector, std::vector >(); + test_find_end_impl< std::list, std::list >(); + test_find_end_impl< std::deque, std::deque >(); + test_find_end_impl< const std::vector, const std::vector >(); + test_find_end_impl< const std::list, const std::list >(); + test_find_end_impl< const std::deque, const std::deque >(); + test_find_end_impl< const std::vector, const std::list >(); + test_find_end_impl< const std::list, const std::vector >(); + test_find_end_impl< const std::vector, std::list >(); + test_find_end_impl< const std::list, std::vector >(); + test_find_end_impl< std::vector, std::list >(); + test_find_end_impl< std::list, std::vector >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_end" ); + + test->add( BOOST_TEST_CASE( &boost::test_find_end ) ); + + return test; +} diff --git a/test/algorithm_test/find_first_of.cpp b/test/algorithm_test/find_first_of.cpp new file mode 100644 index 0000000..b3d18e2 --- /dev/null +++ b/test/algorithm_test/find_first_of.cpp @@ -0,0 +1,181 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include "../test_driver/range_return_test_driver.hpp" +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + class find_first_of_test_policy + { + typedef Container2 container2_t; + public: + explicit find_first_of_test_policy(const Container2& cont) + : m_cont(cont) + { + } + + container2_t& cont() { return m_cont; } + + template + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + return boost::find_first_of(cont, m_cont); + } + + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy& policy, Container& cont) + { + return boost::find_first_of(cont, policy.cont()); + } + }; + + template + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::find_first_of(cont.begin(), cont.end(), + m_cont.begin(), m_cont.end()); + } + + private: + Container2 m_cont; + }; + + template + class find_first_of_pred_test_policy + { + typedef Container2 container2_t; + public: + explicit find_first_of_pred_test_policy(const Container2& cont) + : m_cont(cont) + { + } + + container2_t& cont() { return m_cont; } + BinaryPredicate& pred() { return m_pred; } + + template + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + return boost::find_first_of(cont, m_cont, m_pred); + } + + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy& policy, Container& cont) + { + return boost::find_first_of(cont, policy.cont(), policy.pred()); + } + }; + + template + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::find_first_of(cont.begin(), cont.end(), + m_cont.begin(), m_cont.end(), + m_pred); + } + + private: + Container2 m_cont; + BinaryPredicate m_pred; + }; + + template + void run_tests(Container1& cont1, Container2& cont2) + { + range_test::range_return_test_driver test_driver; + test_driver(cont1, find_first_of_test_policy(cont2)); + test_driver(cont1, find_first_of_pred_test_policy >(cont2)); + test_driver(cont2, find_first_of_pred_test_policy >(cont2)); + } + + template + void test_find_first_of_impl() + { + using namespace boost::assign; + + typedef BOOST_DEDUCED_TYPENAME remove_const::type container1_t; + typedef BOOST_DEDUCED_TYPENAME remove_const::type container2_t; + + container1_t mcont1; + Container1& cont1 = mcont1; + container2_t mcont2; + Container2& cont2 = mcont2; + + run_tests(cont1, cont2); + + mcont1 += 1; + run_tests(cont1, cont2); + + mcont2 += 1; + run_tests(cont1, cont2); + + mcont1 += 2,3,4,5,6,7,8,9; + mcont2 += 2,3,4; + run_tests(cont1, cont2); + + mcont2.clear(); + mcont2 += 7,8,9; + run_tests(cont1, cont2); + } + + void test_find_first_of() + { + test_find_first_of_impl< std::vector, std::vector >(); + test_find_first_of_impl< std::list, std::list >(); + test_find_first_of_impl< std::deque, std::deque >(); + test_find_first_of_impl< const std::vector, const std::vector >(); + test_find_first_of_impl< const std::list, const std::list >(); + test_find_first_of_impl< const std::deque, const std::deque >(); + test_find_first_of_impl< const std::vector, const std::list >(); + test_find_first_of_impl< const std::list, const std::vector >(); + test_find_first_of_impl< const std::vector, std::list >(); + test_find_first_of_impl< const std::list, std::vector >(); + test_find_first_of_impl< std::vector, std::list >(); + test_find_first_of_impl< std::list, std::vector >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_first_of" ); + + test->add( BOOST_TEST_CASE( &boost::test_find_first_of ) ); + + return test; +} diff --git a/test/algorithm_test/find_if.cpp b/test/algorithm_test/find_if.cpp new file mode 100644 index 0000000..4ee85a2 --- /dev/null +++ b/test/algorithm_test/find_if.cpp @@ -0,0 +1,123 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include "../test_driver/range_return_test_driver.hpp" +#include "../test_function/greater_than_x.hpp" +#include "../test_function/false_predicate.hpp" +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + class find_if_test_policy + { + public: + explicit find_if_test_policy(UnaryPredicate pred) + : m_pred(pred) {} + + template + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + return boost::find_if(cont, m_pred); + } + + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME range_return::type + operator()(find_if_test_policy& policy, Container& cont) + { + return boost::find_if(cont, policy.pred()); + } + }; + + template + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::find_if(cont.begin(), cont.end(), m_pred); + } + + UnaryPredicate& pred() { return m_pred; } + + private: + UnaryPredicate m_pred; + }; + + template + find_if_test_policy + make_policy(UnaryPredicate pred) + { + return find_if_test_policy(pred); + } + + template + void test_find_if_container() + { + using namespace boost::assign; + using namespace boost::range_test_function; + + typedef BOOST_DEDUCED_TYPENAME remove_const::type container_t; + + range_test::range_return_test_driver test_driver; + + container_t mcont; + Container& cont = mcont; + test_driver(cont, make_policy(greater_than_x(5))); + test_driver(cont, make_policy(false_predicate())); + + mcont.clear(); + mcont += 1; + test_driver(cont, make_policy(greater_than_x(5))); + test_driver(cont, make_policy(false_predicate())); + + mcont.clear(); + mcont += 1,2,3,4,5,6,7,8,9; + test_driver(cont, make_policy(greater_than_x(5))); + test_driver(cont, make_policy(false_predicate())); + } + + void test_find_if() + { + test_find_if_container< std::vector >(); + test_find_if_container< std::list >(); + test_find_if_container< std::deque >(); + + test_find_if_container< const std::vector >(); + test_find_if_container< const std::list >(); + test_find_if_container< const std::deque >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_if" ); + + test->add( BOOST_TEST_CASE( &boost::test_find_if ) ); + + return test; +} diff --git a/test/algorithm_test/for_each.cpp b/test/algorithm_test/for_each.cpp new file mode 100644 index 0000000..56f2ef5 --- /dev/null +++ b/test/algorithm_test/for_each.cpp @@ -0,0 +1,86 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include "../test_function/check_equal_fn.hpp" + +namespace boost +{ + namespace + { + template< class SinglePassRange > + void test_for_each_impl( SinglePassRange rng ) + { + using namespace boost::range_test_function; + + typedef check_equal_fn< SinglePassRange > fn_t; + + // Test the mutable version + fn_t result_fn = boost::for_each(rng, fn_t(rng)); + BOOST_CHECK_EQUAL( boost::distance(rng), result_fn.invocation_count() ); + + // Test the constant version + const SinglePassRange& cref_rng = rng; + result_fn = boost::for_each(cref_rng, fn_t(cref_rng)); + BOOST_CHECK_EQUAL( boost::distance(cref_rng), result_fn.invocation_count() ); + } + + template< class Container > + void test_for_each_t() + { + using namespace boost::assign; + + // Test empty + Container cont; + test_for_each_impl(cont); + + // Test one element + cont += 0; + test_for_each_impl(cont); + + // Test many elements + cont += 1,2,3,4,5,6,7,8,9; + test_for_each_impl(cont); + } + + void test_for_each() + { + boost::array a = { 0,1,2,3,4,5,6,7,8,9 }; + test_for_each_impl(a); + + test_for_each_t< std::vector >(); + test_for_each_t< std::list >(); + test_for_each_t< std::set >(); + test_for_each_t< std::multiset >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.for_each" ); + + test->add( BOOST_TEST_CASE( &boost::test_for_each ) ); + + return test; +} \ No newline at end of file diff --git a/test/algorithm_test/generate.cpp b/test/algorithm_test/generate.cpp new file mode 100644 index 0000000..ab47b06 --- /dev/null +++ b/test/algorithm_test/generate.cpp @@ -0,0 +1,90 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + class generator_fn + { + public: + typedef int result_type; + + generator_fn() : m_count(0) {} + int operator()() { return ++m_count; } + + private: + int m_count; + }; + + template< class Container > + void test_generate_impl(Container& cont) + { + Container reference(cont); + std::generate(reference.begin(), reference.end(), generator_fn()); + + Container test(cont); + boost::generate(test, generator_fn()); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } + + template< class Container > + void test_generate_impl() + { + using namespace boost::assign; + + Container cont; + test_generate_impl(cont); + + cont.clear(); + cont += 9; + test_generate_impl(cont); + + cont.clear(); + cont += 9,8,7,6,5,4,3,2,1; + test_generate_impl(cont); + } + + void test_generate() + { + test_generate_impl< std::vector >(); + test_generate_impl< std::list >(); + test_generate_impl< std::deque >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.generate" ); + + test->add( BOOST_TEST_CASE( &boost::test_generate ) ); + + return test; +} diff --git a/test/algorithm_test/heap.cpp b/test/algorithm_test/heap.cpp new file mode 100644 index 0000000..933d1f6 --- /dev/null +++ b/test/algorithm_test/heap.cpp @@ -0,0 +1,122 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void check_equal(const Container1& cont1, const Container2& cont2) + { + BOOST_CHECK_EQUAL_COLLECTIONS( + cont1.begin(), cont1.end(), + cont2.begin(), cont2.end() + ); + } + + void test() + { + using namespace boost::assign; + + std::vector reference; + reference += 1,2,3,4,5,6,7,8,9; + + std::vector test_cont(reference); + + std::make_heap(reference.begin(), reference.end()); + boost::make_heap(test_cont); + check_equal(reference, test_cont); + + std::push_heap(reference.begin(), reference.end()); + boost::push_heap(test_cont); + check_equal(reference, test_cont); + + std::make_heap(reference.begin(), reference.end()); + boost::make_heap(test_cont); + + std::sort_heap(reference.begin(), reference.end()); + boost::sort_heap(test_cont); + check_equal(reference, test_cont); + + std::make_heap(reference.begin(), reference.end()); + boost::make_heap(test_cont); + + std::pop_heap(reference.begin(), reference.end()); + boost::pop_heap(test_cont); + check_equal(reference, test_cont); + } + + template + void test_pred(BinaryPredicate pred) + { + using namespace boost::assign; + + std::vector reference; + reference += 1,2,3,4,5,6,7,8,9; + std::sort(reference.begin(), reference.end(), pred); + + std::vector test_cont(reference); + + std::make_heap(reference.begin(), reference.end(), pred); + boost::make_heap(test_cont, pred); + check_equal(reference, test_cont); + + reference.push_back(5); + test_cont.push_back(5); + std::push_heap(reference.begin(), reference.end(), pred); + boost::push_heap(test_cont, pred); + check_equal(reference, test_cont); + + std::make_heap(reference.begin(), reference.end(), pred); + boost::make_heap(test_cont, pred); + + std::sort_heap(reference.begin(), reference.end(), pred); + boost::sort_heap(test_cont, pred); + check_equal(reference, test_cont); + + std::make_heap(reference.begin(), reference.end(), pred); + boost::make_heap(test_cont, pred); + + std::pop_heap(reference.begin(), reference.end(), pred); + boost::pop_heap(test_cont, pred); + check_equal(reference, test_cont); + } + + void test_heap() + { + test(); + test_pred(std::less()); + test_pred(std::greater()); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.heap" ); + + test->add( BOOST_TEST_CASE( &boost::test_heap ) ); + + return test; +} diff --git a/test/algorithm_test/includes.cpp b/test/algorithm_test/includes.cpp new file mode 100644 index 0000000..f928957 --- /dev/null +++ b/test/algorithm_test/includes.cpp @@ -0,0 +1,157 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void test(Container1& cont1, Container2& cont2) + { + Container1 old_cont1(cont1); + Container2 old_cont2(cont2); + + bool reference_result + = std::includes(cont1.begin(), cont1.end(), + cont2.begin(), cont2.end()); + + bool test_result = boost::includes(cont1, cont2); + + BOOST_CHECK( reference_result == test_result ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + old_cont1.begin(), old_cont1.end(), + cont1.begin(), cont1.end() + ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + old_cont2.begin(), old_cont2.end(), + cont2.begin(), cont2.end() + ); + } + + template + void sort_container(Container& cont, BinaryPredicate pred) + { + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + std::vector temp(cont.begin(), cont.end()); + std::sort(temp.begin(), temp.end(), pred); + cont.assign(temp.begin(), temp.end()); + } + + template + void test_pred(Container1 cont1, Container2 cont2, + BinaryPredicate pred) + { + sort_container(cont1, pred); + sort_container(cont2, pred); + + Container1 old_cont1(cont1); + Container2 old_cont2(cont2); + + bool reference_result + = std::includes(cont1.begin(), cont1.end(), + cont2.begin(), cont2.end(), + pred); + + bool test_result = boost::includes(cont1, cont2, pred); + + BOOST_CHECK( reference_result == test_result ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + old_cont1.begin(), old_cont1.end(), + cont1.begin(), cont1.end() + ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + old_cont2.begin(), old_cont2.end(), + cont2.begin(), cont2.end() + ); + } + + template + void test_includes_impl( + Container1& cont1, + Container2& cont2 + ) + { + test(cont1, cont2); + test_pred(cont1, cont2, std::less()); + test_pred(cont1, cont2, std::greater()); + } + + template + void test_includes_impl() + { + using namespace boost::assign; + + Container1 cont1; + Container2 cont2; + + test_includes_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1; + test_includes_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont2 += 1; + test_includes_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1,2,3,4,5,6,7,8,9; + cont2 += 2,3,4; + test_includes_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 2,3,4; + cont2 += 1,2,3,4,5,6,7,8,9; + test_includes_impl(cont1, cont2); + } + + void test_includes() + { + test_includes_impl< std::vector, std::vector >(); + test_includes_impl< std::list, std::list >(); + test_includes_impl< std::deque, std::deque >(); + test_includes_impl< std::vector, std::list >(); + test_includes_impl< std::list, std::vector >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.includes" ); + + test->add( BOOST_TEST_CASE( &boost::test_includes ) ); + + return test; +} diff --git a/test/algorithm_test/inplace_merge.cpp b/test/algorithm_test/inplace_merge.cpp new file mode 100644 index 0000000..f109257 --- /dev/null +++ b/test/algorithm_test/inplace_merge.cpp @@ -0,0 +1,145 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void test(Container1& cont1, Container2& cont2) + { + typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t; + typedef BOOST_DEDUCED_TYPENAME std::vector::iterator iterator_t; + + std::vector reference_target(cont1.begin(), cont1.end()); + reference_target.insert(reference_target.end(), + cont2.begin(), cont2.end()); + + std::vector test_target(reference_target); + + std::inplace_merge(reference_target.begin(), + reference_target.begin() + cont1.size(), + reference_target.end()); + + boost::inplace_merge(test_target, + test_target.begin() + cont1.size()); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference_target.begin(), reference_target.end(), + test_target.begin(), test_target.end() + ); + } + + template + void sort_container(Container& cont, BinaryPredicate pred) + { + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + std::vector temp(cont.begin(), cont.end()); + std::sort(temp.begin(), temp.end(), pred); + cont.assign(temp.begin(), temp.end()); + } + + template + void test_pred(Container1 cont1, Container2 cont2, BinaryPredicate pred) + { + typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t; + typedef BOOST_DEDUCED_TYPENAME std::vector::iterator iterator_t; + + sort_container(cont1, pred); + sort_container(cont2, pred); + + std::vector reference_target(cont1.begin(), cont1.end()); + reference_target.insert(reference_target.end(), + cont2.begin(), cont2.end()); + + std::vector test_target(reference_target); + + std::inplace_merge(reference_target.begin(), + reference_target.begin() + cont1.size(), + reference_target.end(), pred); + + boost::inplace_merge(test_target, + test_target.begin() + cont1.size(), + pred); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference_target.begin(), reference_target.end(), + test_target.begin(), test_target.end() + ); + } + + template + void test_inplace_merge_impl(Container1& cont1, Container2& cont2) + { + test(cont1, cont2); + test_pred(cont1, cont2, std::less()); + test_pred(cont1, cont2, std::greater()); + } + + template + void test_inplace_merge_impl() + { + using namespace boost::assign; + + Container1 cont1; + Container2 cont2; + + test_inplace_merge_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1; + test_inplace_merge_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont2 += 1; + test_inplace_merge_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1,3,5,7,9,11,13,15,17,19; + cont2 += 2,4,6,8,10,12,14,16,18,20; + test_inplace_merge_impl(cont1, cont2); + } + + void test_inplace_merge() + { + test_inplace_merge_impl< std::vector, std::vector >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.inplace_merge" ); + + test->add( BOOST_TEST_CASE( &boost::test_inplace_merge ) ); + + return test; +} diff --git a/test/algorithm_test/lexicographical_compare.cpp b/test/algorithm_test/lexicographical_compare.cpp new file mode 100644 index 0000000..c57f390 --- /dev/null +++ b/test/algorithm_test/lexicographical_compare.cpp @@ -0,0 +1,151 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void test_lexicographical_compare_impl_nopred(ForwardRange1& rng1, + ForwardRange2& rng2) + { + bool reference = std::lexicographical_compare( + boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2)); + + bool test = boost::lexicographical_compare(rng1, rng2); + + BOOST_CHECK( reference == test ); + } + + template + void test_lexicographical_compare_impl_pred(ForwardRange1& rng1, + ForwardRange2& rng2, + BinaryPredicate pred) + { + bool reference = std::lexicographical_compare( + boost::begin(rng1), boost::end(rng1), + boost::begin(rng2), boost::end(rng2), + pred); + + bool test = boost::lexicographical_compare(rng1, rng2, pred); + + BOOST_CHECK( reference == test ); + } + + template + void test_lexicographical_compare_impl(Container1& cont1, + Container2& cont2) + { + typedef BOOST_DEDUCED_TYPENAME boost::range_value::type value_t; + + test_lexicographical_compare_impl_nopred(cont1, cont2); + test_lexicographical_compare_impl_pred(cont1, cont2, std::less()); + test_lexicographical_compare_impl_pred(cont1, cont2, std::greater()); + } + + template + void test_lexicographical_compare_impl() + { + using namespace boost::assign; + + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container1_t; + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container2_t; + + container1_t cont1; + container2_t cont2; + test_lexicographical_compare_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1.push_back(1); + cont2.push_back(1); + test_lexicographical_compare_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 2; + cont2 += 1; + test_lexicographical_compare_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1; + cont2 += 2; + test_lexicographical_compare_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1,2,3,4,5,6,7; + cont2 += 1,2,3,4,5,6,7; + test_lexicographical_compare_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1,2,3,4,5,6,7; + cont2 += 1,2,3,4,5,6; + test_lexicographical_compare_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1,2,3,4,5,6; + cont2 += 1,2,3,4,5,6,7; + test_lexicographical_compare_impl(cont1, cont2); + } + + template + void test_lexicographical_compare_rhs() + { + typedef BOOST_DEDUCED_TYPENAME range_value::type value_t; + + test_lexicographical_compare_impl >(); + test_lexicographical_compare_impl >(); + test_lexicographical_compare_impl >(); + test_lexicographical_compare_impl >(); + test_lexicographical_compare_impl >(); + test_lexicographical_compare_impl >(); + } + + void test_lexicographical_compare() + { + test_lexicographical_compare_rhs< const std::vector >(); + test_lexicographical_compare_rhs< const std::deque >(); + test_lexicographical_compare_rhs< const std::list >(); + test_lexicographical_compare_rhs< std::vector >(); + test_lexicographical_compare_rhs< std::deque >(); + test_lexicographical_compare_rhs< std::list >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.lexicographical_compare" ); + + test->add( BOOST_TEST_CASE( &boost::test_lexicographical_compare ) ); + + return test; +} diff --git a/test/algorithm_test/lower_bound.cpp b/test/algorithm_test/lower_bound.cpp new file mode 100644 index 0000000..44cc120 --- /dev/null +++ b/test/algorithm_test/lower_bound.cpp @@ -0,0 +1,172 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include "../test_driver/range_return_test_driver.hpp" +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + class lower_bound_policy + { + public: + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + return boost::lower_bound(cont, 5); + } + + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy&, Container& cont) + { + return boost::lower_bound(cont, 5); + } + }; + + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::lower_bound(cont.begin(), cont.end(), 5); + } + }; + + template< class BinaryPredicate > + struct lower_bound_pred_policy + { + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + return boost::lower_bound(cont, 5, m_pred); + } + + template< range_return_value return_type > + struct test_range + { + template + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy& policy, Container& cont) + { + return boost::lower_bound( + cont, 5, policy.pred()); + } + }; + + template + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::lower_bound( + cont.begin(), cont.end(), 5, m_pred); + } + + BinaryPredicate& pred() { return m_pred; } + + private: + BinaryPredicate m_pred; + }; + + template + void test_lower_bound_impl(TestPolicy policy, BinaryPredicate pred) + { + using namespace boost::assign; + + typedef BOOST_DEDUCED_TYPENAME remove_const::type container_t; + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + range_test::range_return_test_driver test_driver; + + container_t mcont; + Container& cont = mcont; + + test_driver(cont, policy); + + mcont.clear(); + mcont += 1; + + std::vector temp(mcont.begin(), mcont.end()); + std::sort(temp.begin(), temp.end(), pred); + mcont.assign(temp.begin(), temp.end()); + + test_driver(cont, policy); + + mcont.clear(); + mcont += 1,2,3,4,5,6,7,8,9; + + temp.assign(mcont.begin(), mcont.end()); + std::sort(temp.begin(), temp.end(), pred); + mcont.assign(temp.begin(), temp.end()); + + test_driver(cont, policy); + } + + template + void test_lower_bound_impl() + { + test_lower_bound_impl( + lower_bound_policy(), + std::less() + ); + + test_lower_bound_impl( + lower_bound_pred_policy >(), + std::less() + ); + + test_lower_bound_impl( + lower_bound_pred_policy >(), + std::greater() + ); + } + + void test_lower_bound() + { + test_lower_bound_impl< std::vector >(); + test_lower_bound_impl< std::list >(); + test_lower_bound_impl< std::deque >(); + + test_lower_bound_impl< const std::vector >(); + test_lower_bound_impl< const std::list >(); + test_lower_bound_impl< const std::deque >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.lower_bound" ); + + test->add( BOOST_TEST_CASE( &boost::test_lower_bound ) ); + + return test; +} diff --git a/test/algorithm_test/max_element.cpp b/test/algorithm_test/max_element.cpp new file mode 100644 index 0000000..a9f76b8 --- /dev/null +++ b/test/algorithm_test/max_element.cpp @@ -0,0 +1,149 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include "../test_driver/range_return_test_driver.hpp" +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + class max_element_test_policy + { + public: + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + return boost::max_element(cont); + } + + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy&, Container& cont) + { + return boost::max_element(cont); + } + }; + + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::max_element(cont.begin(), cont.end()); + } + }; + + template + class max_element_pred_test_policy + { + public: + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + return boost::max_element(cont, Pred()); + } + + Pred pred() const { return Pred(); } + + template< range_return_value return_type > + struct test_range + { + template< class Container, class Policy > + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy& policy, Container& cont) + { + return boost::max_element(cont, policy.pred()); + } + }; + + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::max_element(cont.begin(), cont.end(), Pred()); + } + }; + + template + void test_max_element_impl(TestPolicy policy) + { + using namespace boost::assign; + + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + typedef BOOST_DEDUCED_TYPENAME remove_const::type container_t; + + range_test::range_return_test_driver test_driver; + + container_t cont; + + test_driver(cont, policy); + + cont.clear(); + cont += 1; + + test_driver(cont, policy); + + cont.clear(); + cont += 1,2,2,2,3,4,5,6,7,8,9; + + test_driver(cont, policy); + } + + template + void test_max_element_impl() + { + test_max_element_impl(max_element_test_policy()); + + test_max_element_impl( + max_element_pred_test_policy >()); + + test_max_element_impl( + max_element_pred_test_policy >()); + } + + void test_max_element() + { + test_max_element_impl< const std::vector >(); + test_max_element_impl< const std::deque >(); + test_max_element_impl< const std::list >(); + + test_max_element_impl< std::vector >(); + test_max_element_impl< std::deque >(); + test_max_element_impl< std::list >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.max_element" ); + + test->add( BOOST_TEST_CASE( &boost::test_max_element ) ); + + return test; +} diff --git a/test/algorithm_test/merge.cpp b/test/algorithm_test/merge.cpp new file mode 100644 index 0000000..aed7cd7 --- /dev/null +++ b/test/algorithm_test/merge.cpp @@ -0,0 +1,157 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void test(Container1& cont1, Container2& cont2) + { + typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t; + typedef BOOST_DEDUCED_TYPENAME std::vector::iterator iterator_t; + + std::vector reference_target( cont1.size() + cont2.size() ); + + iterator_t reference_it + = std::merge(cont1.begin(), cont1.end(), + cont2.begin(), cont2.end(), + reference_target.begin()); + + std::vector test_target( cont1.size() + cont2.size() ); + + iterator_t test_it + = boost::merge(cont1, cont2, test_target.begin()); + + BOOST_CHECK_EQUAL( + std::distance(reference_target.begin(), reference_it), + std::distance(test_target.begin(), test_it) + ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference_target.begin(), reference_target.end(), + test_target.begin(), test_target.end() + ); + } + + template + void sort_container(Container& cont, BinaryPredicate pred) + { + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + std::vector temp(cont.begin(), cont.end()); + std::sort(temp.begin(), temp.end(), pred); + cont.assign(temp.begin(), temp.end()); + } + + template + void test_pred(Container1 cont1, Container2 cont2, BinaryPredicate pred) + { + typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t; + typedef BOOST_DEDUCED_TYPENAME std::vector::iterator iterator_t; + + sort_container(cont1, pred); + sort_container(cont2, pred); + + std::vector reference_target( cont1.size() + cont2.size() ); + + iterator_t reference_it + = std::merge(cont1.begin(), cont1.end(), + cont2.begin(), cont2.end(), + reference_target.begin(), pred); + + std::vector test_target( cont1.size() + cont2.size() ); + + iterator_t test_it + = boost::merge(cont1, cont2, test_target.begin(), pred); + + BOOST_CHECK_EQUAL( + std::distance(reference_target.begin(), reference_it), + std::distance(test_target.begin(), test_it) + ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference_target.begin(), reference_target.end(), + test_target.begin(), test_target.end() + ); + } + + template + void test_merge_impl(Container1& cont1, Container2& cont2) + { + test(cont1, cont2); + test_pred(cont1, cont2, std::less()); + test_pred(cont1, cont2, std::greater()); + } + + template + void test_merge_impl() + { + using namespace boost::assign; + + Container1 cont1; + Container2 cont2; + + test_merge_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1; + test_merge_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont2 += 1; + test_merge_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1,3,5,7,9,11,13,15,17,19; + cont2 += 2,4,6,8,10,12,14,16,18,20; + test_merge_impl(cont1, cont2); + } + + void test_merge() + { + test_merge_impl< std::vector, std::vector >(); + test_merge_impl< std::list, std::list >(); + test_merge_impl< std::deque, std::deque >(); + + test_merge_impl< std::list, std::vector >(); + test_merge_impl< std::vector, std::list >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.merge" ); + + test->add( BOOST_TEST_CASE( &boost::test_merge ) ); + + return test; +} diff --git a/test/algorithm_test/min_element.cpp b/test/algorithm_test/min_element.cpp new file mode 100644 index 0000000..400372d --- /dev/null +++ b/test/algorithm_test/min_element.cpp @@ -0,0 +1,149 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include "../test_driver/range_return_test_driver.hpp" +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + class min_element_test_policy + { + public: + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + return boost::min_element(cont); + } + + template< range_return_value return_type > + struct test_range + { + template< class Container, class Policy > + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy&, Container& cont) + { + return boost::min_element(cont); + } + }; + + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::min_element(cont.begin(), cont.end()); + } + }; + + template + class min_element_pred_test_policy + { + public: + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + return boost::min_element(cont, Pred()); + } + + Pred pred() const { return Pred(); } + + template< range_return_value return_type > + struct test_range + { + template< class Container, class Policy > + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy& policy, Container& cont) + { + return boost::min_element(cont, policy.pred()); + } + }; + + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::min_element(cont.begin(), cont.end(), Pred()); + } + }; + + template + void test_min_element_impl(TestPolicy policy) + { + using namespace boost::assign; + + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + typedef BOOST_DEDUCED_TYPENAME remove_const::type container_t; + + range_test::range_return_test_driver test_driver; + + container_t cont; + + test_driver(cont, policy); + + cont.clear(); + cont += 1; + + test_driver(cont, policy); + + cont.clear(); + cont += 1,2,2,2,3,4,5,6,7,8,9; + + test_driver(cont, policy); + } + + template + void test_min_element_impl() + { + test_min_element_impl(min_element_test_policy()); + + test_min_element_impl( + min_element_pred_test_policy >()); + + test_min_element_impl( + min_element_pred_test_policy >()); + } + + void test_min_element() + { + test_min_element_impl< const std::vector >(); + test_min_element_impl< const std::deque >(); + test_min_element_impl< const std::list >(); + + test_min_element_impl< std::vector >(); + test_min_element_impl< std::deque >(); + test_min_element_impl< std::list >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.min_element" ); + + test->add( BOOST_TEST_CASE( &boost::test_min_element ) ); + + return test; +} diff --git a/test/algorithm_test/mismatch.cpp b/test/algorithm_test/mismatch.cpp new file mode 100644 index 0000000..eb8f5e7 --- /dev/null +++ b/test/algorithm_test/mismatch.cpp @@ -0,0 +1,181 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container1, class Container2 > + void test_mismatch_impl() + { + using namespace boost::assign; + + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type MutableContainer1; + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type MutableContainer2; + + MutableContainer1 cont1; + const Container1& cref_cont1 = cont1; + MutableContainer2 cont2; + const Container2& cref_cont2 = cont2; + + typedef BOOST_DEDUCED_TYPENAME Container1::iterator iterator1_t; + typedef BOOST_DEDUCED_TYPENAME Container1::const_iterator const_iterator1_t; + typedef BOOST_DEDUCED_TYPENAME Container2::iterator iterator2_t; + typedef BOOST_DEDUCED_TYPENAME Container2::const_iterator const_iterator2_t; + + typedef std::pair pair_mmit_t; + typedef std::pair pair_cmit_t; + typedef std::pair pair_mcit_t; + typedef std::pair pair_ccit_t; + + pair_mmit_t pair_mmit = boost::mismatch(cont1, cont2); + BOOST_CHECK( pair_mmit.first == cont1.end() ); + BOOST_CHECK( pair_mmit.second == cont2.end() ); + pair_mmit = boost::mismatch(cont1, cont2, std::equal_to()); + BOOST_CHECK( pair_mmit.first == cont1.end() ); + BOOST_CHECK( pair_mmit.second == cont2.end() ); + + pair_cmit_t pair_cmit = boost::mismatch(cref_cont1, cont2); + BOOST_CHECK( pair_cmit.first == cref_cont1.end() ); + BOOST_CHECK( pair_cmit.second == cont2.end() ); + pair_cmit = boost::mismatch(cref_cont1, cont2, std::equal_to()); + BOOST_CHECK( pair_cmit.first == cref_cont1.end() ); + BOOST_CHECK( pair_cmit.second == cont2.end() ); + + pair_mcit_t pair_mcit = boost::mismatch(cont1, cref_cont2); + BOOST_CHECK( pair_mcit.first == cont1.end() ); + BOOST_CHECK( pair_mcit.second == cref_cont2.end() ); + pair_mcit = boost::mismatch(cont1, cref_cont2, std::equal_to()); + BOOST_CHECK( pair_mcit.first == cont1.end() ); + BOOST_CHECK( pair_mcit.second == cref_cont2.end() ); + + pair_ccit_t pair_ccit = boost::mismatch(cref_cont1, cref_cont2); + BOOST_CHECK( pair_ccit.first == cref_cont1.end() ); + BOOST_CHECK( pair_ccit.second == cref_cont2.end() ); + pair_ccit = boost::mismatch(cref_cont1, cref_cont2, std::equal_to()); + BOOST_CHECK( pair_ccit.first == cref_cont1.end() ); + BOOST_CHECK( pair_ccit.second == cref_cont2.end() ); + + cont1 += 1,2,3,4; + cont2 += 1,2,3,4; + pair_mmit = boost::mismatch(cont1, cont2); + BOOST_CHECK( pair_mmit.first == cont1.end() ); + BOOST_CHECK( pair_mmit.second == cont2.end() ); + pair_mmit = boost::mismatch(cont1, cont2, std::equal_to()); + BOOST_CHECK( pair_mmit.first == cont1.end() ); + BOOST_CHECK( pair_mmit.second == cont2.end() ); + + pair_cmit = boost::mismatch(cref_cont1, cont2); + BOOST_CHECK( pair_cmit.first == cref_cont1.end() ); + BOOST_CHECK( pair_cmit.second == cont2.end() ); + pair_cmit = boost::mismatch(cref_cont1, cont2, std::equal_to()); + BOOST_CHECK( pair_cmit.first == cref_cont1.end() ); + BOOST_CHECK( pair_cmit.second == cont2.end() ); + + pair_mcit = boost::mismatch(cont1, cref_cont2); + BOOST_CHECK( pair_mcit.first == cont1.end() ); + BOOST_CHECK( pair_mcit.second == cref_cont2.end() ); + pair_mcit = boost::mismatch(cont1, cref_cont2, std::equal_to()); + BOOST_CHECK( pair_mcit.first == cont1.end() ); + BOOST_CHECK( pair_mcit.second == cref_cont2.end() ); + + pair_ccit = boost::mismatch(cref_cont1, cref_cont2); + BOOST_CHECK( pair_ccit.first == cref_cont1.end() ); + BOOST_CHECK( pair_ccit.second == cref_cont2.end() ); + pair_ccit = boost::mismatch(cref_cont1, cref_cont2, std::equal_to()); + BOOST_CHECK( pair_ccit.first == cref_cont1.end() ); + BOOST_CHECK( pair_ccit.second == cref_cont2.end() ); + + cont1.clear(); + cont2.clear(); + cont1 += 1,2,3,4; + cont2 += 1,2,5,4; + pair_mmit = boost::mismatch(cont1, cont2); + BOOST_CHECK( pair_mmit.first != cont1.end() && *pair_mmit.first == 3 ); + BOOST_CHECK( pair_mmit.second != cont2.end() && *pair_mmit.second == 5 ); + pair_mmit = boost::mismatch(cont1, cont2, std::equal_to()); + BOOST_CHECK( pair_mmit.first != cont1.end() && *pair_mmit.first == 3 ); + BOOST_CHECK( pair_mmit.second != cont2.end() && *pair_mmit.second == 5 ); + pair_mmit = boost::mismatch(cont1, cont2, std::not_equal_to()); + BOOST_CHECK( pair_mmit.first == cont1.begin() ); + BOOST_CHECK( pair_mmit.second == cont2.begin() ); + + pair_cmit = boost::mismatch(cref_cont1, cont2); + BOOST_CHECK( pair_cmit.first != cref_cont1.end() && *pair_cmit.first == 3 ); + BOOST_CHECK( pair_cmit.second != cont2.end() && *pair_cmit.second == 5 ); + pair_cmit = boost::mismatch(cref_cont1, cont2, std::equal_to()); + BOOST_CHECK( pair_cmit.first != cref_cont1.end() && *pair_cmit.first == 3 ); + BOOST_CHECK( pair_cmit.second != cont2.end() && *pair_cmit.second == 5 ); + pair_cmit = boost::mismatch(cref_cont1, cont2, std::not_equal_to()); + BOOST_CHECK( pair_cmit.first == cref_cont1.begin() ); + BOOST_CHECK( pair_cmit.second == cont2.begin() ); + + pair_mcit = boost::mismatch(cont1, cref_cont2); + BOOST_CHECK( pair_mcit.first != cont1.end() && *pair_mcit.first == 3 ); + BOOST_CHECK( pair_mcit.second != cref_cont2.end() && *pair_mcit.second == 5 ); + pair_mcit = boost::mismatch(cont1, cref_cont2, std::equal_to()); + BOOST_CHECK( pair_mcit.first != cont1.end() && *pair_mcit.first == 3 ); + BOOST_CHECK( pair_mcit.second != cref_cont2.end() && *pair_mcit.second == 5 ); + pair_mcit = boost::mismatch(cont1, cref_cont2, std::not_equal_to()); + BOOST_CHECK( pair_mcit.first == cont1.begin() ); + BOOST_CHECK( pair_mcit.second == cref_cont2.begin() ); + + pair_ccit = boost::mismatch(cref_cont1, cref_cont2); + BOOST_CHECK( pair_ccit.first != cref_cont1.end() && *pair_ccit.first == 3 ); + BOOST_CHECK( pair_ccit.second != cref_cont2.end() && *pair_ccit.second == 5 ); + pair_ccit = boost::mismatch(cref_cont1, cref_cont2, std::equal_to()); + BOOST_CHECK( pair_ccit.first != cref_cont1.end() && *pair_ccit.first == 3 ); + BOOST_CHECK( pair_ccit.second != cref_cont2.end() && *pair_ccit.second == 5 ); + pair_ccit = boost::mismatch(cref_cont1, cref_cont2, std::not_equal_to()); + BOOST_CHECK( pair_ccit.first == cref_cont1.begin() ); + BOOST_CHECK( pair_ccit.second == cref_cont2.begin() ); + } + + void test_mismatch() + { + test_mismatch_impl< std::list, std::list >(); + test_mismatch_impl< const std::list, std::list >(); + test_mismatch_impl< std::list, const std::list >(); + test_mismatch_impl< const std::list, const std::list >(); + + test_mismatch_impl< std::vector, std::list >(); + test_mismatch_impl< const std::vector, std::list >(); + test_mismatch_impl< std::vector, const std::list >(); + test_mismatch_impl< const std::vector, const std::list >(); + + test_mismatch_impl< std::list, std::vector >(); + test_mismatch_impl< const std::list, std::vector >(); + test_mismatch_impl< std::list, const std::vector >(); + test_mismatch_impl< const std::list, const std::vector >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.mismatch" ); + + test->add( BOOST_TEST_CASE( &boost::test_mismatch ) ); + + return test; +} diff --git a/test/algorithm_test/next_permutation.cpp b/test/algorithm_test/next_permutation.cpp new file mode 100644 index 0000000..c2d782b --- /dev/null +++ b/test/algorithm_test/next_permutation.cpp @@ -0,0 +1,108 @@ +// Copyright Neil Groves 2009. 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 +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void test_next_permutation_impl(const Container& cont) + { + Container reference(cont); + Container test(cont); + + const bool reference_ret + = std::next_permutation(reference.begin(), reference.end()); + + const bool test_ret + = boost::next_permutation(test); + + BOOST_CHECK( reference_ret == test_ret ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + } + + template + void test_next_permutation_pred_impl(const Container& cont, + BinaryPredicate pred) + { + Container reference(cont); + Container test(cont); + + const bool reference_ret + = std::next_permutation(reference.begin(), reference.end(), + pred); + + const bool test_ret + = boost::next_permutation(test, pred); + + BOOST_CHECK( reference_ret == test_ret ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + } + + template + void test_next_permutation_(const Container& cont) + { + test_next_permutation_impl(cont); + test_next_permutation_pred_impl(cont, std::less()); + test_next_permutation_pred_impl(cont, std::greater()); + } + + template + void run_tests() + { + using namespace boost::assign; + + Container cont; + test_next_permutation_(cont); + + cont.clear(); + cont += 1; + test_next_permutation_(cont); + + cont.clear(); + cont += 1,2,3,4,5,6,7,8,9; + test_next_permutation_(cont); + } + + void test_next_permutation() + { + run_tests< std::vector >(); + run_tests< std::list >(); + run_tests< std::deque >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.next_permutation" ); + + test->add( BOOST_TEST_CASE( &boost::test_next_permutation ) ); + + return test; +} diff --git a/test/algorithm_test/nth_element.cpp b/test/algorithm_test/nth_element.cpp new file mode 100644 index 0000000..dac2a2f --- /dev/null +++ b/test/algorithm_test/nth_element.cpp @@ -0,0 +1,149 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + struct nth_element_policy + { + template + void test_nth_element(Container& cont, Iterator mid) + { + boost::nth_element(cont, mid); + } + + template + void reference_nth_element(Container& cont, Iterator mid) + { + std::nth_element(cont.begin(), mid, cont.end()); + } + }; + + template + struct nth_element_pred_policy + { + template + void test_nth_element(Container& cont, Iterator mid) + { + boost::nth_element(cont, mid, BinaryPredicate()); + } + + template + void reference_nth_element(Container& cont, Iterator mid) + { + std::nth_element(cont.begin(), mid, cont.end(), BinaryPredicate()); + } + }; + + template + void test_nth_element_tp_impl(Container& cont, TestPolicy policy) + { + Container reference(cont); + Container test(cont); + + typedef BOOST_DEDUCED_TYPENAME range_iterator::type iterator_t; + + BOOST_CHECK_EQUAL( reference.size(), test.size() ); + if (reference.size() != test.size()) + return; + + iterator_t reference_mid = reference.begin(); + iterator_t test_mid = test.begin(); + + bool complete = false; + while (!complete) + { + if (reference_mid == reference.end()) + complete = true; + + policy.test_nth_element(test, test_mid); + policy.reference_nth_element(reference, reference_mid); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + + if (reference_mid != reference.end()) + { + ++reference_mid; + ++test_mid; + } + } + } + + template + void test_nth_element_impl(Container& cont) + { + test_nth_element_tp_impl(cont, nth_element_policy()); + } + + template + void test_nth_element_impl(Container& cont, BinaryPredicate pred) + { + test_nth_element_tp_impl(cont, nth_element_pred_policy()); + } + + template + void run_tests(Container& cont) + { + test_nth_element_impl(cont); + test_nth_element_impl(cont, std::less()); + test_nth_element_impl(cont, std::greater()); + } + + template + void test_nth_element_impl() + { + using namespace boost::assign; + + Container cont; + run_tests(cont); + + cont.clear(); + cont += 1; + run_tests(cont); + + cont.clear(); + cont += 1,2,3,4,5,6,7,8,9; + run_tests(cont); + } + + void test_nth_element() + { + test_nth_element_impl< std::vector >(); + test_nth_element_impl< std::deque >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.nth_element" ); + + test->add( BOOST_TEST_CASE( &boost::test_nth_element ) ); + + return test; +} diff --git a/test/algorithm_test/partial_sort.cpp b/test/algorithm_test/partial_sort.cpp new file mode 100644 index 0000000..62ff64b --- /dev/null +++ b/test/algorithm_test/partial_sort.cpp @@ -0,0 +1,149 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + struct partial_sort_policy + { + template + void test_partial_sort(Container& cont, Iterator mid) + { + boost::partial_sort(cont, mid); + } + + template + void reference_partial_sort(Container& cont, Iterator mid) + { + std::partial_sort(cont.begin(), mid, cont.end()); + } + }; + + template + struct partial_sort_pred_policy + { + template + void test_partial_sort(Container& cont, Iterator mid) + { + boost::partial_sort(cont, mid, BinaryPredicate()); + } + + template + void reference_partial_sort(Container& cont, Iterator mid) + { + std::partial_sort(cont.begin(), mid, cont.end(), BinaryPredicate()); + } + }; + + template + void test_partial_sort_tp_impl(Container& cont, TestPolicy policy) + { + Container reference(cont); + Container test(cont); + + typedef BOOST_DEDUCED_TYPENAME range_iterator::type iterator_t; + + BOOST_CHECK_EQUAL( reference.size(), test.size() ); + if (reference.size() != test.size()) + return; + + iterator_t reference_mid = reference.begin(); + iterator_t test_mid = test.begin(); + + bool complete = false; + while (!complete) + { + if (reference_mid == reference.end()) + complete = true; + + policy.test_partial_sort(test, test_mid); + policy.reference_partial_sort(reference, reference_mid); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + + if (reference_mid != reference.end()) + { + ++reference_mid; + ++test_mid; + } + } + } + + template + void test_partial_sort_impl(Container& cont) + { + test_partial_sort_tp_impl(cont, partial_sort_policy()); + } + + template + void test_partial_sort_impl(Container& cont, BinaryPredicate pred) + { + test_partial_sort_tp_impl(cont, partial_sort_pred_policy()); + } + + template + void test_partial_sort_impl() + { + using namespace boost::assign; + + Container cont; + test_partial_sort_impl(cont); + test_partial_sort_impl(cont, std::less()); + test_partial_sort_impl(cont, std::greater()); + + cont.clear(); + cont += 1; + test_partial_sort_impl(cont); + test_partial_sort_impl(cont, std::less()); + test_partial_sort_impl(cont, std::greater()); + + cont.clear(); + cont += 1,2,3,4,5,6,7,8,9; + test_partial_sort_impl(cont); + test_partial_sort_impl(cont, std::less()); + test_partial_sort_impl(cont, std::greater()); + } + + void test_partial_sort() + { + test_partial_sort_impl< std::vector >(); + test_partial_sort_impl< std::deque >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.partial_sort" ); + + test->add( BOOST_TEST_CASE( &boost::test_partial_sort ) ); + + return test; +} diff --git a/test/algorithm_test/partition.cpp b/test/algorithm_test/partition.cpp new file mode 100644 index 0000000..e71c9a7 --- /dev/null +++ b/test/algorithm_test/partition.cpp @@ -0,0 +1,111 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include "../test_driver/range_return_test_driver.hpp" +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + struct equal_to_5 + { + typedef bool result_type; + typedef int argument_type; + bool operator()(int x) const { return x == 5; } + }; + + // test the 'partition' algorithm + template + class partition_test_policy + { + public: + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + return boost::partition(cont, UnaryPredicate()); + } + + UnaryPredicate pred() const { return UnaryPredicate(); } + + template< range_return_value return_type > + struct test_range + { + template< class Container, class Policy > + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy& policy, Container& cont) + { + return boost::partition(cont, policy.pred()); + } + }; + + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::partition(cont.begin(), cont.end(), UnaryPredicate()); + } + }; + + template + void test_partition_impl() + { + using namespace boost::assign; + + range_test::range_return_test_driver test_driver; + + partition_test_policy< equal_to_5 > policy; + + Container cont; + test_driver(cont, policy); + + cont.clear(); + cont += 1; + test_driver(cont, policy); + + cont.clear(); + cont += 1,2,2,2,2,2,3,4,5,6,7,8,9; + test_driver(cont, policy); + + cont.clear(); + cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9; + test_driver(cont, policy); + } + + void test_partition() + { + test_partition_impl< std::vector >(); + test_partition_impl< std::list >(); + test_partition_impl< std::deque >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.partition" ); + + test->add( BOOST_TEST_CASE( &boost::test_partition ) ); + + return test; +} diff --git a/test/algorithm_test/prev_permutation.cpp b/test/algorithm_test/prev_permutation.cpp new file mode 100644 index 0000000..e1073c9 --- /dev/null +++ b/test/algorithm_test/prev_permutation.cpp @@ -0,0 +1,108 @@ +// Copyright Neil Groves 2009. 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 +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void test_prev_permutation_impl(const Container& cont) + { + Container reference(cont); + Container test(cont); + + const bool reference_ret + = std::prev_permutation(reference.begin(), reference.end()); + + const bool test_ret + = boost::prev_permutation(test); + + BOOST_CHECK( reference_ret == test_ret ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + } + + template + void test_prev_permutation_pred_impl(const Container& cont, + BinaryPredicate pred) + { + Container reference(cont); + Container test(cont); + + const bool reference_ret + = std::prev_permutation(reference.begin(), reference.end(), + pred); + + const bool test_ret + = boost::prev_permutation(test, pred); + + BOOST_CHECK( reference_ret == test_ret ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + } + + template + void test_prev_permutation_(const Container& cont) + { + test_prev_permutation_impl(cont); + test_prev_permutation_pred_impl(cont, std::less()); + test_prev_permutation_pred_impl(cont, std::greater()); + } + + template + void run_tests() + { + using namespace boost::assign; + + Container cont; + test_prev_permutation_(cont); + + cont.clear(); + cont += 1; + test_prev_permutation_(cont); + + cont.clear(); + cont += 1,2,3,4,5,6,7,8,9; + test_prev_permutation_(cont); + } + + void test_prev_permutation() + { + run_tests< std::vector >(); + run_tests< std::list >(); + run_tests< std::deque >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.prev_permutation" ); + + test->add( BOOST_TEST_CASE( &boost::test_prev_permutation ) ); + + return test; +} diff --git a/test/algorithm_test/random_shuffle.cpp b/test/algorithm_test/random_shuffle.cpp new file mode 100644 index 0000000..ba55f51 --- /dev/null +++ b/test/algorithm_test/random_shuffle.cpp @@ -0,0 +1,178 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include "../test_function/counted_function.hpp" +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + class counted_generator + : private range_test_function::counted_function + { + public: + typedef Int result_type; + typedef Int argument_type; + + using range_test_function::counted_function::invocation_count; + + result_type operator()(argument_type modulo_value) + { + invoked(); + return static_cast(std::rand() % modulo_value); + } + }; + + template + bool test_shuffle_result( + const Container& old_cont, + const Container& new_cont + ) + { + typedef BOOST_DEDUCED_TYPENAME range_iterator::type iterator_t; + + // The size must remain equal + BOOST_CHECK_EQUAL( old_cont.size(), new_cont.size() ); + if (old_cont.size() != new_cont.size()) + return false; + + if (new_cont.size() < 2) + { + BOOST_CHECK_EQUAL_COLLECTIONS( + old_cont.begin(), old_cont.end(), + new_cont.begin(), new_cont.end() + ); + + return std::equal(old_cont.begin(), old_cont.end(), + new_cont.begin()); + } + + // Elements must only be moved around. This is tested by + // ensuring the count of each element remains the + // same. + bool failed = false; + iterator_t last = old_cont.end(); + for (iterator_t it = old_cont.begin(); !failed && (it != last); ++it) + { + const std::size_t old_count + = std::count(old_cont.begin(), old_cont.end(), *it); + + const std::size_t new_count + = std::count(new_cont.begin(), new_cont.end(), *it); + + BOOST_CHECK_EQUAL( old_count, new_count ); + + failed = (old_count != new_count); + } + + return !failed; + } + + template + void test_random_shuffle_nogen_impl(Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME range_iterator::type iterator_t; + + const int MAX_RETRIES = 10000; + + bool shuffled = false; + for (int attempt = 0; !shuffled && (attempt < MAX_RETRIES); ++attempt) + { + Container test(cont); + boost::random_shuffle(test); + bool ok = test_shuffle_result(cont, test); + if (!ok) + break; + + // Since the counts are equal, then if they are + // not equal the contents must have been shuffled + if (cont.size() == test.size() + && !std::equal(cont.begin(), cont.end(), test.begin())) + { + shuffled = true; + } + } + } + + template + void test_random_shuffle_gen_impl(Container& cont) + { + RandomGenerator gen; + Container old_cont(cont); + boost::random_shuffle(cont, gen); + test_shuffle_result(cont, old_cont); + if (cont.size() > 2) + { + BOOST_CHECK( gen.invocation_count() > 0 ); + } + } + + template + void test_random_shuffle_impl(Container& cont) + { + Container old_cont(cont); + boost::random_shuffle(cont); + test_shuffle_result(cont, old_cont); + } + + template + void test_random_shuffle_impl() + { + using namespace boost::assign; + + typedef counted_generator< + BOOST_DEDUCED_TYPENAME range_difference::type > generator_t; + + Container cont; + test_random_shuffle_nogen_impl(cont); + test_random_shuffle_gen_impl(cont); + + cont.clear(); + cont += 1; + test_random_shuffle_nogen_impl(cont); + test_random_shuffle_gen_impl(cont); + + cont.clear(); + cont += 1,2,3,4,5,6,7,8,9; + test_random_shuffle_nogen_impl(cont); + test_random_shuffle_gen_impl(cont); + } + + void test_random_shuffle() + { + test_random_shuffle_impl< std::vector >(); + test_random_shuffle_impl< std::deque >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.random_shuffle" ); + + test->add( BOOST_TEST_CASE( &boost::test_random_shuffle ) ); + + return test; +} diff --git a/test/algorithm_test/remove.cpp b/test/algorithm_test/remove.cpp new file mode 100644 index 0000000..46e6591 --- /dev/null +++ b/test/algorithm_test/remove.cpp @@ -0,0 +1,92 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container, class Value > + void test_remove_impl( const Container& c, Value to_remove ) + { + Container reference(c); + + typedef BOOST_DEDUCED_TYPENAME Container::iterator iterator_t; + + iterator_t reference_it + = std::remove(reference.begin(), reference.end(), to_remove); + + Container test(c); + iterator_t test_it = boost::remove(test, to_remove); + + BOOST_CHECK_EQUAL( std::distance(test.begin(), test_it), + std::distance(reference.begin(), reference_it) ); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } + + template< class Container > + void test_remove_impl() + { + using namespace boost::assign; + + Container cont; + test_remove_impl(cont, 0); + + cont.clear(); + cont += 1; + test_remove_impl(cont, 0); + test_remove_impl(cont, 1); + + cont.clear(); + cont += 1,1,1,1,1; + test_remove_impl(cont, 0); + test_remove_impl(cont, 1); + + cont.clear(); + cont += 1,2,3,4,5,6,7,8,9; + test_remove_impl(cont, 1); + test_remove_impl(cont, 9); + test_remove_impl(cont, 4); + } + + void test_remove() + { + test_remove_impl< std::vector >(); + test_remove_impl< std::list >(); + test_remove_impl< std::deque >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.remove" ); + + test->add( BOOST_TEST_CASE( &boost::test_remove ) ); + + return test; +} diff --git a/test/algorithm_test/remove_if.cpp b/test/algorithm_test/remove_if.cpp new file mode 100644 index 0000000..1e77e7b --- /dev/null +++ b/test/algorithm_test/remove_if.cpp @@ -0,0 +1,99 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container, class UnaryPredicate > + void test_remove_if_impl( const Container& c, UnaryPredicate pred ) + { + Container reference(c); + + typedef BOOST_DEDUCED_TYPENAME Container::iterator iterator_t; + + iterator_t reference_it + = std::remove_if(reference.begin(), reference.end(), pred); + + Container test(c); + iterator_t test_it = boost::remove_if(test, pred); + + BOOST_CHECK_EQUAL( std::distance(test.begin(), test_it), + std::distance(reference.begin(), reference_it) ); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + } + + template< class Container > + void test_remove_if_( const Container& c, int to_remove ) + { + test_remove_if_impl(c, boost::bind(std::equal_to(), _1, to_remove)); + test_remove_if_impl(c, boost::bind(std::not_equal_to(), _1, to_remove)); + } + + template< class Container > + void test_remove_if_impl() + { + using namespace boost::assign; + + Container cont; + test_remove_if_(cont, 0); + + cont.clear(); + cont += 1; + test_remove_if_(cont, 0); + test_remove_if_(cont, 1); + + cont.clear(); + cont += 1,1,1,1,1; + test_remove_if_(cont, 0); + test_remove_if_(cont, 1); + + cont.clear(); + cont += 1,2,3,4,5,6,7,8,9; + test_remove_if_(cont, 1); + test_remove_if_(cont, 9); + test_remove_if_(cont, 4); + } + + inline void test_remove_if() + { + test_remove_if_impl< std::vector >(); + test_remove_if_impl< std::list >(); + test_remove_if_impl< std::deque >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.remove_if" ); + + test->add( BOOST_TEST_CASE( &boost::test_remove_if ) ); + + return test; +} diff --git a/test/algorithm_test/replace.cpp b/test/algorithm_test/replace.cpp new file mode 100644 index 0000000..4a882dc --- /dev/null +++ b/test/algorithm_test/replace.cpp @@ -0,0 +1,79 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container > + void test_replace_impl(Container& cont) + { + const int what = 2; + const int with_what = 5; + + std::vector reference(cont.begin(), cont.end()); + std::replace(reference.begin(), reference.end(), what, with_what); + + std::vector target(cont.begin(), cont.end()); + boost::replace(target, what, with_what); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + target.begin(), target.end() ); + + } + + template< class Container > + void test_replace_impl() + { + using namespace boost::assign; + + Container cont; + test_replace_impl(cont); + + cont.clear(); + cont += 1; + test_replace_impl(cont); + + cont.clear(); + cont += 1,2,3,4,5,6,7,8,9; + test_replace_impl(cont); + } + + void test_replace() + { + test_replace_impl< std::vector >(); + test_replace_impl< std::list >(); + test_replace_impl< std::deque >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.replace" ); + + test->add( BOOST_TEST_CASE( &boost::test_replace ) ); + + return test; +} diff --git a/test/algorithm_test/replace_if.cpp b/test/algorithm_test/replace_if.cpp new file mode 100644 index 0000000..e1dd26f --- /dev/null +++ b/test/algorithm_test/replace_if.cpp @@ -0,0 +1,90 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container, class UnaryPredicate > + void test_replace_if_impl(Container& cont, UnaryPredicate pred) + { + const int what = 2; + const int with_what = 5; + + std::vector reference(cont.begin(), cont.end()); + std::replace_if(reference.begin(), reference.end(), + boost::bind(pred, _1, what), with_what); + + std::vector target(cont.begin(), cont.end()); + boost::replace_if(target, boost::bind(pred, _1, what), with_what); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + target.begin(), target.end() ); + + } + + template< class Container > + void test_replace_if_impl(Container& cont) + { + test_replace_if_impl(cont, std::equal_to()); + test_replace_if_impl(cont, std::not_equal_to()); + } + + template< class Container > + void test_replace_if_impl() + { + using namespace boost::assign; + + Container cont; + test_replace_if_impl(cont); + + cont.clear(); + cont += 1; + test_replace_if_impl(cont); + + cont.clear(); + cont += 1,2,3,4,5,6,7,8,9; + test_replace_if_impl(cont); + } + + void test_replace_if() + { + test_replace_if_impl< std::vector >(); + test_replace_if_impl< std::list >(); + test_replace_if_impl< std::deque >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.replace_if" ); + + test->add( BOOST_TEST_CASE( &boost::test_replace_if ) ); + + return test; +} diff --git a/test/algorithm_test/reverse.cpp b/test/algorithm_test/reverse.cpp new file mode 100644 index 0000000..611a464 --- /dev/null +++ b/test/algorithm_test/reverse.cpp @@ -0,0 +1,78 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void test_reverse_impl(Container& cont) + { + Container reference(cont); + Container test(cont); + + boost::reverse(test); + std::reverse(reference.begin(), reference.end()); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + } + + template + void test_reverse_impl() + { + using namespace boost::assign; + + Container cont; + test_reverse_impl(cont); + + cont.clear(); + cont += 1; + test_reverse_impl(cont); + + cont.clear(); + cont += 1,2,3,4,5,6,7,8,9; + test_reverse_impl(cont); + } + + void test_reverse() + { + test_reverse_impl< std::vector >(); + test_reverse_impl< std::list >(); + test_reverse_impl< std::deque >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.reverse" ); + + test->add( BOOST_TEST_CASE( &boost::test_reverse ) ); + + return test; +} diff --git a/test/algorithm_test/rotate.cpp b/test/algorithm_test/rotate.cpp new file mode 100644 index 0000000..f8b394a --- /dev/null +++ b/test/algorithm_test/rotate.cpp @@ -0,0 +1,99 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void test_rotate_impl(Container& cont, Iterator where_it) + { + Container reference(cont); + Container test(cont); + + Iterator reference_where_it = reference.begin(); + std::advance(reference_where_it, + std::distance(cont.begin(), where_it)); + + std::rotate(reference.begin(), reference_where_it, reference.end()); + + Iterator test_where_it = test.begin(); + std::advance(test_where_it, + std::distance(cont.begin(), where_it)); + + boost::rotate(test, test_where_it); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + } + + template + void test_rotate_impl(Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME range_iterator::type iterator_t; + + iterator_t last = cont.end(); + for (iterator_t it = cont.begin(); it != last; ++it) + { + test_rotate_impl(cont, it); + } + } + + template + void test_rotate_impl() + { + using namespace boost::assign; + + Container cont; + test_rotate_impl(cont); + + cont.clear(); + cont += 1; + test_rotate_impl(cont); + + cont.clear(); + cont += 1,2,3,4,5,6,7,8,9; + test_rotate_impl(cont); + } + + void test_rotate() + { + test_rotate_impl< std::vector >(); + test_rotate_impl< std::list >(); + test_rotate_impl< std::deque >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.rotate" ); + + test->add( BOOST_TEST_CASE( &boost::test_rotate ) ); + + return test; +} diff --git a/test/algorithm_test/search.cpp b/test/algorithm_test/search.cpp new file mode 100644 index 0000000..460f70d --- /dev/null +++ b/test/algorithm_test/search.cpp @@ -0,0 +1,97 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container1, class Container2 > + void test_search_impl(Container1& cont1, Container2& cont2) + { + typedef BOOST_DEDUCED_TYPENAME Container1::const_iterator const_iterator1_t; + typedef BOOST_DEDUCED_TYPENAME Container1::iterator iterator1_t; + + const Container1& ccont1 = cont1; + const Container2& ccont2 = cont2; + + iterator1_t it = boost::search(cont1, cont2); + iterator1_t it2 = boost::search(cont1, ccont2); + const_iterator1_t cit = boost::search(ccont1, cont2); + const_iterator1_t cit2 = boost::search(ccont1, ccont2); + + BOOST_CHECK( it == std::search(cont1.begin(), cont1.end(), cont2.begin(), cont2.end()) ); + BOOST_CHECK( it2 == std::search(cont1.begin(), cont1.end(), ccont2.begin(), ccont2.end()) ); + BOOST_CHECK( cit == std::search(ccont1.begin(), ccont1.end(), cont2.begin(), cont2.end()) ); + BOOST_CHECK( cit2 == std::search(ccont1.begin(), ccont1.end(), ccont2.begin(), ccont2.end()) ); + } + + template< class Container1, class Container2 > + void test_search_impl() + { + using namespace boost::assign; + + Container1 cont1; + Container2 cont2; + + test_search_impl(cont1, cont2); + + cont1 += 1; + test_search_impl(cont1, cont2); + + cont1.clear(); + cont2 += 1; + test_search_impl(cont1, cont2); + + cont1 += 1; + test_search_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1,2,3,4,5,6,7,8,9; + cont2 += 10,11,12; + test_search_impl(cont1, cont2); + + cont2.clear(); + cont2 += 4,5,6; + test_search_impl(cont1, cont2); + } + + void test_search() + { + test_search_impl< std::list, std::list >(); + test_search_impl< std::vector, std::vector >(); + test_search_impl< std::set, std::set >(); + test_search_impl< std::list, std::vector >(); + test_search_impl< std::vector, std::list >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.search" ); + + test->add( BOOST_TEST_CASE( &boost::test_search ) ); + + return test; +} diff --git a/test/algorithm_test/set_difference.cpp b/test/algorithm_test/set_difference.cpp new file mode 100644 index 0000000..7fb0974 --- /dev/null +++ b/test/algorithm_test/set_difference.cpp @@ -0,0 +1,170 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void check_result( + Container1& reference, + Iterator reference_result, + Container2& test_cont, + Iterator test_result + ) + { + BOOST_CHECK_EQUAL( + std::distance(reference.begin(), reference_result), + std::distance(test_cont.begin(), test_result) + ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test_cont.begin(), test_cont.end() + ); + } + + template + void test(Container1& cont1, Container2& cont2) + { + typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t; + typedef BOOST_DEDUCED_TYPENAME std::vector::iterator iterator_t; + + std::vector reference(cont1.size() + cont2.size()); + std::vector test_cont(reference); + + iterator_t reference_result + = std::set_difference(cont1.begin(), cont1.end(), + cont2.begin(), cont2.end(), + reference.begin()); + + iterator_t test_result + = boost::set_difference(cont1, cont2, test_cont.begin()); + + check_result(reference, reference_result, + test_cont, test_result); + } + + template + void sort_container(Container& cont, BinaryPredicate pred) + { + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + std::vector temp(cont.begin(), cont.end()); + std::sort(temp.begin(), temp.end(), pred); + cont.assign(temp.begin(), temp.end()); + } + + template + void test_pred(Container1 cont1, Container2 cont2, + BinaryPredicate pred) + { + typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t; + typedef BOOST_DEDUCED_TYPENAME std::vector::iterator iterator_t; + + sort_container(cont1, pred); + sort_container(cont2, pred); + + std::vector reference(cont1.size() + cont2.size()); + std::vector test_cont(reference); + + iterator_t reference_result + = std::set_difference(cont1.begin(), cont1.end(), + cont2.begin(), cont2.end(), + reference.begin(), + pred); + + iterator_t test_result + = boost::set_difference(cont1, cont2, test_cont.begin(), pred); + + check_result(reference, reference_result, + test_cont, test_result); + } + + template + void test_set_difference_impl( + Container1& cont1, + Container2& cont2 + ) + { + test(cont1, cont2); + test_pred(cont1, cont2, std::less()); + test_pred(cont1, cont2, std::greater()); + } + + template + void test_set_difference_impl() + { + using namespace boost::assign; + + Container1 cont1; + Container2 cont2; + + test_set_difference_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1; + test_set_difference_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont2 += 1; + test_set_difference_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1,2,3,4,5,6,7,8,9; + cont2 += 2,3,4; + test_set_difference_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 2,3,4; + cont2 += 1,2,3,4,5,6,7,8,9; + test_set_difference_impl(cont1, cont2); + } + + void test_set_difference() + { + test_set_difference_impl< std::vector, std::vector >(); + test_set_difference_impl< std::list, std::list >(); + test_set_difference_impl< std::deque, std::deque >(); + test_set_difference_impl< std::vector, std::list >(); + test_set_difference_impl< std::list, std::vector >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.set_difference" ); + + test->add( BOOST_TEST_CASE( &boost::test_set_difference ) ); + + return test; +} diff --git a/test/algorithm_test/set_intersection.cpp b/test/algorithm_test/set_intersection.cpp new file mode 100644 index 0000000..5e2ce1b --- /dev/null +++ b/test/algorithm_test/set_intersection.cpp @@ -0,0 +1,170 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void check_result( + Container1& reference, + Iterator reference_result, + Container2& test_cont, + Iterator test_result + ) + { + BOOST_CHECK_EQUAL( + std::distance(reference.begin(), reference_result), + std::distance(test_cont.begin(), test_result) + ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test_cont.begin(), test_cont.end() + ); + } + + template + void test(Container1& cont1, Container2& cont2) + { + typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t; + typedef BOOST_DEDUCED_TYPENAME std::vector::iterator iterator_t; + + std::vector reference(cont1.size() + cont2.size()); + std::vector test_cont(reference); + + iterator_t reference_result + = std::set_intersection(cont1.begin(), cont1.end(), + cont2.begin(), cont2.end(), + reference.begin()); + + iterator_t test_result + = boost::set_intersection(cont1, cont2, test_cont.begin()); + + check_result(reference, reference_result, + test_cont, test_result); + } + + template + void sort_container(Container& cont, BinaryPredicate pred) + { + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + std::vector temp(cont.begin(), cont.end()); + std::sort(temp.begin(), temp.end(), pred); + cont.assign(temp.begin(), temp.end()); + } + + template + void test_pred(Container1 cont1, Container2 cont2, + BinaryPredicate pred) + { + typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t; + typedef BOOST_DEDUCED_TYPENAME std::vector::iterator iterator_t; + + sort_container(cont1, pred); + sort_container(cont2, pred); + + std::vector reference(cont1.size() + cont2.size()); + std::vector test_cont(reference); + + iterator_t reference_result + = std::set_intersection(cont1.begin(), cont1.end(), + cont2.begin(), cont2.end(), + reference.begin(), + pred); + + iterator_t test_result + = boost::set_intersection(cont1, cont2, test_cont.begin(), pred); + + check_result(reference, reference_result, + test_cont, test_result); + } + + template + void test_set_intersection_impl( + Container1& cont1, + Container2& cont2 + ) + { + test(cont1, cont2); + test_pred(cont1, cont2, std::less()); + test_pred(cont1, cont2, std::greater()); + } + + template + void test_set_intersection_impl() + { + using namespace boost::assign; + + Container1 cont1; + Container2 cont2; + + test_set_intersection_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1; + test_set_intersection_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont2 += 1; + test_set_intersection_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1,2,3,4,5,6,7,8,9; + cont2 += 2,3,4; + test_set_intersection_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 2,3,4; + cont2 += 1,2,3,4,5,6,7,8,9; + test_set_intersection_impl(cont1, cont2); + } + + void test_set_intersection() + { + test_set_intersection_impl< std::vector, std::vector >(); + test_set_intersection_impl< std::list, std::list >(); + test_set_intersection_impl< std::deque, std::deque >(); + test_set_intersection_impl< std::vector, std::list >(); + test_set_intersection_impl< std::list, std::vector >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.set_intersection" ); + + test->add( BOOST_TEST_CASE( &boost::test_set_intersection ) ); + + return test; +} diff --git a/test/algorithm_test/set_symmetric_difference.cpp b/test/algorithm_test/set_symmetric_difference.cpp new file mode 100644 index 0000000..149532c --- /dev/null +++ b/test/algorithm_test/set_symmetric_difference.cpp @@ -0,0 +1,172 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void check_result( + Container1& reference, + Iterator reference_result, + Container2& test_cont, + Iterator test_result + ) + { + BOOST_CHECK_EQUAL( + std::distance(reference.begin(), reference_result), + std::distance(test_cont.begin(), test_result) + ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test_cont.begin(), test_cont.end() + ); + } + + template + void test(Container1& cont1, Container2& cont2) + { + typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t; + typedef BOOST_DEDUCED_TYPENAME std::vector::iterator iterator_t; + + std::vector reference(cont1.size() + cont2.size()); + std::vector test_cont(reference); + + iterator_t reference_result + = std::set_symmetric_difference(cont1.begin(), cont1.end(), + cont2.begin(), cont2.end(), + reference.begin()); + + iterator_t test_result + = boost::set_symmetric_difference(cont1, cont2, + test_cont.begin()); + + check_result(reference, reference_result, + test_cont, test_result); + } + + template + void sort_container(Container& cont, BinaryPredicate pred) + { + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + std::vector temp(cont.begin(), cont.end()); + std::sort(temp.begin(), temp.end(), pred); + cont.assign(temp.begin(), temp.end()); + } + + template + void test_pred(Container1 cont1, Container2 cont2, + BinaryPredicate pred) + { + typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t; + typedef BOOST_DEDUCED_TYPENAME std::vector::iterator iterator_t; + + sort_container(cont1, pred); + sort_container(cont2, pred); + + std::vector reference(cont1.size() + cont2.size()); + std::vector test_cont(reference); + + iterator_t reference_result + = std::set_symmetric_difference(cont1.begin(), cont1.end(), + cont2.begin(), cont2.end(), + reference.begin(), + pred); + + iterator_t test_result + = boost::set_symmetric_difference(cont1, cont2, + test_cont.begin(), pred); + + check_result(reference, reference_result, + test_cont, test_result); + } + + template + void test_set_symmetric_difference_impl( + Container1& cont1, + Container2& cont2 + ) + { + test(cont1, cont2); + test_pred(cont1, cont2, std::less()); + test_pred(cont1, cont2, std::greater()); + } + + template + void test_set_symmetric_difference_impl() + { + using namespace boost::assign; + + Container1 cont1; + Container2 cont2; + + test_set_symmetric_difference_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1; + test_set_symmetric_difference_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont2 += 1; + test_set_symmetric_difference_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1,2,3,4,5,6,7,8,9; + cont2 += 2,3,4; + test_set_symmetric_difference_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 2,3,4; + cont2 += 1,2,3,4,5,6,7,8,9; + test_set_symmetric_difference_impl(cont1, cont2); + } + + void test_set_symmetric_difference() + { + test_set_symmetric_difference_impl< std::vector, std::vector >(); + test_set_symmetric_difference_impl< std::list, std::list >(); + test_set_symmetric_difference_impl< std::deque, std::deque >(); + test_set_symmetric_difference_impl< std::vector, std::list >(); + test_set_symmetric_difference_impl< std::list, std::vector >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.set_symmetric_difference" ); + + test->add( BOOST_TEST_CASE( &boost::test_set_symmetric_difference ) ); + + return test; +} diff --git a/test/algorithm_test/set_union.cpp b/test/algorithm_test/set_union.cpp new file mode 100644 index 0000000..f9450b3 --- /dev/null +++ b/test/algorithm_test/set_union.cpp @@ -0,0 +1,170 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void check_result( + Container1& reference, + Iterator reference_result, + Container2& test_cont, + Iterator test_result + ) + { + BOOST_CHECK_EQUAL( + std::distance(reference.begin(), reference_result), + std::distance(test_cont.begin(), test_result) + ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test_cont.begin(), test_cont.end() + ); + } + + template + void test(Container1& cont1, Container2& cont2) + { + typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t; + typedef BOOST_DEDUCED_TYPENAME std::vector::iterator iterator_t; + + std::vector reference(cont1.size() + cont2.size()); + std::vector test_cont(reference); + + iterator_t reference_result + = std::set_union(cont1.begin(), cont1.end(), + cont2.begin(), cont2.end(), + reference.begin()); + + iterator_t test_result + = boost::set_union(cont1, cont2, test_cont.begin()); + + check_result(reference, reference_result, + test_cont, test_result); + } + + template + void sort_container(Container& cont, BinaryPredicate pred) + { + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + std::vector temp(cont.begin(), cont.end()); + std::sort(temp.begin(), temp.end(), pred); + cont.assign(temp.begin(), temp.end()); + } + + template + void test_pred(Container1 cont1, Container2 cont2, + BinaryPredicate pred) + { + typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t; + typedef BOOST_DEDUCED_TYPENAME std::vector::iterator iterator_t; + + sort_container(cont1, pred); + sort_container(cont2, pred); + + std::vector reference(cont1.size() + cont2.size()); + std::vector test_cont(reference); + + iterator_t reference_result + = std::set_union(cont1.begin(), cont1.end(), + cont2.begin(), cont2.end(), + reference.begin(), + pred); + + iterator_t test_result + = boost::set_union(cont1, cont2, test_cont.begin(), pred); + + check_result(reference, reference_result, + test_cont, test_result); + } + + template + void test_set_union_impl( + Container1& cont1, + Container2& cont2 + ) + { + test(cont1, cont2); + test_pred(cont1, cont2, std::less()); + test_pred(cont1, cont2, std::greater()); + } + + template + void test_set_union_impl() + { + using namespace boost::assign; + + Container1 cont1; + Container2 cont2; + + test_set_union_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1; + test_set_union_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont2 += 1; + test_set_union_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 1,2,3,4,5,6,7,8,9; + cont2 += 2,3,4; + test_set_union_impl(cont1, cont2); + + cont1.clear(); + cont2.clear(); + cont1 += 2,3,4; + cont2 += 1,2,3,4,5,6,7,8,9; + test_set_union_impl(cont1, cont2); + } + + void test_set_union() + { + test_set_union_impl< std::vector, std::vector >(); + test_set_union_impl< std::list, std::list >(); + test_set_union_impl< std::deque, std::deque >(); + test_set_union_impl< std::vector, std::list >(); + test_set_union_impl< std::list, std::vector >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.set_union" ); + + test->add( BOOST_TEST_CASE( &boost::test_set_union ) ); + + return test; +} diff --git a/test/algorithm_test/sort.cpp b/test/algorithm_test/sort.cpp new file mode 100644 index 0000000..b1b26e7 --- /dev/null +++ b/test/algorithm_test/sort.cpp @@ -0,0 +1,97 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void test_sort_impl(Container& cont) + { + Container reference(cont); + Container test(cont); + + boost::sort(test); + std::sort(reference.begin(), reference.end()); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + } + + template + void test_sort_impl(Container& cont, BinaryPredicate pred) + { + Container reference(cont); + Container test(cont); + + boost::sort(test, pred); + std::sort(reference.begin(), reference.end(), pred); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + } + + template + void test_sort_impl() + { + using namespace boost::assign; + + Container cont; + test_sort_impl(cont); + test_sort_impl(cont, std::less()); + test_sort_impl(cont, std::greater()); + + cont.clear(); + cont += 1; + test_sort_impl(cont); + test_sort_impl(cont, std::less()); + test_sort_impl(cont, std::greater()); + + cont.clear(); + cont += 1,2,3,4,5,6,7,8,9; + test_sort_impl(cont); + test_sort_impl(cont, std::less()); + test_sort_impl(cont, std::greater()); + } + + void test_sort() + { + test_sort_impl< std::vector >(); + test_sort_impl< std::deque >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.sort" ); + + test->add( BOOST_TEST_CASE( &boost::test_sort ) ); + + return test; +} diff --git a/test/algorithm_test/stable_partition.cpp b/test/algorithm_test/stable_partition.cpp new file mode 100644 index 0000000..99db6be --- /dev/null +++ b/test/algorithm_test/stable_partition.cpp @@ -0,0 +1,112 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include "../test_driver/range_return_test_driver.hpp" +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + struct equal_to_5 + { + typedef bool result_type; + typedef int argument_type; + bool operator()(int x) const { return x == 5; } + }; + + // test the 'partition' algorithm + template + class stable_partition_test_policy + { + public: + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + return boost::stable_partition(cont, UnaryPredicate()); + } + + UnaryPredicate pred() const { return UnaryPredicate(); } + + template< range_return_value return_type > + struct test_range + { + template< class Container, class Policy > + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy& policy, Container& cont) + { + return boost::stable_partition(cont, policy.pred()); + } + }; + + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::stable_partition(cont.begin(), cont.end(), UnaryPredicate()); + } + }; + + template + void test_stable_partition_impl() + { + using namespace boost::assign; + + range_test::range_return_test_driver test_driver; + + stable_partition_test_policy< equal_to_5 > policy; + + Container cont; + test_driver(cont, policy); + + cont.clear(); + cont += 1; + test_driver(cont, policy); + + cont.clear(); + cont += 1,2,2,2,2,2,3,4,5,6,7,8,9; + test_driver(cont, policy); + + cont.clear(); + cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9; + test_driver(cont, policy); + } + + void test_stable_partition() + { + test_stable_partition_impl< std::vector >(); + test_stable_partition_impl< std::list >(); + test_stable_partition_impl< std::deque >(); + } + } +} + + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.stable_partition" ); + + test->add( BOOST_TEST_CASE( &boost::test_stable_partition ) ); + + return test; +} diff --git a/test/algorithm_test/stable_sort.cpp b/test/algorithm_test/stable_sort.cpp new file mode 100644 index 0000000..eb5518c --- /dev/null +++ b/test/algorithm_test/stable_sort.cpp @@ -0,0 +1,97 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template + void test_stable_sort_impl(Container& cont) + { + Container reference(cont); + Container test(cont); + + boost::stable_sort(test); + std::stable_sort(reference.begin(), reference.end()); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + } + + template + void test_stable_sort_impl(Container& cont, BinaryPredicate pred) + { + Container reference(cont); + Container test(cont); + + boost::stable_sort(test, pred); + std::stable_sort(reference.begin(), reference.end(), pred); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + } + + template + void test_stable_sort_impl() + { + using namespace boost::assign; + + Container cont; + test_stable_sort_impl(cont); + test_stable_sort_impl(cont, std::less()); + test_stable_sort_impl(cont, std::greater()); + + cont.clear(); + cont += 1; + test_stable_sort_impl(cont); + test_stable_sort_impl(cont, std::less()); + test_stable_sort_impl(cont, std::greater()); + + cont.clear(); + cont += 1,2,3,4,5,6,7,8,9; + test_stable_sort_impl(cont); + test_stable_sort_impl(cont, std::less()); + test_stable_sort_impl(cont, std::greater()); + } + + void test_stable_sort() + { + test_stable_sort_impl< std::vector >(); + test_stable_sort_impl< std::deque >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.stable_sort" ); + + test->add( BOOST_TEST_CASE( &boost::test_stable_sort ) ); + + return test; +} diff --git a/test/algorithm_test/transform.cpp b/test/algorithm_test/transform.cpp new file mode 100644 index 0000000..7f016a2 --- /dev/null +++ b/test/algorithm_test/transform.cpp @@ -0,0 +1,158 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include "../test_function/multiply_by_x.hpp" +#include +#include +#include +#include + +namespace boost +{ + namespace + { + template< class Container > + void test_transform_impl1(Container& cont) + { + using namespace boost::range_test_function; + + const Container& ccont = cont; + + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + std::vector target(cont.size()); + std::vector reference(cont.size()); + typedef BOOST_DEDUCED_TYPENAME std::vector::iterator iterator_t; + + multiply_by_x fn(2); + + iterator_t reference_it + = std::transform(cont.begin(), cont.end(), reference.begin(), fn); + + iterator_t test_it + = boost::transform(cont, target.begin(), fn); + + BOOST_CHECK( test_it == target.end() ); + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + target.begin(), target.end() ); + + target.clear(); + target.resize(ccont.size()); + + test_it = boost::transform(ccont, target.begin(), fn); + + BOOST_CHECK( test_it == target.end() ); + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + target.begin(), target.end() ); + } + + template< class Container > + void test_transform_impl1() + { + using namespace boost::assign; + + Container cont; + + test_transform_impl1(cont); + + cont += 1; + test_transform_impl1(cont); + + cont += 2,3,4,5,6,7; + test_transform_impl1(cont); + } + + template< class Container1, class Container2 > + void test_transform_impl2(Container1& cont1, Container2& cont2) + { + const Container1& ccont1 = cont1; + const Container2& ccont2 = cont2; + + BOOST_CHECK_EQUAL( cont1.size(), cont2.size() ); + + typedef BOOST_DEDUCED_TYPENAME Container1::value_type value_t; + + std::vector target(cont1.size()); + std::vector reference(cont1.size()); + typedef BOOST_DEDUCED_TYPENAME std::vector::iterator iterator_t; + + std::multiplies fn; + + iterator_t reference_it + = std::transform(cont1.begin(), cont1.end(), + cont2.begin(), reference.begin(), fn); + + iterator_t test_it + = boost::transform(cont1, cont2, target.begin(), fn); + + BOOST_CHECK( test_it == target.end() ); + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + target.begin(), target.end() ); + + target.clear(); + target.resize(ccont1.size()); + + test_it = boost::transform(ccont1, ccont2, target.begin(), fn); + + BOOST_CHECK( test_it == target.end() ); + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + target.begin(), target.end() ); + } + + template< class Container1, class Container2 > + void test_transform_impl2() + { + using namespace boost::assign; + + Container1 cont1; + Container2 cont2; + + test_transform_impl2(cont1, cont2); + + cont1 += 1; + cont2 += 2; + test_transform_impl2(cont1, cont2); + + cont1 += 2,3,4,5,6,7; + cont2 += 4,6,8,10,12,14; + test_transform_impl2(cont1, cont2); + } + + void test_transform() + { + test_transform_impl1< std::vector >(); + test_transform_impl1< std::list >(); + test_transform_impl1< std::set >(); + test_transform_impl1< std::multiset >(); + + test_transform_impl2< std::vector, std::list >(); + test_transform_impl2< std::list, std::vector >(); + test_transform_impl2< std::set, std::set >(); + test_transform_impl2< std::multiset, std::list >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.transform" ); + + test->add( BOOST_TEST_CASE( &boost::test_transform ) ); + + return test; +} diff --git a/test/algorithm_test/unique.cpp b/test/algorithm_test/unique.cpp new file mode 100644 index 0000000..f5d75cf --- /dev/null +++ b/test/algorithm_test/unique.cpp @@ -0,0 +1,166 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include "../test_driver/range_return_test_driver.hpp" +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + // test the 'unique' algorithm without a predicate + class unique_test_policy + { + public: + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + // There isn't an iterator return version of boost::unique, so just + // perform the standard algorithm + return std::unique(cont.begin(), cont.end()); + } + + template< range_return_value return_type > + struct test_range + { + template< class Container, class Policy > + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy&, Container& cont) + { + return boost::unique(cont); + } + }; + + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::unique(cont.begin(), cont.end()); + } + }; + + // test the 'unique' algorithm with a predicate + template + class unique_pred_test_policy + { + public: + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + // There isn't an iterator return version of boost::unique, so just + // perform the standard algorithm + return std::unique(cont.begin(), cont.end(), Pred()); + } + + Pred pred() const { return Pred(); } + + template< range_return_value return_type > + struct test_range + { + template< class Container, class Policy > + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy& policy, Container& cont) + { + return boost::unique(cont, policy.pred()); + } + }; + + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::unique(cont.begin(), cont.end(), Pred()); + } + }; + + template + void test_unique_impl(TestPolicy policy, Pred pred) + { + using namespace boost::assign; + + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + range_test::range_return_test_driver test_driver; + + Container cont; + + test_driver(cont, policy); + + cont.clear(); + cont += 1; + + std::vector temp(cont.begin(), cont.end()); + std::sort(temp.begin(), temp.end(), pred); + cont.assign(temp.begin(), temp.end()); + + test_driver(cont, policy); + + cont.clear(); + cont += 1,2,2,2,2,3,4,5,6,7,8,9; + + temp.assign(cont.begin(), cont.end()); + std::sort(temp.begin(), temp.end(), pred); + cont.assign(temp.begin(), temp.end()); + + test_driver(cont, policy); + } + + template + void test_unique_impl() + { + test_unique_impl( + unique_test_policy(), + std::less() + ); + + test_unique_impl( + unique_pred_test_policy >(), + std::less() + ); + + test_unique_impl( + unique_pred_test_policy >(), + std::greater() + ); + } + + void test_unique() + { + test_unique_impl< std::vector >(); + test_unique_impl< std::list >(); + test_unique_impl< std::deque >(); + } + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.unique" ); + + test->add( BOOST_TEST_CASE( &boost::test_unique ) ); + + return test; +} diff --git a/test/algorithm_test/upper_bound.cpp b/test/algorithm_test/upper_bound.cpp new file mode 100644 index 0000000..3df7164 --- /dev/null +++ b/test/algorithm_test/upper_bound.cpp @@ -0,0 +1,170 @@ +// Copyright Neil Groves 2009. 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 + +#include +#include + +#include +#include +#include "../test_driver/range_return_test_driver.hpp" +#include +#include +#include +#include +#include +#include + +namespace boost +{ + namespace + { + class upper_bound_policy + { + public: + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + return boost::upper_bound(cont, 5); + } + + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy&, Container& cont) + { + return boost::upper_bound(cont, 5); + } + }; + + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::upper_bound(cont.begin(), cont.end(), 5); + } + }; + + template< class BinaryPredicate > + struct upper_bound_pred_policy + { + template< class Container > + BOOST_DEDUCED_TYPENAME range_iterator::type + test_iter(Container& cont) + { + return boost::upper_bound(cont, 5, BinaryPredicate()); + } + + template< range_return_value result_type> + struct test_range + { + template< class Container, class Policy > + BOOST_DEDUCED_TYPENAME range_return::type + operator()(Policy& policy, Container& cont) + { + return boost::upper_bound( + cont, 5, policy.pred()); + } + }; + + template + BOOST_DEDUCED_TYPENAME range_iterator::type + reference(Container& cont) + { + return std::upper_bound( + cont.begin(), cont.end(), 5, BinaryPredicate()); + } + + BinaryPredicate& pred() { return m_pred; } + + private: + BinaryPredicate m_pred; + }; + + template + void test_upper_bound_impl(TestPolicy policy, BinaryPredicate pred) + { + using namespace boost::assign; + + typedef BOOST_DEDUCED_TYPENAME remove_const::type container_t; + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + range_test::range_return_test_driver test_driver; + + container_t mcont; + Container& cont = mcont; + + test_driver(cont, policy); + + mcont.clear(); + mcont += 1; + + std::vector temp(mcont.begin(), mcont.end()); + std::sort(temp.begin(), temp.end(), pred); + mcont.assign(temp.begin(), temp.end()); + + test_driver(cont, policy); + + mcont.clear(); + mcont += 1,2,3,4,5,6,7,8,9; + + temp.assign(mcont.begin(), mcont.end()); + std::sort(temp.begin(), temp.end(), pred); + mcont.assign(temp.begin(), temp.end()); + + test_driver(cont, policy); + } + + template + void test_upper_bound_impl() + { + test_upper_bound_impl( + upper_bound_policy(), + std::less() + ); + + test_upper_bound_impl( + upper_bound_pred_policy >(), + std::less() + ); + + test_upper_bound_impl( + upper_bound_pred_policy >(), + std::greater() + ); + } + } + + void test_upper_bound() + { + test_upper_bound_impl< std::vector >(); + test_upper_bound_impl< std::list >(); + test_upper_bound_impl< std::deque >(); + + test_upper_bound_impl< const std::vector >(); + test_upper_bound_impl< const std::list >(); + test_upper_bound_impl< const std::deque >(); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.upper_bound" ); + + test->add( BOOST_TEST_CASE( &boost::test_upper_bound ) ); + + return test; +} diff --git a/test/combine.cpp b/test/combine.cpp new file mode 100644 index 0000000..9e29a11 --- /dev/null +++ b/test/combine.cpp @@ -0,0 +1,69 @@ +// Boost.Range library +// +// Copyright Thorsten Ottosen 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) +// +// For more information, see http://www.boost.org/libs/range/ +// + +#include +#include +#include +#include +#include +#include + + +struct add +{ + template< class T > + int operator()( const T& tuple ) const + { + return boost::get<0>(tuple) + boost::get<1>(tuple); + } +}; + +template< class CombinedRng > +void apply( const CombinedRng& r ) +{ + std::vector v; + for( typename boost::range_iterator::type + i = boost::begin(r), + e = boost::end(r); + i != e; ++i ) + { + + } +} + +void test_combine() +{ + std::vector v1, v2, v3; + v1 = boost::assign::list_of(1)(2)(3)(4); + v2 = boost::assign::list_of(1)(2)(3)(4); + + int i1, i2; + BOOST_FOREACH( boost::tie( i1, i2 ), boost::combine(v1,v2) ) + { + v3.push_back( i1 + i2 ); + } + + BOOST_CHECK_EQUAL( v3.size(), v1.size() ); +} + + + +using boost::unit_test::test_suite; + +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); + + test->add( BOOST_TEST_CASE( &test_combine ) ); + + return test; +} + + diff --git a/test/compat2.cpp b/test/compat2.cpp old mode 100755 new mode 100644 index 412fb7e..1a5359c --- a/test/compat2.cpp +++ b/test/compat2.cpp @@ -42,7 +42,7 @@ template< typename C > class iterator_of { public: - typedef range_iterator::BOOST_NESTED_TEMPLATE pts::type type; + typedef BOOST_DEDUCED_TYPENAME range_iterator::BOOST_NESTED_TEMPLATE pts::type type; }; #include diff --git a/test/const_ranges.cpp b/test/const_ranges.cpp old mode 100755 new mode 100644 index 6360317..cd0b06a --- a/test/const_ranges.cpp +++ b/test/const_ranges.cpp @@ -21,9 +21,6 @@ #include #include -using namespace boost; -using namespace std; - template< class T > const T& as_const( const T& r ) { @@ -33,27 +30,23 @@ const T& as_const( const T& r ) void check_const_ranges() { std::string foo( "foo" ); - const std::string bar( "bar" ); - - BOOST_CHECK( const_begin( foo ) == begin( as_const( foo ) ) ); - BOOST_CHECK( const_end( foo ) == end( as_const( foo ) ) ); - BOOST_CHECK( const_rbegin( foo ) == rbegin( as_const( foo ) ) ); - BOOST_CHECK( const_rend( foo ) == rend( as_const( foo ) ) ); + const std::string bar( "bar" ); - BOOST_CHECK( const_begin( bar ) == begin( as_const( bar ) ) ); - BOOST_CHECK( const_end( bar ) == end( as_const( bar ) ) ); - BOOST_CHECK( const_rbegin( bar ) == rbegin( as_const( bar ) ) ); - BOOST_CHECK( const_rend( bar ) == rend( as_const( bar ) ) ); + BOOST_CHECK( boost::const_begin( foo ) == boost::begin( as_const( foo ) ) ); + BOOST_CHECK( boost::const_end( foo ) == boost::end( as_const( foo ) ) ); + BOOST_CHECK( boost::const_rbegin( foo ) == boost::rbegin( as_const( foo ) ) ); + BOOST_CHECK( boost::const_rend( foo ) == boost::rend( as_const( foo ) ) ); + + BOOST_CHECK( boost::const_begin( bar ) == boost::begin( as_const( bar ) ) ); + BOOST_CHECK( boost::const_end( bar ) == boost::end( as_const( bar ) ) ); + BOOST_CHECK( boost::const_rbegin( bar ) == boost::rbegin( as_const( bar ) ) ); + BOOST_CHECK( boost::const_rend( bar ) == boost::rend( as_const( bar ) ) ); } - - -using boost::unit_test::test_suite; - -test_suite* init_unit_test_suite( int argc, char* argv[] ) +boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] ) { - test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); + boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); test->add( BOOST_TEST_CASE( &check_const_ranges ) ); diff --git a/test/counting_range.cpp b/test/counting_range.cpp new file mode 100644 index 0000000..b5d79a1 --- /dev/null +++ b/test/counting_range.cpp @@ -0,0 +1,73 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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/ +// +// Disable a warning from since this noise might +// stop us detecting a problem in our code. +#include + +#include +#include + +#include + +#include +#include +#include +#include +#include +namespace boost +{ + namespace + { + template + void counting_range_test_impl(int first, int last) + { + Container reference; + for (int i = first; i < last; ++i) + reference.push_back(i); + + Container test; + push_back( test, counting_range(first, last) ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end()); + } + + template + void counting_range_test_impl() + { + counting_range_test_impl(0, 0); + counting_range_test_impl(-1, -1); + counting_range_test_impl(-1, 0); + counting_range_test_impl(0, 1); + counting_range_test_impl(-100, 100); + counting_range_test_impl(50, 55); + } + } + + void counting_range_test() + { + counting_range_test_impl >(); + counting_range_test_impl >(); + counting_range_test_impl >(); + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.counting_range" ); + + test->add( BOOST_TEST_CASE( &boost::counting_range_test ) ); + + return test; +} \ No newline at end of file diff --git a/test/irange.cpp b/test/irange.cpp new file mode 100644 index 0000000..d71f184 --- /dev/null +++ b/test/irange.cpp @@ -0,0 +1,131 @@ +// Boost.Range library +// +// Copyright Neil Groves 2010. 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 +#include +#include +#include +#include +#include +#include +#include + +namespace boost +{ + // Test an integer range with a step size of 1. + template + void test_irange_impl(Integer first, Integer last) + { + std::vector reference; + for (Integer i = first; i < last; ++i) + { + reference.push_back(i); + } + + std::vector test; + boost::push_back(test, boost::irange(first, last)); + + BOOST_CHECK_EQUAL_COLLECTIONS( test.begin(), test.end(), + reference.begin(), reference.end() ); + } + + // Test an integer range with a runtime specified step size. + template + void test_irange_impl(Integer first, Integer last, int step) + { + BOOST_ASSERT( step != 0 ); + std::vector reference; + if (step > 0) + { + for (Integer i = first; i < last; i += step) + reference.push_back(i); + } + else + { + for (Integer i = first; i > last; i += step) + reference.push_back(i); + } + + std::vector test; + boost::push_back(test, boost::irange(first, last, step)); + + BOOST_CHECK_EQUAL_COLLECTIONS( test.begin(), test.end(), + reference.begin(), reference.end() ); + } + + // Test driver function that for an integer range [first, last) + // drives the test implementation through various integer + // types. + void test_irange(int first, int last) + { + test_irange_impl(first,last); + test_irange_impl(first, last); + test_irange_impl(first, last); + test_irange_impl(first, last); + test_irange_impl(first, last); + test_irange_impl(first, last); + test_irange_impl(first, last); + test_irange_impl(first, last); + } + + // Test driver function that for an integer range [first, last) + // drives the test implementation through various integer + // types step_size items at a time. + void test_irange(int first, int last, int step_size) + { + BOOST_ASSERT( step_size != 0 ); + BOOST_ASSERT( (last - first) % step_size == 0 ); + test_irange_impl(first, last, step_size); + test_irange_impl(first, last, step_size); + test_irange_impl(first, last, step_size); + test_irange_impl(first, last, step_size); + test_irange_impl(first, last, step_size); + test_irange_impl(first, last, step_size); + test_irange_impl(first, last, step_size); + test_irange_impl(first, last, step_size); + } + + // Implementation of the unit test for the integer range + // function. + // This starts the test drivers to drive a set of integer types + // for a combination of range values chosen to exercise a large + // number of implementation branches. + void irange_unit_test() + { + // Test the single-step version of irange(first, last) + test_irange(0, 0); + test_irange(0, 1); + test_irange(0, 10); + test_irange(1, 1); + test_irange(1, 2); + test_irange(1, 11); + + // Test the n-step version of irange(first, last, step-size) + test_irange(0, 0, 1); + test_irange(0, 0, -1); + test_irange(0, 10, 1); + test_irange(10, 0, -1); + test_irange(0, 2, 2); + test_irange(2, 0, -2); + test_irange(10, 20, 5); + test_irange(20, 10, -5); + } +} // namespace boost + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.irange" ); + + test->add(BOOST_TEST_CASE( &boost::irange_unit_test )); + + return test; +} diff --git a/test/iterator_pair.cpp b/test/iterator_pair.cpp old mode 100755 new mode 100644 index 2546817..495bd6f --- a/test/iterator_pair.cpp +++ b/test/iterator_pair.cpp @@ -23,8 +23,6 @@ #include #include -using namespace boost; - void check_iterator_pair() { typedef std::vector vec_t; @@ -35,57 +33,56 @@ void check_iterator_pair() typedef std::pair const_pair_t; typedef const pair_t const_pair_tt; - pair_t pair = std::make_pair( begin( vec ), end( vec ) ); - const_pair_t const_pair = std::make_pair( begin( vec ), end( vec ) ); + pair_t pair = std::make_pair( boost::begin( vec ), boost::end( vec ) ); + const_pair_t const_pair = std::make_pair( boost::begin( vec ), boost::end( vec ) ); const_pair_tt constness_pair( pair ); - - BOOST_STATIC_ASSERT(( is_same< range_value::type, - detail::iterator_traits::value_type>::value )); - BOOST_STATIC_ASSERT(( is_same< range_iterator::type, pair_t::first_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_const_iterator::type, pair_t::first_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_difference::type, - detail::iterator_traits::difference_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_size::type, std::size_t >::value )); - BOOST_STATIC_ASSERT(( is_same< range_iterator::type, pair_t::first_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const_pair_t::first_type >::value )); - - BOOST_STATIC_ASSERT(( is_same< range_value::type, - detail::iterator_traits::value_type>::value )); - BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const_pair_tt::first_type >::value )); + + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_value::type, + boost::detail::iterator_traits::value_type>::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_iterator::type, pair_t::first_type >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_const_iterator::type, pair_t::first_type >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_difference::type, + boost::detail::iterator_traits::difference_type >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_size::type, std::size_t >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_iterator::type, pair_t::first_type >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_iterator::type, const_pair_t::first_type >::value )); + + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_value::type, + boost::detail::iterator_traits::value_type>::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_iterator::type, const_pair_tt::first_type >::value )); // // This behavior is not supported with v2. //BOOST_STATIC_ASSERT(( is_same< range_const_iterator::type, const_pair_tt::first_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_difference::type, - detail::iterator_traits::difference_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_size::type, std::size_t >::value )); - BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const_pair_tt::first_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_iterator::type, const_pair_tt::first_type >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_difference::type, + boost::detail::iterator_traits::difference_type >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_size::type, std::size_t >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_iterator::type, const_pair_tt::first_type >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_iterator::type, const_pair_tt::first_type >::value )); - BOOST_CHECK( begin( pair ) == pair.first ); - BOOST_CHECK( end( pair ) == pair.second ); - BOOST_CHECK( empty( pair ) == (pair.first == pair.second) ); - BOOST_CHECK( size( pair ) == std::distance( pair.first, pair.second ) ); - - BOOST_CHECK( begin( const_pair ) == const_pair.first ); - BOOST_CHECK( end( const_pair ) == const_pair.second ); - BOOST_CHECK( empty( const_pair ) == (const_pair.first == const_pair.second) ); - BOOST_CHECK( size( const_pair ) == std::distance( const_pair.first, const_pair.second ) ); + BOOST_CHECK( boost::begin( pair ) == pair.first ); + BOOST_CHECK( boost::end( pair ) == pair.second ); + BOOST_CHECK( boost::empty( pair ) == (pair.first == pair.second) ); + BOOST_CHECK( boost::size( pair ) == std::distance( pair.first, pair.second ) ); - BOOST_CHECK( begin( constness_pair ) == constness_pair.first ); - BOOST_CHECK( end( constness_pair ) == constness_pair.second ); - BOOST_CHECK( empty( constness_pair ) == (constness_pair.first == const_pair.second) ); - BOOST_CHECK( size( constness_pair ) == std::distance( constness_pair.first, constness_pair.second ) ); + BOOST_CHECK( boost::begin( const_pair ) == const_pair.first ); + BOOST_CHECK( boost::end( const_pair ) == const_pair.second ); + BOOST_CHECK( boost::empty( const_pair ) == (const_pair.first == const_pair.second) ); + BOOST_CHECK( boost::size( const_pair ) == std::distance( const_pair.first, const_pair.second ) ); + + BOOST_CHECK( boost::begin( constness_pair ) == constness_pair.first ); + BOOST_CHECK( boost::end( constness_pair ) == constness_pair.second ); + BOOST_CHECK( boost::empty( constness_pair ) == (constness_pair.first == const_pair.second) ); + BOOST_CHECK( boost::size( constness_pair ) == std::distance( constness_pair.first, constness_pair.second ) ); } #include -using boost::unit_test::test_suite; -test_suite* init_unit_test_suite( int argc, char* argv[] ) +boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] ) { - test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); + boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); test->add( BOOST_TEST_CASE( &check_iterator_pair ) ); diff --git a/test/iterator_range.cpp b/test/iterator_range.cpp old mode 100755 new mode 100644 index db531d3..47bc565 --- a/test/iterator_range.cpp +++ b/test/iterator_range.cpp @@ -19,32 +19,29 @@ #include #include -#include +#include #include #include #include #include -using namespace boost; -using namespace std; - void check_reference_type(); void check_iterator_range() { - - typedef string::iterator iterator; - typedef string::const_iterator const_iterator; - typedef iterator_range irange; - typedef iterator_range cirange; - string str = "hello world"; - const string cstr = "const world"; - irange r = make_iterator_range( str ); - r = make_iterator_range( str.begin(), str.end() ); - cirange r2 = make_iterator_range( cstr ); - r2 = make_iterator_range( cstr.begin(), cstr.end() ); - r2 = make_iterator_range( str ); - + + typedef std::string::iterator iterator; + typedef std::string::const_iterator const_iterator; + typedef boost::iterator_range irange; + typedef boost::iterator_range cirange; + std::string str = "hello world"; + const std::string cstr = "const world"; + irange r = boost::make_iterator_range( str ); + r = boost::make_iterator_range( str.begin(), str.end() ); + cirange r2 = boost::make_iterator_range( cstr ); + r2 = boost::make_iterator_range( cstr.begin(), cstr.end() ); + r2 = boost::make_iterator_range( str ); + BOOST_CHECK( !r.empty() ); BOOST_CHECK( !r2.empty() ); @@ -53,7 +50,7 @@ void check_iterator_range() // BOOST_CHECK( false ); // if( !(bool)r2 ) // BOOST_CHECK( false ); -//#else +//#else if( !r ) BOOST_CHECK( false ); if( !r2 ) @@ -62,55 +59,53 @@ void check_iterator_range() BOOST_CHECK_EQUAL( r.size(), size( r ) ); BOOST_CHECK_EQUAL( r2.size(), size( r2 ) ); - - BOOST_CHECK_EQUAL( distance( r.begin(), r.end() ), - distance( begin( r2 ), end( r2 ) ) ); - cout << r << r2; - + BOOST_CHECK_EQUAL( std::distance( r.begin(), r.end() ), + std::distance( begin( r2 ), end( r2 ) ) ); + std::cout << r << r2; + + #ifndef BOOST_NO_STD_WSTRING - wcout << make_iterator_range( wstring( L"a wide string" ) ) - << make_iterator_range( L"another wide string" ); -#endif - - string res = copy_range( r ); - BOOST_CHECK( equal( res.begin(), res.end(), r.begin() ) ); + std::wcout << boost::make_iterator_range( std::wstring( L"a wide string" ) ) + << boost::make_iterator_range( L"another wide string" ); +#endif - irange rr = make_iterator_range( str ); + std::string res = boost::copy_range( r ); + BOOST_CHECK_EQUAL_COLLECTIONS( res.begin(), res.end(), r.begin(), r.end() ); + + irange rr = boost::make_iterator_range( str ); BOOST_CHECK( rr.equal( r ) ); - rr = make_iterator_range( str.begin(), str.begin() + 5 ); - BOOST_CHECK( rr == as_literal("hello") ); - BOOST_CHECK( rr != as_literal("hell") ); - BOOST_CHECK( rr < as_literal("hello dude") ); - BOOST_CHECK( as_literal("hello") == rr ); - BOOST_CHECK( as_literal("hell") != rr ); - BOOST_CHECK( ! (as_literal("hello dude") < rr ) ); + rr = boost::make_iterator_range( str.begin(), str.begin() + 5 ); + BOOST_CHECK( rr == boost::as_literal("hello") ); + BOOST_CHECK( rr != boost::as_literal("hell") ); + BOOST_CHECK( rr < boost::as_literal("hello dude") ); + BOOST_CHECK( boost::as_literal("hello") == rr ); + BOOST_CHECK( boost::as_literal("hell") != rr ); + BOOST_CHECK( ! (boost::as_literal("hello dude") < rr ) ); irange rrr = rr; BOOST_CHECK( rrr == rr ); BOOST_CHECK( !( rrr != rr ) ); BOOST_CHECK( !( rrr < rr ) ); - const irange cr = make_iterator_range( str ); + const irange cr = boost::make_iterator_range( str ); BOOST_CHECK_EQUAL( cr.front(), 'h' ); BOOST_CHECK_EQUAL( cr.back(), 'd' ); BOOST_CHECK_EQUAL( cr[1], 'e' ); BOOST_CHECK_EQUAL( cr(1), 'e' ); - rrr = make_iterator_range( str, 1, -1 ); - BOOST_CHECK( rrr == as_literal("ello worl") ); - rrr = make_iterator_range( rrr, -1, 1 ); + rrr = boost::make_iterator_range( str, 1, -1 ); + BOOST_CHECK( rrr == boost::as_literal("ello worl") ); + rrr = boost::make_iterator_range( rrr, -1, 1 ); BOOST_CHECK( rrr == str ); check_reference_type(); } -using boost::unit_test::test_suite; - -test_suite* init_unit_test_suite( int argc, char* argv[] ) +boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] ) { - test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); + boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); test->add( BOOST_TEST_CASE( &check_iterator_range ) ); @@ -122,16 +117,16 @@ test_suite* init_unit_test_suite( int argc, char* argv[] ) // // Check that constness is propgated correct from // the iterator types. -// +// // Test contributed by Larry Evans. -// +// template< class Container > int test_iter_range( Container& a_cont ) { - typedef BOOST_DEDUCED_TYPENAME range_iterator::type citer_type; - typedef iterator_range riter_type; - riter_type a_riter( make_iterator_range( a_cont ) ); + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type citer_type; + typedef boost::iterator_range riter_type; + riter_type a_riter( boost::make_iterator_range( a_cont ) ); a_riter.front(); a_riter.back(); int i = a_riter[0]; @@ -142,7 +137,7 @@ int test_iter_range( Container& a_cont ) void check_reference_type() { - typedef vector veci_type; + typedef std::vector veci_type; veci_type a_vec; a_vec.push_back( 999 ); test_iter_range(a_vec); diff --git a/test/join.cpp b/test/join.cpp new file mode 100644 index 0000000..290e651 --- /dev/null +++ b/test/join.cpp @@ -0,0 +1,273 @@ +// Boost.Range library +// +// Copyright Neil Groves 2010. 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 + +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include + +namespace boost +{ + namespace + { + // This function is a helper function that writes integers + // of increasing value into a range. It is used to test + // that joined ranged may be written to. + // + // Requires: + // - Range uses shallow copy semantics. + template< typename Range > + void fill_with_ints(Range rng) + { + typedef typename range_iterator::type iterator; + iterator target = boost::begin(rng); + const int count = boost::distance(rng); + for (int i = 0; i < count; ++i) + { + *target = i; + ++target; + } + } + + // The test_join_traversal function is used to provide additional + // tests based upon the underlying join iterator traversal. + // The join iterator takes care of the appropriate demotion, and + // this demotion. + + // test_join_traversal - additional tests for input and forward + // traversal iterators. This is of course a no-op. + template< typename Range1, typename Range2, typename TraversalTag > + void test_join_traversal(Range1& rng1, Range2& rng2, TraversalTag) + { + } + + // test_join_traversal - additional tests for bidirectional + // traversal iterators. + template< typename Range1, typename Range2 > + void test_join_traversal(Range1& rng1, Range2& rng2, boost::bidirectional_traversal_tag) + { + typedef typename range_value::type value_type; + std::vector reference(boost::begin(rng1), boost::end(rng1)); + boost::push_back(reference, rng2); + std::reverse(reference.begin(), reference.end()); + + std::vector test_result; + BOOST_REVERSE_FOREACH( value_type x, join(rng1, rng2) ) + { + test_result.push_back(x); + } + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test_result.begin(), test_result.end() ); + } + + // Test helper function to implement the additional tests for random + // access traversal iterators. This is used by the test_join_traversal + // function for random access iterators. The reason that the test + // implementation is put into this function is to utilise + // template parameter type deduction for the joined range type. + template< typename Range1, typename Range2, typename JoinedRange > + void test_random_access_join(Range1& rng1, Range2& rng2, JoinedRange joined) + { + BOOST_CHECK_EQUAL( boost::end(joined) - boost::begin(joined), boost::distance(joined) ); + BOOST_CHECK( boost::end(joined) <= boost::begin(joined) ); + BOOST_CHECK( boost::begin(joined) >= boost::end(joined) ); + if (boost::empty(joined)) + { + BOOST_CHECK(!(boost::begin(joined) < boost::end(joined))); + BOOST_CHECK(!(boost::end(joined) > boost::begin(joined))); + } + else + { + BOOST_CHECK(boost::begin(joined) < boost::end(joined)); + BOOST_CHECK(boost::end(joined) < boost::begin(joined)); + } + + typedef typename boost::range_difference::type difference_t; + const difference_t count = boost::distance(joined); + BOOST_CHECK( boost::begin(joined) + count == boost::end(joined) ); + BOOST_CHECK( boost::end(joined) - count == boost::begin(joined) ); + + typedef typename boost::range_iterator::type iterator_t; + iterator_t it = boost::begin(joined); + it += count; + BOOST_CHECK( it == boost::end(joined) ); + + it = boost::end(joined); + it -= count; + BOOST_CHECK( it == boost::begin(joined) ); + } + + // test_join_traversal function for random access traversal joined + // ranges. + template< typename Range1, typename Range2 > + void test_join_traversal(Range1& rng1, Range2& rng2, boost::random_access_traversal_tag) + { + test_join_traversal(rng1, rng2, boost::bidirectional_traversal_tag()); + test_random_access_join(rng1, rng2, join(rng1, rng2)); + } + + // Test the ability to write values into a joined range. This is + // achieved by copying the constant collections, altering them + // and then checking the result. Hence this relies upon both + // rng1 and rng2 having value copy semantics. + template< typename Collection1, typename Collection2 > + void test_write_to_joined_range(const Collection1& rng1, const Collection2& rng2) + { + Collection1 c1(rng1); + Collection2 c2(rng2); + typedef typename boost::range_value::type value_t; + fill_with_ints(boost::join(c1,c2)); + + // Ensure that the size of the written range has not been + // altered. + BOOST_CHECK_EQUAL( boost::distance(c1), boost::distance(rng1) ); + BOOST_CHECK_EQUAL( boost::distance(c2), boost::distance(rng2) ); + + // For each element x, in c1 ensure that it has been written to + // with incrementing integers + int x = 0; + typedef typename range_iterator::type iterator1; + iterator1 it1 = boost::begin(c1); + for (; it1 != boost::end(c1); ++it1) + { + BOOST_CHECK_EQUAL( x, *it1 ); + ++x; + } + + // For each element y, in c2 ensure that it has been written to + // with incrementing integers + typedef typename range_iterator::type iterator2; + iterator2 it2 = boost::begin(c2); + for (; it2 != boost::end(c2); ++it2) + { + BOOST_CHECK_EQUAL( x, *it2 ); + ++x; + } + } + + // Perform a unit test of a Boost.Range join() comparing + // it to a reference that is populated by appending + // elements from both source ranges into a vector. + template< typename Collection1, typename Collection2 > + void test_join_impl(Collection1& rng1, Collection2& rng2) + { + typedef typename range_value::type value_type; + std::vector reference(boost::begin(rng1), boost::end(rng1)); + boost::push_back(reference, rng2); + + std::vector test_result; + boost::push_back(test_result, join(rng1, rng2)); + + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test_result.begin(), test_result.end() ); + + typedef boost::range_detail::join_iterator< + typename boost::range_iterator::type, + typename boost::range_iterator::type + > join_iterator_t; + + typedef boost::iterator_traversal< join_iterator_t > tag_t; + + test_join_traversal(rng1, rng2, tag_t()); + + test_write_to_joined_range(rng1, rng2); + } + + // Make a collection filling it with items from the source + // range. This is used to build collections of various + // sizes populated with various values designed to optimize + // the code coverage exercised by the core test function + // test_join_impl. + template + boost::shared_ptr makeCollection(const Range& source) + { + boost::shared_ptr c(new Collection); + c->insert(c->end(), boost::begin(source), boost::end(source)); + return c; + } + + // This templatised version of the test_join_impl function + // generates and populates collections which are later + // used as input to the core test function. + // The caller of this function explicitly provides the + // template parameters. This supports the generation + // of testing a large combination of range types to be + // joined. It is of particular importance to remember + // to combine a random_access range with a bidirectional + // range to determine that the correct demotion of + // types occurs in the join_iterator. + template< typename Collection1, typename Collection2 > + void test_join_impl() + { + typedef boost::shared_ptr collection1_ptr; + typedef boost::shared_ptr collection2_ptr; + typedef boost::shared_ptr collection1_cptr; + typedef boost::shared_ptr collection2_cptr; + std::vector< collection1_cptr > left_containers; + std::vector< collection2_cptr > right_containers; + + left_containers.push_back(collection1_ptr(new Collection1)); + left_containers.push_back(makeCollection(irange(0,1))); + left_containers.push_back(makeCollection(irange(0,100))); + + right_containers.push_back(collection2_ptr(new Collection2)); + right_containers.push_back(makeCollection(irange(0,1))); + right_containers.push_back(makeCollection(irange(0,100))); + + BOOST_FOREACH( collection1_cptr left_container, left_containers ) + { + BOOST_FOREACH( collection2_cptr right_container, right_containers ) + { + test_join_impl(*left_container, *right_container); + } + } + } + + // entry-point into the unit test for the join() function + // this tests a representative sample of combinations of + // source range type. + void join_test() + { + test_join_impl< std::vector, std::vector >(); + test_join_impl< std::list, std::list >(); + test_join_impl< std::deque, std::deque >(); + + test_join_impl< std::vector, std::list >(); + test_join_impl< std::list, std::vector >(); + test_join_impl< std::vector, std::deque >(); + test_join_impl< std::deque, std::vector >(); + } + + } +} + +boost::unit_test::test_suite* +init_unit_test_suite(int argc, char* argv[]) +{ + boost::unit_test::test_suite* test + = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.joined" ); + + test->add( BOOST_TEST_CASE( &boost::join_test ) ); + + return test; +} diff --git a/test/reversible_range.cpp b/test/reversible_range.cpp old mode 100755 new mode 100644 index 9dfe8d0..98cc423 --- a/test/reversible_range.cpp +++ b/test/reversible_range.cpp @@ -27,44 +27,39 @@ #include #include -using namespace boost; -using namespace std; - void check_iterator() { - typedef vector vec_t; - typedef vec_t::iterator iterator; - typedef pair pair_t; - typedef range_reverse_iterator::type rev_iterator; - typedef pair rev_pair_t; - + typedef std::vector vec_t; + typedef vec_t::iterator iterator; + typedef std::pair pair_t; + typedef boost::range_reverse_iterator::type rev_iterator; + typedef std::pair rev_pair_t; + vec_t vec; - pair_t p = make_pair( vec.begin(), vec.end() ); - rev_pair_t rp = make_pair( rbegin( p ), rend( p ) ); + pair_t p = std::make_pair( vec.begin(), vec.end() ); + rev_pair_t rp = std::make_pair( boost::rbegin( p ), boost::rend( p ) ); int a[] = {1,2,3,4,5,6,7,8,9,10}; - const int ca[] = {1,2,3,4,5,6,7,8,9,10,11,12}; - BOOST_CHECK( rbegin( vec ) == range_reverse_iterator::type( vec.end() ) ); - BOOST_CHECK( rend( vec ) == range_reverse_iterator::type( vec.begin() ) ); - BOOST_CHECK( std::distance( rbegin( vec ), rend( vec ) ) == std::distance( begin( vec ), end( vec ) ) ); + const int ca[] = {1,2,3,4,5,6,7,8,9,10,11,12}; + BOOST_CHECK( boost::rbegin( vec ) == boost::range_reverse_iterator::type( vec.end() ) ); + BOOST_CHECK( boost::rend( vec ) == boost::range_reverse_iterator::type( vec.begin() ) ); + BOOST_CHECK( std::distance( boost::rbegin( vec ), boost::rend( vec ) ) == std::distance( boost::begin( vec ), boost::end( vec ) ) ); - BOOST_CHECK( rbegin( p ) == begin( rp ) ); - BOOST_CHECK( rend( p ) == end( rp ) ); - BOOST_CHECK( std::distance( rbegin( p ), rend( p ) ) == std::distance( begin( rp ), end( rp ) ) ); - BOOST_CHECK( std::distance( begin( p ), end( p ) ) == std::distance( rbegin( rp ), rend( rp ) ) ); + BOOST_CHECK( boost::rbegin( p ) == boost::begin( rp ) ); + BOOST_CHECK( boost::rend( p ) == boost::end( rp ) ); + BOOST_CHECK( std::distance( boost::rbegin( p ), boost::rend( p ) ) == std::distance( boost::begin( rp ), boost::end( rp ) ) ); + BOOST_CHECK( std::distance( boost::begin( p ), boost::end( p ) ) == std::distance( boost::rbegin( rp ), boost::rend( rp ) ) ); - BOOST_CHECK_EQUAL( &*begin( a ), &*( rend( a ) - 1 ) ); - BOOST_CHECK_EQUAL( &*( end( a ) - 1 ), &*rbegin( a ) ); - BOOST_CHECK_EQUAL( &*begin( ca ), &*( rend( ca ) - 1 ) ); - BOOST_CHECK_EQUAL( &*( end( ca ) - 1 ), &*rbegin( ca ) ); + BOOST_CHECK_EQUAL( &*boost::begin( a ), &*( boost::rend( a ) - 1 ) ); + BOOST_CHECK_EQUAL( &*( boost::end( a ) - 1 ), &*boost::rbegin( a ) ); + BOOST_CHECK_EQUAL( &*boost::begin( ca ), &*( boost::rend( ca ) - 1 ) ); + BOOST_CHECK_EQUAL( &*( boost::end( ca ) - 1 ), &*boost::rbegin( ca ) ); } -using boost::unit_test::test_suite; - -test_suite* init_unit_test_suite( int argc, char* argv[] ) +boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] ) { - test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); + boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); test->add( BOOST_TEST_CASE( &check_iterator ) ); diff --git a/test/std_container.cpp b/test/std_container.cpp old mode 100755 new mode 100644 index e2ee692..9b8f284 --- a/test/std_container.cpp +++ b/test/std_container.cpp @@ -24,46 +24,43 @@ #include #include -using namespace boost; - void check_std_container() { typedef std::vector vec_t; vec_t vec; vec.push_back( 3 ); vec.push_back( 4 ); - const vec_t cvec( vec ); + const vec_t cvec( vec ); - BOOST_STATIC_ASSERT(( is_same< range_value::type, vec_t::value_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_iterator::type, vec_t::iterator >::value )); - BOOST_STATIC_ASSERT(( is_same< range_iterator::type, vec_t::const_iterator >::value )); - BOOST_STATIC_ASSERT(( is_same< range_difference::type, vec_t::difference_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_size::type, vec_t::size_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_iterator::type, vec_t::iterator >::value )); - BOOST_STATIC_ASSERT(( is_same< range_iterator::type, vec_t::const_iterator >::value )); - - BOOST_STATIC_ASSERT(( is_same< range_value::type, vec_t::value_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_difference::type, vec_t::difference_type >::value )); - BOOST_STATIC_ASSERT(( is_same< range_size::type, vec_t::size_type >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_value::type, vec_t::value_type >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_iterator::type, vec_t::iterator >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_iterator::type, vec_t::const_iterator >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_difference::type, vec_t::difference_type >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_size::type, vec_t::size_type >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_iterator::type, vec_t::iterator >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_iterator::type, vec_t::const_iterator >::value )); - BOOST_CHECK( begin( vec ) == vec.begin() ); - BOOST_CHECK( end( vec ) == vec.end() ); - BOOST_CHECK( empty( vec ) == vec.empty() ); - BOOST_CHECK( (std::size_t)size( vec ) == vec.size() ); - - BOOST_CHECK( begin( cvec ) == cvec.begin() ); - BOOST_CHECK( end( cvec ) == cvec.end() ); - BOOST_CHECK( empty( cvec ) == cvec.empty() ); - BOOST_CHECK( (std::size_t)size( cvec ) == cvec.size() ); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_value::type, vec_t::value_type >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_difference::type, vec_t::difference_type >::value )); + BOOST_STATIC_ASSERT(( boost::is_same< boost::range_size::type, vec_t::size_type >::value )); + + BOOST_CHECK( boost::begin( vec ) == vec.begin() ); + BOOST_CHECK( boost::end( vec ) == vec.end() ); + BOOST_CHECK( boost::empty( vec ) == vec.empty() ); + BOOST_CHECK( static_cast(boost::size( vec )) == vec.size() ); + + BOOST_CHECK( boost::begin( cvec ) == cvec.begin() ); + BOOST_CHECK( boost::end( cvec ) == cvec.end() ); + BOOST_CHECK( boost::empty( cvec ) == cvec.empty() ); + BOOST_CHECK( static_cast(boost::size( cvec )) == cvec.size() ); } #include -using boost::unit_test::test_suite; -test_suite* init_unit_test_suite( int argc, char* argv[] ) +boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] ) { - test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); + boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); test->add( BOOST_TEST_CASE( &check_std_container ) ); diff --git a/test/sub_range.cpp b/test/sub_range.cpp old mode 100755 new mode 100644 index 7d5bf05..80c942f --- a/test/sub_range.cpp +++ b/test/sub_range.cpp @@ -17,51 +17,48 @@ #endif #include -#include +#include #include #include #include #include -using namespace boost; -using namespace std; - void check_sub_range() { - - typedef string::iterator iterator; - typedef string::const_iterator const_iterator; - typedef iterator_range irange; - typedef iterator_range cirange; - string str = "hello world"; - const string cstr = "const world"; - irange r = make_iterator_range( str ); - r = make_iterator_range( str.begin(), str.end() ); - cirange r2 = make_iterator_range( cstr ); - r2 = make_iterator_range( cstr.begin(), cstr.end() ); - r2 = make_iterator_range( str ); - - typedef sub_range srange; - typedef sub_range csrange; + + typedef std::string::iterator iterator; + typedef std::string::const_iterator const_iterator; + typedef boost::iterator_range irange; + typedef boost::iterator_range cirange; + std::string str = "hello world"; + const std::string cstr = "const world"; + irange r = boost::make_iterator_range( str ); + r = boost::make_iterator_range( str.begin(), str.end() ); + cirange r2 = boost::make_iterator_range( cstr ); + r2 = boost::make_iterator_range( cstr.begin(), cstr.end() ); + r2 = boost::make_iterator_range( str ); + + typedef boost::sub_range srange; + typedef boost::sub_range csrange; srange s = r; BOOST_CHECK( r == r ); BOOST_CHECK( s == r ); - s = make_iterator_range( str ); + s = boost::make_iterator_range( str ); csrange s2 = r; s2 = r2; - s2 = make_iterator_range( cstr ); + s2 = boost::make_iterator_range( cstr ); BOOST_CHECK( r2 == r2 ); BOOST_CHECK( s2 != r2 ); - s2 = make_iterator_range( str ); + s2 = boost::make_iterator_range( str ); BOOST_CHECK( !(s != s) ); - + BOOST_CHECK( r.begin() == s.begin() ); BOOST_CHECK( r2.begin()== s2.begin() ); BOOST_CHECK( r.end() == s.end() ); BOOST_CHECK( r2.end() == s2.end() ); BOOST_CHECK_EQUAL( r.size(), s.size() ); BOOST_CHECK_EQUAL( r2.size(), s2.size() ); - + //#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) // if( !(bool)r ) // BOOST_CHECK( false ); @@ -70,7 +67,7 @@ void check_sub_range() // if( !(bool)s ) // BOOST_CHECK( false ); // if( !(bool)s2 ) -// BOOST_CHECK( false ); +// BOOST_CHECK( false ); //#else if( !r ) BOOST_CHECK( false ); @@ -80,13 +77,13 @@ void check_sub_range() BOOST_CHECK( false ); if( !s2 ) BOOST_CHECK( false ); -//#endif +//#endif + + std::cout << r << r2 << s << s2; + + std::string res = boost::copy_range( r ); + BOOST_CHECK_EQUAL_COLLECTIONS( res.begin(), res.end(), r.begin(), r.end() ); - cout << r << r2 << s << s2; - - string res = copy_range( r ); - BOOST_CHECK( equal( res.begin(), res.end(), r.begin() ) ); - r.empty(); s.empty(); r.size(); @@ -107,44 +104,43 @@ void check_sub_range() //BOOST_CHECK( empty( singular_srange ) ); // - srange rr = make_iterator_range( str ); + srange rr = boost::make_iterator_range( str ); BOOST_CHECK( rr.equal( r ) ); - rr = make_iterator_range( str.begin(), str.begin() + 5 ); - BOOST_CHECK( rr == as_literal("hello") ); - BOOST_CHECK( rr != as_literal("hell") ); - BOOST_CHECK( rr < as_literal("hello dude") ); - BOOST_CHECK( as_literal("hello") == rr ); - BOOST_CHECK( as_literal("hell") != rr ); - BOOST_CHECK( ! (as_literal("hello dude") < rr ) ); - + rr = boost::make_iterator_range( str.begin(), str.begin() + 5 ); + BOOST_CHECK( rr == boost::as_literal("hello") ); + BOOST_CHECK( rr != boost::as_literal("hell") ); + BOOST_CHECK( rr < boost::as_literal("hello dude") ); + BOOST_CHECK( boost::as_literal("hello") == rr ); + BOOST_CHECK( boost::as_literal("hell") != rr ); + BOOST_CHECK( ! (boost::as_literal("hello dude") < rr ) ); + irange rrr = rr; BOOST_CHECK( rrr == rr ); BOOST_CHECK( !( rrr != rr ) ); BOOST_CHECK( !( rrr < rr ) ); - const irange cr = make_iterator_range( str ); + const irange cr = boost::make_iterator_range( str ); BOOST_CHECK_EQUAL( cr.front(), 'h' ); BOOST_CHECK_EQUAL( cr.back(), 'd' ); BOOST_CHECK_EQUAL( cr[1], 'e' ); BOOST_CHECK_EQUAL( cr(1), 'e' ); - rrr = make_iterator_range( str, 1, -1 ); - BOOST_CHECK( rrr == as_literal("ello worl") ); - rrr = make_iterator_range( rrr, -1, 1 ); + rrr = boost::make_iterator_range( str, 1, -1 ); + BOOST_CHECK( rrr == boost::as_literal("ello worl") ); + rrr = boost::make_iterator_range( rrr, -1, 1 ); BOOST_CHECK( rrr == str ); rrr.front() = 'H'; rrr.back() = 'D'; rrr[1] = 'E'; - BOOST_CHECK( rrr == as_literal("HEllo worlD") ); -} + BOOST_CHECK( rrr == boost::as_literal("HEllo worlD") ); +} #include -using boost::unit_test::test_suite; -test_suite* init_unit_test_suite( int argc, char* argv[] ) +boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] ) { - test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); + boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); test->add( BOOST_TEST_CASE( &check_sub_range ) ); diff --git a/test/test_driver/range_return_test_driver.hpp b/test/test_driver/range_return_test_driver.hpp new file mode 100644 index 0000000..6f4fc3b --- /dev/null +++ b/test/test_driver/range_return_test_driver.hpp @@ -0,0 +1,405 @@ +// Copyright Neil Groves 2009. 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_TEST_TEST_DRIVER_RANGE_RETURN_TEST_DRIVER_HPP_INCLUDED +#define BOOST_RANGE_TEST_TEST_DRIVER_RANGE_RETURN_TEST_DRIVER_HPP_INCLUDED + +#include +#include +#include + +namespace boost +{ + namespace range_test + { + // check the results of an algorithm that returns + // a range_return. + // + // This version is the general version. It should never be called. + // All calls should invoke specialized implementations. + template< range_return_value return_type > + struct check_results + { + template< class Container, class Iterator > + static void check( + Container& test, + Container& reference, + Iterator test_it, + Iterator reference_it + ) + { + BOOST_ASSERT( false ); + } + }; + + // check the results of an algorithm that returns + // a 'found' iterator + template< > + struct check_results + { + template< class Container, class Iterator > + static void check( + Container& test, + Container& reference, + Iterator test_it, + Iterator reference_it + ) + { + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + + BOOST_CHECK_EQUAL( std::distance(test.begin(), test_it), + std::distance(reference.begin(), reference_it) ); + } + }; + + // check the results of an algorithm that returns + // a 'next(found)' iterator + template< > + struct check_results + { + template< class Container, class Iterator > + static void check( + Container& test, + Container& reference, + Iterator test_it, + Iterator reference_it + ) + { + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + + if (reference_it == reference.end()) + { + BOOST_CHECK( test_it == test.end() ); + } + else + { + BOOST_CHECK_EQUAL( + std::distance(test.begin(), test_it), + std::distance(reference.begin(), reference_it) + 1); + } + } + }; + + // check the results of an algorithm that returns + // a 'prior(found)' iterator + template< > + struct check_results + { + template< class Container, class Iterator > + static void check( + Container& test, + Container& reference, + Iterator test_it, + Iterator reference_it + ) + { + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + + if (reference_it == reference.begin()) + { + BOOST_CHECK( test_it == test.begin() ); + } + else + { + BOOST_CHECK_EQUAL( + std::distance(test.begin(), test_it) + 1, + std::distance(reference.begin(), reference_it)); + } + } + }; + + // check the results of an algorithm that returns + // a '[begin, found)' range + template< > + struct check_results + { + template< class Container, class Iterator > + static void check( + Container& test, + Container& reference, + iterator_range test_rng, + Iterator reference_it + ) + { + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + + BOOST_CHECK( test_rng.begin() == test.begin() ); + + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference_it, + boost::begin(test_rng), boost::end(test_rng) + ); + } + }; + + // check the results of an algorithm that returns + // a '[begin, next(found))' range + template< > + struct check_results + { + template< class Container, class Iterator > + static void check( + Container& test, + Container& reference, + iterator_range test_rng, + Iterator reference_it + ) + { + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + + BOOST_CHECK( test_rng.begin() == test.begin() ); + + if (reference_it == reference.end()) + { + BOOST_CHECK( test_rng.end() == test.end() ); + } + else + { + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), boost::next(reference_it), + test_rng.begin(), test_rng.end()); + } + } + }; + + // check the results of an algorithm that returns + // a '[begin, prior(found))' range + template< > + struct check_results + { + template< class Container, class Iterator > + static void check( + Container& test, + Container& reference, + iterator_range test_rng, + Iterator reference_it + ) + { + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + + BOOST_CHECK( test_rng.begin() == test.begin() ); + + if (reference_it == reference.begin()) + { + BOOST_CHECK( boost::end(test_rng) == test.begin() ); + } + else + { + BOOST_CHECK_EQUAL( std::distance(boost::begin(test_rng), boost::end(test_rng)) + 1, + std::distance(reference.begin(), reference_it) ); + } + } + }; + + // check the results of an algorithm that returns + // a '[found, end)' range + template< > + struct check_results + { + template< class Container, class Iterator > + static void check( + Container& test, + Container& reference, + iterator_range test_rng, + Iterator reference_it + ) + { + BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), + test.begin(), test.end() ); + + BOOST_CHECK_EQUAL( + std::distance(test.begin(), boost::begin(test_rng)), + std::distance(reference.begin(), reference_it)); + + BOOST_CHECK( boost::end(test_rng) == test.end() ); + } + }; + + // check the results of an algorithm that returns + // a '[next(found), end)' range + template< > + struct check_results + { + template< class Container, class Iterator > + static void check( + Container& test, + Container& reference, + iterator_range test_rng, + Iterator reference_it + ) + { + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + + BOOST_CHECK( test_rng.end() == test.end() ); + + if (reference_it == reference.end()) + { + BOOST_CHECK( test_rng.begin() == test.end() ); + } + else + { + BOOST_CHECK_EQUAL_COLLECTIONS( + boost::next(reference_it), reference.end(), + test_rng.begin(), test_rng.end() + ); + } + } + }; + + // check the results of an algorithm that returns + // a 'prior(found), end)' range + template< > + struct check_results + { + template< class Container, class Iterator > + static void check( + Container& test, + Container& reference, + iterator_range test_rng, + Iterator reference_it + ) + { + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + + BOOST_CHECK( test_rng.end() == test.end() ); + + if (reference_it == reference.begin()) + { + BOOST_CHECK( test_rng.begin() == test.begin() ); + } + else + { + BOOST_CHECK_EQUAL_COLLECTIONS( + boost::prior(reference_it), reference.end(), + test_rng.begin(), test_rng.end() + ); + } + } + }; + + // check the results of an algorithm that returns + // a '[begin, end)' range + template< > + struct check_results + { + template< class Container, class Iterator > + static void check( + Container& test, + Container& reference, + iterator_range test_rng, + Iterator reference_it + ) + { + BOOST_CHECK_EQUAL_COLLECTIONS( + reference.begin(), reference.end(), + test.begin(), test.end() + ); + + BOOST_CHECK( test_rng.begin() == test.begin() ); + BOOST_CHECK( test_rng.end() == test.end() ); + } + }; + + // A test driver to exercise a test through all of the range_return + // combinations. + // + // The test driver also contains the code required to check the + // return value correctness. + // + // The TestPolicy needs to implement two functions: + // + // - perform the boost range version of the algorithm that returns + // a range_return::type + // template + // BOOST_DEDUCED_TYPENAME range_return::type + // test(Container& cont); + // + // - perform the reference std version of the algorithm that + // returns the standard iterator result + // template + // BOOST_DEDUCED_TYPENAME range_iterator::type + // reference(Container& cont); + class range_return_test_driver + { + public: + template< class Container, + class TestPolicy > + void operator()(Container& cont, TestPolicy policy) + { + test_range_iter (cont, policy); + test_range ()(cont, policy); + test_range ()(cont, policy); + test_range ()(cont, policy); + test_range()(cont, policy); + test_range ()(cont, policy); + test_range()(cont, policy); + test_range ()(cont, policy); + test_range ()(cont, policy); + test_range ()(cont, policy); + test_range ()(cont, policy); + } + + private: + template< class Container, class TestPolicy > + void test_range_iter( + Container& cont, + TestPolicy policy + ) + { + typedef BOOST_DEDUCED_TYPENAME range_iterator::type iterator_t; + + Container reference(cont); + Container test(cont); + + iterator_t range_result = policy.test_iter(test); + iterator_t reference_it = policy.reference(reference); + + check_results::check(test, reference, + range_result, reference_it); + } + + template< range_return_value result_type, class Container, class TestPolicy > + struct test_range + { + void operator()(Container& cont, TestPolicy policy) + { + typedef BOOST_DEDUCED_TYPENAME range_iterator::type iterator_t; + typedef BOOST_DEDUCED_TYPENAME range_return::type range_return_t; + typedef BOOST_DEDUCED_TYPENAME TestPolicy::template test_range test_range_t; + + Container reference(cont); + Container test_cont(cont); + + range_return_t range_result = test_range_t()(policy, test_cont); + iterator_t reference_it = policy.reference(reference); + + check_results::check(test_cont, reference, + range_result, reference_it); + } + }; + }; + } +} + +#endif // include guard diff --git a/test/test_function/check_equal_fn.hpp b/test/test_function/check_equal_fn.hpp new file mode 100644 index 0000000..8da2ed8 --- /dev/null +++ b/test/test_function/check_equal_fn.hpp @@ -0,0 +1,49 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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_TEST_FUNCTIONS_CHECK_EQUAL_FN_HPP_INCLUDED +#define BOOST_RANGE_TEST_FUNCTIONS_CHECK_EQUAL_FN_HPP_INCLUDED + +#include "counted_function.hpp" + +namespace boost +{ + namespace range_test_function + { + template< class Collection > + class check_equal_fn : private counted_function + { + typedef BOOST_DEDUCED_TYPENAME Collection::const_iterator iter_t; + public: + explicit check_equal_fn( const Collection& c ) + : m_it(boost::begin(c)), m_last(boost::end(c)) {} + + using counted_function::invocation_count; + + void operator()(int x) const + { + invoked(); + BOOST_CHECK( m_it != m_last ); + if (m_it != m_last) + { + BOOST_CHECK_EQUAL( *m_it, x ); + ++m_it; + } + } + + private: + mutable iter_t m_it; + iter_t m_last; + }; + + } // namespace range_test_function +} // namespace boost + +#endif // include guard diff --git a/test/test_function/counted_function.hpp b/test/test_function/counted_function.hpp new file mode 100644 index 0000000..4a74515 --- /dev/null +++ b/test/test_function/counted_function.hpp @@ -0,0 +1,40 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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_TEST_FUNCTION_COUNTED_FUNCTION_HPP_INCLUDED +#define BOOST_RANGE_TEST_FUNCTION_COUNTED_FUNCTION_HPP_INCLUDED + +namespace boost +{ + namespace range_test_function + { + + class counted_function + { + public: + counted_function() : m_count(0u) {} + + void invoked() const + { + ++m_count; + } + + // Return the number of times that this function object + // has been invoked. + unsigned int invocation_count() const { return m_count; } + + private: + mutable unsigned int m_count; + }; + + } +} + +#endif // include guard diff --git a/test/test_function/equal_to_x.hpp b/test/test_function/equal_to_x.hpp new file mode 100644 index 0000000..14d0016 --- /dev/null +++ b/test/test_function/equal_to_x.hpp @@ -0,0 +1,33 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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_TEST_TEST_FUNCTION_EQUAL_TO_X_HPP_INCLUDED +#define BOOST_RANGE_TEST_TEST_FUNCTION_EQUAL_TO_X_HPP_INCLUDED + +namespace boost +{ + namespace range_test_function + { + template + struct equal_to_x + { + typedef bool result_type; + typedef Arg argument_type; + + explicit equal_to_x(Arg x) : m_x(x) {} + bool operator()(Arg x) const { return x == m_x; } + + private: + Arg m_x; + }; + } +} + +#endif // include guard diff --git a/test/test_function/false_predicate.hpp b/test/test_function/false_predicate.hpp new file mode 100644 index 0000000..533e83d --- /dev/null +++ b/test/test_function/false_predicate.hpp @@ -0,0 +1,29 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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_TEST_TEST_FUNCTION_FALSE_PREDICATE_HPP_INCLUDED +#define BOOST_RANGE_TEST_TEST_FUNCTION_FALSE_PREDICATE_HPP_INCLUDED + +namespace boost +{ + namespace range_test_function + { + struct false_predicate + { + typedef bool result_type; + + bool operator()() const { return false; } + template bool operator()(Arg) const { return false; } + template bool operator()(Arg1,Arg2) const { return false; } + }; + } +} + +#endif // include guard diff --git a/test/test_function/greater_than_x.hpp b/test/test_function/greater_than_x.hpp new file mode 100644 index 0000000..032f594 --- /dev/null +++ b/test/test_function/greater_than_x.hpp @@ -0,0 +1,32 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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_TEST_FUNCTION_GREATER_THAN_X_HPP_INCLUDED +#define BOOST_RANGE_TEST_FUNCTION_GREATER_THAN_X_HPP_INCLUDED + +namespace boost +{ + namespace range_test_function + { + template< class Number > + struct greater_than_x + { + typedef bool result_type; + typedef Number argument_type; + + explicit greater_than_x(Number x) : m_x(x) {} + bool operator()(Number x) const { return x > m_x; } + private: + Number m_x; + }; + } // namespace range_test_function +} // namespace boost + +#endif // include guard diff --git a/test/test_function/multiply_by_x.hpp b/test/test_function/multiply_by_x.hpp new file mode 100644 index 0000000..b343c61 --- /dev/null +++ b/test/test_function/multiply_by_x.hpp @@ -0,0 +1,32 @@ +// Boost.Range library +// +// Copyright Neil Groves 2009. 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_TEST_TEST_FUNCTION_MULTIPLY_BY_X_HPP_INCLUDED +#define BOOST_RANGE_TEST_TEST_FUNCTION_MULTIPLY_BY_X_HPP_INCLUDED + +namespace boost +{ + namespace range_test_function + { + template< class Arg > + struct multiply_by_x + { + typedef Arg result_type; + typedef Arg argument_type; + + explicit multiply_by_x(Arg x) : m_x(x) {} + Arg operator()(Arg x) const { return x * m_x; } + private: + Arg m_x; + }; + } +} + +#endif // include guard