Some generic additions to the C++ Standard Template Library
by
Thomas Becker
thomas@styleadvisor.com
COPYRIGHT (C) 2000 Thomas BeckerPERMISSION NOTICE:
PERMISSION TO USE, COPY, MODIFY, AND DISTRIBUTE THIS SOFTWARE FOR ANY PURPOSE AND WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT ALL COPIES ARE ACCOMPANIED BY THE COMPLETE MACHINE-READABLE SOURCE CODE, ALL MODIFIED FILES CARRY PROMINENT NOTICES AS TO WHEN AND BY WHOM THEY WERE MODIFIED, THE ABOVE COPYRIGHT NOTICE, THIS PERMISSION NOTICE AND THE NO-WARRANTY NOTICE BELOW APPEAR IN ALL SOURCE FILES AND IN ALL SUPPORTING DOCUMENTATION.
NO-WARRANTY NOTICE:
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.
// #define _EXCLUDE_CONST_MEM_FUN_ADAPTERSin StdSuppl.h.
The const member function adapters are completely analogous to the regular member function adapters. The actual adapters are:
const_mem_fun_t const_mem_fun1_t const_mem_fun_ref_t const_mem_fun1_ref_tThe corresponding generating non-member functions are simply oveloads of the existing ones:
mem_fun mem_fun1 mem_fun_ref mem_fun1_ref
void_mem_fun_t void_mem_fun1_t void_mem_fun_ref_t void_mem_fun1_ref_t void_const_mem_fun_t void_const_mem_fun1_t void_const_mem_fun_ref_t void_const_mem_fun1_ref_tThe corresponding generating non-member functions are not oveloads of the existing ones. That is because it would require for the compiler to handle partial template specialization, which many compilers don't. Instead, the generating non-member functions are:
void_mem_fun void_mem_fun1 void_mem_fun_ref void_mem_fun1_ref
unary_and binary_and unary_or binary_orfill this gap. They come with corresponding generating non-member functions
and1 and2 or1 or2Usage of these adapters and generating functions is completely analogous to STL's unary_negation, binary_negation, not1, and not2. The only difference is that you must supply two predicates instead of one, and the signatures of the two predicates must match.
unary_compose binary_compose void_unary_compose void_binary_composeprovide functionals that represent the composition of two given functionals. The corresponding generating non-member functions are:
compose1 compose2 void_compose1 void_compose2Each of these take two functionals f and g as arguments and generate functionals that act as f(g()). In each case, the result type of g must allow a conversion to the type of the sole argument of f.
compose1 and void_compose1 require the inner functional g to take exactly one argument. compose2 and void_compose2 require g to take exactly two arguments. The prefix void_ indicates that the outer functional f must return void.
Some implementations of the STL already contain the non-void versions of composition. If this is the case, you should uncomment the line
// #define _EXCLUDE_NON_VOID_COMPOSITION_ADAPTERSin the header file StdSuppl.h.
templateandinline RanIt lower_bound_find(RanIt first, RanIt last, const T& val);
templateact like STL's find algorithm, and they guarantee logarithmic complexity. There are two prerequisites for their usage:inline RanIt lower_bound_find(RanIt first, RanIt last, const T& val, Pred pred);