Version 0.4, March 06, 2017
Pure’s interface to C++ vectors, specialized to hold pointers to arbitrary Pure expressions, and the C++ Standard Template Library algorithms that act on them.
All rights reserved.
pure-stlvec is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
pure-stlvec is distributed under a BSD-style license, see the COPYING file for details.
pure-stlvec-0.4 is included in the “umbrella” addon, pure-stllib, which is available at https://bitbucket.org/purelang/pure-lang/downloads. After you have downloaded and installed pure-stllib, you will be able to use pure-stlvec (and pure-stlmap, as well).
The C++ Standard Template Library (“STL”) is a library of generic containers (data structures designed for storing other objects) and a rich set of generic algorithms that operate on them. pure-stlvec provides an interface to one of its most useful containers, “vector”, adopted to hold pointers to Pure expressions. The interface provides Pure programmers with a mutable container “stlvec”, that, like the STL’s vector, holds a sequence of objects that can be accessed in constant time according to their position in the sequence.
The usual operations for creating, accessing and modifying stlvecs are provided by the stlvec module. Most of the operations are similar in name and function to those provided by the Pure Library for other containers. As is the case for their Pure Library counterparts, these operations are in the global namespace. There are a few operations that have been placed in the stl namespace usually because they do not have Pure Library counterparts.
In addition to the stlvec module, pure-stlvec provides a group of modules, stlvec::modifying, stlvec::nonmodifying, stlvec::sort, stlvec::merge, stlvec::heap, stlvec::minmax and stlvec::numeric, that are straight wrappers the STL algorithms (specialized to work with STL vectors of pointers to Pure expressions). This grouping of the STL algorithms follows that found at http://www.cplusplus.com/reference/algorithm/. This web page contains a table that summarizes of all of the algorithms in one place.
pure-stlvec provides an “umbrella” module, stlvec::algorithms, that pulls in all of the STL algorithm interface modules in one go. The STL algorithm wrapper functions reside in the stl namespace and have the same names as their counterparts in the STL.
Here are some examples that use the basic operations provided by the stlvec module.
> using stlvec;
> let sv1 = stlvec (0..4); members sv1;
[0,1,2,3,4]
> insert (sv1,stl::svend) (5..7); members sv1;
STLVEC #<pointer 0xaf4d2c0>
[0,1,2,3,4,5,6,7]
> sv1!3;
3
> sv1!![2,4,6];
[2,4,6]
> replace sv1 3 33; members sv1;
STLVEC #<pointer 0xaf4d2c0>
[0,1,2,33,4,5,6,7]
> stl::erase (sv1,2,5); members sv1;
STLVEC #<pointer 0xaf4d2c0>
[0,1,5,6,7]
> insert (sv1,2) [2,3,4]; members sv1;
STLVEC #<pointer 0xaf4d2c0>
[0,1,2,3,4,5,6,7]
> let pure_vector = stl::vector (sv1,1,5); pure_vector;
{1,2,3,4}
> stlvec pure_vector;
STLVEC #<pointer 0x9145a38>
> members ans;
[1,2,3,4]
> map (+10) sv1;
[10,11,12,13,14,15,16,17]
> map (+10) (sv1,2,5);
[12,13,14]
> foldl (+) 0 sv1;
28
> [x+10 | x = sv1; x mod 2];
[11,13,15,17]
> {x+10 | x = (sv1,2,6); x mod 2};
{13,15}
Here are some examples that use STL algorithms.
> using stlvec::algorithms;
> stl::reverse (sv1,2,6); members sv1;
()
[0,1,5,4,3,2,6,7]
> stl::stable_sort sv1 (>); members sv1;
()
[7,6,5,4,3,2,1,0]
> stl::random_shuffle sv1; members sv1 1;
()
[1,3,5,4,0,7,6,2]
> stl::partition sv1 (<3); members (sv1,0,ans); members sv1;
3
[1,2,0]
[1,2,0,4,5,7,6,3]
> stl::transform sv1 (sv1,0) (*2); members sv1;
-1
[2,4,0,8,10,14,12,6]
> let sv2 = emptystlvec;
> stl::transform sv1 (sv2,stl::svback) (div 2); members sv2;
-1
[1,2,0,4,5,7,6,3]
Many more examples can be found in the pure-stlvec/ut directory.
Throughout the documentation for pure-stlvec, the member of a stlvec that is at the nth position in the sequence of expressions stored in the stlvec is referred to as its nth member or nth element. The nth member of a stlvec, sv, is sometimes denoted by sv!n. The sequence of members of sv starting at position i up to but not including j is denoted by sv[i,j). There is a “past-the-end” symbol, stl::svend, that denotes the position after that occupied by the last member contained by a stlvec.
For example, if sv contains the sequence “a”, “b”, “c” “d” and “e”, sv!0 is “a”, sv[1,3) is the sequence consisting of “b” followed by “c” and v[3,stl::svend) denotes the sequence consisting of “d” followed by “e”.
In C++ a programmer accesses a STL container’s elements by means of “iterators”, which can be thought of as pointers to the container’s elements. A single iterator can be used to access a specific element, and a pair of iterators can be used to access a “range” of elements. By convention, such a range includes the member pointed to by the first iterator and all succeeding members up to but not including the member pointed to by the second iterator. Each container has a past-the-end iterator that can be used to specifiy ranges that include the container’s last member.
In the case of vectors there is an obvious correspondence between an iterator that points to an element and the element’s position (starting at zero) in the vector. pure-stlvec uses this correspondence to designate a stlvec’s members in a way that makes it relatively easy to see how pure-stlvec’s functions are acting on the stlvec’s underlying STL vector by referencing the STL’s documentation. Thus, if sv is a stlvec, and j is an int, “replace sv j x” uses the STL to replace the element pointed to by the iterator for position j of sv’s underlying STL vector. If, in addition, k is an int, stl::sort (sv,j,k) (<) uses the STL to sort the elements in the range designated by the “jth” and “kth” iterators for sv’s underlying STL vector. This range, written as sv[j,k), is the subsequence of sv that begins with the element at position j and ends with the element at position (k-1).
Besides iterators, another cornerstone of the STL is its “value semantics”, i.e., all of the STL containers are mutable and if a container is copied, all of its elements are copied. pure-stlvec deals with the STL’s value semantics by introducing mutable and nonmutable stlvecs, and by storing smart pointers to objects (which have cheap copies) rather than the actual objects.
As mentioned in the previous section, in C++ ranges are specified by a pair of STL iterators.
In pure-stlvec ranges of elements in a stlvec are specified by “iterator tuples” rather than, say, actual pointers to STL iterators. Iterator tuples consist of the name of a stlvec followed by one of more ints that indicate positions (starting from zero) of the stlvec’s elements.
To illustrate how iterator tuples are used, consider the STL stable_sort function, which sorts objects in the range [first, last) in the order imposed by comp. Its C++ signature looks like this:
void stable_sort ( RandomAccessIterator first, RandomAccessIterator last, Compare comp )
The corresponding pure-stlvec function, from the stlvec::sort module, looks like this:
stable_sort (msv, first, last) comp
where msv is a mutable stlvec, and first and last are ints. The first thing that the Pure stable_sort does is create a pair of C++ iterators that point to the elements in msv’s underlying STL vector that occupy the positions designated by first and last. Next it wraps the Pure comp function in a C++ function object that, along with the two iterators, is passed to the C++ stable_sort function.
For convenience, (sv,stl::svbeg, stl::svend) can be written simply as sv. Thus, if first were stl::svbeg (or 0), and last were stl::svend (or #msv, the number of elements in msv), the last Pure call could be written:
stable_sort msv comp
It should be noted that often the STL library provides a default version of its functions, which like stable_sort, use a comparator or other callback function provided by the caller. E.g., the C++ stable_sort has a default version that assumes the “<” operator can be used on the elements held by the container in question:
void stable_sort ( RandomAccessIterator first, RandomAccessIterator last)
The corresponding functions provided by the pure-stlvec modules rarely, if ever, supply a default version. A typical example is stlvec::sort’s stable_sort which must be called with a comparator callback function:
stable_sort msv (<);
Note also that the comparator (e.g., (<)), or other function being passed to a pure-stlvec algorithm wrapper is almost always the last parameter. This is the opposite of what is required for similar Pure functions, but is consistent with the STL calling conventions.
The following integer constants are defined in the stl namespace for use in iterator tuples.
stl::svbeg = 0
, stl::svend = -1
, stl::svback = -2
These three symbols are declared as nonfix. svend
corresponds to STL’s past-end iterator for STL vectors. It makes it possible to specify ranges that include the last element of an stlvec. I.e., the iterator tuple (sv,stl::svbeg,stl::svend) would specify sv[0,n), where n is the number of elements in sv. In order to understand the purpose of svback
, it is necessary to understand a bit about STL’s “back insert iterators.”
Many of the STL algorithms insert members into a target range designated by an iterator that points to the first member of the target range. Consistent with raw C usage, it is ok to copy over existing elements the target stlvec. E.g.,:
> using stlvec::modifying;
> let v1 = stlvec (0..2);
> let v2 = stlvec ("a".."g");
> stl::copy v1 (v2,2) $$ members v2;
["a","b",0,1,2,"f","g"]
This is great for C++ programmers, but for Pure programmers it is almost always preferable to append the copied items to the end of a target stlvec, rather than overwriting all or part or part of it. This can be accomplished using stl::svback. E.g.,:
> stl::copy v1 (v2,stl::svback) $$ members v2;
["a","b",0,1,2,"f","g",0,1,2]
In short, when a pure-stlvec function detects “stl::svback” in a target iterator tuple, it constructs a STL “back inserter iterator” and passes it on to the corresponding wrapped STL function.
Currently, stlvecs are of the form (STLVEC x) or (CONST_STLVEC x), where STLVEC AND CONST_STLVEC are defined as nonfix symbols in the global namespace and x is a pointer to the underlying STL vector. The stlvec module defines corresponding type tags, stlvec and const_stlvec, so the programmer never needs to worry about the underlying representaton.
This representation may change in the future, and must not be relied upon by client modules. In particular, one must never attempt to use the embedded pointer directly.
As the names suggest, stlvecs are mutable and const_stlvecs are immutable. Functions that modify a stlvec will simply fail unless the stlvec is mutable.
> let v = const_stlvec $ stlvec (0..3); v2;
CONST_STLVEC #<pointer 0x8c1dbf0>
> replace v 0 100; // fails
replace (CONST_STLVEC #<pointer 0x9f07690> 0 100
pure-stlvec introduces six type tags, all of which are in the global namespace:
mutable_stlvec
const_stlvec
stlvec
mutable_svit
const_svit
svit
The pure-stlvec module functions do not implement automatic copy-on-write semantics. Functions that modify stlvec parameters will simply fail if they are passed a const_stlvec when they expect a mutable_stlvec.
For those that prefer immutable data structures, stlvecs can be converted to const_stlvecs (usually after they have been created and modified within a function) by the const_stlvec
function. This function converts a mutable stlvec to an immutable stlvec without changing the underlying STL vector.
Typically, a “pure” function that “modifies” a stlvec passed to it as an argument will first copy the input stlvec to a new locally scoped (mutable) stlvec using the stlvec function. It will then modify the new stlvec and use const_stlvec to make the new stlvec immutable before it is returned. It should be noted that several of the STL algorithms have “copy” versions which place their results directly into a new stlvec, which can eliminate the need to copy the input stlvec. E.g.:
> let sv1 = stlvec ("a".."e");
> let sv2 = emptystlvec;
> stl::reverse_copy sv1 (sv2,stl::svback) $$ members sv2;
["e","d","c","b","a"]
Without reverse_copy, one would have had to copy sv1 into sv2 and then reverse sv2.
If desired, in Pure it is easy to write functions that have automatic copy-on-write semantics. E.g.,
> my_replace csv::const_stlvec i x = my_replace (stlvec csv) i x;
> my_replace sv::stlvec i x = replace sv i x;
The pure-stllib/doc directory includes a rudimentary cheatsheet, pure-stllib-cheatsheet.pdf, that shows the signatures of all of the functions provided by pure-stlvec (and by pure-stlmap as well).
The documentation of the functions provided by the stlvec module are reasonably complete. In contrast, the descriptions of functions provided by the STL algorithm modules are purposely simplified (and may not, therefore, be technically accurate). This reflects that fact that the functions provided by pure-stlvec have an obvious correspondence to the functions provided by the STL, and the STL is extremely well documented. Furthermore, using the Pure interpreter, it is very easy to simply play around with with any of the pure-stlvec functions if there are doubts, especially with respect to “corner cases.” Often this leads to a deeper understanding compared to reading a precise technical description.
A good book on the STL is STL Tutorial and Reference Guide, Second Edition, by David R. Musser, Gillmer J. Derge and Atul Saini. A summary of all of the STL algorithms can be found at http://www.cplusplus.com/reference/stl/.
In the descriptions of functions that follow, parameter names used in function descriptions represent specific types of Pure objects:
stlvec (mutable or immutable)
const (i.e., immutable) stlvec
mutable stlvec
an arbitrary Pure expression
a list of arbitrary Pure expressions
whole numbers to indicate a number of elements, size of a vector, etc
whole numbers used to designate indexes into a stlvec
whole numbers (or stl::beg or stl::svend) designating the “first”, “middle” or “last” iterators in a stlvec iterator tuple
a whole number (or other iterator constant such as stl::svend or stl::svback) used in a two element iterator tuple (e.g., (sv,p))
an iterator tuple that will be mapped to an iterator that points to the pth position of sv’s underlying STL vector, v, (or to a back iterator on v if p is stl::svback)
an iterator tuple that will be mapped to the pair of iterators that are designated by (sv,f) and (sv,l)
an iterator tuple that will be mapped to the iterators that are designated by (sv,f), (sv,m) and (sv,l)
the range of members beginning with that at (sv,f) up to but not including that at (con,l)
a function that accepts two objects and returns true if the first argument is less than the second (in the strict weak ordering defined by comp), and false otherwise
a function that accepts one object and returns true or false
a function that accepts two objects and returns true or false
a function that accepts one objects and returns another
a function that accepts two objects and returns another
a function of one parameter that produces a sequence of objects, one for each call
For readability, and to correspond with the STL documentation, the words “first”, “middle”, and “last”, or variants such as “first1” are often used instead of f,m,l.
The functions provided this module handle errors by throwing exceptions.
bad_argument
bad_function
failed_cond
out_of_bounds
range_overflow
range_overlap
In addition, any exception thrown by a Pure callback function passed to a pure-stlvec function will be caught and be rethrown by the pure-stlvec function.
> using stlvec, stlvec::modifying;
> let sv1 = stlvec (0..4); members sv1;
[0,1,2,3,4]
> let sv2 = stlvec ("a".."e"); members sv2;
["a","b","c","d","e"]
> sv1!10;
<stdin>, line 25: unhandled exception 'out_of_bounds' ...
> stl::copy sv1 (sv2,10);
<stdin>, line 26: unhandled exception 'out_of_bounds' ...
> stl::copy sv1 (sv2,2,3); // sb (sv2,pos)
<stdin>, line 22: unhandled exception 'bad_argument' ...
> stl::copy sv1 (sv2,2);
<stdin>, line 23: unhandled exception 'range_overflow' ...
> stl::copy sv2 (sv2,2);
<stdin>, line 24: unhandled exception 'range_overlap' ...
> stl::copy (sv1,1,3) (sv2,0); members sv2; // ok
2
[1,2,"c","d","e"]
> stl::sort sv2 (>); // apples and oranges
<stdin>, line 31: unhandled exception 'failed_cond'
> listmap (\x->throw DOA) sv1; // callback function throws exception
<stdin>, line 34: unhandled exception 'DOA' ...
The stlvec module provides functions for creating, accessing and modifying stlvecs. In general, operations that have the same name as a corresponding function in the Pure standard library are in the global namespace. The remaining functions, which are usually specific to stlvecs, are in the stl namespace.
Please note that “stlvec to stlvec” functions are provided by the pure-stl algorithm modules. Thus, for example, the stlvec module does not provide a function that maps one stlvec onto a new stlvec. That functionality, and more, is provided by stl::transform, which can be found in the stlvec::modifying module.
To use the operations of this module, add the following import declaration to your program:
using stlvec;
When reading the function descriptions that follow, please bear in mind that whenever a function is passed an iterator tuple of the form (sv,first, last), first and last can be dropped, leaving (sv), or simply sv. The function will treat the “unary” iterator tuple (sv) as (sv, stl::svbeg, stl::svend).
emptystlvec
stlvec source /stlvec
mkstlvec x count
const_stlvec source
# sv
Note that # applied to an iterator tuple like (sv,b,e) will just return the number of elements in the tuple. Use stl::bounds if you need to know the number of elements in the range denoted by an iterator tuple.
sv ! i
Note that !k applied to an iterator tuple like (sv,b,e) will just return the kth element of the tuple. In addition, in stlvec, integers used to denote postions (as in !k) or in iterators, always, are relative to the beginning of the underlying vector. So it makes no sense to apply ! to an iterator tuple.
first sv
, last sv
members (sv, first, last)
replace msv i x
update msv i x
append sv x
insert (msv,p) xs
, insert (msv,p) (sv,first,last)
rmfirst msv
, rmlast msv
erase (msv,first,last)
, erase (msv,p)
, erase msv
sv1 == sv2
, sv1 ~= sv2
Note that ==
and ~==
are not defined for iterator tuples (the rules would never be executed because == is defined on tuples in the Prelude).
The stlvec module provides convenience functions that apply map, catmap, foldl, etc, to directly access Pure expressions stored in a stlvec.
map unary_fun (sv, first, last)
listmap unary_fun (sv, first, last)
catmap unary_fun (sv, first, last)
do unary_fun (sv, first, last)
foldl bin_fun x (sv, first, last)
foldl1 bin_fun (sv, first, last)
filter unary_pred (sv, first, last)
The following four functions map (or catmap) stlvecs onto row and col matrixes, primarily for use in matrix comprehensions.
rowmap unary_fun (sv, first, last)
, rowcatmap unary_fun (sv, first, last)
, colmap unary_fun (sv, first, last)
, colcatmap unary_fun (sv, first, last)
stl::empty sv
stl::vector (sv,first,last)
stl::allpairs bin_pred (sv1, first1, last1) (sv2, first2, last2)
stl::bounds (sv,first,last)
stl::reserve msv count
stl::capacity sv
See ut_stlvec.pure and ut_global_stlvec.pure in the pure-stlvec/ut directory.
The stlvec::nonmodifying module provides an interface to the STL’s non-modifying sequence operations.
To use the operations of this module, add the following import declaration to your program:
using stlvec::nonmodifying;
All of the functions are in the stl namespace.
stl::for_each (sv, first, last) unary_fun
stl::find (sv, first, last) x
stl::find_if (sv, first, last) unary_pred
stl::find_first_of (sv1, first1, last1) (sv2, first2, last2) bin_pred
stl::adjacent_find (sv, first, last) bin_pred
stl::count (sv, first, last) x
stl::count_if (sv, first, last) unary_pred
stl::mismatch (sv1, first1, last1) (sv2, first2) bin_pred
stl::equal (sv1, first1, last1) (sv2, first2) bin_pred
stl::search (sv1, first1, last1) (sv2, first2) bin_pred
stl::search_n (sv, first, last) count x bin_pred
stl::find_end (sv1, first1, last1) (sv2, first2, last2) bin_pred
See ut_nonmodifying.pure in the pure-stlvec/ut directory.
The stlvec::modifying module provides an interface to the STL’s modifying algorithms.
To use the operations of this module, add the following import declaration to your program:
using stlvec::modifying;
All of the functions are in the stl namespace.
stl::copy (sv, first1, last1) (msv, first2)
stl::copy_backward (sv,first1,last1) (msv,last2)
stl::swap_ranges (sv,first,last) (msv, p)
stl::transform (sv,first,last) (msv, p) unary_fun
stl::transform_2 (sv1,first1,last1) (sv2,first2) (msv, p) bin_fun
stl::replace_if (msv,first,last) unary_pred x
stl::replace_copy (sv,first,last) (msv,p) x y
replace
(msv,first,last) x y except that the modified sequence is placed in msv[p,p+last-first)
stl::replace_copy_if (sv,first,last) (msv,p) unary_pred x
replace_if
except that the modified sequence is placed in msv[p,p+last-first)
stl::fill (msv,first,last) x
stl::fill_n (msv,first) n x
stl::generate (msv,first,last) gen_fun
replace the elements in msv[first,last) with the sequence generated by successive calls to gen_fun (), e.g.,
> let count = ref 0;
> g _ = n when n = get count + 1; put count n; end;
> let sv = mkstlvec 0 10;
> stl::generate sv g $$ members sv;
[1,2,3,4,5,6,7,8,9,10]
stl::generate_n (msv,first) n gen_fun
stl::remove (msv,first,last) x
remove_if
(msv,first,last) (==x).
stl::remove_if (msv,first,last) unary_pred
stl::remove_copy (sv,first,last) (msv,first) x
remove
except that the purged sequence is copied to (msv,first) and sv[first,last) is not changed
stl::remove_copy_if (sv,first,last) (msv,first) unary_pred
remove_if
except that the purged sequence is copied to (msv,first) and sv[first,last) is not changed
stl::unique (msv,first,last) bin_pred
stl::unique_copy (sv,first,last) (msv,first) bin_pred
unique
except that the purged sequence is copied to (msv,first) and sv[first,last) is not changed
stl::reverse (msv,first,last)
stl::reverse_copy (sv,first,last) (msv,first)
reverse
except that the reversed sequence is copied to (msv,first) and sv[first,last) is not changed.
stl::rotate (msv,first,middle,last)
stl::rotate_copy (msv,first,middle,last) (msv,first)
stl::random_shuffle (msv,first,last) int::seed
stl::partition (msv,first,last) unary_pred
stl::stable_partition (msv,first,last) unary_pred
See ut_modifying.pure in the pure-stlvec/ut directory.
The stlvec::sort module provides an interface to the STL’s sorting and binary search algorithms.
To use the operations of this module, add the following import declaration to your program:
using stlvec::sort;
All of the functions are in the stl namespace.
All of the functions in this module require the caller to supply an ordering function, comp. The functions (<) and (>) are commonly passed as comp.
stl::sort (msv, first, last) comp
stl::stable_sort (msv, first, last) comp
stl::partial_sort (msv, first, middle, last) comp
stl::partial_sort_copy (sv, first1, last1) (msv, first2, last2) comp
partial_sort_copy
fills msv[first2, last2) with the first r elements of what sv[first1, last1) would be if it had been sorted. If r >= n, it fills msv[first2, first2+n) with the elements of sv[first1, last1) in sorted order. sv[first1,last1) is unchanged
stl::nth_element (msv, first, middle, last) comp
The next four functions assume that sv[first, last) is ordered by comp.
stl::lower_bound (sv, first, last) x comp
stl::upper_bound (sv, first, last) x comp
stl::equal_range (sv, first, last) x comp
stl::binary_search (sv, first, last) x comp
See ut_sort.pure in the pure-stlvec/ut directory.
The stlvec::merge module provides an interface to the STL’s merge algorithms. These algorithms operate on sorted ranges.
To use the operations of this module, add the following import declaration to your program:
using stlvec::merge;
All of the functions are in the stl namespace.
All of the functions in this module require the caller to supply an ordering function, comp (as for the Pure library sort function). They only work properly on input ranges that have been previously sorted using comp. The set operations generally do not check for range overflow because it is not generally possible to determine the length of the result of a set operation until after it is completed. In most cases you will get a nasty segmentation fault if the result is bigger than the target range. The best way to avoid this possibility it to use a back iterator to specifify the target range.
See parameter naming conventions at ..
stl::merge (sv1,first1,last1) (sv2,first2,last2) (msv,p) comp
stl::inplace_merge (msv,first, middle, last) comp
stl::includes (sv1,first1,last1) (sv2,first2,last2) comp
stl::set_union (sv1,first1,last1) (sv2,first2,last2) (msv,p) comp
stl::set_intersection (sv1,first1,last1) (sv2,first2,last2) (msv,p) comp
stl::set_difference (sv1,first1,last1) (sv2,first2,last2) (msv,p) comp
stl::set_symmetric_difference (sv1,first1,last1) (sv2,first2,last2) (msv,p) comp
See ut_merge.pure in the pure-stlvec/ut directory.
The stlvec::heap module provides an interface to the STL’s heap operations.
To use the operations of this module, add the following import declaration to your program:
using stlvec::heap;
All of the functions are in the stl namespace.
All of the functions in this module require the caller to supply an ordering function, comp (as for the Pure library sort function). The functions (<) and (>) are commonly passed as comp.
stl::make_heap (msv,first,last) comp
stl::push_heap (msv,first,last) comp
stl::pop_heap (msv,first,last) comp
stl::sort_heap (msv,first,last) comp
See ut_heap.pure in the pure-stlvec/ut directory.
The stlvec::minmax module provides an interface to a few additional STL algorithms.
To use the operations of this module, add the following import declaration to your program:
using stlvec::minmax;
All of the functions are in the stl namespace.
All of the functions in this module require the caller to supply an ordering function, comp (as for the Pure library sort function). The functions (<) and (>) are commonly passed as comp.
stl::min_element (sv,first,last) comp
stl::max_element (sv,first,last) comp
stl::lexicographical_compare (sv1,first1,last1) (sv2,first2,last2) comp
Algorithms are provided for stepping through all the permutations the elements of a stlvec. For these purposes, the first permutation has the elements of msv[first,last) sorted in ascending order and the last has the elements sorted in descending order.
stl::next_permutation (msv,first,last) comp
stl::prev_permutation (msv,first,last) comp
See ut_minmax.pure in the pure-stlvec/ut directory.
The stlvec::numeric module provides an interface to the STL’s numeric algorithms.
To use the operations of this module, add the following import declaration to your program:
using stlvec::numeric;
All of the functions are in the stl namespace.
stl::accumulate (sv,first,last) x bin_fun
stl::inner_product (sv1,first1,last1) (sv2,first2,last2) x bin_fun1 bin_fun2
stl::partial_sum (sv,first,last) (msv, p) bin_fun
stl::adjacent_difference (sv,first,last) (msv, p) bin_fun
See ut_numeric.pure in the pure-stlvec/ut directory.
The following function, also in the stl namespace, is available if you want to observe how pure-stlvec maintains reference counts for items in its containers.
stl::refc x
This section documents changes in pure-stlvec that might have introduced backward compatiblity issues.
Bug fixes.
Version 0.3 reflects some changes made to make pure-stlvec consistent with its sister package, pure-stlmap.
The update
function was deprecated. Please use replace
instead.
The replace
function was added to the stlvec module. This function is the same as update
except that “replace
sv i x” returns x instead of sv.
The stl::replace
function was removed from the stlvec/modifying module. You can use “stl::replace_if
(sv,first,last) (x==) y” instead of “stl::replace
(sv,first,last) x y” to replace all instances of x in the specified range.
The function null
was removed and stl::empty
was added to replace it.
The function list
was removed. You can use members
instead.
The function stl::random_shuffle
was changed to take a seed as a second parameter.
All of the tracing functions were removed.
Fixed (>) predicate operating on plain old data when passed to STL algorithms.