1 #ifndef _theplu_yat_utility_stl_utility_
2 #define _theplu_yat_utility_stl_utility_
37 #include "concept_check.h"
38 #include "DataWeight.h"
39 #include "Exception.h"
41 #include <boost/concept_check.hpp>
42 #include <boost/iterator/transform_iterator.hpp>
43 #include <boost/mpl/if.hpp>
44 #include <boost/type_traits/add_const.hpp>
45 #include <boost/type_traits/is_const.hpp>
46 #include <boost/type_traits/remove_reference.hpp>
63 #ifndef YAT_STD_DISABLE
71 template <
class T1,
class T2>
72 std::ostream& operator<<(std::ostream& out, const std::pair<T1,T2>& p)
73 { out << p.first <<
"\t" << p.second;
return out; }
86 struct abs : std::unary_function<T, T>
92 {
return std::abs(x); }
121 template<
typename Po
inter>
123 public std::unary_function<Pointer,
124 typename std::iterator_traits<Pointer>::reference>
135 typename std::iterator_traits<Pointer>::reference
163 template<
class F,
class G,
class H>
165 public std::binary_function<typename G::argument_type,
166 typename H::argument_type,
167 typename F::result_type>
181 : f_(f), g_(g), h_(h)
188 typename F::result_type
operator()(
typename G::argument_type x,
189 typename H::argument_type y)
const
191 return f_(g_(x), h_(y));
207 template<
class F,
class G,
class H>
235 template<
class F,
class G>
237 public std::binary_function<typename G::first_argument_type,
238 typename G::second_argument_type,
239 typename F::result_type>
260 typename F::result_type
262 typename G::second_argument_type y)
const
281 template<
class F,
class G>
311 template<
class F,
class G>
312 class compose_f_gx :
public std::unary_function<typename G::argument_type,
313 typename F::result_type>
334 typename F::result_type
354 template<
class F,
class G>
387 template<
class F,
class G,
class H>
389 typename F::result_type>
403 : f_(f), g_(g), h_(h)
410 typename F::result_type
operator()(
typename G::argument_type x)
const
412 return f_(g_(x), h_(x));
430 template<
class F,
class G,
class H>
445 struct Exp : std::unary_function<T, T>
451 {
return std::exp(x); }
476 template <
typename Key,
typename Tp,
typename Compare,
typename Alloc>
477 const Tp&
get(
const std::map<Key, Tp, Compare, Alloc>& m,
const Key& k);
492 template<
typename InputIterator,
typename Key,
typename Comp>
493 void inverse(InputIterator first, InputIterator last,
494 std::map<Key, std::vector<size_t>, Comp >& m)
496 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
497 BOOST_CONCEPT_ASSERT((boost::Convertible<
typename std::iterator_traits<InputIterator>::value_type, Key>));
499 for (
size_t i=0; first!=last; ++i, ++first)
500 m[*first].push_back(i);
511 template<
typename Key,
typename InputIterator,
typename Comp>
512 void inverse(InputIterator first, InputIterator last,
513 std::multimap<Key, size_t, Comp>& m)
515 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
516 BOOST_CONCEPT_ASSERT((boost::Convertible<
typename std::iterator_traits<InputIterator>::value_type, Key>));
518 for (
size_t i=0; first!=last; ++i, ++first)
519 m.insert(std::make_pair(*first, i));
534 template<
typename InputIterator,
typename Key,
typename Comp>
535 void inverse(InputIterator first, InputIterator last,
536 std::map<Key, size_t, Comp >& m)
538 BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
539 BOOST_CONCEPT_ASSERT((boost::Convertible<
typename std::iterator_traits<InputIterator>::value_type, Key>));
541 for (
size_t i=0; first!=last; ++i, ++first)
589 : std::binary_function<DataWeight, DataWeight, bool>
610 class Log : std::unary_function<T, T>
622 explicit Log(
double base) : log_base_(std::log(base)) {}
628 {
return std::log(x)/log_base_; }
637 template <
typename T>
638 T
max(
const T& a,
const T& b,
const T& c)
647 template <
typename T>
648 T
max(
const T& a,
const T& b,
const T& c,
const T& d)
657 template <
typename T>
658 T
max(
const T& a,
const T& b,
const T& c,
const T& d,
const T& e)
667 template <
typename T>
668 T
max(
const T& a,
const T& b,
const T& c,
const T& d,
const T& e,
const T& f)
681 template <
class T1,
class T2>
689 const std::pair<T1,T2>& y) {
690 return ((x.second<y.second) ||
691 (!(y.second<x.second) && (x.first<y.first)));
702 template <
class Pair>
710 typedef typename boost::mpl::if_<
711 typename boost::is_const<Pair>::type,
712 typename boost::add_const<typename Pair::first_type>::type&,
736 template <
class Pair>
744 typedef typename boost::mpl::if_<
745 typename boost::is_const<Pair>::type,
746 typename boost::add_const<typename Pair::second_type>::type&,
781 boost::transform_iterator<
782 PairFirst<
typename boost::remove_reference<
783 typename std::iterator_traits<Iter>::reference
789 typedef typename std::iterator_traits<Iter>::reference ref_type;
790 typedef typename boost::remove_reference<ref_type>::type val_type;
792 return boost::transform_iterator<PF, Iter>(i, PF());
812 boost::transform_iterator<
813 PairSecond<
typename boost::remove_reference<
814 typename std::iterator_traits<Iter>::reference
820 typedef typename std::iterator_traits<Iter>::reference ref_type;
821 typedef typename boost::remove_reference<ref_type>::type val_type;
823 return boost::transform_iterator<PS, Iter>(i, PS());
855 template<
typename Po
inter,
class Compare>
856 compose_f_gx_hy<Compare, Dereferencer<Pointer>, Dereferencer<Pointer> >
869 template<
typename Po
inter>
870 compose_f_gx_hy<std::less<typename std::iterator_traits<Pointer>::value_type>,
871 Dereferencer<Pointer>, Dereferencer<Pointer> >
874 typedef typename std::iterator_traits<Pointer>::value_type value_type;
875 BOOST_CONCEPT_ASSERT((boost::LessThanComparable<value_type>));
876 std::less<value_type> compare;
884 std::string&
to_lower(std::string& s);
889 std::string&
to_upper(std::string& s);
894 template <
typename Key,
typename Tp,
typename Compare,
typename Alloc>
895 const Tp&
get(
const std::map<Key, Tp, Compare, Alloc>& m,
const Key& key)
897 typename std::map<Key, Tp, Compare,Alloc>::const_iterator iter(m.find(key));
899 std::stringstream ss;
900 ss <<
"utility::get(const Map&, const Key&): '"
901 << key <<
"' not found in map\n";
Functor that behaves like std::less with the exception that it treates NaN as a number larger than in...
Definition: stl_utility.h:566
Functor that return std::pair.second.
Definition: stl_utility.h:737
void inverse(InputIterator first, InputIterator last, std::map< Key, std::vector< size_t >, Comp > &m)
Definition: stl_utility.h:493
Concept check for Trivial Iterator
Definition: concept_check.h:175
compose_f_gx_hx< F, G, H > make_compose_f_gx_hx(F f, G g, H h)
Definition: stl_utility.h:431
F::result_type operator()(typename G::first_argument_type x, typename G::second_argument_type y) const
Does the work.
Definition: stl_utility.h:261
bool operator()(const std::pair< T1, T2 > &x, const std::pair< T1, T2 > &y)
Definition: stl_utility.h:688
F::result_type operator()(typename G::argument_type x, typename H::argument_type y) const
Does the work.
Definition: stl_utility.h:188
boost::transform_iterator< PairSecond< typename boost::remove_reference< typename std::iterator_traits< Iter >::reference >::type >, Iter > pair_second_iterator(Iter i)
Definition: stl_utility.h:816
compose_f_gxy(F f, G g)
Constructor.
Definition: stl_utility.h:252
Definition: stl_utility.h:312
Definition: stl_utility.h:388
Pair & argument_type
Definition: stl_utility.h:752
boost::mpl::if_< typename boost::is_const< Pair >::type, typename boost::add_const< typename Pair::second_type >::type &, typename Pair::second_type & >::type result_type
Definition: stl_utility.h:747
compose_f_gx_hx(F f, G g, H h)
Constructor.
Definition: stl_utility.h:402
Functor that return std::pair.first.
Definition: stl_utility.h:703
compose_f_gx_hy(F f, G g, H h)
Constructor.
Definition: stl_utility.h:180
T operator()(T x) const
Definition: stl_utility.h:450
compose_f_gx_hx(void)
default constructor
Definition: stl_utility.h:397
std::string & to_lower(std::string &s)
Function converting a string to lower case.
Holds a pair of data and associated weight.
Definition: DataWeight.h:39
compose_f_gx(F f, G g)
Constructor.
Definition: stl_utility.h:326
F::result_type operator()(typename G::argument_type x) const
Does the work.
Definition: stl_utility.h:410
T max(const T &a, const T &b, const T &c)
Definition: stl_utility.h:638
Definition: stl_utility.h:236
Class used for all runtime error detected within yat library.
Definition: Exception.h:38
boost::mpl::if_< typename boost::is_const< Pair >::type, typename boost::add_const< typename Pair::first_type >::type &, typename Pair::first_type & >::type result_type
Definition: stl_utility.h:713
compose_f_gx_hy< F, G, H > make_compose_f_gx_hy(F f, G g, H h)
Definition: stl_utility.h:208
boost::transform_iterator< PairFirst< typename boost::remove_reference< typename std::iterator_traits< Iter >::reference >::type >, Iter > pair_first_iterator(Iter i)
Definition: stl_utility.h:785
Adaptor between pointer and pointee interface.
Definition: stl_utility.h:122
T operator()(T arg) const
Definition: stl_utility.h:463
result_type operator()(argument_type p) const
Definition: stl_utility.h:723
compose_f_gxy< F, G > make_compose_f_gxy(F f, G g)
Definition: stl_utility.h:282
Definition: stl_utility.h:610
Dereferencer(void)
constructor
Definition: stl_utility.h:129
std::string & to_upper(std::string &s)
Function converting a string to upper case.
Definition: stl_utility.h:86
compose_f_gx(void)
default constructor
Definition: stl_utility.h:321
Identity functor that returns its argument.
Definition: stl_utility.h:460
F::result_type operator()(typename G::argument_type x) const
Does the work.
Definition: stl_utility.h:335
compose_f_gxy(void)
default constructor
Definition: stl_utility.h:247
Functor comparing pairs using second.
Definition: stl_utility.h:682
T operator()(T x) const
Definition: stl_utility.h:91
compose_f_gx< F, G > make_compose_f_gx(F f, G g)
Definition: stl_utility.h:355
Definition: stl_utility.h:445
compose_f_gx_hy(void)
default constructor
Definition: stl_utility.h:175
bool operator()(const DataWeight &x, const DataWeight &y) const
Definition: stl_utility.h:594
T operator()(T x) const
Definition: stl_utility.h:627
bool operator()(T x, T y) const
Definition: stl_utility.h:573
Log(double base)
Definition: stl_utility.h:622
Definition: stl_utility.h:164
Log(void)
Definition: stl_utility.h:616
result_type operator()(argument_type p) const
Definition: stl_utility.h:757
Pair & argument_type
Definition: stl_utility.h:718
std::iterator_traits< Pointer >::reference operator()(Pointer ti) const
Definition: stl_utility.h:136
compose_f_gx_hy< Compare, Dereferencer< Pointer >, Dereferencer< Pointer > > make_ptr_compare(Pointer p, Compare compare)
Definition: stl_utility.h:857